##// END OF EJS Templates
profiling: introduce a "profiling.time-track" option...
Boris Feld -
r38279:15a1e37f default
parent child Browse files
Show More
@@ -867,6 +867,9 b" coreconfigitem('profiling', 'sort',"
867 coreconfigitem('profiling', 'statformat',
867 coreconfigitem('profiling', 'statformat',
868 default='hotpath',
868 default='hotpath',
869 )
869 )
870 coreconfigitem('profiling', 'time-track',
871 default='cpu',
872 )
870 coreconfigitem('profiling', 'type',
873 coreconfigitem('profiling', 'type',
871 default='stat',
874 default='stat',
872 )
875 )
@@ -1652,6 +1652,10 b' statistical text report generated from t'
1652 ``inlinetime``.
1652 ``inlinetime``.
1653 (default: inlinetime)
1653 (default: inlinetime)
1654
1654
1655 ``time-track``
1656 Control if the stat profiler track ``cpu`` or ``real`` time.
1657 (default: ``cpu``)
1658
1655 ``limit``
1659 ``limit``
1656 Number of lines to show. Specific to the ``ls`` instrumenting profiler.
1660 Number of lines to show. Specific to the ``ls`` instrumenting profiler.
1657 (default: 30)
1661 (default: 30)
@@ -101,7 +101,8 b' def statprofile(ui, fp):'
101 else:
101 else:
102 ui.warn(_("invalid sampling frequency '%s' - ignoring\n") % freq)
102 ui.warn(_("invalid sampling frequency '%s' - ignoring\n") % freq)
103
103
104 statprof.start(mechanism='thread')
104 track = ui.config('profiling', 'time-track')
105 statprof.start(mechanism='thread', track=track)
105
106
106 try:
107 try:
107 yield
108 yield
@@ -148,6 +148,7 b' def clock():'
148 class ProfileState(object):
148 class ProfileState(object):
149 def __init__(self, frequency=None):
149 def __init__(self, frequency=None):
150 self.reset(frequency)
150 self.reset(frequency)
151 self.track = 'cpu'
151
152
152 def reset(self, frequency=None):
153 def reset(self, frequency=None):
153 # total so far
154 # total so far
@@ -180,7 +181,13 b' class ProfileState(object):'
180 )
181 )
181
182
182 def seconds_per_sample(self):
183 def seconds_per_sample(self):
183 return self.accumulated_time[0] / len(self.samples)
184 return self.accumulated_time[self.timeidx] / len(self.samples)
185
186 @property
187 def timeidx(self):
188 if self.track == 'real':
189 return 1
190 return 0
184
191
185 state = ProfileState()
192 state = ProfileState()
186
193
@@ -268,7 +275,8 b' def profile_signal_handler(signum, frame'
268 now = clock()
275 now = clock()
269 state.accumulate_time(now)
276 state.accumulate_time(now)
270
277
271 state.samples.append(Sample.from_frame(frame, state.accumulated_time[0]))
278 timestamp = state.accumulated_time[state.timeidx]
279 state.samples.append(Sample.from_frame(frame, timestamp))
272
280
273 signal.setitimer(signal.ITIMER_PROF,
281 signal.setitimer(signal.ITIMER_PROF,
274 state.sample_interval, 0.0)
282 state.sample_interval, 0.0)
@@ -281,7 +289,9 b' def samplerthread(tid):'
281 state.accumulate_time(now)
289 state.accumulate_time(now)
282
290
283 frame = sys._current_frames()[tid]
291 frame = sys._current_frames()[tid]
284 state.samples.append(Sample.from_frame(frame, state.accumulated_time[0]))
292
293 timestamp = state.accumulated_time[state.timeidx]
294 state.samples.append(Sample.from_frame(frame, timestamp))
285
295
286 state.last_start_time = now
296 state.last_start_time = now
287 time.sleep(state.sample_interval)
297 time.sleep(state.sample_interval)
@@ -295,8 +305,9 b' def is_active():'
295 return state.profile_level > 0
305 return state.profile_level > 0
296
306
297 lastmechanism = None
307 lastmechanism = None
298 def start(mechanism='thread'):
308 def start(mechanism='thread', track='cpu'):
299 '''Install the profiling signal handler, and start profiling.'''
309 '''Install the profiling signal handler, and start profiling.'''
310 state.track = track # note: nesting different mode won't work
300 state.profile_level += 1
311 state.profile_level += 1
301 if state.profile_level == 1:
312 if state.profile_level == 1:
302 state.last_start_time = clock()
313 state.last_start_time = clock()
General Comments 0
You need to be logged in to leave comments. Login now