Browse Source

lint run_perf.py

parent
commit
0d08e3d910
No known key found for this signature in database
1 changed files with 20 additions and 21 deletions
  1. 20
    21
      run_perf.py

+ 20
- 21
run_perf.py View File

@@ -5,6 +5,9 @@ import json
5 5
 import subprocess
6 6
 from operator import itemgetter
7 7
 
8
+sys.path.insert(1, os.path.abspath('enigmail-linux'))
9
+import test
10
+
8 11
 try:
9 12
     path = sys.argv[1]
10 13
     assert os.path.exists(path)
@@ -13,51 +16,47 @@ except (IndexError, AssertionError):
13 16
     exit(1)
14 17
 
15 18
 try:
16
-    own_identity = json.load(open('%s/.pEp/perf-identity'%os.getenv('HOME')))
19
+    own_identity = json.load(open('%s/.pEp/perf-identity' % os.getenv('HOME')))
17 20
 except (FileNotFoundError, json.decoder.JSONDecodeError) as e:
18 21
     print('write the identity to be used into ~/.pEp/perf-identity - see ./perf-identity')
19 22
     raise(e)
20 23
 
21
-#input('will now search your homedir for pepmda')
24
+# input('will now search your homedir for pepmda')
22 25
 pepmda_path_all = subprocess.check_output(
23 26
     'find ~ -xdev -type f -executable -name pep-json-server',
24
-     shell=True).splitlines()
25
-pepmda_path = max( ( (p,os.path.getctime(p)) for p in pepmda_path_all if os.access(p, os.X_OK)),
26
-                    key=itemgetter(1))[0]
27
+    shell=True).splitlines()
28
+pepmda_path = max(((p, os.path.getctime(p)) for p in pepmda_path_all if os.access(p, os.X_OK)),
29
+                  key=itemgetter(1))[0]
27 30
 
28
-print('found pepmda at %s'%pepmda_path.decode())
31
+print('found pepmda at %s' % pepmda_path.decode())
29 32
 pepmda_cwd = pepmda_path.replace(b'bin/pep-json-server', b'share/pEp')
30 33
 print(pepmda_cwd)
31 34
 
32 35
 print(subprocess.check_output(pepmda_path, cwd=pepmda_cwd))
33 36
 
34
-sys.path.insert(1,os.path.abspath('enigmail-linux'))
35
-
36
-import test
37
-test.call('myself',own_identity)
37
+test.call('myself', own_identity)
38 38
 
39
-
40
-
41
-processinfo = subprocess.check_output(('ss', '-ntlp', 'src :%i'%test.token['port']))
42
-pid = re.search(br'pid=(\d{1,5})(?!\d)',processinfo).group(1).decode()
39
+processinfo = subprocess.check_output(('ss', '-ntlp', 'src :%i' % test.token['port']))
40
+pid = re.search(br'pid=(\d{1,5})(?!\d)', processinfo).group(1).decode()
43 41
 
44 42
 perfprocess = subprocess.Popen(('perf', 'record', '-F', '10000', '-g', '-p', pid))
45 43
 
46
-for path,dirs,files in os.walk(path):
44
+for path, dirs, files in os.walk(path):
47 45
     for fname in files:
48
-        test.decryptMime(os.path.join(path,fname))
49
-        print('decrypted "%s"'%fname)
46
+        test.decryptMime(os.path.join(path, fname))
47
+        print('decrypted "%s"' % fname)
50 48
 
51 49
 perfprocess.terminate()
52 50
 perfprocess.wait(5)
53 51
 if perfprocess.returncode is None:
54 52
     print('seems we have to terminate pep-json-server, sorry')
55
-    os.kill(int(pid),15)
53
+    os.kill(int(pid), 15)
56 54
 perfprocess.terminate()
57 55
 perfprocess.wait(5)
58
-if perfprocess.returncode not in (0,-15):
56
+if perfprocess.returncode not in (0, -15):
59 57
     sys.exit(perfprocess.returncode)
60 58
 
61
-subprocess.run('perf script | FlameGraph/stackcollapse-perf.pl | FlameGraph/flamegraph.pl > /tmp/perf.svg', shell=True)
59
+subprocess.run(
60
+    'perf script | FlameGraph/stackcollapse-perf.pl | FlameGraph/flamegraph.pl > /tmp/perf.svg',
61
+    shell=True)
62 62
 print('flamegraph written to /tmp/perf.svg')
63
-

Loading…
Cancel
Save