Index: trunk/tools/bandbreakdown/bandbreakdown.py |
— | — | @@ -15,21 +15,36 @@ |
16 | 16 | groups = [group for (group, regex) in matchTypes] |
17 | 17 | groups.append("other") |
18 | 18 | |
19 | | -totalHits = 0 |
20 | | -totalBytes = 0 |
21 | | -hits = {} |
22 | | -bytes = {} |
| 19 | +interval = 1000 |
| 20 | + |
| 21 | +hits = {"total": 0} |
| 22 | +bytes = {"total": 0} |
23 | 23 | for group in groups: |
24 | 24 | hits[group] = 0 |
25 | 25 | bytes[group] = 0 |
26 | 26 | |
| 27 | +def dump(groups, hits, bytes): |
| 28 | + print "--" |
| 29 | + if hits["total"] == 0 or bytes["total"] == 0: |
| 30 | + print "no hits detected :(" |
| 31 | + |
| 32 | + for group in groups: |
| 33 | + if hits[group] > 0: |
| 34 | + print "%12s %8d hits (%6.2f%%) %16d bytes (%6.2f%%) %10.1f bytes/hit" % ( |
| 35 | + group, |
| 36 | + hits[group], |
| 37 | + 100.0 * float(hits[group]) / float(hits["total"]), |
| 38 | + bytes[group], |
| 39 | + 100.0 * float(bytes[group]) / float(bytes["total"]), |
| 40 | + float(bytes[group]) / float(hits[group])) |
| 41 | + |
27 | 42 | for line in sys.stdin: |
28 | 43 | matches = lineSplit.match(line) |
29 | 44 | if matches: |
30 | 45 | size = int(matches.group(1)) |
31 | 46 | url = matches.group(2) |
32 | | - totalHits += 1 |
33 | | - totalBytes += size |
| 47 | + hits["total"] += 1 |
| 48 | + bytes["total"] += size |
34 | 49 | for (group, regex) in matchTypes: |
35 | 50 | if regex.match(url): |
36 | 51 | hits[group] += 1 |
— | — | @@ -38,16 +53,8 @@ |
39 | 54 | else: |
40 | 55 | hits["other"] += 1 |
41 | 56 | bytes["other"] += size |
| 57 | + if hits["total"] % interval == 0: |
| 58 | + dump(groups, hits, bytes) |
42 | 59 | |
43 | | -if totalHits == 0 or totalBytes == 0: |
44 | | - print "no hits detected :(" |
45 | | - |
46 | | -for group in groups: |
47 | | - if hits[group] > 0: |
48 | | - print "%12s %8d hits (%6.2f%%) %16d bytes (%6.2f%%) %10.1f bytes/hit" % ( |
49 | | - group, |
50 | | - hits[group], |
51 | | - 100.0 * float(hits[group]) / float(totalHits), |
52 | | - bytes[group], |
53 | | - 100.0 * float(bytes[group]) / float(totalBytes), |
54 | | - float(bytes[group]) / float(hits[group])) |
| 60 | +if hits["total"] % interval != 0: |
| 61 | + dump(groups, hits, bytes) |