Skip to content

Instantly share code, notes, and snippets.

@maliubiao
Created December 16, 2013 08:30
Show Gist options
  • Save maliubiao/7983892 to your computer and use it in GitHub Desktop.
Save maliubiao/7983892 to your computer and use it in GitHub Desktop.
profile2csv.py file -> profile.csv, cProfile->pstats->csv.
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