Because print() expects str and we want to write bytes.
There should be no functional changes as part of this.
| pulkit | 
| hg-reviewers | 
Because print() expects str and we want to write bytes.
There should be no functional changes as part of this.
| Automatic diff as part of commit; lint not applicable. | 
| Automatic diff as part of commit; unit tests not applicable. | 
| Path | Packages | |||
|---|---|---|---|---|
| M | mercurial/lsprofcalltree.py (34 lines) | 
| """ | """ | ||||
| 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, print_function | from __future__ import absolute_import | ||||
| def label(code): | def label(code): | ||||
| if isinstance(code, str): | if isinstance(code, str): | ||||
| return '~' + code # built-in functions ('~' sorts at the end) | return '~' + code # built-in functions ('~' sorts at the end) | ||||
| else: | else: | ||||
| return '%s %s:%d' % (code.co_name, | return '%s %s:%d' % (code.co_name, | ||||
| code.co_filename, | 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): | ||||
| self.out_file = out_file | self.out_file = out_file | ||||
| print('events: Ticks', file=out_file) | out_file.write(b'events: Ticks\n') | ||||
| self._print_summary() | self._print_summary() | ||||
| for entry in self.data: | for entry in self.data: | ||||
| self._entry(entry) | self._entry(entry) | ||||
| def _print_summary(self): | def _print_summary(self): | ||||
| max_cost = 0 | max_cost = 0 | ||||
| for entry in self.data: | for entry in self.data: | ||||
| totaltime = int(entry.totaltime * 1000) | totaltime = int(entry.totaltime * 1000) | ||||
| max_cost = max(max_cost, totaltime) | max_cost = max(max_cost, totaltime) | ||||
| print('summary: %d' % max_cost, file=self.out_file) | self.out_file.write(b'summary: %d\n' % max_cost) | ||||
| 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): | ||||
| print('fi=~', file=out_file) | out_file.write(b'fi=~\n') | ||||
| else: | else: | ||||
| print('fi=%s' % code.co_filename, file=out_file) | out_file.write(b'fi=%s\n' % code.co_filename) | ||||
| print('fn=%s' % label(code), file=out_file) | |||||
| 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): | ||||
| print('0 ', inlinetime, file=out_file) | out_file.write(b'0 %d\n' % inlinetime) | ||||
| else: | else: | ||||
| print('%d %d' % (code.co_firstlineno, inlinetime), file=out_file) | out_file.write(b'%d %d\n' % (code.co_firstlineno, inlinetime)) | ||||
| # recursive calls are counted in entry.calls | # recursive calls are counted in entry.calls | ||||
| if entry.calls: | if entry.calls: | ||||
| calls = entry.calls | calls = entry.calls | ||||
| else: | else: | ||||
| calls = [] | calls = [] | ||||
| if isinstance(code, str): | if isinstance(code, str): | ||||
| lineno = 0 | lineno = 0 | ||||
| else: | else: | ||||
| lineno = code.co_firstlineno | lineno = code.co_firstlineno | ||||
| for subentry in calls: | for subentry in calls: | ||||
| self._subentry(lineno, subentry) | self._subentry(lineno, subentry) | ||||
| print(file=out_file) | |||||
| out_file.write(b'\n') | |||||
| 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 | ||||
| print('cfn=%s' % label(code), file=out_file) | out_file.write(b'cfn=%s\n' % label(code)) | ||||
| if isinstance(code, str): | if isinstance(code, str): | ||||
| print('cfi=~', file=out_file) | out_file.write(b'cfi=~\n') | ||||
| print('calls=%d 0' % subentry.callcount, file=out_file) | out_file.write(b'calls=%d 0\n' % subentry.callcount) | ||||
| else: | else: | ||||
| print('cfi=%s' % code.co_filename, file=out_file) | out_file.write(b'cfi=%s\n' % code.co_filename) | ||||
| print('calls=%d %d' % ( | out_file.write(b'calls=%d %d\n' % ( | ||||
| subentry.callcount, code.co_firstlineno), file=out_file) | subentry.callcount, code.co_firstlineno)) | ||||
| totaltime = int(subentry.totaltime * 1000) | totaltime = int(subentry.totaltime * 1000) | ||||
| print('%d %d' % (lineno, totaltime), file=out_file) | out_file.write(b'%d %d\n' % (lineno, totaltime)) | ||||