Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Added invocation arguments to json #667

Merged
merged 2 commits into from
Aug 24, 2023
Merged
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
5 changes: 4 additions & 1 deletion scalene/scalene_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from collections import OrderedDict, defaultdict
from operator import itemgetter
from pathlib import Path
from typing import Any, Callable, Dict, List
from typing import Any, Callable, Dict, List, Optional

from scalene.scalene_leak_analysis import ScaleneLeakAnalysis
from scalene.scalene_statistics import Filename, LineNumber, ScaleneStatistics
Expand Down Expand Up @@ -237,6 +237,7 @@ def output_profiles(
profile_this_code: Callable[[Filename, LineNumber], bool],
python_alias_dir: Path,
program_path: Path,
program_args: Optional[List[str]],
profile_memory: bool = True,
reduced_profile: bool = False,
) -> Dict[str, Any]:
Expand Down Expand Up @@ -294,6 +295,8 @@ def output_profiles(

output: Dict[str, Any] = {
"program": program,
"args": program_args,
"filename": program_path,
"alloc_samples": stats.alloc_samples,
"elapsed_time_sec": stats.elapsed_time,
"growth_rate": growth_rate,
Expand Down
1 change: 1 addition & 0 deletions scalene/scalene_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ def output_profiles(
profile_this_code: Callable[[Filename, LineNumber], bool],
python_alias_dir: Path,
program_path: Path,
left: List[str],
profile_memory: bool = True,
reduced_profile: bool = False,
) -> bool:
Expand Down
10 changes: 6 additions & 4 deletions scalene/scalene_profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ def flamegraph_format() -> str:
return output

@staticmethod
def output_profile() -> bool:
def output_profile(program_args: Optional[List[str]] = None) -> bool:
# sourcery skip: inline-immediately-returned-variable
# print(Scalene.flamegraph_format())
"""Output the profile. Returns true iff there was any info reported the profile."""
Expand All @@ -948,6 +948,7 @@ def output_profile() -> bool:
Scalene.profile_this_code,
Scalene.__python_alias_dir,
Scalene.__program_path,
program_args,
profile_memory=Scalene.__args.memory,
reduced_profile=Scalene.__args.reduced_profile,
)
Expand Down Expand Up @@ -1786,7 +1787,7 @@ def stop_signal_handler(
Scalene.stop()
# Output the profile if `--outfile` was set to a file.
if Scalene.__output.output_file:
Scalene.output_profile()
Scalene.output_profile(sys.argv)

@staticmethod
def disable_signals(retry: bool = True) -> None:
Expand Down Expand Up @@ -1863,6 +1864,7 @@ def profile_code(
code: str,
the_globals: Dict[str, str],
the_locals: Dict[str, str],
left: List[str],
) -> int:
"""Initiate execution and profiling."""
if Scalene.__args.memory:
Expand Down Expand Up @@ -1900,7 +1902,7 @@ def profile_code(
last_line
] += stats.memory_current_highwater_mark[last_file][last_line]
# If we've collected any samples, dump them.
did_output = Scalene.output_profile()
did_output = Scalene.output_profile(left)
if not did_output:
print(
"Scalene: Program did not run for long enough to profile."
Expand Down Expand Up @@ -2115,7 +2117,7 @@ def run_profiler(
try:
# We exit with this status (returning error code as appropriate).
exit_status = profiler.profile_code(
code, the_locals, the_globals
code, the_locals, the_globals, left
)
if not is_jupyter:
sys.exit(exit_status)
Expand Down