Skip to content

Commit ca9bc39

Browse files
authored
Adds support for --help option (#170)
Fixes #165
2 parents e148671 + 97b2f7f commit ca9bc39

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

scorep/__main__.py

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,48 @@
33

44
import scorep.instrumenter
55
import scorep.subsystem
6-
from scorep.helper import print_err
6+
import scorep.helper
7+
from scorep.helper import get_scorep_version, print_err
78

89

910
def _err_exit(msg):
1011
print_err("scorep: " + msg)
1112
sys.exit(1)
1213

1314

15+
def print_help():
16+
print("""\
17+
Usage: python -m scorep [options] [--] <script> [args]
18+
19+
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'.
20+
21+
--help Show this help message and exit.
22+
--keep-files Keep temporary files after execution.
23+
--verbose, -v Enable verbose output for debugging and tracing.
24+
--nopython Disable instrumentation of Python code.
25+
Instrumentation can still be enabled later from within the application's source code.
26+
--noinstrumenter Same as --nopython.
27+
--instrumenter-type=<type>
28+
Specify custom instrumenter type (e.g., cProfile).
29+
--instrumenter-file=<file>
30+
Path to a Python script that is executed before the application.
31+
Allows instrumentation of specific modules and functions without modifying their source code.
32+
-- Stop parsing Score-P options; interpret all following arguments verbatim as the program with its arguments.
33+
34+
Other options starting with '-' are passed directly to 'scorep-config'.
35+
To view all available Score-P configuration options, run: scorep-config --help
36+
37+
Example:
38+
scorep --mpi --thread=pthread -- ./your_script.py --arg1 --arg2
39+
40+
Note:
41+
If using --noinstrumenter, Score-P will not trace Python code, but it may still collect MPI or threading events
42+
if configured.
43+
You can enable Python instrumentation manually from within your application's source code,
44+
e.g., by calling 'scorep.instrumenter.enable()'.
45+
""") # noqa: E501
46+
47+
1448
def scorep_main(argv=None):
1549
if argv is None:
1650
argv = sys.argv
@@ -19,9 +53,11 @@ def scorep_main(argv=None):
1953
prog_argv = []
2054
parse_scorep_commands = True
2155

56+
show_help = False
2257
keep_files = False
2358
verbose = False
2459
no_instrumenter = False
60+
2561
if scorep.instrumenter.has_c_instrumenter():
2662
instrumenter_type = "cProfile"
2763
else:
@@ -32,7 +68,12 @@ def scorep_main(argv=None):
3268
if parse_scorep_commands:
3369
if elem == "--":
3470
parse_scorep_commands = False
71+
if elem == "--help":
72+
show_help = True
73+
break
3574
elif elem == "--mpi":
75+
print_err(f"scorep: Warning: The option '{elem}' is deprecated "
76+
"and will be removed in future.")
3677
scorep_config.append("--mpp=mpi")
3778
elif elem == "--keep-files":
3879
keep_files = True
@@ -42,7 +83,7 @@ def scorep_main(argv=None):
4283
no_instrumenter = True
4384
elif elem == "--noinstrumenter":
4485
no_instrumenter = True
45-
elif elem in ["--io=runtime:posix", "--io=posix"]:
86+
elif elem in ["--io=runtime:posix", "--io=posix"] and get_scorep_version() >= 9.0:
4687
print_err(f"scorep: Warning: The option '{elem}' is deprecated.")
4788
if "SCOREP_IO_POSIX" in os.environ:
4889
print_err(" Will not overwrite existing value for environment variable "
@@ -64,6 +105,10 @@ def scorep_main(argv=None):
64105
else:
65106
prog_argv.append(elem)
66107

108+
# fast exit on "--help"
109+
if show_help:
110+
print_help()
111+
sys.exit(0)
67112
if len(prog_argv) == 0:
68113
_err_exit("Did not find a script to run")
69114

test/test_scorep.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,3 +463,10 @@ def test_force_finalize(scorep_env, instrumenter):
463463
trace = OTF2_Trace(trace_path)
464464
assert OTF2_Region("__main__:foo") in trace
465465
assert OTF2_Region("__main__:bar") not in trace
466+
467+
468+
def test_help():
469+
std_out, std_err = utils.call_with_scorep("", ["--help"])
470+
471+
assert "Usage: python -m scorep" in std_out
472+
assert "--help" in std_out

0 commit comments

Comments
 (0)