--- a/mercurial/profiling.py Sun Oct 06 09:45:02 2019 -0400
+++ b/mercurial/profiling.py Sun Oct 06 09:48:39 2019 -0400
@@ -33,22 +33,24 @@
@contextlib.contextmanager
def lsprofile(ui, fp):
- format = ui.config('profiling', 'format')
- field = ui.config('profiling', 'sort')
- limit = ui.configint('profiling', 'limit')
- climit = ui.configint('profiling', 'nested')
+ format = ui.config(b'profiling', b'format')
+ field = ui.config(b'profiling', b'sort')
+ limit = ui.configint(b'profiling', b'limit')
+ climit = ui.configint(b'profiling', b'nested')
- if format not in ['text', 'kcachegrind']:
- ui.warn(_("unrecognized profiling format '%s'" " - Ignored\n") % format)
- format = 'text'
+ if format not in [b'text', b'kcachegrind']:
+ ui.warn(
+ _(b"unrecognized profiling format '%s'" b" - Ignored\n") % format
+ )
+ format = b'text'
try:
from . import lsprof
except ImportError:
raise error.Abort(
_(
- 'lsprof not available - install from '
- 'http://codespeak.net/svn/user/arigo/hack/misc/lsprof/'
+ b'lsprof not available - install from '
+ b'http://codespeak.net/svn/user/arigo/hack/misc/lsprof/'
)
)
p = lsprof.Profiler()
@@ -58,7 +60,7 @@
finally:
p.disable()
- if format == 'kcachegrind':
+ if format == b'kcachegrind':
from . import lsprofcalltree
calltree = lsprofcalltree.KCacheGrind(p)
@@ -77,12 +79,12 @@
except ImportError:
raise error.Abort(
_(
- 'flamegraph not available - install from '
- 'https://github.com/evanhempel/python-flamegraph'
+ b'flamegraph not available - install from '
+ b'https://github.com/evanhempel/python-flamegraph'
)
)
# developer config: profiling.freq
- freq = ui.configint('profiling', 'freq')
+ freq = ui.configint(b'profiling', b'freq')
filter_ = None
collapse_recursion = True
thread = flamegraph.ProfileThread(
@@ -96,7 +98,7 @@
thread.stop()
thread.join()
print(
- 'Collected %d stack frames (%d unique) in %2.2f seconds.'
+ b'Collected %d stack frames (%d unique) in %2.2f seconds.'
% (
util.timer() - start_time,
thread.num_frames(),
@@ -109,38 +111,38 @@
def statprofile(ui, fp):
from . import statprof
- freq = ui.configint('profiling', 'freq')
+ freq = ui.configint(b'profiling', b'freq')
if freq > 0:
# Cannot reset when profiler is already active. So silently no-op.
if statprof.state.profile_level == 0:
statprof.reset(freq)
else:
- ui.warn(_("invalid sampling frequency '%s' - ignoring\n") % freq)
+ ui.warn(_(b"invalid sampling frequency '%s' - ignoring\n") % freq)
track = ui.config(
- 'profiling', 'time-track', pycompat.iswindows and 'cpu' or 'real'
+ b'profiling', b'time-track', pycompat.iswindows and b'cpu' or b'real'
)
- statprof.start(mechanism='thread', track=track)
+ statprof.start(mechanism=b'thread', track=track)
try:
yield
finally:
data = statprof.stop()
- profformat = ui.config('profiling', 'statformat')
+ profformat = ui.config(b'profiling', b'statformat')
formats = {
- 'byline': statprof.DisplayFormats.ByLine,
- 'bymethod': statprof.DisplayFormats.ByMethod,
- 'hotpath': statprof.DisplayFormats.Hotpath,
- 'json': statprof.DisplayFormats.Json,
- 'chrome': statprof.DisplayFormats.Chrome,
+ b'byline': statprof.DisplayFormats.ByLine,
+ b'bymethod': statprof.DisplayFormats.ByMethod,
+ b'hotpath': statprof.DisplayFormats.Hotpath,
+ b'json': statprof.DisplayFormats.Json,
+ b'chrome': statprof.DisplayFormats.Chrome,
}
if profformat in formats:
displayformat = formats[profformat]
else:
- ui.warn(_('unknown profiler output format: %s\n') % profformat)
+ ui.warn(_(b'unknown profiler output format: %s\n') % profformat)
displayformat = statprof.DisplayFormats.Hotpath
kwargs = {}
@@ -148,7 +150,7 @@
def fraction(s):
if isinstance(s, (float, int)):
return float(s)
- if s.endswith('%'):
+ if s.endswith(b'%'):
v = float(s[:-1]) / 100
else:
v = float(s)
@@ -156,15 +158,15 @@
return v
raise ValueError(s)
- if profformat == 'chrome':
- showmin = ui.configwith(fraction, 'profiling', 'showmin', 0.005)
- showmax = ui.configwith(fraction, 'profiling', 'showmax')
+ if profformat == b'chrome':
+ showmin = ui.configwith(fraction, b'profiling', b'showmin', 0.005)
+ showmax = ui.configwith(fraction, b'profiling', b'showmax')
kwargs.update(minthreshold=showmin, maxthreshold=showmax)
- elif profformat == 'hotpath':
+ elif profformat == b'hotpath':
# inconsistent config: profiling.showmin
- limit = ui.configwith(fraction, 'profiling', 'showmin', 0.05)
+ limit = ui.configwith(fraction, b'profiling', b'showmin', 0.05)
kwargs[r'limit'] = limit
- showtime = ui.configbool('profiling', 'showtime')
+ showtime = ui.configbool(b'profiling', b'showtime')
kwargs[r'showtime'] = showtime
statprof.display(fp, data=data, format=displayformat, **kwargs)
@@ -204,27 +206,27 @@
if self._started:
return
self._started = True
- profiler = encoding.environ.get('HGPROF')
+ profiler = encoding.environ.get(b'HGPROF')
proffn = None
if profiler is None:
- profiler = self._ui.config('profiling', 'type')
- if profiler not in ('ls', 'stat', 'flame'):
+ profiler = self._ui.config(b'profiling', b'type')
+ if profiler not in (b'ls', b'stat', b'flame'):
# try load profiler from extension with the same name
proffn = _loadprofiler(self._ui, profiler)
if proffn is None:
self._ui.warn(
- _("unrecognized profiler '%s' - ignored\n") % profiler
+ _(b"unrecognized profiler '%s' - ignored\n") % profiler
)
- profiler = 'stat'
+ profiler = b'stat'
- self._output = self._ui.config('profiling', 'output')
+ self._output = self._ui.config(b'profiling', b'output')
try:
- if self._output == 'blackbox':
+ if self._output == b'blackbox':
self._fp = util.stringio()
elif self._output:
path = self._ui.expandpath(self._output)
- self._fp = open(path, 'wb')
+ self._fp = open(path, b'wb')
elif pycompat.iswindows:
# parse escape sequence by win32print()
class uifp(object):
@@ -245,9 +247,9 @@
if proffn is not None:
pass
- elif profiler == 'ls':
+ elif profiler == b'ls':
proffn = lsprofile
- elif profiler == 'flame':
+ elif profiler == b'flame':
proffn = flameprofile
else:
proffn = statprofile
@@ -264,12 +266,12 @@
propagate = self._profiler.__exit__(
exception_type, exception_value, traceback
)
- if self._output == 'blackbox':
- val = 'Profile:\n%s' % self._fp.getvalue()
+ if self._output == b'blackbox':
+ val = b'Profile:\n%s' % self._fp.getvalue()
# ui.log treats the input as a format string,
# so we need to escape any % signs.
- val = val.replace('%', '%%')
- self._ui.log('profile', val)
+ val = val.replace(b'%', b'%%')
+ self._ui.log(b'profile', val)
self._closefp()
return propagate