From eb071af14011d3069136613db61bf6ec7d8c5bd2 Mon Sep 17 00:00:00 2001 From: NanoNabla <43477372+NanoNabla@users.noreply.github.com> Date: Mon, 7 Jul 2025 13:56:58 +0200 Subject: [PATCH 1/5] Adds support for --help option. Fixes #165 --- scorep/__main__.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/scorep/__main__.py b/scorep/__main__.py index 01c0821..15927e1 100644 --- a/scorep/__main__.py +++ b/scorep/__main__.py @@ -3,6 +3,7 @@ import scorep.instrumenter import scorep.subsystem +import scorep.helper from scorep.helper import print_err @@ -11,6 +12,38 @@ def _err_exit(msg): sys.exit(1) +def print_help(): + print(""" +Usage: python -m scorep [options] [--] your_program.py [args] + +Score-P Python instrumentation wrapper. The following options control how the program is instrumented and executed: + + --help Show this help message and exit. + --mpi Enable MPI instrumentation (equivalent to --mpp=mpi). + --keep-files Keep temporary files after execution. + --verbose, -v Enable verbose output for debugging and tracing. + --nopython Disable instrumentation of Python code. + Instrumentation can still be enabled later from within the application's source code. + --noinstrumenter Same as --nopython. + --instrumenter-type= Specify custom instrumenter type (e.g., cProfile). + --instrumenter-file= Path to a Python script that is executed before the application. + Allows instrumentation of specific modules and functions without modifying their source code. + -- Stop parsing Score-P options; pass following args to your script. + +Other options starting with '-' are passed directly to 'scorep-config'. +To view all available Score-P configuration options, run: scorep-config --help + +Example: + scorep --mpi --thread=pthread -- your_script.py --arg1 --arg2 + +Note: + If using --noinstrumenter, Score-P will not trace Python code, but it may still collect MPI or threading events + if configured. + You can enable Python instrumentation manually from within your application's source code, + e.g., by calling 'scorep.instrumenter.enable()'. +""") + + def scorep_main(argv=None): if argv is None: argv = sys.argv @@ -19,9 +52,11 @@ def scorep_main(argv=None): prog_argv = [] parse_scorep_commands = True + show_help = False keep_files = False verbose = False no_instrumenter = False + if scorep.instrumenter.has_c_instrumenter(): instrumenter_type = "cProfile" else: @@ -32,6 +67,9 @@ def scorep_main(argv=None): if parse_scorep_commands: if elem == "--": parse_scorep_commands = False + if elem == "--help": + show_help = True + break elif elem == "--mpi": scorep_config.append("--mpp=mpi") elif elem == "--keep-files": @@ -64,6 +102,10 @@ def scorep_main(argv=None): else: prog_argv.append(elem) + # fast exit on "--help" + if show_help: + print_help() + sys.exit(0) if len(prog_argv) == 0: _err_exit("Did not find a script to run") From 3784d04a9fde2cf118afefc5601e48ab9ba91c23 Mon Sep 17 00:00:00 2001 From: NanoNabla <43477372+NanoNabla@users.noreply.github.com> Date: Fri, 1 Aug 2025 12:19:42 +0200 Subject: [PATCH 2/5] Adds test for --help --- test/test_scorep.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/test_scorep.py b/test/test_scorep.py index 228c8de..ae703d9 100755 --- a/test/test_scorep.py +++ b/test/test_scorep.py @@ -463,3 +463,10 @@ def test_force_finalize(scorep_env, instrumenter): trace = OTF2_Trace(trace_path) assert OTF2_Region("__main__:foo") in trace assert OTF2_Region("__main__:bar") not in trace + + +def test_help(): + std_out, std_err = utils.call_with_scorep("", ["--help"]) + + assert "Usage: python -m scorep" in std_out + assert "--help" in std_out From 3eca6b89d7fb1f2faf8904d7077def4ff78cd545 Mon Sep 17 00:00:00 2001 From: Sebastian <43477372+NanoNabla@users.noreply.github.com> Date: Mon, 4 Aug 2025 20:00:51 +0200 Subject: [PATCH 3/5] Apply suggestions from code review Co-authored-by: Bert Wesarg --- scorep/__main__.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/scorep/__main__.py b/scorep/__main__.py index 15927e1..242d955 100644 --- a/scorep/__main__.py +++ b/scorep/__main__.py @@ -16,7 +16,7 @@ def print_help(): print(""" Usage: python -m scorep [options] [--] your_program.py [args] -Score-P Python instrumentation wrapper. The following options control how the program is instrumented and executed: +Score-P Python instrumentation wrapper. The following options control how the program is instrumented and executed. Any unknown option are passed directly to 'scorep-config'. --help Show this help message and exit. --mpi Enable MPI instrumentation (equivalent to --mpp=mpi). @@ -25,8 +25,10 @@ def print_help(): --nopython Disable instrumentation of Python code. Instrumentation can still be enabled later from within the application's source code. --noinstrumenter Same as --nopython. - --instrumenter-type= Specify custom instrumenter type (e.g., cProfile). - --instrumenter-file= Path to a Python script that is executed before the application. + --instrumenter-type= + Specify custom instrumenter type (e.g., cProfile). + --instrumenter-file= + Path to a Python script that is executed before the application. Allows instrumentation of specific modules and functions without modifying their source code. -- Stop parsing Score-P options; pass following args to your script. @@ -34,7 +36,7 @@ def print_help(): To view all available Score-P configuration options, run: scorep-config --help Example: - scorep --mpi --thread=pthread -- your_script.py --arg1 --arg2 + scorep --mpi --thread=pthread -- ./your_script.py --arg1 --arg2 Note: If using --noinstrumenter, Score-P will not trace Python code, but it may still collect MPI or threading events From c535b3ae457d56267d01afc3dcfa7d3d175b331a Mon Sep 17 00:00:00 2001 From: Sebastian <43477372+NanoNabla@users.noreply.github.com> Date: Mon, 4 Aug 2025 20:01:08 +0200 Subject: [PATCH 4/5] Update scorep/__main__.py Co-authored-by: Bert Wesarg --- scorep/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scorep/__main__.py b/scorep/__main__.py index 242d955..0d73d02 100644 --- a/scorep/__main__.py +++ b/scorep/__main__.py @@ -14,7 +14,7 @@ def _err_exit(msg): def print_help(): print(""" -Usage: python -m scorep [options] [--] your_program.py [args] +Usage: python -m scorep [options] [--]