Skip to content

Commit

Permalink
Blackened.
Browse files Browse the repository at this point in the history
  • Loading branch information
emeryberger committed Dec 8, 2022
1 parent a20708e commit be88daf
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
20 changes: 10 additions & 10 deletions scalene/scalene_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@
from scalene.scalene_leak_analysis import ScaleneLeakAnalysis
from scalene.scalene_statistics import Filename, LineNumber, ScaleneStatistics

if sys.platform != 'win32':
if sys.platform != "win32":
from crdp import rdp

class ScaleneJSON:

class ScaleneJSON:
@staticmethod
def memory_consumed_str(size_in_mb: float) -> str:
"""Return a string corresponding to amount of memory consumed."""
gigabytes = size_in_mb // 1024
terabytes = gigabytes // 1024
if terabytes > 0:
return(f"{(size_in_mb / 1048576):3.3f} TB")
return f"{(size_in_mb / 1048576):3.3f} TB"
elif gigabytes > 0:
return(f"{(size_in_mb / 1024):3.3f} GB")
return f"{(size_in_mb / 1024):3.3f} GB"
else:
return(f"{size_in_mb:3.3f} MB")
return f"{size_in_mb:3.3f} MB"

@staticmethod
def time_consumed_str(time_in_ms: float) -> str:
Expand All @@ -40,14 +40,14 @@ def time_consumed_str(time_in_ms: float) -> str:
minutes_exact = (time_in_ms % 3600000) / 60000
seconds_exact = (time_in_ms % 60000) / 1000
if hours > 0:
return(f"{hours_exact:.0f}h:{minutes_exact:.0f}m:{seconds_exact:3.3f}s")
return f"{hours_exact:.0f}h:{minutes_exact:.0f}m:{seconds_exact:3.3f}s"
elif minutes > 0:
return(f"{minutes_exact:.0f}m:{seconds_exact:3.3f}s")
return f"{minutes_exact:.0f}m:{seconds_exact:3.3f}s"
elif seconds > 0:
return(f"{seconds_exact:3.3f}s")
return f"{seconds_exact:3.3f}s"
else:
return(f"{time_in_ms:3.3f}ms")
return f"{time_in_ms:3.3f}ms"

# Default threshold for percent of CPU time to report a file.
cpu_percent_threshold = 1

Expand Down
2 changes: 1 addition & 1 deletion scalene/scalene_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ def output_profiles(
f" (max: {ScaleneJSON.memory_consumed_str(stats.max_footprint)}, growth rate: {growth_rate:3.0f}%)\n"
),
)

null = tempfile.TemporaryFile(mode="w+")

console = Console(
Expand Down
2 changes: 2 additions & 0 deletions scalene/scalene_profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,7 @@ def malloc_signal_handler(
# This should never happen, but we fail gracefully.
return
from scalene import pywhere

if this_frame:
Scalene.enter_function_meta(this_frame, Scalene.__stats)
# Walk the stack till we find a line of code in a file we are tracing.
Expand Down Expand Up @@ -1763,6 +1764,7 @@ def profile_code(
"""Initiate execution and profiling."""
if Scalene.__args.memory:
from scalene import pywhere

pywhere.populate_struct()
# If --off is set, tell all children to not profile and stop profiling before we even start.
if "off" not in Scalene.__args or not Scalene.__args.off:
Expand Down

0 comments on commit be88daf

Please sign in to comment.