| 1 |
import json |
| 2 |
import subprocess |
| 3 |
import re |
| 4 |
import statistics |
| 5 |
from glob import glob |
| 6 |
from collections import defaultdict |
| 7 |
import sys |
| 8 |
|
| 9 |
cmds = { |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
"yappi_wall": ["python3", "-m", "yappi", "-o", "/dev/null", "-c", "wall"], |
| 33 |
"yappi_cpu": ["python3", "-m", "yappi", "-o", "/dev/null", "-c", "cpu"], |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
} |
| 39 |
result_regexp = re.compile(r"Time elapsed:\s+([0-9]*\.[0-9]+)") |
| 40 |
|
| 41 |
|
| 42 |
def main(): |
| 43 |
out = defaultdict(lambda: {}) |
| 44 |
|
| 45 |
for progname in [ |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
"./test/expensive_benchmarks/bm_docutils.py" |
| 56 |
]: |
| 57 |
for profile_name, profile_cmd in cmds.items(): |
| 58 |
times = [] |
| 59 |
for i in range(5): |
| 60 |
print( |
| 61 |
f"Running {profile_name} on {progname} using \"{' '.join(profile_cmd + progname.split(' '))}\"...", |
| 62 |
end="", |
| 63 |
flush=True, |
| 64 |
) |
| 65 |
result = subprocess.run( |
| 66 |
profile_cmd + progname.split(" "), |
| 67 |
stderr=subprocess.STDOUT, |
| 68 |
stdout=subprocess.PIPE, |
| 69 |
) |
| 70 |
|
| 71 |
output = result.stdout.decode("utf-8") |
| 72 |
|
| 73 |
match = result_regexp.search(output) |
| 74 |
if match is not None: |
| 75 |
print( |
| 76 |
f"... {match.group(1)}", |
| 77 |
end=("\n" if profile_name != "memray" else ""), |
| 78 |
) |
| 79 |
times.append(round(100 * float(match.group(1))) / 100.0) |
| 80 |
if profile_name == "memray": |
| 81 |
res2 = subprocess.run( |
| 82 |
[ |
| 83 |
"time", |
| 84 |
sys.executable, |
| 85 |
"-m", |
| 86 |
"memray", |
| 87 |
"flamegraph", |
| 88 |
"-f", |
| 89 |
"/tmp/memray.out", |
| 90 |
], |
| 91 |
capture_output=True, |
| 92 |
env={"TIME": "Time elapsed: %e"}, |
| 93 |
) |
| 94 |
output2 = res2.stderr.decode("utf-8") |
| 95 |
match2 = result_regexp.search(output2) |
| 96 |
if match2 is not None: |
| 97 |
print(f"... {match2.group(1)}") |
| 98 |
times[-1] += round(100 * float(match2.group(1))) / 100.0 |
| 99 |
else: |
| 100 |
print("... RUN FAILED") |
| 101 |
|
| 102 |
else: |
| 103 |
print("RUN FAILED") |
| 104 |
|
| 105 |
out[profile_name][progname] = times |
| 106 |
with open("yappi.json", "w+") as f: |
| 107 |
json.dump(dict(out), f) |
| 108 |
|
| 109 |
|
| 110 |
if __name__ == "__main__": |
| 111 |
main() |