Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:

- name: select Xcode version
# MacOS > 14.2 requires Xcode >= 15.3; otherwise loading native extension modules fails with e.g.:
# dlopen(/opt/homebrew/lib/python3.11/site-packages/slipcover/probe.abi3.so, 0x0002): bad bind opcode 0x00
# dlopen(/opt/homebrew/lib/python3.11/site-packages/slipcover/probe.abi3.so, 0x0002): bad bind opcode 0x00
if: startsWith(matrix.os, 'macos-')
run: |
if [ -d /Applications/Xcode_15.3.app/Contents/Developer ]; then sudo xcode-select --switch /Applications/Xcode_15.3.app/Contents/Developer; fi
Expand Down
4 changes: 2 additions & 2 deletions scalene/scalene_config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Current version of Scalene; reported by --version."""

scalene_version = "1.5.54"
scalene_date = "2025.08.25"
scalene_version = "1.5.55"
scalene_date = "2025.09.23"

# Port to use for Scalene UI
SCALENE_PORT = 11235
Expand Down
13 changes: 10 additions & 3 deletions scalene/scalene_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,11 +685,18 @@ def output_profiles(
)
console.print(md)
if not self.output_file:
self.output_file = "/dev/stdout"
console.save_html(self.output_file, clear=False)
console.save_html(path="/dev/stdout", clear=False)
else:
console.save_html(
path=str(Path(self.output_file).with_suffix(".html")), clear=False
)
elif self.output_file:
# Don't output styles to text file.
console.save_text(self.output_file, styles=False, clear=False)
console.save_text(
str(Path(self.output_file).with_suffix(".txt")),
styles=False,
clear=False,
)
else:
# No output file specified: write to stdout.
sys.stdout.write(console.export_text(styles=True))
Expand Down
31 changes: 16 additions & 15 deletions scalene/scalene_profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,7 @@ def cpu_signal_handler(
@staticmethod
def output_profile(program_args: list[str] | None = None) -> bool:
"""Output the profile. Returns true iff there was any info reported the profile."""
did_output: bool = False
if Scalene.__args.json:
json_output = Scalene.__json.output_profiles(
Scalene.__program_being_profiled,
Expand All @@ -725,23 +726,18 @@ def output_profile(program_args: list[str] | None = None) -> bool:
return True
outfile = Scalene.__output.output_file
if Scalene.__args.outfile:
outfile = os.path.join(
os.path.dirname(Scalene.__args.outfile),
os.path.splitext(os.path.basename(Scalene.__args.outfile))[0]
+ ".json",
)
outfile = str(pathlib.Path(Scalene.__args.outfile).with_suffix(".json"))
# If there was no output file specified, print to the console.
if not outfile:
if sys.platform == "win32":
outfile = "CON"
else:
outfile = "/dev/stdout"
outfile = "CON" if sys.platform == "win32" else "/dev/stdout"
# Write the JSON to the output file (or console).
with open(outfile, "w") as f:
f.write(json.dumps(json_output, sort_keys=True, indent=4) + "\n")
return json_output != {}
did_output = json_output != {}

else:
condition_1 = Scalene.__args.cli and Scalene.__args.outfile
condition_2 = Scalene.__args.cli and not Scalene.__args.json
if condition_1 or condition_2:
output = Scalene.__output
column_width = Scalene.__args.column_width
if not Scalene.__args.html:
Expand All @@ -753,8 +749,11 @@ def output_profile(program_args: list[str] | None = None) -> bool:
else:
import shutil

column_width = shutil.get_terminal_size().columns
did_output: bool = output.output_profiles(
# Fallback to the specified `column_width` if the terminal width cannot be obtained.
column_width = shutil.get_terminal_size(
fallback=(column_width, column_width)
).columns
did_output = output.output_profiles(
column_width,
Scalene.__stats,
Scalene.__pid,
Expand All @@ -765,7 +764,7 @@ def output_profile(program_args: list[str] | None = None) -> bool:
profile_memory=Scalene.__args.memory,
reduced_profile=Scalene.__args.reduced_profile,
)
return did_output
return did_output

@staticmethod
def _set_in_jupyter() -> None:
Expand Down Expand Up @@ -1392,7 +1391,9 @@ def profile_code(
output_fname=(
Scalene.__profiler_html
if not Scalene.__args.outfile
else Scalene.__args.outfile
else Filename(
str(pathlib.Path(Scalene.__args.outfile).with_suffix(".html"))
)
),
)
if Scalene._in_jupyter():
Expand Down