Skip to content

Commit

Permalink
Fix python styling and flake8 issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Flamefire committed May 19, 2020
1 parent 1794ab3 commit e0006f8
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 47 deletions.
1 change: 0 additions & 1 deletion .github/workflows/static_analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@ jobs:
pip install --upgrade flake8
- name: Run flake8
run: flake8 benchmark scorep test
continue-on-error: true # Not conformant yet
17 changes: 7 additions & 10 deletions benchmark/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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))

Expand Down
2 changes: 1 addition & 1 deletion benchmark/benchmark_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions scorep/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
import scorep.user
import scorep.instrumenter
__all__ = ["user", "instrumenter"]
9 changes: 5 additions & 4 deletions scorep/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand All @@ -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')
Expand Down Expand Up @@ -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)

Expand Down
31 changes: 17 additions & 14 deletions scorep/instrumenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.
"""
Expand All @@ -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"
Expand All @@ -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()

Expand All @@ -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()

Expand All @@ -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:
Expand Down
1 change: 1 addition & 0 deletions scorep/instrumenters/dummy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 2 additions & 10 deletions test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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]
Expand All @@ -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(
Expand Down
1 change: 1 addition & 0 deletions test/test_instrumentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ def foo():
test_instrumentation2.baz()
test_instrumentation2.bar()


foo()
10 changes: 5 additions & 5 deletions test/test_numpy_dot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
a = [[1, 2], [3, 4]]
b = [[1, 2], [3, 4]]

c = numpy.dot(a, b)
print(c)
1 change: 1 addition & 0 deletions test/test_user_instrumentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ def foo():
test_instrumentation2.baz()
test_instrumentation2.bar()


with scorep.instrumenter.enable():
foo()

0 comments on commit e0006f8

Please sign in to comment.