Skip to content

Instantly share code, notes, and snippets.

@nascheme
Created September 5, 2017 22:51
Show Gist options
  • Save nascheme/0bff5c49bb6b518f5ce23a9aea27f14b to your computer and use it in GitHub Desktop.
Save nascheme/0bff5c49bb6b518f5ce23a9aea27f14b to your computer and use it in GitHub Desktop.
Pretty printer for module import dtrace output
!/usr/bin/env python3
#
# Pretty print module import dtrace output. First column is elapsed time in ms. Second column is % of total time.
import sys
import fileinput
def main():
first = None
lines = []
for line in fileinput.input():
if not line.strip():
break
ts, _, rest = line.partition('\t')
ts = int(ts)
rest = rest.strip()
if first is None:
first = ts
ts = 0
else:
ts -= first
lines.append((ts, rest))
last = ts
for ts, line in lines:
print('%8.3f %6.1f %s' % (float(ts)/1e6, 100*float(ts)/last, line))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment