##// END OF EJS Templates
statprof: also gather wall time...
Boris Feld -
r38278:af402c6b default
parent child Browse files
Show More
@@ -139,7 +139,7 b' skips = {"util.py:check", "extensions.py'
139
139
140 def clock():
140 def clock():
141 times = os.times()
141 times = os.times()
142 return times[0] + times[1]
142 return (times[0] + times[1], times[4])
143
143
144
144
145 ###########################################################################
145 ###########################################################################
@@ -151,7 +151,7 b' class ProfileState(object):'
151
151
152 def reset(self, frequency=None):
152 def reset(self, frequency=None):
153 # total so far
153 # total so far
154 self.accumulated_time = 0.0
154 self.accumulated_time = (0.0, 0.0)
155 # start_time when timer is active
155 # start_time when timer is active
156 self.last_start_time = None
156 self.last_start_time = None
157 # a float
157 # a float
@@ -170,10 +170,17 b' class ProfileState(object):'
170 self.samples = []
170 self.samples = []
171
171
172 def accumulate_time(self, stop_time):
172 def accumulate_time(self, stop_time):
173 self.accumulated_time += stop_time - self.last_start_time
173 increment = (
174 stop_time[0] - self.last_start_time[0],
175 stop_time[1] - self.last_start_time[1],
176 )
177 self.accumulated_time = (
178 self.accumulated_time[0] + increment[0],
179 self.accumulated_time[1] + increment[1],
180 )
174
181
175 def seconds_per_sample(self):
182 def seconds_per_sample(self):
176 return self.accumulated_time / len(self.samples)
183 return self.accumulated_time[0] / len(self.samples)
177
184
178 state = ProfileState()
185 state = ProfileState()
179
186
@@ -261,7 +268,7 b' def profile_signal_handler(signum, frame'
261 now = clock()
268 now = clock()
262 state.accumulate_time(now)
269 state.accumulate_time(now)
263
270
264 state.samples.append(Sample.from_frame(frame, state.accumulated_time))
271 state.samples.append(Sample.from_frame(frame, state.accumulated_time[0]))
265
272
266 signal.setitimer(signal.ITIMER_PROF,
273 signal.setitimer(signal.ITIMER_PROF,
267 state.sample_interval, 0.0)
274 state.sample_interval, 0.0)
@@ -274,7 +281,7 b' def samplerthread(tid):'
274 state.accumulate_time(now)
281 state.accumulate_time(now)
275
282
276 frame = sys._current_frames()[tid]
283 frame = sys._current_frames()[tid]
277 state.samples.append(Sample.from_frame(frame, state.accumulated_time))
284 state.samples.append(Sample.from_frame(frame, state.accumulated_time[0]))
278
285
279 state.last_start_time = now
286 state.last_start_time = now
280 time.sleep(state.sample_interval)
287 time.sleep(state.sample_interval)
@@ -465,7 +472,8 b' def display(fp=None, format=3, data=None'
465 if format not in (DisplayFormats.Json, DisplayFormats.Chrome):
472 if format not in (DisplayFormats.Json, DisplayFormats.Chrome):
466 print('---', file=fp)
473 print('---', file=fp)
467 print('Sample count: %d' % len(data.samples), file=fp)
474 print('Sample count: %d' % len(data.samples), file=fp)
468 print('Total time: %f seconds' % data.accumulated_time, file=fp)
475 print('Total time: %f seconds (%f wall)' % data.accumulated_time,
476 file=fp)
469
477
470 def display_by_line(data, fp):
478 def display_by_line(data, fp):
471 '''Print the profiler data with each sample line represented
479 '''Print the profiler data with each sample line represented
General Comments 0
You need to be logged in to leave comments. Login now