Last active
June 21, 2018 07:13
-
-
Save ihnorton/05f1dea38e596e75ba106855d490e66a to your computer and use it in GitHub Desktop.
bare-bones uniq for cmake trace profiling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# usage: | |
# > cmake --trace > foo | |
# > cmake_prof.py foo | |
# Return a sorted list of (hitcount, line) for lines in a given file | |
# dramatically faster than running `sort | uniq` on large files. | |
def file_line_hitcount(fname): | |
with open(fname) as f: | |
h = {} | |
for l in f.readlines(): h[l] = h.get(l, 0) + 1 | |
rev_paired = [(h[key],key) for key in h.keys()] | |
return sorted(rev_paired, cmp=lambda x,y: y[0] - x[0]) | |
if __name__ == '__main__' and not '__file__' in globals(): | |
import sys | |
assert(len(sys.argv) == 2) | |
for c,l in file_line_hitcount(sys.argv[1]): | |
s1,s2 = l.strip().split(':') | |
print s1 + ": " + str(c) + " -- " + s2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment