Created
December 16, 2013 08:30
-
-
Save maliubiao/7983892 to your computer and use it in GitHub Desktop.
profile2csv.py file -> profile.csv, cProfile->pstats->csv.
This file contains hidden or 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
import sys | |
import marshal | |
def main(): | |
if len(sys.argv) < 2: | |
print "usage: profile2csv file -> profile.csv" | |
f = open(sys.argv[1], "r") | |
k = marshal.loads(f.read()) | |
f.close() | |
f = open("profile.csv", "w") | |
f.write('"ncalls", "tottime", "cumtime", "function", "location"%s' % "\n") | |
for func, (cc, nc, tt, ct, callers) in k.iteritems(): | |
f.write('%d, %f, %f, "%s", "%s:%d", %s' % (nc, tt, ct, func[-1], func[0], func[1], "\n")) | |
f.close() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment