Browse Source

lint run_perf.py

master
parent
commit
0d08e3d910
No known key found for this signature in database GPG Key ID: 49B08FCFF6BC3B2
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
import subprocess
from operator import itemgetter

sys.path.insert(1, os.path.abspath('enigmail-linux'))
import test

try:
path = sys.argv[1]
assert os.path.exists(path)
@@ -13,51 +16,47 @@ except (IndexError, AssertionError):
exit(1)

try:
own_identity = json.load(open('%s/.pEp/perf-identity'%os.getenv('HOME')))
own_identity = json.load(open('%s/.pEp/perf-identity' % os.getenv('HOME')))
except (FileNotFoundError, json.decoder.JSONDecodeError) as e:
print('write the identity to be used into ~/.pEp/perf-identity - see ./perf-identity')
raise(e)

#input('will now search your homedir for pepmda')
# input('will now search your homedir for pepmda')
pepmda_path_all = subprocess.check_output(
'find ~ -xdev -type f -executable -name pep-json-server',
shell=True).splitlines()
pepmda_path = max( ( (p,os.path.getctime(p)) for p in pepmda_path_all if os.access(p, os.X_OK)),
key=itemgetter(1))[0]
shell=True).splitlines()
pepmda_path = max(((p, os.path.getctime(p)) for p in pepmda_path_all if os.access(p, os.X_OK)),
key=itemgetter(1))[0]

print('found pepmda at %s'%pepmda_path.decode())
print('found pepmda at %s' % pepmda_path.decode())
pepmda_cwd = pepmda_path.replace(b'bin/pep-json-server', b'share/pEp')
print(pepmda_cwd)

print(subprocess.check_output(pepmda_path, cwd=pepmda_cwd))

sys.path.insert(1,os.path.abspath('enigmail-linux'))

import test
test.call('myself',own_identity)
test.call('myself', own_identity)



processinfo = subprocess.check_output(('ss', '-ntlp', 'src :%i'%test.token['port']))
pid = re.search(br'pid=(\d{1,5})(?!\d)',processinfo).group(1).decode()
processinfo = subprocess.check_output(('ss', '-ntlp', 'src :%i' % test.token['port']))
pid = re.search(br'pid=(\d{1,5})(?!\d)', processinfo).group(1).decode()

perfprocess = subprocess.Popen(('perf', 'record', '-F', '10000', '-g', '-p', pid))

for path,dirs,files in os.walk(path):
for path, dirs, files in os.walk(path):
for fname in files:
test.decryptMime(os.path.join(path,fname))
print('decrypted "%s"'%fname)
test.decryptMime(os.path.join(path, fname))
print('decrypted "%s"' % fname)

perfprocess.terminate()
perfprocess.wait(5)
if perfprocess.returncode is None:
print('seems we have to terminate pep-json-server, sorry')
os.kill(int(pid),15)
os.kill(int(pid), 15)
perfprocess.terminate()
perfprocess.wait(5)
if perfprocess.returncode not in (0,-15):
if perfprocess.returncode not in (0, -15):
sys.exit(perfprocess.returncode)

subprocess.run('perf script | FlameGraph/stackcollapse-perf.pl | FlameGraph/flamegraph.pl > /tmp/perf.svg', shell=True)
subprocess.run(
'perf script | FlameGraph/stackcollapse-perf.pl | FlameGraph/flamegraph.pl > /tmp/perf.svg',
shell=True)
print('flamegraph written to /tmp/perf.svg')


Loading…
Cancel
Save