contrib: use a monotonic timer in catapipe
authorBoris Feld <boris.feld@octobus.net>
Fri, 07 Sep 2018 17:54:55 -0400
changeset 39514 b29ec19748a7
parent 39513 e9706686451b
child 39515 93486cc46125
contrib: use a monotonic timer in catapipe As spotted by Gregory, we should use a monotonic timer to get better timings. Differential Revision: https://phab.mercurial-scm.org/D4516
contrib/catapipe.py
--- a/contrib/catapipe.py	Fri Sep 07 17:51:07 2018 -0400
+++ b/contrib/catapipe.py	Fri Sep 07 17:54:55 2018 -0400
@@ -29,9 +29,9 @@
 from __future__ import absolute_import, print_function
 
 import argparse
-import datetime
 import json
 import os
+import timeit
 
 _TYPEMAP = {
     'START': 'B',
@@ -40,6 +40,10 @@
 
 _threadmap = {}
 
+# Timeit already contains the whole logic about which timer to use based on
+# Python version and OS
+timer = timeit.default_timer
+
 def main():
     parser = argparse.ArgumentParser()
     parser.add_argument('pipe', type=str, nargs=1,
@@ -55,12 +59,12 @@
     try:
         with open(fn) as f, open(args.output, 'w') as out:
             out.write('[\n')
-            start = datetime.datetime.now()
+            start = timer()
             while True:
                 ev = f.readline().strip()
                 if not ev:
                     continue
-                now = datetime.datetime.now()
+                now = timer()
                 if args.debug:
                     print(ev)
                 verb, session, label = ev.split(' ', 2)