You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
2.0KB

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