##// 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 867 coreconfigitem('profiling', 'statformat',
868 868 default='hotpath',
869 869 )
870 coreconfigitem('profiling', 'time-track',
871 default='cpu',
872 )
870 873 coreconfigitem('profiling', 'type',
871 874 default='stat',
872 875 )
@@ -1652,6 +1652,10 b' statistical text report generated from t'
1652 1652 ``inlinetime``.
1653 1653 (default: inlinetime)
1654 1654
1655 ``time-track``
1656 Control if the stat profiler track ``cpu`` or ``real`` time.
1657 (default: ``cpu``)
1658
1655 1659 ``limit``
1656 1660 Number of lines to show. Specific to the ``ls`` instrumenting profiler.
1657 1661 (default: 30)
@@ -101,7 +101,8 b' def statprofile(ui, fp):'
101 101 else:
102 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 107 try:
107 108 yield
@@ -148,6 +148,7 b' def clock():'
148 148 class ProfileState(object):
149 149 def __init__(self, frequency=None):
150 150 self.reset(frequency)
151 self.track = 'cpu'
151 152
152 153 def reset(self, frequency=None):
153 154 # total so far
@@ -180,7 +181,13 b' class ProfileState(object):'
180 181 )
181 182
182 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 192 state = ProfileState()
186 193
@@ -268,7 +275,8 b' def profile_signal_handler(signum, frame'
268 275 now = clock()
269 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 281 signal.setitimer(signal.ITIMER_PROF,
274 282 state.sample_interval, 0.0)
@@ -281,7 +289,9 b' def samplerthread(tid):'
281 289 state.accumulate_time(now)
282 290
283 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 296 state.last_start_time = now
287 297 time.sleep(state.sample_interval)
@@ -295,8 +305,9 b' def is_active():'
295 305 return state.profile_level > 0
296 306
297 307 lastmechanism = None
298 def start(mechanism='thread'):
308 def start(mechanism='thread', track='cpu'):
299 309 '''Install the profiling signal handler, and start profiling.'''
310 state.track = track # note: nesting different mode won't work
300 311 state.profile_level += 1
301 312 if state.profile_level == 1:
302 313 state.last_start_time = clock()
General Comments 0
You need to be logged in to leave comments. Login now