serverlog: add a script to extract hourly per-repo totals
authorGregory Szorc <gps@mozilla.com>
Thu, 19 Mar 2015 18:00:08 -0700
changeset 360617 4cf797566c54b52d8d6f363a8b333fc1bfe2bcba
parent 360616 b31baf5ce72279528f73ea1626b028fe18995773
child 360618 672c05c1db2db77d87eb52eff53cd6cc05b0a08b
push id16998
push userrwood@mozilla.com
push dateMon, 02 May 2016 19:42:03 +0000
serverlog: add a script to extract hourly per-repo totals
hgext/serverlog/scripts/repo-totals-by-hour.py
new file mode 100755
--- /dev/null
+++ b/hgext/serverlog/scripts/repo-totals-by-hour.py
@@ -0,0 +1,40 @@
+#!/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_hour(fh):
+    hours = {}
+
+    for line in fh:
+        parts = line.rstrip().split()
+
+        try:
+            when, repo, ip, command, size, t_wall, t_cpu = parts
+            when = datetime.datetime.strptime(when, '%Y-%m-%dT%H:%M:%S')
+        except (TypeError, ValueError):
+            continue
+
+        size = int(size)
+        t_wall = float(t_wall)
+        t_cpu = float(t_cpu)
+
+        t = when.time().replace(minute=0, second=0, microsecond=0)
+        when = when.combine(when.date(), t)
+
+        repos = hours.setdefault(when, {})
+        totals = repos.setdefault(repo, [0, 0.0, 0.0])
+        totals[0] += size
+        totals[1] += t_wall
+        totals[2] += t_cpu
+
+    for date, repos in sorted(hours.items()):
+        for repo, totals in sorted(repos.items()):
+            print('%s\t%s\t%d\t%d\t%d' % (
+                date.isoformat(), repo, totals[0], totals[1], totals[2]))
+
+if __name__ == '__main__':
+    totals_by_hour(sys.stdin)