diff --git a/.github/workflows/static_analysis.yml b/.github/workflows/static_analysis.yml index 717747d..4cab99f 100644 --- a/.github/workflows/static_analysis.yml +++ b/.github/workflows/static_analysis.yml @@ -24,4 +24,3 @@ jobs: pip install --upgrade flake8 - name: Run flake8 run: flake8 benchmark scorep test - continue-on-error: true # Not conformant yet diff --git a/benchmark/benchmark.py b/benchmark/benchmark.py index ae85b1f..83af6d4 100644 --- a/benchmark/benchmark.py +++ b/benchmark/benchmark.py @@ -10,15 +10,14 @@ tests = ["test_1.py", "test_2.py"] results = {} -reps_x={} -reps_x["test_1.py"]=["1000000", "2000000", "3000000", "4000000", "5000000"] -reps_x["test_2.py"]=["100000", "200000", "300000", "400000", "500000"] - +reps_x = {} +reps_x["test_1.py"] = ["1000000", "2000000", "3000000", "4000000", "5000000"] +reps_x["test_2.py"] = ["100000", "200000", "300000", "400000", "500000"] for test in tests: results[test] = {"profile": {}, "trace": {}, "dummy": {}, "None": {}} for instrumenter in results[test]: - if instrumenter is "None": + if instrumenter == "None": enable_scorep = False scorep_settings = [] else: @@ -29,11 +28,9 @@ print("{}: {}".format(test, scorep_settings)) print("#########") for reps in reps_x[test]: - times = bench.call( - test, - [reps], - enable_scorep, - scorep_settings=scorep_settings) + times = bench.call(test, [reps], + enable_scorep, + scorep_settings=scorep_settings) results[test][instrumenter][reps] = times print("{:<8}: {}".format(reps, times)) diff --git a/benchmark/benchmark_helper.py b/benchmark/benchmark_helper.py index 5cdc465..6c34751 100644 --- a/benchmark/benchmark_helper.py +++ b/benchmark/benchmark_helper.py @@ -40,7 +40,7 @@ def call(self, script="", ops=[], enable_scorep=True, scorep_settings=[]): runtimes = [] for i in range(self.repetitions): begin = time.time() - print (arguments) + print(arguments) out = subprocess.run( arguments, env=self.env, diff --git a/scorep/__init__.py b/scorep/__init__.py index fad41d1..8a33224 100644 --- a/scorep/__init__.py +++ b/scorep/__init__.py @@ -1,3 +1 @@ -import scorep.user -import scorep.instrumenter __all__ = ["user", "instrumenter"] diff --git a/scorep/__main__.py b/scorep/__main__.py index 2344462..023deb6 100644 --- a/scorep/__main__.py +++ b/scorep/__main__.py @@ -66,7 +66,6 @@ def scorep_main(argv=None): os.environ["SCOREP_PYTHON_BINDINGS_INITALISED"] != "true"): scorep.subsystem.init_environment(scorep_config, keep_files) os.environ["SCOREP_PYTHON_BINDINGS_INITALISED"] = "true" - """ python -m starts the module as skript. i.e. sys.argv will loke like: ['/home/gocht/Dokumente/code/scorep_python/scorep.py', '--mpi', 'mpi_test.py'] @@ -91,8 +90,9 @@ def scorep_main(argv=None): progname = prog_argv[0] sys.path[0] = os.path.split(progname)[0] - tracer = scorep.instrumenter.get_instrumenter( - scorep_bindings, not no_instrumenter, instrumenter_type) + tracer = scorep.instrumenter.get_instrumenter(scorep_bindings, + not no_instrumenter, + instrumenter_type) try: with open(progname) as fp: code = compile(fp.read(), progname, 'exec') @@ -120,7 +120,8 @@ def main(argv=None): call_stack_string += elem _err_exit( "Someone called scorep.__main__.main(argv).\n" - "This is not supposed to happen, but might be triggered, if your application calls \"sys.modules['__main__'].main\".\n" + "This is not supposed to happen, but might be triggered, " + "if your application calls \"sys.modules['__main__'].main\".\n" "This python stacktrace might be helpfull to find the reason:\n%s" % call_stack_string) diff --git a/scorep/instrumenter.py b/scorep/instrumenter.py index 18ef6b4..e620984 100644 --- a/scorep/instrumenter.py +++ b/scorep/instrumenter.py @@ -8,16 +8,16 @@ global_instrumenter = None -def get_instrumenter( - bindings=None, - enable_instrumenter=False, - instrumenter_type="dummy"): +def get_instrumenter(bindings=None, + enable_instrumenter=False, + instrumenter_type="dummy"): """ returns an instrumenter @param bindings the c/c++ scorep bindings @param enable_instrumenter True if the Instrumenter should be enabled when run is called - @param instrumenter_type which python tracing interface to use. Currently available: `profile` (default), `trace` and `dummy` + @param instrumenter_type which python tracing interface to use. + Currently available: `profile` (default), `trace` and `dummy` """ global global_instrumenter if global_instrumenter is None: @@ -47,7 +47,8 @@ def register(): def unregister(): """ Disables the python-tracing. - Disabling the python-tracing is more efficient than disable_recording, as python does not longer call the tracing module. + Disabling the python-tracing is more efficient than disable_recording, + as python does not longer call the tracing module. However, all the other things that are traced by Score-P will still be recorded. Please call register() to enable tracing again. """ @@ -62,14 +63,14 @@ class enable(): do stuff ``` This overides --no-instrumenter (--nopython leagacy) - @param region_name: if a region name is given, the region the contextmanager is active will be marked in the trace or profile + If a region name is given, the region the contextmanager is active will be marked in the trace or profile """ - def __init__(self, region_name=None): self.region_name = region_name def __enter__(self): - self.tracer_registered = scorep.instrumenter.get_instrumenter().get_registered() + self.tracer_registered = scorep.instrumenter.get_instrumenter( + ).get_registered() if not self.tracer_registered: if self.region_name: self.module_name = "user_instrumenter" @@ -82,7 +83,8 @@ def __enter__(self): full_file_name = "None" scorep.instrumenter.get_instrumenter().region_begin( - self.module_name, self.region_name, full_file_name, line_number) + self.module_name, self.region_name, full_file_name, + line_number) scorep.instrumenter.get_instrumenter().register() @@ -103,14 +105,14 @@ class disable(): do stuff ``` This overides --no-instrumenter (--nopython leagacy) - @param region_name: if a region name is given, the region the contextmanager is active will be marked in the trace or profile + If a region name is given, the region the contextmanager is active will be marked in the trace or profile """ - def __init__(self, region_name=None): self.region_name = region_name def __enter__(self): - self.tracer_registered = scorep.instrumenter.get_instrumenter().get_registered() + self.tracer_registered = scorep.instrumenter.get_instrumenter( + ).get_registered() if self.tracer_registered: scorep.instrumenter.get_instrumenter().unregister() @@ -125,7 +127,8 @@ def __enter__(self): full_file_name = "None" scorep.instrumenter.get_instrumenter().region_begin( - self.module_name, self.region_name, full_file_name, line_number) + self.module_name, self.region_name, full_file_name, + line_number) def __exit__(self, exc_type, exc_value, traceback): if self.tracer_registered: diff --git a/scorep/instrumenters/dummy.py b/scorep/instrumenters/dummy.py index 8196242..909d103 100644 --- a/scorep/instrumenters/dummy.py +++ b/scorep/instrumenters/dummy.py @@ -2,6 +2,7 @@ import scorep.instrumenters.base_instrumenter as base_instrumenter + class ScorepDummy(base_instrumenter.BaseInstrumenter): def __init__(self, scorep_bindings=None, enable_instrumenter=True): pass diff --git a/test/test.py b/test/test.py index 3b2cc47..1ba7611 100755 --- a/test/test.py +++ b/test/test.py @@ -298,7 +298,6 @@ def test_mpi(self): env = self.env env["SCOREP_EXPERIMENT_DIRECTORY"] += "/test_mpi" - trace_path = env["SCOREP_EXPERIMENT_DIRECTORY"] + "/traces.otf2" out = call(["mpirun", "-n", "2", @@ -316,19 +315,15 @@ def test_mpi(self): std_out = out[1] std_err = out[2] - expected_std_err = "" - expected_std_out = u"\[0[0-9]\] \[0. 1. 2. 3. 4.\]\\n\[0[0-9]] \[0. 1. 2. 3. 4.\]\\n" + expected_std_out = r"\[0[0-9]\] \[0. 1. 2. 3. 4.\]\n\[0[0-9]] \[0. 1. 2. 3. 4.\]\n" self.assertRegex(std_err, - '\[Score-P\] [\w/.: ]*MPI_THREAD_FUNNELED') + r'\[Score-P\] [\w/.: ]*MPI_THREAD_FUNNELED') self.assertRegex(std_out, expected_std_out) - expected_std_out - def test_call_main(self): env = self.env env["SCOREP_EXPERIMENT_DIRECTORY"] += "/test_call_main" - trace_path = env["SCOREP_EXPERIMENT_DIRECTORY"] + "/traces.otf2" out = call([self.python, "-m", "scorep", @@ -346,7 +341,6 @@ def test_call_main(self): def test_dummy(self): env = self.env env["SCOREP_EXPERIMENT_DIRECTORY"] += "/test_dummy" - trace_path = env["SCOREP_EXPERIMENT_DIRECTORY"] + "/traces.otf2" out = call([self.python, "-m", @@ -382,7 +376,6 @@ def test_numpy_dot(self): self.assertEqual(std_out, "[[ 7 10]\n [15 22]]\n") self.assertEqual(std_err, self.expected_std_err) - out = call(["otf2-print", trace_path]) std_out = out[1] @@ -394,7 +387,6 @@ def test_numpy_dot(self): self.assertRegex(std_out, 'LEAVE[ ]*[0-9 ]*[0-9 ]*Region: "numpy.__array_function__:dot"') - def tearDown(self): # pass shutil.rmtree( diff --git a/test/test_instrumentation.py b/test/test_instrumentation.py index 177bfad..b0e2356 100644 --- a/test/test_instrumentation.py +++ b/test/test_instrumentation.py @@ -6,4 +6,5 @@ def foo(): test_instrumentation2.baz() test_instrumentation2.bar() + foo() diff --git a/test/test_numpy_dot.py b/test/test_numpy_dot.py index 934c129..0e6a199 100644 --- a/test/test_numpy_dot.py +++ b/test/test_numpy_dot.py @@ -2,8 +2,8 @@ import scorep.instrumenter with scorep.instrumenter.enable(): - a = [[1, 2],[3, 4]] - b = [[1, 2],[3, 4]] - - c = numpy.dot(a,b) - print(c) \ No newline at end of file + a = [[1, 2], [3, 4]] + b = [[1, 2], [3, 4]] + + c = numpy.dot(a, b) + print(c) diff --git a/test/test_user_instrumentation.py b/test/test_user_instrumentation.py index a1dc753..fdd2496 100644 --- a/test/test_user_instrumentation.py +++ b/test/test_user_instrumentation.py @@ -7,5 +7,6 @@ def foo(): test_instrumentation2.baz() test_instrumentation2.bar() + with scorep.instrumenter.enable(): foo()