Details
Details
- Reviewers
pulkit - Group Reviewers
hg-reviewers - Commits
- rHG720355c7b7c9: py3: use sysbytes for converting code attributes
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Lint
Lint Skipped - Unit
Unit Tests Skipped
| pulkit |
| hg-reviewers |
| Lint Skipped |
| Unit Tests Skipped |
| Path | Packages | |||
|---|---|---|---|---|
| M | mercurial/lsprofcalltree.py (15 lines) |
| Commit | Parents | Author | Summary | Date |
|---|---|---|---|---|
| Gregory Szorc | Oct 12 2018, 12:30 PM |
| """ | """ | ||||
| lsprofcalltree.py - lsprof output which is readable by kcachegrind | lsprofcalltree.py - lsprof output which is readable by kcachegrind | ||||
| Authors: | Authors: | ||||
| * David Allouche <david <at> allouche.net> | * David Allouche <david <at> allouche.net> | ||||
| * Jp Calderone & Itamar Shtull-Trauring | * Jp Calderone & Itamar Shtull-Trauring | ||||
| * Johan Dahlin | * Johan Dahlin | ||||
| This software may be used and distributed according to the terms | This software may be used and distributed according to the terms | ||||
| of the GNU General Public License, incorporated herein by reference. | of the GNU General Public License, incorporated herein by reference. | ||||
| """ | """ | ||||
| from __future__ import absolute_import | from __future__ import absolute_import | ||||
| from . import ( | |||||
| pycompat, | |||||
| ) | |||||
| def label(code): | def label(code): | ||||
| if isinstance(code, str): | if isinstance(code, str): | ||||
| return '~' + code # built-in functions ('~' sorts at the end) | # built-in functions ('~' sorts at the end) | ||||
| return '~' + pycompat.sysbytes(code) | |||||
| else: | else: | ||||
| return '%s %s:%d' % (code.co_name, | return '%s %s:%d' % (pycompat.sysbytes(code.co_name), | ||||
| code.co_filename, | pycompat.sysbytes(code.co_filename), | ||||
| code.co_firstlineno) | code.co_firstlineno) | ||||
| class KCacheGrind(object): | class KCacheGrind(object): | ||||
| def __init__(self, profiler): | def __init__(self, profiler): | ||||
| self.data = profiler.getstats() | self.data = profiler.getstats() | ||||
| self.out_file = None | self.out_file = None | ||||
| def output(self, out_file): | def output(self, out_file): | ||||
| def _entry(self, entry): | def _entry(self, entry): | ||||
| out_file = self.out_file | out_file = self.out_file | ||||
| code = entry.code | code = entry.code | ||||
| if isinstance(code, str): | if isinstance(code, str): | ||||
| out_file.write(b'fi=~\n') | out_file.write(b'fi=~\n') | ||||
| else: | else: | ||||
| out_file.write(b'fi=%s\n' % code.co_filename) | out_file.write(b'fi=%s\n' % pycompat.sysbytes(code.co_filename)) | ||||
| out_file.write(b'fn=%s\n' % label(code)) | out_file.write(b'fn=%s\n' % label(code)) | ||||
| inlinetime = int(entry.inlinetime * 1000) | inlinetime = int(entry.inlinetime * 1000) | ||||
| if isinstance(code, str): | if isinstance(code, str): | ||||
| out_file.write(b'0 %d\n' % inlinetime) | out_file.write(b'0 %d\n' % inlinetime) | ||||
| else: | else: | ||||
| out_file.write(b'%d %d\n' % (code.co_firstlineno, inlinetime)) | out_file.write(b'%d %d\n' % (code.co_firstlineno, inlinetime)) | ||||
| def _subentry(self, lineno, subentry): | def _subentry(self, lineno, subentry): | ||||
| out_file = self.out_file | out_file = self.out_file | ||||
| code = subentry.code | code = subentry.code | ||||
| out_file.write(b'cfn=%s\n' % label(code)) | out_file.write(b'cfn=%s\n' % label(code)) | ||||
| if isinstance(code, str): | if isinstance(code, str): | ||||
| out_file.write(b'cfi=~\n') | out_file.write(b'cfi=~\n') | ||||
| out_file.write(b'calls=%d 0\n' % subentry.callcount) | out_file.write(b'calls=%d 0\n' % subentry.callcount) | ||||
| else: | else: | ||||
| out_file.write(b'cfi=%s\n' % code.co_filename) | out_file.write(b'cfi=%s\n' % pycompat.sysbytes(code.co_filename)) | ||||
| out_file.write(b'calls=%d %d\n' % ( | out_file.write(b'calls=%d %d\n' % ( | ||||
| subentry.callcount, code.co_firstlineno)) | subentry.callcount, code.co_firstlineno)) | ||||
| totaltime = int(subentry.totaltime * 1000) | totaltime = int(subentry.totaltime * 1000) | ||||
| out_file.write(b'%d %d\n' % (lineno, totaltime)) | out_file.write(b'%d %d\n' % (lineno, totaltime)) | ||||