##// END OF EJS Templates
profiling: use vendored statprof and upstream enhancements (BC)...
Gregory Szorc -
r30316:faf1b892 default
parent child Browse files
Show More
@@ -1409,9 +1409,9 b' profiling is done using lsprof.'
1409 1409 first line of a function. This restriction makes it difficult to
1410 1410 identify the expensive parts of a non-trivial function.
1411 1411 ``stat``
1412 Use a third-party statistical profiler, statprof. This profiler
1413 currently runs only on Unix systems, and is most useful for
1414 profiling commands that run for longer than about 0.1 seconds.
1412 Use a statistical profiler, statprof. This profiler is most
1413 most useful for profiling commands that run for longer than
1414 about 0.1 seconds.
1415 1415
1416 1416 ``format``
1417 1417 Profiling format. Specific to the ``ls`` instrumenting profiler.
@@ -1426,6 +1426,20 b' profiling is done using lsprof.'
1426 1426 file, the generated file can directly be loaded into
1427 1427 kcachegrind.
1428 1428
1429 ``statformat``
1430 Profiling format for the ``stat`` profiler.
1431 (default: hotpath)
1432
1433 ``hotpath``
1434 Show a tree-based display containing the hot path of execution (where
1435 most time was spent).
1436 ``bymethod``
1437 Show a table of methods ordered by how frequently they are active.
1438 ``byline``
1439 Show a table of lines in files ordered by how frequently they are active.
1440 ``json``
1441 Render profiling data as JSON.
1442
1429 1443 ``frequency``
1430 1444 Sampling frequency. Specific to the ``stat`` sampling profiler.
1431 1445 (default: 1000)
@@ -80,11 +80,7 b' def flameprofile(ui, fp):'
80 80
81 81 @contextlib.contextmanager
82 82 def statprofile(ui, fp):
83 try:
84 import statprof
85 except ImportError:
86 raise error.Abort(_(
87 'statprof not available - install using "easy_install statprof"'))
83 from . import statprof
88 84
89 85 freq = ui.configint('profiling', 'freq', default=1000)
90 86 if freq > 0:
@@ -94,12 +90,29 b' def statprofile(ui, fp):'
94 90 else:
95 91 ui.warn(_("invalid sampling frequency '%s' - ignoring\n") % freq)
96 92
97 statprof.start()
93 statprof.start(mechanism='thread')
94
98 95 try:
99 96 yield
100 97 finally:
101 statprof.stop()
102 statprof.display(fp)
98 data = statprof.stop()
99
100 profformat = ui.config('profiling', 'statformat', 'hotpath')
101
102 formats = {
103 'byline': statprof.DisplayFormats.ByLine,
104 'bymethod': statprof.DisplayFormats.ByMethod,
105 'hotpath': statprof.DisplayFormats.Hotpath,
106 'json': statprof.DisplayFormats.Json,
107 }
108
109 if profformat in formats:
110 displayformat = formats[profformat]
111 else:
112 ui.warn(_('unknown profiler output format: %s\n') % profformat)
113 displayformat = statprof.DisplayFormats.Hotpath
114
115 statprof.display(fp, data=data, format=displayformat)
103 116
104 117 @contextlib.contextmanager
105 118 def profile(ui):
@@ -47,4 +47,49 b' A single profile is logged because file '
47 47
48 48 #endif
49 49
50 Install an extension that can sleep and guarantee a profiler has time to run
51
52 $ cat >> sleepext.py << EOF
53 > import time
54 > from mercurial import cmdutil, commands
55 > cmdtable = {}
56 > command = cmdutil.command(cmdtable)
57 > @command('sleep', [], 'hg sleep')
58 > def sleep(ui, *args, **kwargs):
59 > time.sleep(0.1)
60 > EOF
61
62 $ cat >> $HGRCPATH << EOF
63 > [extensions]
64 > sleep = `pwd`/sleepext.py
65 > EOF
66
67 statistical profiler works
68
69 $ HGPROF=stat hg --profile sleep 2>../out
70 $ grep Sample ../out
71 Sample count: \d+ (re)
72
73 Various statprof formatters work
74
75 $ HGPROF=stat hg --profile --config profiling.statformat=byline sleep 2>../out
76 $ head -n 1 ../out
77 % cumulative self
78 $ grep Sample ../out
79 Sample count: \d+ (re)
80
81 $ HGPROF=stat hg --profile --config profiling.statformat=bymethod sleep 2>../out
82 $ head -n 1 ../out
83 % cumulative self
84 $ grep Sample ../out
85 Sample count: \d+ (re)
86
87 $ HGPROF=stat hg --profile --config profiling.statformat=hotpath sleep 2>../out
88 $ grep Sample ../out
89 Sample count: \d+ (re)
90
91 $ HGPROF=stat hg --profile --config profiling.statformat=json sleep 2>../out
92 $ cat ../out
93 \[\[\d+.* (re)
94
50 95 $ cd ..
General Comments 0
You need to be logged in to leave comments. Login now