Details
Details
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Lint
Lint Skipped - Unit
Unit Tests Skipped
Lint Skipped |
Unit Tests Skipped |
Path | Packages | |||
---|---|---|---|---|
M | mercurial/statprof.py (11 lines) |
Commit | Parents | Author | Summary | Date |
---|---|---|---|---|
3cea5f27f1bc | 9a2302bbdd78 | Martin von Zweigbergk | Aug 30 2019, 7:44 PM |
Status | Author | Revision | |
---|---|---|---|
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz |
def write_to_flame(data, fp, scriptpath=None, outputfile=None, **kwargs): | def write_to_flame(data, fp, scriptpath=None, outputfile=None, **kwargs): | ||||
if scriptpath is None: | if scriptpath is None: | ||||
scriptpath = encoding.environ['HOME'] + '/flamegraph.pl' | scriptpath = encoding.environ['HOME'] + '/flamegraph.pl' | ||||
if not os.path.exists(scriptpath): | if not os.path.exists(scriptpath): | ||||
fp.write(b'error: missing %s\n' % scriptpath) | fp.write(b'error: missing %s\n' % scriptpath) | ||||
fp.write(b'get it here: https://github.com/brendangregg/FlameGraph\n') | fp.write(b'get it here: https://github.com/brendangregg/FlameGraph\n') | ||||
return | return | ||||
fd, path = pycompat.mkstemp() | |||||
file = open(path, "w+") | |||||
lines = {} | lines = {} | ||||
for sample in data.samples: | for sample in data.samples: | ||||
sites = [s.function for s in sample.stack] | sites = [s.function for s in sample.stack] | ||||
sites.reverse() | sites.reverse() | ||||
line = ';'.join(sites) | line = ';'.join(sites) | ||||
if line in lines: | if line in lines: | ||||
lines[line] = lines[line] + 1 | lines[line] = lines[line] + 1 | ||||
else: | else: | ||||
lines[line] = 1 | lines[line] = 1 | ||||
fd, path = pycompat.mkstemp() | |||||
with open(path, "w+") as file: | |||||
for line, count in lines.iteritems(): | for line, count in lines.iteritems(): | ||||
file.write("%s %d\n" % (line, count)) | file.write("%s %d\n" % (line, count)) | ||||
file.close() | |||||
if outputfile is None: | if outputfile is None: | ||||
outputfile = '~/flamegraph.svg' | outputfile = '~/flamegraph.svg' | ||||
os.system("perl ~/flamegraph.pl %s > %s" % (path, outputfile)) | os.system("perl ~/flamegraph.pl %s > %s" % (path, outputfile)) | ||||
fp.write(b'Written to %s\n' % outputfile) | fp.write(b'Written to %s\n' % outputfile) | ||||
_pathcache = {} | _pathcache = {} | ||||
def simplifypath(path): | def simplifypath(path): |