diff options
Diffstat (limited to 'scripts/logreport.py')
| -rw-r--r-- | scripts/logreport.py | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/scripts/logreport.py b/scripts/logreport.py index c2d7712..69b6e46 100644 --- a/scripts/logreport.py +++ b/scripts/logreport.py @@ -4,17 +4,15 @@ import collections import datetime import functools import itertools -import locale import math import operator import psycopg2 +import re import sys import time from writer import ConsoleWriter, HtmlWriter -locale.setlocale(locale.LC_ALL, "") - Nickset = None SlowReqThreshold = 1000 WindowInterval = datetime.timedelta(minutes=5) @@ -32,8 +30,9 @@ def fetch_nicks(): print "Profile urls will be incorrectly classified as 'Other'" return set() -def comma_format(i): - return locale.format('%d', i, True) +def comma_format(x): + # http://code.activestate.com/recipes/498181-add-thousands-separator-commas-to-formatted-number/ + return re.sub(r'(\d{3})(?=\d)', r'\1,', str(x)[::-1])[::-1] def format_unit(val, units, factors): for unit, factor in zip(units, factors): @@ -181,8 +180,14 @@ class DumpReport(object): self.end_time = None self.urlgroup_stats = {} self.slow_request_threshold = slow_thresh + self.printed_dates = set() def record_window(self, ts, window): + date_str = ts.strftime('%D') + if date_str not in self.printed_dates: + print "processing %s" % date_str + self.printed_dates.add(date_str) + if len(window) > 0: if self.start_time is None: self.start_time = window[0]['ts'] @@ -245,7 +250,7 @@ class DumpReport(object): def _output_urlgroups(self, writer): - headers = ['#', 'min', 'mean', 'max', '# slow', '% slow', 'bytes'] + headers = ['#', 'min', 'mean', 'max', '# slow', '% slow', 'bytes', 'bytes / req'] data = [] for group in sorted(self.urlgroup_stats.keys()): stats = self.urlgroup_stats[group] @@ -296,7 +301,7 @@ class DumpReport(object): duration), '%s requests (%.02f r/s)' % (comma_format(self.requests), self.requests / duration.seconds), - '%s slow requests (%s)' % (self.slow_requests, + '%s slow requests (%s)' % (comma_format(self.slow_requests), format_pct(float(self.slow_requests) / self.requests)), '%s bytes sent' % format_bytes(self.bytes_sent)] writer.list(summary) |
