Skip to content

Instantly share code, notes, and snippets.

@brson
Last active April 7, 2019 04:09
Show Gist options
  • Save brson/819c52c6e9f09f5eaa450e623c686e4e to your computer and use it in GitHub Desktop.
Save brson/819c52c6e9f09f5eaa450e623c686e4e to your computer and use it in GitHub Desktop.
Sum and sort rustc -Ztime-passes
import sys
import re
import operator
file = sys.argv[1]
r = re.compile("time: (\S.*); rss: (\S*)\s*(.*)")
map = { }
with open(file) as f:
for line in f:
line = line.strip()
if not line.startswith("time"):
continue
m = r.match(line)
assert m
time = m.group(1)
desc = m.group(3)
# strip tail of `codegen passes [incr module name]`
if desc.startswith("codegen passes"):
desc = "codegen passes"
if desc.startswith("llvm module passes"):
desc = "llvm module passes"
if desc.startswith("llvm function passes"):
desc = "llvm function passes"
if desc.startswith("encode_query_results"):
desc = "encode_query_results"
if desc.startswith("solve_nll_region_constraints"):
desc = "solve_nll_region_constraints"
if desc.startswith("ll link"):
desc = "ll link"
if desc.startswith("decode"):
desc = "decode"
if desc.startswith("altering"):
desc = "altering"
time = float(time)
if map.get(desc):
map[desc] = map[desc] + time
else:
map[desc] = time
sorted = sorted(map.items(), key=operator.itemgetter(1))
for (time, pass_name) in sorted:
print("{} - {:.2f}".format(time, pass_name))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment