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
50 changes: 48 additions & 2 deletions scorep/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,48 @@

import scorep.instrumenter
import scorep.subsystem
from scorep.helper import print_err
from scorep.helper import get_scorep_version, print_err


def _err_exit(msg):
print_err("scorep: " + msg)
sys.exit(1)


def print_help():
print("""
Usage: python -m scorep [options] [--] <script> [args]

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.
--keep-files Keep temporary files after execution.
--verbose, -v Enable verbose output for debugging and tracing.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what means "tracing" in this context?

--nocompiler Disable compiler-based instrumentation.
--nopython Disable instrumentation of Python code.
Instrumentation can still be enabled later from within the application's source code.
--noinstrumenter Same as --nopython.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

time to deprecate that option?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add --instrumenter-type=none in the future? and make --noinstrumenter an alias?

--instrumenter-type=<type>
Specify custom instrumenter type (e.g., cProfile).
--instrumenter-file=<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; interpret all following arguments verbatim as the program with its arguments.

Other options starting with '-' are passed directly to 'scorep-config'.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that needs to be more prominent at the beginning

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
Expand All @@ -19,10 +53,12 @@ def scorep_main(argv=None):
prog_argv = []
parse_scorep_commands = True

show_help = False
keep_files = False
verbose = False
no_default_compiler = False
no_instrumenter = False

if scorep.instrumenter.has_c_instrumenter():
instrumenter_type = "cProfile"
else:
Expand All @@ -33,7 +69,12 @@ 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":
print_err(f"scorep: Warning: The option '{elem}' is deprecated "
"and will be removed in future.")
scorep_config.append("--mpp=mpi")
elif elem == "--keep-files":
keep_files = True
Expand All @@ -46,7 +87,7 @@ def scorep_main(argv=None):
no_instrumenter = True
elif elem == "--noinstrumenter":
no_instrumenter = True
elif elem in ["--io=runtime:posix", "--io=posix"]:
elif elem in ["--io=runtime:posix", "--io=posix"] and get_scorep_version() >= 9.0:
print_err(f"scorep: Warning: The option '{elem}' is deprecated.")
if "SCOREP_IO_POSIX" in os.environ:
print_err(" Will not overwrite existing value for environment variable "
Expand All @@ -71,6 +112,11 @@ def scorep_main(argv=None):
if not no_default_compiler:
scorep_config.append("--compiler")

# 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")

Expand Down
7 changes: 7 additions & 0 deletions test/test_scorep.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading