Show More
@@ -181,7 +181,7 def _runextsetup(name, ui): | |||||
181 |
|
181 | |||
182 | def loadall(ui, whitelist=None): |
|
182 | def loadall(ui, whitelist=None): | |
183 | result = ui.configitems("extensions") |
|
183 | result = ui.configitems("extensions") | |
184 | if whitelist: |
|
184 | if whitelist is not None: | |
185 | result = [(k, v) for (k, v) in result if k in whitelist] |
|
185 | result = [(k, v) for (k, v) in result if k in whitelist] | |
186 | newindex = len(_order) |
|
186 | newindex = len(_order) | |
187 | for (name, path) in result: |
|
187 | for (name, path) in result: |
@@ -13,9 +13,21 from .i18n import _ | |||||
13 | from . import ( |
|
13 | from . import ( | |
14 | encoding, |
|
14 | encoding, | |
15 | error, |
|
15 | error, | |
|
16 | extensions, | |||
16 | util, |
|
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 | @contextlib.contextmanager |
|
31 | @contextlib.contextmanager | |
20 | def lsprofile(ui, fp): |
|
32 | def lsprofile(ui, fp): | |
21 | format = ui.config('profiling', 'format', default='text') |
|
33 | format = ui.config('profiling', 'format', default='text') | |
@@ -137,11 +149,15 def profile(ui): | |||||
137 | manager exits, profiling results will be written to the configured output. |
|
149 | manager exits, profiling results will be written to the configured output. | |
138 | """ |
|
150 | """ | |
139 | profiler = encoding.environ.get('HGPROF') |
|
151 | profiler = encoding.environ.get('HGPROF') | |
|
152 | proffn = None | |||
140 | if profiler is None: |
|
153 | if profiler is None: | |
141 | profiler = ui.config('profiling', 'type', default='stat') |
|
154 | profiler = ui.config('profiling', 'type', default='stat') | |
142 | if profiler not in ('ls', 'stat', 'flame'): |
|
155 | if profiler not in ('ls', 'stat', 'flame'): | |
143 | ui.warn(_("unrecognized profiler '%s' - ignored\n") % profiler) |
|
156 | # try load profiler from extension with the same name | |
144 | profiler = 'stat' |
|
157 | proffn = _loadprofiler(ui, profiler) | |
|
158 | if proffn is None: | |||
|
159 | ui.warn(_("unrecognized profiler '%s' - ignored\n") % profiler) | |||
|
160 | profiler = 'stat' | |||
145 |
|
161 | |||
146 | output = ui.config('profiling', 'output') |
|
162 | output = ui.config('profiling', 'output') | |
147 |
|
163 | |||
@@ -154,7 +170,9 def profile(ui): | |||||
154 | fp = ui.ferr |
|
170 | fp = ui.ferr | |
155 |
|
171 | |||
156 | try: |
|
172 | try: | |
157 |
if prof |
|
173 | if proffn is not None: | |
|
174 | pass | |||
|
175 | elif profiler == 'ls': | |||
158 | proffn = lsprofile |
|
176 | proffn = lsprofile | |
159 | elif profiler == 'flame': |
|
177 | elif profiler == 'flame': | |
160 | proffn = flameprofile |
|
178 | proffn = flameprofile |
@@ -99,3 +99,51 statprof can be used as a standalone mod | |||||
99 | [1] |
|
99 | [1] | |
100 |
|
100 | |||
101 | $ cd .. |
|
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