##// END OF EJS Templates
configitems: register the 'profiling.showmax' config
Boris Feld -
r34411:fecea78f default
parent child Browse files
Show More
@@ -1,671 +1,674
1 # configitems.py - centralized declaration of configuration option
1 # configitems.py - centralized declaration of configuration option
2 #
2 #
3 # Copyright 2017 Pierre-Yves David <pierre-yves.david@octobus.net>
3 # Copyright 2017 Pierre-Yves David <pierre-yves.david@octobus.net>
4 #
4 #
5 # This software may be used and distributed according to the terms of the
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version.
6 # GNU General Public License version 2 or any later version.
7
7
8 from __future__ import absolute_import
8 from __future__ import absolute_import
9
9
10 import functools
10 import functools
11
11
12 from . import (
12 from . import (
13 encoding,
13 encoding,
14 error,
14 error,
15 )
15 )
16
16
17 def loadconfigtable(ui, extname, configtable):
17 def loadconfigtable(ui, extname, configtable):
18 """update config item known to the ui with the extension ones"""
18 """update config item known to the ui with the extension ones"""
19 for section, items in configtable.items():
19 for section, items in configtable.items():
20 knownitems = ui._knownconfig.setdefault(section, {})
20 knownitems = ui._knownconfig.setdefault(section, {})
21 knownkeys = set(knownitems)
21 knownkeys = set(knownitems)
22 newkeys = set(items)
22 newkeys = set(items)
23 for key in sorted(knownkeys & newkeys):
23 for key in sorted(knownkeys & newkeys):
24 msg = "extension '%s' overwrite config item '%s.%s'"
24 msg = "extension '%s' overwrite config item '%s.%s'"
25 msg %= (extname, section, key)
25 msg %= (extname, section, key)
26 ui.develwarn(msg, config='warn-config')
26 ui.develwarn(msg, config='warn-config')
27
27
28 knownitems.update(items)
28 knownitems.update(items)
29
29
30 class configitem(object):
30 class configitem(object):
31 """represent a known config item
31 """represent a known config item
32
32
33 :section: the official config section where to find this item,
33 :section: the official config section where to find this item,
34 :name: the official name within the section,
34 :name: the official name within the section,
35 :default: default value for this item,
35 :default: default value for this item,
36 :alias: optional list of tuples as alternatives.
36 :alias: optional list of tuples as alternatives.
37 """
37 """
38
38
39 def __init__(self, section, name, default=None, alias=()):
39 def __init__(self, section, name, default=None, alias=()):
40 self.section = section
40 self.section = section
41 self.name = name
41 self.name = name
42 self.default = default
42 self.default = default
43 self.alias = list(alias)
43 self.alias = list(alias)
44
44
45 coreitems = {}
45 coreitems = {}
46
46
47 def _register(configtable, *args, **kwargs):
47 def _register(configtable, *args, **kwargs):
48 item = configitem(*args, **kwargs)
48 item = configitem(*args, **kwargs)
49 section = configtable.setdefault(item.section, {})
49 section = configtable.setdefault(item.section, {})
50 if item.name in section:
50 if item.name in section:
51 msg = "duplicated config item registration for '%s.%s'"
51 msg = "duplicated config item registration for '%s.%s'"
52 raise error.ProgrammingError(msg % (item.section, item.name))
52 raise error.ProgrammingError(msg % (item.section, item.name))
53 section[item.name] = item
53 section[item.name] = item
54
54
55 # special value for case where the default is derived from other values
55 # special value for case where the default is derived from other values
56 dynamicdefault = object()
56 dynamicdefault = object()
57
57
58 # Registering actual config items
58 # Registering actual config items
59
59
60 def getitemregister(configtable):
60 def getitemregister(configtable):
61 return functools.partial(_register, configtable)
61 return functools.partial(_register, configtable)
62
62
63 coreconfigitem = getitemregister(coreitems)
63 coreconfigitem = getitemregister(coreitems)
64
64
65 coreconfigitem('auth', 'cookiefile',
65 coreconfigitem('auth', 'cookiefile',
66 default=None,
66 default=None,
67 )
67 )
68 # bookmarks.pushing: internal hack for discovery
68 # bookmarks.pushing: internal hack for discovery
69 coreconfigitem('bookmarks', 'pushing',
69 coreconfigitem('bookmarks', 'pushing',
70 default=list,
70 default=list,
71 )
71 )
72 # bundle.mainreporoot: internal hack for bundlerepo
72 # bundle.mainreporoot: internal hack for bundlerepo
73 coreconfigitem('bundle', 'mainreporoot',
73 coreconfigitem('bundle', 'mainreporoot',
74 default='',
74 default='',
75 )
75 )
76 # bundle.reorder: experimental config
76 # bundle.reorder: experimental config
77 coreconfigitem('bundle', 'reorder',
77 coreconfigitem('bundle', 'reorder',
78 default='auto',
78 default='auto',
79 )
79 )
80 coreconfigitem('censor', 'policy',
80 coreconfigitem('censor', 'policy',
81 default='abort',
81 default='abort',
82 )
82 )
83 coreconfigitem('chgserver', 'idletimeout',
83 coreconfigitem('chgserver', 'idletimeout',
84 default=3600,
84 default=3600,
85 )
85 )
86 coreconfigitem('chgserver', 'skiphash',
86 coreconfigitem('chgserver', 'skiphash',
87 default=False,
87 default=False,
88 )
88 )
89 coreconfigitem('cmdserver', 'log',
89 coreconfigitem('cmdserver', 'log',
90 default=None,
90 default=None,
91 )
91 )
92 coreconfigitem('color', 'mode',
92 coreconfigitem('color', 'mode',
93 default='auto',
93 default='auto',
94 )
94 )
95 coreconfigitem('color', 'pagermode',
95 coreconfigitem('color', 'pagermode',
96 default=dynamicdefault,
96 default=dynamicdefault,
97 )
97 )
98 coreconfigitem('commands', 'status.relative',
98 coreconfigitem('commands', 'status.relative',
99 default=False,
99 default=False,
100 )
100 )
101 coreconfigitem('commands', 'status.skipstates',
101 coreconfigitem('commands', 'status.skipstates',
102 default=[],
102 default=[],
103 )
103 )
104 coreconfigitem('commands', 'status.verbose',
104 coreconfigitem('commands', 'status.verbose',
105 default=False,
105 default=False,
106 )
106 )
107 coreconfigitem('commands', 'update.requiredest',
107 coreconfigitem('commands', 'update.requiredest',
108 default=False,
108 default=False,
109 )
109 )
110 coreconfigitem('devel', 'all-warnings',
110 coreconfigitem('devel', 'all-warnings',
111 default=False,
111 default=False,
112 )
112 )
113 coreconfigitem('devel', 'bundle2.debug',
113 coreconfigitem('devel', 'bundle2.debug',
114 default=False,
114 default=False,
115 )
115 )
116 coreconfigitem('devel', 'check-locks',
116 coreconfigitem('devel', 'check-locks',
117 default=False,
117 default=False,
118 )
118 )
119 coreconfigitem('devel', 'check-relroot',
119 coreconfigitem('devel', 'check-relroot',
120 default=False,
120 default=False,
121 )
121 )
122 coreconfigitem('devel', 'default-date',
122 coreconfigitem('devel', 'default-date',
123 default=None,
123 default=None,
124 )
124 )
125 coreconfigitem('devel', 'deprec-warn',
125 coreconfigitem('devel', 'deprec-warn',
126 default=False,
126 default=False,
127 )
127 )
128 coreconfigitem('devel', 'disableloaddefaultcerts',
128 coreconfigitem('devel', 'disableloaddefaultcerts',
129 default=False,
129 default=False,
130 )
130 )
131 coreconfigitem('devel', 'legacy.exchange',
131 coreconfigitem('devel', 'legacy.exchange',
132 default=list,
132 default=list,
133 )
133 )
134 coreconfigitem('devel', 'servercafile',
134 coreconfigitem('devel', 'servercafile',
135 default='',
135 default='',
136 )
136 )
137 coreconfigitem('devel', 'serverexactprotocol',
137 coreconfigitem('devel', 'serverexactprotocol',
138 default='',
138 default='',
139 )
139 )
140 coreconfigitem('devel', 'serverrequirecert',
140 coreconfigitem('devel', 'serverrequirecert',
141 default=False,
141 default=False,
142 )
142 )
143 coreconfigitem('devel', 'strip-obsmarkers',
143 coreconfigitem('devel', 'strip-obsmarkers',
144 default=True,
144 default=True,
145 )
145 )
146 coreconfigitem('email', 'charsets',
146 coreconfigitem('email', 'charsets',
147 default=list,
147 default=list,
148 )
148 )
149 coreconfigitem('email', 'method',
149 coreconfigitem('email', 'method',
150 default='smtp',
150 default='smtp',
151 )
151 )
152 coreconfigitem('experimental', 'bundle-phases',
152 coreconfigitem('experimental', 'bundle-phases',
153 default=False,
153 default=False,
154 )
154 )
155 coreconfigitem('experimental', 'bundle2-advertise',
155 coreconfigitem('experimental', 'bundle2-advertise',
156 default=True,
156 default=True,
157 )
157 )
158 coreconfigitem('experimental', 'bundle2-output-capture',
158 coreconfigitem('experimental', 'bundle2-output-capture',
159 default=False,
159 default=False,
160 )
160 )
161 coreconfigitem('experimental', 'bundle2.pushback',
161 coreconfigitem('experimental', 'bundle2.pushback',
162 default=False,
162 default=False,
163 )
163 )
164 coreconfigitem('experimental', 'bundle2lazylocking',
164 coreconfigitem('experimental', 'bundle2lazylocking',
165 default=False,
165 default=False,
166 )
166 )
167 coreconfigitem('experimental', 'bundlecomplevel',
167 coreconfigitem('experimental', 'bundlecomplevel',
168 default=None,
168 default=None,
169 )
169 )
170 coreconfigitem('experimental', 'changegroup3',
170 coreconfigitem('experimental', 'changegroup3',
171 default=False,
171 default=False,
172 )
172 )
173 coreconfigitem('experimental', 'clientcompressionengines',
173 coreconfigitem('experimental', 'clientcompressionengines',
174 default=list,
174 default=list,
175 )
175 )
176 coreconfigitem('experimental', 'copytrace',
176 coreconfigitem('experimental', 'copytrace',
177 default='on',
177 default='on',
178 )
178 )
179 coreconfigitem('experimental', 'copytrace.sourcecommitlimit',
179 coreconfigitem('experimental', 'copytrace.sourcecommitlimit',
180 default=100,
180 default=100,
181 )
181 )
182 coreconfigitem('experimental', 'crecordtest',
182 coreconfigitem('experimental', 'crecordtest',
183 default=None,
183 default=None,
184 )
184 )
185 coreconfigitem('experimental', 'editortmpinhg',
185 coreconfigitem('experimental', 'editortmpinhg',
186 default=False,
186 default=False,
187 )
187 )
188 coreconfigitem('experimental', 'stabilization',
188 coreconfigitem('experimental', 'stabilization',
189 default=list,
189 default=list,
190 alias=[('experimental', 'evolution')],
190 alias=[('experimental', 'evolution')],
191 )
191 )
192 coreconfigitem('experimental', 'stabilization.bundle-obsmarker',
192 coreconfigitem('experimental', 'stabilization.bundle-obsmarker',
193 default=False,
193 default=False,
194 alias=[('experimental', 'evolution.bundle-obsmarker')],
194 alias=[('experimental', 'evolution.bundle-obsmarker')],
195 )
195 )
196 coreconfigitem('experimental', 'stabilization.track-operation',
196 coreconfigitem('experimental', 'stabilization.track-operation',
197 default=True,
197 default=True,
198 alias=[('experimental', 'evolution.track-operation')]
198 alias=[('experimental', 'evolution.track-operation')]
199 )
199 )
200 coreconfigitem('experimental', 'exportableenviron',
200 coreconfigitem('experimental', 'exportableenviron',
201 default=list,
201 default=list,
202 )
202 )
203 coreconfigitem('experimental', 'extendedheader.index',
203 coreconfigitem('experimental', 'extendedheader.index',
204 default=None,
204 default=None,
205 )
205 )
206 coreconfigitem('experimental', 'extendedheader.similarity',
206 coreconfigitem('experimental', 'extendedheader.similarity',
207 default=False,
207 default=False,
208 )
208 )
209 coreconfigitem('experimental', 'format.compression',
209 coreconfigitem('experimental', 'format.compression',
210 default='zlib',
210 default='zlib',
211 )
211 )
212 coreconfigitem('experimental', 'graphshorten',
212 coreconfigitem('experimental', 'graphshorten',
213 default=False,
213 default=False,
214 )
214 )
215 coreconfigitem('experimental', 'hook-track-tags',
215 coreconfigitem('experimental', 'hook-track-tags',
216 default=False,
216 default=False,
217 )
217 )
218 coreconfigitem('experimental', 'httppostargs',
218 coreconfigitem('experimental', 'httppostargs',
219 default=False,
219 default=False,
220 )
220 )
221 coreconfigitem('experimental', 'manifestv2',
221 coreconfigitem('experimental', 'manifestv2',
222 default=False,
222 default=False,
223 )
223 )
224 coreconfigitem('experimental', 'mergedriver',
224 coreconfigitem('experimental', 'mergedriver',
225 default=None,
225 default=None,
226 )
226 )
227 coreconfigitem('experimental', 'obsmarkers-exchange-debug',
227 coreconfigitem('experimental', 'obsmarkers-exchange-debug',
228 default=False,
228 default=False,
229 )
229 )
230 coreconfigitem('experimental', 'rebase.multidest',
230 coreconfigitem('experimental', 'rebase.multidest',
231 default=False,
231 default=False,
232 )
232 )
233 coreconfigitem('experimental', 'revertalternateinteractivemode',
233 coreconfigitem('experimental', 'revertalternateinteractivemode',
234 default=True,
234 default=True,
235 )
235 )
236 coreconfigitem('experimental', 'revlogv2',
236 coreconfigitem('experimental', 'revlogv2',
237 default=None,
237 default=None,
238 )
238 )
239 coreconfigitem('experimental', 'spacemovesdown',
239 coreconfigitem('experimental', 'spacemovesdown',
240 default=False,
240 default=False,
241 )
241 )
242 coreconfigitem('experimental', 'treemanifest',
242 coreconfigitem('experimental', 'treemanifest',
243 default=False,
243 default=False,
244 )
244 )
245 coreconfigitem('experimental', 'updatecheck',
245 coreconfigitem('experimental', 'updatecheck',
246 default=None,
246 default=None,
247 )
247 )
248 coreconfigitem('format', 'aggressivemergedeltas',
248 coreconfigitem('format', 'aggressivemergedeltas',
249 default=False,
249 default=False,
250 )
250 )
251 coreconfigitem('format', 'chunkcachesize',
251 coreconfigitem('format', 'chunkcachesize',
252 default=None,
252 default=None,
253 )
253 )
254 coreconfigitem('format', 'dotencode',
254 coreconfigitem('format', 'dotencode',
255 default=True,
255 default=True,
256 )
256 )
257 coreconfigitem('format', 'generaldelta',
257 coreconfigitem('format', 'generaldelta',
258 default=False,
258 default=False,
259 )
259 )
260 coreconfigitem('format', 'manifestcachesize',
260 coreconfigitem('format', 'manifestcachesize',
261 default=None,
261 default=None,
262 )
262 )
263 coreconfigitem('format', 'maxchainlen',
263 coreconfigitem('format', 'maxchainlen',
264 default=None,
264 default=None,
265 )
265 )
266 coreconfigitem('format', 'obsstore-version',
266 coreconfigitem('format', 'obsstore-version',
267 default=None,
267 default=None,
268 )
268 )
269 coreconfigitem('format', 'usefncache',
269 coreconfigitem('format', 'usefncache',
270 default=True,
270 default=True,
271 )
271 )
272 coreconfigitem('format', 'usegeneraldelta',
272 coreconfigitem('format', 'usegeneraldelta',
273 default=True,
273 default=True,
274 )
274 )
275 coreconfigitem('format', 'usestore',
275 coreconfigitem('format', 'usestore',
276 default=True,
276 default=True,
277 )
277 )
278 coreconfigitem('hostsecurity', 'ciphers',
278 coreconfigitem('hostsecurity', 'ciphers',
279 default=None,
279 default=None,
280 )
280 )
281 coreconfigitem('hostsecurity', 'disabletls10warning',
281 coreconfigitem('hostsecurity', 'disabletls10warning',
282 default=False,
282 default=False,
283 )
283 )
284 coreconfigitem('http_proxy', 'always',
284 coreconfigitem('http_proxy', 'always',
285 default=False,
285 default=False,
286 )
286 )
287 coreconfigitem('http_proxy', 'host',
287 coreconfigitem('http_proxy', 'host',
288 default=None,
288 default=None,
289 )
289 )
290 coreconfigitem('http_proxy', 'no',
290 coreconfigitem('http_proxy', 'no',
291 default=list,
291 default=list,
292 )
292 )
293 coreconfigitem('http_proxy', 'passwd',
293 coreconfigitem('http_proxy', 'passwd',
294 default=None,
294 default=None,
295 )
295 )
296 coreconfigitem('http_proxy', 'user',
296 coreconfigitem('http_proxy', 'user',
297 default=None,
297 default=None,
298 )
298 )
299 coreconfigitem('merge', 'followcopies',
299 coreconfigitem('merge', 'followcopies',
300 default=True,
300 default=True,
301 )
301 )
302 coreconfigitem('pager', 'ignore',
302 coreconfigitem('pager', 'ignore',
303 default=list,
303 default=list,
304 )
304 )
305 coreconfigitem('patch', 'eol',
305 coreconfigitem('patch', 'eol',
306 default='strict',
306 default='strict',
307 )
307 )
308 coreconfigitem('patch', 'fuzz',
308 coreconfigitem('patch', 'fuzz',
309 default=2,
309 default=2,
310 )
310 )
311 coreconfigitem('paths', 'default',
311 coreconfigitem('paths', 'default',
312 default=None,
312 default=None,
313 )
313 )
314 coreconfigitem('paths', 'default-push',
314 coreconfigitem('paths', 'default-push',
315 default=None,
315 default=None,
316 )
316 )
317 coreconfigitem('phases', 'checksubrepos',
317 coreconfigitem('phases', 'checksubrepos',
318 default='follow',
318 default='follow',
319 )
319 )
320 coreconfigitem('phases', 'publish',
320 coreconfigitem('phases', 'publish',
321 default=True,
321 default=True,
322 )
322 )
323 coreconfigitem('profiling', 'enabled',
323 coreconfigitem('profiling', 'enabled',
324 default=False,
324 default=False,
325 )
325 )
326 coreconfigitem('profiling', 'format',
326 coreconfigitem('profiling', 'format',
327 default='text',
327 default='text',
328 )
328 )
329 coreconfigitem('profiling', 'freq',
329 coreconfigitem('profiling', 'freq',
330 default=1000,
330 default=1000,
331 )
331 )
332 coreconfigitem('profiling', 'limit',
332 coreconfigitem('profiling', 'limit',
333 default=30,
333 default=30,
334 )
334 )
335 coreconfigitem('profiling', 'nested',
335 coreconfigitem('profiling', 'nested',
336 default=0,
336 default=0,
337 )
337 )
338 coreconfigitem('profiling', 'output',
338 coreconfigitem('profiling', 'output',
339 default=None,
339 default=None,
340 )
340 )
341 coreconfigitem('profiling', 'showmax',
342 default=0.999,
343 )
341 coreconfigitem('profiling', 'sort',
344 coreconfigitem('profiling', 'sort',
342 default='inlinetime',
345 default='inlinetime',
343 )
346 )
344 coreconfigitem('profiling', 'statformat',
347 coreconfigitem('profiling', 'statformat',
345 default='hotpath',
348 default='hotpath',
346 )
349 )
347 coreconfigitem('progress', 'assume-tty',
350 coreconfigitem('progress', 'assume-tty',
348 default=False,
351 default=False,
349 )
352 )
350 coreconfigitem('progress', 'changedelay',
353 coreconfigitem('progress', 'changedelay',
351 default=1,
354 default=1,
352 )
355 )
353 coreconfigitem('progress', 'clear-complete',
356 coreconfigitem('progress', 'clear-complete',
354 default=True,
357 default=True,
355 )
358 )
356 coreconfigitem('progress', 'debug',
359 coreconfigitem('progress', 'debug',
357 default=False,
360 default=False,
358 )
361 )
359 coreconfigitem('progress', 'delay',
362 coreconfigitem('progress', 'delay',
360 default=3,
363 default=3,
361 )
364 )
362 coreconfigitem('progress', 'disable',
365 coreconfigitem('progress', 'disable',
363 default=False,
366 default=False,
364 )
367 )
365 coreconfigitem('progress', 'estimateinterval',
368 coreconfigitem('progress', 'estimateinterval',
366 default=60.0,
369 default=60.0,
367 )
370 )
368 coreconfigitem('progress', 'refresh',
371 coreconfigitem('progress', 'refresh',
369 default=0.1,
372 default=0.1,
370 )
373 )
371 coreconfigitem('progress', 'width',
374 coreconfigitem('progress', 'width',
372 default=dynamicdefault,
375 default=dynamicdefault,
373 )
376 )
374 coreconfigitem('push', 'pushvars.server',
377 coreconfigitem('push', 'pushvars.server',
375 default=False,
378 default=False,
376 )
379 )
377 coreconfigitem('server', 'bundle1',
380 coreconfigitem('server', 'bundle1',
378 default=True,
381 default=True,
379 )
382 )
380 coreconfigitem('server', 'bundle1gd',
383 coreconfigitem('server', 'bundle1gd',
381 default=None,
384 default=None,
382 )
385 )
383 coreconfigitem('server', 'compressionengines',
386 coreconfigitem('server', 'compressionengines',
384 default=list,
387 default=list,
385 )
388 )
386 coreconfigitem('server', 'concurrent-push-mode',
389 coreconfigitem('server', 'concurrent-push-mode',
387 default='strict',
390 default='strict',
388 )
391 )
389 coreconfigitem('server', 'disablefullbundle',
392 coreconfigitem('server', 'disablefullbundle',
390 default=False,
393 default=False,
391 )
394 )
392 coreconfigitem('server', 'maxhttpheaderlen',
395 coreconfigitem('server', 'maxhttpheaderlen',
393 default=1024,
396 default=1024,
394 )
397 )
395 coreconfigitem('server', 'preferuncompressed',
398 coreconfigitem('server', 'preferuncompressed',
396 default=False,
399 default=False,
397 )
400 )
398 coreconfigitem('server', 'uncompressed',
401 coreconfigitem('server', 'uncompressed',
399 default=True,
402 default=True,
400 )
403 )
401 coreconfigitem('server', 'uncompressedallowsecret',
404 coreconfigitem('server', 'uncompressedallowsecret',
402 default=False,
405 default=False,
403 )
406 )
404 coreconfigitem('server', 'validate',
407 coreconfigitem('server', 'validate',
405 default=False,
408 default=False,
406 )
409 )
407 coreconfigitem('server', 'zliblevel',
410 coreconfigitem('server', 'zliblevel',
408 default=-1,
411 default=-1,
409 )
412 )
410 coreconfigitem('smtp', 'host',
413 coreconfigitem('smtp', 'host',
411 default=None,
414 default=None,
412 )
415 )
413 coreconfigitem('smtp', 'local_hostname',
416 coreconfigitem('smtp', 'local_hostname',
414 default=None,
417 default=None,
415 )
418 )
416 coreconfigitem('smtp', 'password',
419 coreconfigitem('smtp', 'password',
417 default=None,
420 default=None,
418 )
421 )
419 coreconfigitem('smtp', 'tls',
422 coreconfigitem('smtp', 'tls',
420 default='none',
423 default='none',
421 )
424 )
422 coreconfigitem('smtp', 'username',
425 coreconfigitem('smtp', 'username',
423 default=None,
426 default=None,
424 )
427 )
425 coreconfigitem('sparse', 'missingwarning',
428 coreconfigitem('sparse', 'missingwarning',
426 default=True,
429 default=True,
427 )
430 )
428 coreconfigitem('trusted', 'groups',
431 coreconfigitem('trusted', 'groups',
429 default=list,
432 default=list,
430 )
433 )
431 coreconfigitem('trusted', 'users',
434 coreconfigitem('trusted', 'users',
432 default=list,
435 default=list,
433 )
436 )
434 coreconfigitem('ui', '_usedassubrepo',
437 coreconfigitem('ui', '_usedassubrepo',
435 default=False,
438 default=False,
436 )
439 )
437 coreconfigitem('ui', 'allowemptycommit',
440 coreconfigitem('ui', 'allowemptycommit',
438 default=False,
441 default=False,
439 )
442 )
440 coreconfigitem('ui', 'archivemeta',
443 coreconfigitem('ui', 'archivemeta',
441 default=True,
444 default=True,
442 )
445 )
443 coreconfigitem('ui', 'askusername',
446 coreconfigitem('ui', 'askusername',
444 default=False,
447 default=False,
445 )
448 )
446 coreconfigitem('ui', 'clonebundlefallback',
449 coreconfigitem('ui', 'clonebundlefallback',
447 default=False,
450 default=False,
448 )
451 )
449 coreconfigitem('ui', 'clonebundleprefers',
452 coreconfigitem('ui', 'clonebundleprefers',
450 default=list,
453 default=list,
451 )
454 )
452 coreconfigitem('ui', 'clonebundles',
455 coreconfigitem('ui', 'clonebundles',
453 default=True,
456 default=True,
454 )
457 )
455 coreconfigitem('ui', 'color',
458 coreconfigitem('ui', 'color',
456 default='auto',
459 default='auto',
457 )
460 )
458 coreconfigitem('ui', 'commitsubrepos',
461 coreconfigitem('ui', 'commitsubrepos',
459 default=False,
462 default=False,
460 )
463 )
461 coreconfigitem('ui', 'debug',
464 coreconfigitem('ui', 'debug',
462 default=False,
465 default=False,
463 )
466 )
464 coreconfigitem('ui', 'debugger',
467 coreconfigitem('ui', 'debugger',
465 default=None,
468 default=None,
466 )
469 )
467 coreconfigitem('ui', 'fallbackencoding',
470 coreconfigitem('ui', 'fallbackencoding',
468 default=None,
471 default=None,
469 )
472 )
470 coreconfigitem('ui', 'forcecwd',
473 coreconfigitem('ui', 'forcecwd',
471 default=None,
474 default=None,
472 )
475 )
473 coreconfigitem('ui', 'forcemerge',
476 coreconfigitem('ui', 'forcemerge',
474 default=None,
477 default=None,
475 )
478 )
476 coreconfigitem('ui', 'formatdebug',
479 coreconfigitem('ui', 'formatdebug',
477 default=False,
480 default=False,
478 )
481 )
479 coreconfigitem('ui', 'formatjson',
482 coreconfigitem('ui', 'formatjson',
480 default=False,
483 default=False,
481 )
484 )
482 coreconfigitem('ui', 'formatted',
485 coreconfigitem('ui', 'formatted',
483 default=None,
486 default=None,
484 )
487 )
485 coreconfigitem('ui', 'graphnodetemplate',
488 coreconfigitem('ui', 'graphnodetemplate',
486 default=None,
489 default=None,
487 )
490 )
488 coreconfigitem('ui', 'http2debuglevel',
491 coreconfigitem('ui', 'http2debuglevel',
489 default=None,
492 default=None,
490 )
493 )
491 coreconfigitem('ui', 'interactive',
494 coreconfigitem('ui', 'interactive',
492 default=None,
495 default=None,
493 )
496 )
494 coreconfigitem('ui', 'interface',
497 coreconfigitem('ui', 'interface',
495 default=None,
498 default=None,
496 )
499 )
497 coreconfigitem('ui', 'logblockedtimes',
500 coreconfigitem('ui', 'logblockedtimes',
498 default=False,
501 default=False,
499 )
502 )
500 coreconfigitem('ui', 'logtemplate',
503 coreconfigitem('ui', 'logtemplate',
501 default=None,
504 default=None,
502 )
505 )
503 coreconfigitem('ui', 'merge',
506 coreconfigitem('ui', 'merge',
504 default=None,
507 default=None,
505 )
508 )
506 coreconfigitem('ui', 'mergemarkers',
509 coreconfigitem('ui', 'mergemarkers',
507 default='basic',
510 default='basic',
508 )
511 )
509 coreconfigitem('ui', 'mergemarkertemplate',
512 coreconfigitem('ui', 'mergemarkertemplate',
510 default=('{node|short} '
513 default=('{node|short} '
511 '{ifeq(tags, "tip", "", '
514 '{ifeq(tags, "tip", "", '
512 'ifeq(tags, "", "", "{tags} "))}'
515 'ifeq(tags, "", "", "{tags} "))}'
513 '{if(bookmarks, "{bookmarks} ")}'
516 '{if(bookmarks, "{bookmarks} ")}'
514 '{ifeq(branch, "default", "", "{branch} ")}'
517 '{ifeq(branch, "default", "", "{branch} ")}'
515 '- {author|user}: {desc|firstline}')
518 '- {author|user}: {desc|firstline}')
516 )
519 )
517 coreconfigitem('ui', 'nontty',
520 coreconfigitem('ui', 'nontty',
518 default=False,
521 default=False,
519 )
522 )
520 coreconfigitem('ui', 'origbackuppath',
523 coreconfigitem('ui', 'origbackuppath',
521 default=None,
524 default=None,
522 )
525 )
523 coreconfigitem('ui', 'paginate',
526 coreconfigitem('ui', 'paginate',
524 default=True,
527 default=True,
525 )
528 )
526 coreconfigitem('ui', 'patch',
529 coreconfigitem('ui', 'patch',
527 default=None,
530 default=None,
528 )
531 )
529 coreconfigitem('ui', 'portablefilenames',
532 coreconfigitem('ui', 'portablefilenames',
530 default='warn',
533 default='warn',
531 )
534 )
532 coreconfigitem('ui', 'promptecho',
535 coreconfigitem('ui', 'promptecho',
533 default=False,
536 default=False,
534 )
537 )
535 coreconfigitem('ui', 'quiet',
538 coreconfigitem('ui', 'quiet',
536 default=False,
539 default=False,
537 )
540 )
538 coreconfigitem('ui', 'quietbookmarkmove',
541 coreconfigitem('ui', 'quietbookmarkmove',
539 default=False,
542 default=False,
540 )
543 )
541 coreconfigitem('ui', 'remotecmd',
544 coreconfigitem('ui', 'remotecmd',
542 default='hg',
545 default='hg',
543 )
546 )
544 coreconfigitem('ui', 'report_untrusted',
547 coreconfigitem('ui', 'report_untrusted',
545 default=True,
548 default=True,
546 )
549 )
547 coreconfigitem('ui', 'rollback',
550 coreconfigitem('ui', 'rollback',
548 default=True,
551 default=True,
549 )
552 )
550 coreconfigitem('ui', 'slash',
553 coreconfigitem('ui', 'slash',
551 default=False,
554 default=False,
552 )
555 )
553 coreconfigitem('ui', 'ssh',
556 coreconfigitem('ui', 'ssh',
554 default='ssh',
557 default='ssh',
555 )
558 )
556 coreconfigitem('ui', 'statuscopies',
559 coreconfigitem('ui', 'statuscopies',
557 default=False,
560 default=False,
558 )
561 )
559 coreconfigitem('ui', 'strict',
562 coreconfigitem('ui', 'strict',
560 default=False,
563 default=False,
561 )
564 )
562 coreconfigitem('ui', 'style',
565 coreconfigitem('ui', 'style',
563 default='',
566 default='',
564 )
567 )
565 coreconfigitem('ui', 'supportcontact',
568 coreconfigitem('ui', 'supportcontact',
566 default=None,
569 default=None,
567 )
570 )
568 coreconfigitem('ui', 'textwidth',
571 coreconfigitem('ui', 'textwidth',
569 default=78,
572 default=78,
570 )
573 )
571 coreconfigitem('ui', 'timeout',
574 coreconfigitem('ui', 'timeout',
572 default='600',
575 default='600',
573 )
576 )
574 coreconfigitem('ui', 'traceback',
577 coreconfigitem('ui', 'traceback',
575 default=False,
578 default=False,
576 )
579 )
577 coreconfigitem('ui', 'tweakdefaults',
580 coreconfigitem('ui', 'tweakdefaults',
578 default=False,
581 default=False,
579 )
582 )
580 coreconfigitem('ui', 'usehttp2',
583 coreconfigitem('ui', 'usehttp2',
581 default=False,
584 default=False,
582 )
585 )
583 coreconfigitem('ui', 'username',
586 coreconfigitem('ui', 'username',
584 alias=[('ui', 'user')]
587 alias=[('ui', 'user')]
585 )
588 )
586 coreconfigitem('ui', 'verbose',
589 coreconfigitem('ui', 'verbose',
587 default=False,
590 default=False,
588 )
591 )
589 coreconfigitem('verify', 'skipflags',
592 coreconfigitem('verify', 'skipflags',
590 default=None,
593 default=None,
591 )
594 )
592 coreconfigitem('web', 'accesslog',
595 coreconfigitem('web', 'accesslog',
593 default='-',
596 default='-',
594 )
597 )
595 coreconfigitem('web', 'address',
598 coreconfigitem('web', 'address',
596 default='',
599 default='',
597 )
600 )
598 coreconfigitem('web', 'allow_archive',
601 coreconfigitem('web', 'allow_archive',
599 default=list,
602 default=list,
600 )
603 )
601 coreconfigitem('web', 'allow_read',
604 coreconfigitem('web', 'allow_read',
602 default=list,
605 default=list,
603 )
606 )
604 coreconfigitem('web', 'baseurl',
607 coreconfigitem('web', 'baseurl',
605 default=None,
608 default=None,
606 )
609 )
607 coreconfigitem('web', 'cacerts',
610 coreconfigitem('web', 'cacerts',
608 default=None,
611 default=None,
609 )
612 )
610 coreconfigitem('web', 'certificate',
613 coreconfigitem('web', 'certificate',
611 default=None,
614 default=None,
612 )
615 )
613 coreconfigitem('web', 'collapse',
616 coreconfigitem('web', 'collapse',
614 default=False,
617 default=False,
615 )
618 )
616 coreconfigitem('web', 'csp',
619 coreconfigitem('web', 'csp',
617 default=None,
620 default=None,
618 )
621 )
619 coreconfigitem('web', 'deny_read',
622 coreconfigitem('web', 'deny_read',
620 default=list,
623 default=list,
621 )
624 )
622 coreconfigitem('web', 'descend',
625 coreconfigitem('web', 'descend',
623 default=True,
626 default=True,
624 )
627 )
625 coreconfigitem('web', 'description',
628 coreconfigitem('web', 'description',
626 default="",
629 default="",
627 )
630 )
628 coreconfigitem('web', 'encoding',
631 coreconfigitem('web', 'encoding',
629 default=lambda: encoding.encoding,
632 default=lambda: encoding.encoding,
630 )
633 )
631 coreconfigitem('web', 'errorlog',
634 coreconfigitem('web', 'errorlog',
632 default='-',
635 default='-',
633 )
636 )
634 coreconfigitem('web', 'ipv6',
637 coreconfigitem('web', 'ipv6',
635 default=False,
638 default=False,
636 )
639 )
637 coreconfigitem('web', 'port',
640 coreconfigitem('web', 'port',
638 default=8000,
641 default=8000,
639 )
642 )
640 coreconfigitem('web', 'prefix',
643 coreconfigitem('web', 'prefix',
641 default='',
644 default='',
642 )
645 )
643 coreconfigitem('web', 'refreshinterval',
646 coreconfigitem('web', 'refreshinterval',
644 default=20,
647 default=20,
645 )
648 )
646 coreconfigitem('web', 'stripes',
649 coreconfigitem('web', 'stripes',
647 default=1,
650 default=1,
648 )
651 )
649 coreconfigitem('web', 'style',
652 coreconfigitem('web', 'style',
650 default='paper',
653 default='paper',
651 )
654 )
652 coreconfigitem('web', 'templates',
655 coreconfigitem('web', 'templates',
653 default=None,
656 default=None,
654 )
657 )
655 coreconfigitem('worker', 'backgroundclose',
658 coreconfigitem('worker', 'backgroundclose',
656 default=dynamicdefault,
659 default=dynamicdefault,
657 )
660 )
658 # Windows defaults to a limit of 512 open files. A buffer of 128
661 # Windows defaults to a limit of 512 open files. A buffer of 128
659 # should give us enough headway.
662 # should give us enough headway.
660 coreconfigitem('worker', 'backgroundclosemaxqueue',
663 coreconfigitem('worker', 'backgroundclosemaxqueue',
661 default=384,
664 default=384,
662 )
665 )
663 coreconfigitem('worker', 'backgroundcloseminfilecount',
666 coreconfigitem('worker', 'backgroundcloseminfilecount',
664 default=2048,
667 default=2048,
665 )
668 )
666 coreconfigitem('worker', 'backgroundclosethreadcount',
669 coreconfigitem('worker', 'backgroundclosethreadcount',
667 default=4,
670 default=4,
668 )
671 )
669 coreconfigitem('worker', 'numcpus',
672 coreconfigitem('worker', 'numcpus',
670 default=None,
673 default=None,
671 )
674 )
@@ -1,238 +1,238
1 # profiling.py - profiling functions
1 # profiling.py - profiling functions
2 #
2 #
3 # Copyright 2016 Gregory Szorc <gregory.szorc@gmail.com>
3 # Copyright 2016 Gregory Szorc <gregory.szorc@gmail.com>
4 #
4 #
5 # This software may be used and distributed according to the terms of the
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version.
6 # GNU General Public License version 2 or any later version.
7
7
8 from __future__ import absolute_import, print_function
8 from __future__ import absolute_import, print_function
9
9
10 import contextlib
10 import contextlib
11
11
12 from .i18n import _
12 from .i18n import _
13 from . import (
13 from . import (
14 encoding,
14 encoding,
15 error,
15 error,
16 extensions,
16 extensions,
17 util,
17 util,
18 )
18 )
19
19
20 def _loadprofiler(ui, profiler):
20 def _loadprofiler(ui, profiler):
21 """load profiler extension. return profile method, or None on failure"""
21 """load profiler extension. return profile method, or None on failure"""
22 extname = profiler
22 extname = profiler
23 extensions.loadall(ui, whitelist=[extname])
23 extensions.loadall(ui, whitelist=[extname])
24 try:
24 try:
25 mod = extensions.find(extname)
25 mod = extensions.find(extname)
26 except KeyError:
26 except KeyError:
27 return None
27 return None
28 else:
28 else:
29 return getattr(mod, 'profile', None)
29 return getattr(mod, 'profile', None)
30
30
31 @contextlib.contextmanager
31 @contextlib.contextmanager
32 def lsprofile(ui, fp):
32 def lsprofile(ui, fp):
33 format = ui.config('profiling', 'format')
33 format = ui.config('profiling', 'format')
34 field = ui.config('profiling', 'sort')
34 field = ui.config('profiling', 'sort')
35 limit = ui.configint('profiling', 'limit')
35 limit = ui.configint('profiling', 'limit')
36 climit = ui.configint('profiling', 'nested')
36 climit = ui.configint('profiling', 'nested')
37
37
38 if format not in ['text', 'kcachegrind']:
38 if format not in ['text', 'kcachegrind']:
39 ui.warn(_("unrecognized profiling format '%s'"
39 ui.warn(_("unrecognized profiling format '%s'"
40 " - Ignored\n") % format)
40 " - Ignored\n") % format)
41 format = 'text'
41 format = 'text'
42
42
43 try:
43 try:
44 from . import lsprof
44 from . import lsprof
45 except ImportError:
45 except ImportError:
46 raise error.Abort(_(
46 raise error.Abort(_(
47 'lsprof not available - install from '
47 'lsprof not available - install from '
48 'http://codespeak.net/svn/user/arigo/hack/misc/lsprof/'))
48 'http://codespeak.net/svn/user/arigo/hack/misc/lsprof/'))
49 p = lsprof.Profiler()
49 p = lsprof.Profiler()
50 p.enable(subcalls=True)
50 p.enable(subcalls=True)
51 try:
51 try:
52 yield
52 yield
53 finally:
53 finally:
54 p.disable()
54 p.disable()
55
55
56 if format == 'kcachegrind':
56 if format == 'kcachegrind':
57 from . import lsprofcalltree
57 from . import lsprofcalltree
58 calltree = lsprofcalltree.KCacheGrind(p)
58 calltree = lsprofcalltree.KCacheGrind(p)
59 calltree.output(fp)
59 calltree.output(fp)
60 else:
60 else:
61 # format == 'text'
61 # format == 'text'
62 stats = lsprof.Stats(p.getstats())
62 stats = lsprof.Stats(p.getstats())
63 stats.sort(field)
63 stats.sort(field)
64 stats.pprint(limit=limit, file=fp, climit=climit)
64 stats.pprint(limit=limit, file=fp, climit=climit)
65
65
66 @contextlib.contextmanager
66 @contextlib.contextmanager
67 def flameprofile(ui, fp):
67 def flameprofile(ui, fp):
68 try:
68 try:
69 from flamegraph import flamegraph
69 from flamegraph import flamegraph
70 except ImportError:
70 except ImportError:
71 raise error.Abort(_(
71 raise error.Abort(_(
72 'flamegraph not available - install from '
72 'flamegraph not available - install from '
73 'https://github.com/evanhempel/python-flamegraph'))
73 'https://github.com/evanhempel/python-flamegraph'))
74 # developer config: profiling.freq
74 # developer config: profiling.freq
75 freq = ui.configint('profiling', 'freq')
75 freq = ui.configint('profiling', 'freq')
76 filter_ = None
76 filter_ = None
77 collapse_recursion = True
77 collapse_recursion = True
78 thread = flamegraph.ProfileThread(fp, 1.0 / freq,
78 thread = flamegraph.ProfileThread(fp, 1.0 / freq,
79 filter_, collapse_recursion)
79 filter_, collapse_recursion)
80 start_time = util.timer()
80 start_time = util.timer()
81 try:
81 try:
82 thread.start()
82 thread.start()
83 yield
83 yield
84 finally:
84 finally:
85 thread.stop()
85 thread.stop()
86 thread.join()
86 thread.join()
87 print('Collected %d stack frames (%d unique) in %2.2f seconds.' % (
87 print('Collected %d stack frames (%d unique) in %2.2f seconds.' % (
88 util.timer() - start_time, thread.num_frames(),
88 util.timer() - start_time, thread.num_frames(),
89 thread.num_frames(unique=True)))
89 thread.num_frames(unique=True)))
90
90
91 @contextlib.contextmanager
91 @contextlib.contextmanager
92 def statprofile(ui, fp):
92 def statprofile(ui, fp):
93 from . import statprof
93 from . import statprof
94
94
95 freq = ui.configint('profiling', 'freq')
95 freq = ui.configint('profiling', 'freq')
96 if freq > 0:
96 if freq > 0:
97 # Cannot reset when profiler is already active. So silently no-op.
97 # Cannot reset when profiler is already active. So silently no-op.
98 if statprof.state.profile_level == 0:
98 if statprof.state.profile_level == 0:
99 statprof.reset(freq)
99 statprof.reset(freq)
100 else:
100 else:
101 ui.warn(_("invalid sampling frequency '%s' - ignoring\n") % freq)
101 ui.warn(_("invalid sampling frequency '%s' - ignoring\n") % freq)
102
102
103 statprof.start(mechanism='thread')
103 statprof.start(mechanism='thread')
104
104
105 try:
105 try:
106 yield
106 yield
107 finally:
107 finally:
108 data = statprof.stop()
108 data = statprof.stop()
109
109
110 profformat = ui.config('profiling', 'statformat')
110 profformat = ui.config('profiling', 'statformat')
111
111
112 formats = {
112 formats = {
113 'byline': statprof.DisplayFormats.ByLine,
113 'byline': statprof.DisplayFormats.ByLine,
114 'bymethod': statprof.DisplayFormats.ByMethod,
114 'bymethod': statprof.DisplayFormats.ByMethod,
115 'hotpath': statprof.DisplayFormats.Hotpath,
115 'hotpath': statprof.DisplayFormats.Hotpath,
116 'json': statprof.DisplayFormats.Json,
116 'json': statprof.DisplayFormats.Json,
117 'chrome': statprof.DisplayFormats.Chrome,
117 'chrome': statprof.DisplayFormats.Chrome,
118 }
118 }
119
119
120 if profformat in formats:
120 if profformat in formats:
121 displayformat = formats[profformat]
121 displayformat = formats[profformat]
122 else:
122 else:
123 ui.warn(_('unknown profiler output format: %s\n') % profformat)
123 ui.warn(_('unknown profiler output format: %s\n') % profformat)
124 displayformat = statprof.DisplayFormats.Hotpath
124 displayformat = statprof.DisplayFormats.Hotpath
125
125
126 kwargs = {}
126 kwargs = {}
127
127
128 def fraction(s):
128 def fraction(s):
129 if isinstance(s, (float, int)):
129 if isinstance(s, (float, int)):
130 return float(s)
130 return float(s)
131 if s.endswith('%'):
131 if s.endswith('%'):
132 v = float(s[:-1]) / 100
132 v = float(s[:-1]) / 100
133 else:
133 else:
134 v = float(s)
134 v = float(s)
135 if 0 <= v <= 1:
135 if 0 <= v <= 1:
136 return v
136 return v
137 raise ValueError(s)
137 raise ValueError(s)
138
138
139 if profformat == 'chrome':
139 if profformat == 'chrome':
140 showmin = ui.configwith(fraction, 'profiling', 'showmin', 0.005)
140 showmin = ui.configwith(fraction, 'profiling', 'showmin', 0.005)
141 showmax = ui.configwith(fraction, 'profiling', 'showmax', 0.999)
141 showmax = ui.configwith(fraction, 'profiling', 'showmax')
142 kwargs.update(minthreshold=showmin, maxthreshold=showmax)
142 kwargs.update(minthreshold=showmin, maxthreshold=showmax)
143 elif profformat == 'hotpath':
143 elif profformat == 'hotpath':
144 # inconsistent config: profiling.showmin
144 # inconsistent config: profiling.showmin
145 limit = ui.configwith(fraction, 'profiling', 'showmin', 0.05)
145 limit = ui.configwith(fraction, 'profiling', 'showmin', 0.05)
146 kwargs['limit'] = limit
146 kwargs['limit'] = limit
147
147
148 statprof.display(fp, data=data, format=displayformat, **kwargs)
148 statprof.display(fp, data=data, format=displayformat, **kwargs)
149
149
150 class profile(object):
150 class profile(object):
151 """Start profiling.
151 """Start profiling.
152
152
153 Profiling is active when the context manager is active. When the context
153 Profiling is active when the context manager is active. When the context
154 manager exits, profiling results will be written to the configured output.
154 manager exits, profiling results will be written to the configured output.
155 """
155 """
156 def __init__(self, ui, enabled=True):
156 def __init__(self, ui, enabled=True):
157 self._ui = ui
157 self._ui = ui
158 self._output = None
158 self._output = None
159 self._fp = None
159 self._fp = None
160 self._fpdoclose = True
160 self._fpdoclose = True
161 self._profiler = None
161 self._profiler = None
162 self._enabled = enabled
162 self._enabled = enabled
163 self._entered = False
163 self._entered = False
164 self._started = False
164 self._started = False
165
165
166 def __enter__(self):
166 def __enter__(self):
167 self._entered = True
167 self._entered = True
168 if self._enabled:
168 if self._enabled:
169 self.start()
169 self.start()
170 return self
170 return self
171
171
172 def start(self):
172 def start(self):
173 """Start profiling.
173 """Start profiling.
174
174
175 The profiling will stop at the context exit.
175 The profiling will stop at the context exit.
176
176
177 If the profiler was already started, this has no effect."""
177 If the profiler was already started, this has no effect."""
178 if not self._entered:
178 if not self._entered:
179 raise error.ProgrammingError()
179 raise error.ProgrammingError()
180 if self._started:
180 if self._started:
181 return
181 return
182 self._started = True
182 self._started = True
183 profiler = encoding.environ.get('HGPROF')
183 profiler = encoding.environ.get('HGPROF')
184 proffn = None
184 proffn = None
185 if profiler is None:
185 if profiler is None:
186 profiler = self._ui.config('profiling', 'type', default='stat')
186 profiler = self._ui.config('profiling', 'type', default='stat')
187 if profiler not in ('ls', 'stat', 'flame'):
187 if profiler not in ('ls', 'stat', 'flame'):
188 # try load profiler from extension with the same name
188 # try load profiler from extension with the same name
189 proffn = _loadprofiler(self._ui, profiler)
189 proffn = _loadprofiler(self._ui, profiler)
190 if proffn is None:
190 if proffn is None:
191 self._ui.warn(_("unrecognized profiler '%s' - ignored\n")
191 self._ui.warn(_("unrecognized profiler '%s' - ignored\n")
192 % profiler)
192 % profiler)
193 profiler = 'stat'
193 profiler = 'stat'
194
194
195 self._output = self._ui.config('profiling', 'output')
195 self._output = self._ui.config('profiling', 'output')
196
196
197 try:
197 try:
198 if self._output == 'blackbox':
198 if self._output == 'blackbox':
199 self._fp = util.stringio()
199 self._fp = util.stringio()
200 elif self._output:
200 elif self._output:
201 path = self._ui.expandpath(self._output)
201 path = self._ui.expandpath(self._output)
202 self._fp = open(path, 'wb')
202 self._fp = open(path, 'wb')
203 else:
203 else:
204 self._fpdoclose = False
204 self._fpdoclose = False
205 self._fp = self._ui.ferr
205 self._fp = self._ui.ferr
206
206
207 if proffn is not None:
207 if proffn is not None:
208 pass
208 pass
209 elif profiler == 'ls':
209 elif profiler == 'ls':
210 proffn = lsprofile
210 proffn = lsprofile
211 elif profiler == 'flame':
211 elif profiler == 'flame':
212 proffn = flameprofile
212 proffn = flameprofile
213 else:
213 else:
214 proffn = statprofile
214 proffn = statprofile
215
215
216 self._profiler = proffn(self._ui, self._fp)
216 self._profiler = proffn(self._ui, self._fp)
217 self._profiler.__enter__()
217 self._profiler.__enter__()
218 except: # re-raises
218 except: # re-raises
219 self._closefp()
219 self._closefp()
220 raise
220 raise
221
221
222 def __exit__(self, exception_type, exception_value, traceback):
222 def __exit__(self, exception_type, exception_value, traceback):
223 propagate = None
223 propagate = None
224 if self._profiler is not None:
224 if self._profiler is not None:
225 propagate = self._profiler.__exit__(exception_type, exception_value,
225 propagate = self._profiler.__exit__(exception_type, exception_value,
226 traceback)
226 traceback)
227 if self._output == 'blackbox':
227 if self._output == 'blackbox':
228 val = 'Profile:\n%s' % self._fp.getvalue()
228 val = 'Profile:\n%s' % self._fp.getvalue()
229 # ui.log treats the input as a format string,
229 # ui.log treats the input as a format string,
230 # so we need to escape any % signs.
230 # so we need to escape any % signs.
231 val = val.replace('%', '%%')
231 val = val.replace('%', '%%')
232 self._ui.log('profile', val)
232 self._ui.log('profile', val)
233 self._closefp()
233 self._closefp()
234 return propagate
234 return propagate
235
235
236 def _closefp(self):
236 def _closefp(self):
237 if self._fpdoclose and self._fp is not None:
237 if self._fpdoclose and self._fp is not None:
238 self._fp.close()
238 self._fp.close()
General Comments 0
You need to be logged in to leave comments. Login now