serverlog: add a totals-by-minute script
authorGregory Szorc <gps@mozilla.com>
Thu, 19 Mar 2015 14:46:40 -0700
changeset 360613 00c37783ff0c234c8d771fd0425f4ef5d86a0faa
parent 360612 c6357bfdab768a76acd6dec92ef44577028323dd
child 360614 762a64b6f8597e11b8c1e2a2acd2c1115a551f45
push id16998
push userrwood@mozilla.com
push dateMon, 02 May 2016 19:42:03 +0000
serverlog: add a totals-by-minute script
hgext/serverlog/scripts/totals-by-minute.py
new file mode 100755
--- /dev/null
+++ b/hgext/serverlog/scripts/totals-by-minute.py
@@ -0,0 +1,33 @@
+#!/usr/bin/env python
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+import datetime
+import sys
+
+def totals_by_minute(fh):
+    minutes = {}
+
+    for line in fh:
+        parts = line.rstrip().split()
+
+        when, repo, ip, command, size, t_wall, t_cpu = parts
+        when = datetime.datetime.strptime(when, '%Y-%m-%dT%H:%M:%S')
+        size = int(size)
+        t_wall = float(t_wall)
+        t_cpu = float(t_cpu)
+
+        t = when.time().replace(second=0, microsecond=0)
+        when = when.combine(when.date(), t)
+
+        totals = minutes.setdefault(when, [0, 0.0, 0.0])
+        totals[0] += size
+        totals[1] += t_wall
+        totals[2] += t_cpu
+
+    for date, totals in sorted(minutes.items()):
+        print('%s\t%d\t%d\t%d' % (date.isoformat(), totals[0], totals[1], totals[2]))
+
+if __name__ == '__main__':
+    totals_by_minute(sys.stdin)