changeset 38259:af402c6b90db

statprof: also gather wall time Gathering wall time information is useful for operations that are IO (files, network) intensive. For now we only expose it in the final summary.
author Boris Feld <boris.feld@octobus.net>
date Fri, 01 Jun 2018 11:23:27 +0200
parents ae6e02fcee24
children 15a1e37f80bd
files mercurial/statprof.py
diffstat 1 files changed, 15 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/statprof.py	Thu May 31 19:34:08 2018 +0200
+++ b/mercurial/statprof.py	Fri Jun 01 11:23:27 2018 +0200
@@ -139,7 +139,7 @@
 
 def clock():
     times = os.times()
-    return times[0] + times[1]
+    return (times[0] + times[1], times[4])
 
 
 ###########################################################################
@@ -151,7 +151,7 @@
 
     def reset(self, frequency=None):
         # total so far
-        self.accumulated_time = 0.0
+        self.accumulated_time = (0.0, 0.0)
         # start_time when timer is active
         self.last_start_time = None
         # a float
@@ -170,10 +170,17 @@
         self.samples = []
 
     def accumulate_time(self, stop_time):
-        self.accumulated_time += stop_time - self.last_start_time
+        increment = (
+            stop_time[0] - self.last_start_time[0],
+            stop_time[1] - self.last_start_time[1],
+        )
+        self.accumulated_time = (
+            self.accumulated_time[0] + increment[0],
+            self.accumulated_time[1] + increment[1],
+        )
 
     def seconds_per_sample(self):
-        return self.accumulated_time / len(self.samples)
+        return self.accumulated_time[0] / len(self.samples)
 
 state = ProfileState()
 
@@ -261,7 +268,7 @@
         now = clock()
         state.accumulate_time(now)
 
-        state.samples.append(Sample.from_frame(frame, state.accumulated_time))
+        state.samples.append(Sample.from_frame(frame, state.accumulated_time[0]))
 
         signal.setitimer(signal.ITIMER_PROF,
             state.sample_interval, 0.0)
@@ -274,7 +281,7 @@
         state.accumulate_time(now)
 
         frame = sys._current_frames()[tid]
-        state.samples.append(Sample.from_frame(frame, state.accumulated_time))
+        state.samples.append(Sample.from_frame(frame, state.accumulated_time[0]))
 
         state.last_start_time = now
         time.sleep(state.sample_interval)
@@ -465,7 +472,8 @@
     if format not in (DisplayFormats.Json, DisplayFormats.Chrome):
         print('---', file=fp)
         print('Sample count: %d' % len(data.samples), file=fp)
-        print('Total time: %f seconds' % data.accumulated_time, file=fp)
+        print('Total time: %f seconds (%f wall)' % data.accumulated_time,
+              file=fp)
 
 def display_by_line(data, fp):
     '''Print the profiler data with each sample line represented