Show More
@@ -181,7 +181,7 b' def _runextsetup(name, ui):' | |||
|
181 | 181 | |
|
182 | 182 | def loadall(ui, whitelist=None): |
|
183 | 183 | result = ui.configitems("extensions") |
|
184 | if whitelist: | |
|
184 | if whitelist is not None: | |
|
185 | 185 | result = [(k, v) for (k, v) in result if k in whitelist] |
|
186 | 186 | newindex = len(_order) |
|
187 | 187 | for (name, path) in result: |
@@ -13,9 +13,21 b' from .i18n import _' | |||
|
13 | 13 | from . import ( |
|
14 | 14 | encoding, |
|
15 | 15 | error, |
|
16 | extensions, | |
|
16 | 17 | util, |
|
17 | 18 | ) |
|
18 | 19 | |
|
20 | def _loadprofiler(ui, profiler): | |
|
21 | """load profiler extension. return profile method, or None on failure""" | |
|
22 | extname = profiler | |
|
23 | extensions.loadall(ui, whitelist=[extname]) | |
|
24 | try: | |
|
25 | mod = extensions.find(extname) | |
|
26 | except KeyError: | |
|
27 | return None | |
|
28 | else: | |
|
29 | return getattr(mod, 'profile', None) | |
|
30 | ||
|
19 | 31 | @contextlib.contextmanager |
|
20 | 32 | def lsprofile(ui, fp): |
|
21 | 33 | format = ui.config('profiling', 'format', default='text') |
@@ -137,9 +149,13 b' def profile(ui):' | |||
|
137 | 149 | manager exits, profiling results will be written to the configured output. |
|
138 | 150 | """ |
|
139 | 151 | profiler = encoding.environ.get('HGPROF') |
|
152 | proffn = None | |
|
140 | 153 | if profiler is None: |
|
141 | 154 | profiler = ui.config('profiling', 'type', default='stat') |
|
142 | 155 | if profiler not in ('ls', 'stat', 'flame'): |
|
156 | # try load profiler from extension with the same name | |
|
157 | proffn = _loadprofiler(ui, profiler) | |
|
158 | if proffn is None: | |
|
143 | 159 | ui.warn(_("unrecognized profiler '%s' - ignored\n") % profiler) |
|
144 | 160 | profiler = 'stat' |
|
145 | 161 | |
@@ -154,7 +170,9 b' def profile(ui):' | |||
|
154 | 170 | fp = ui.ferr |
|
155 | 171 | |
|
156 | 172 | try: |
|
157 |
if prof |
|
|
173 | if proffn is not None: | |
|
174 | pass | |
|
175 | elif profiler == 'ls': | |
|
158 | 176 | proffn = lsprofile |
|
159 | 177 | elif profiler == 'flame': |
|
160 | 178 | proffn = flameprofile |
@@ -99,3 +99,51 b' statprof can be used as a standalone mod' | |||
|
99 | 99 | [1] |
|
100 | 100 | |
|
101 | 101 | $ cd .. |
|
102 | ||
|
103 | profiler extension could be loaded before other extensions | |
|
104 | ||
|
105 | $ cat > fooprof.py <<EOF | |
|
106 | > from __future__ import absolute_import | |
|
107 | > import contextlib | |
|
108 | > @contextlib.contextmanager | |
|
109 | > def profile(ui, fp): | |
|
110 | > print('fooprof: start profile') | |
|
111 | > yield | |
|
112 | > print('fooprof: end profile') | |
|
113 | > def extsetup(ui): | |
|
114 | > ui.write('fooprof: loaded\n') | |
|
115 | > EOF | |
|
116 | ||
|
117 | $ cat > otherextension.py <<EOF | |
|
118 | > from __future__ import absolute_import | |
|
119 | > def extsetup(ui): | |
|
120 | > ui.write('otherextension: loaded\n') | |
|
121 | > EOF | |
|
122 | ||
|
123 | $ hg init b | |
|
124 | $ cd b | |
|
125 | $ cat >> .hg/hgrc <<EOF | |
|
126 | > [extensions] | |
|
127 | > other = $TESTTMP/otherextension.py | |
|
128 | > fooprof = $TESTTMP/fooprof.py | |
|
129 | > EOF | |
|
130 | ||
|
131 | $ hg root | |
|
132 | otherextension: loaded | |
|
133 | fooprof: loaded | |
|
134 | $TESTTMP/b (glob) | |
|
135 | $ HGPROF=fooprof hg root --profile | |
|
136 | fooprof: loaded | |
|
137 | fooprof: start profile | |
|
138 | otherextension: loaded | |
|
139 | $TESTTMP/b (glob) | |
|
140 | fooprof: end profile | |
|
141 | ||
|
142 | $ HGPROF=other hg root --profile 2>&1 | head -n 2 | |
|
143 | otherextension: loaded | |
|
144 | unrecognized profiler 'other' - ignored | |
|
145 | ||
|
146 | $ HGPROF=unknown hg root --profile 2>&1 | head -n 1 | |
|
147 | unrecognized profiler 'unknown' - ignored | |
|
148 | ||
|
149 | $ cd .. |
General Comments 0
You need to be logged in to leave comments.
Login now