tzh
2024-08-22 c7d0944258c7d0943aa7b2211498fd612971ce27
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env python
 
"""
  chewperf.py: Chew an http perf log
  bucketize
 
"""
 
import sys, time
 
def resets():
    f = open(sys.argv[1]).read()
    rawLines = f.split('\n')
 
    times = []
    for x in range(len(rawLines)):
        line = rawLines[x].split()
        try:
            if line[-1] == "SIGNAL_STRENGTH":
                ts = int(rawLines[x - 1].split()[-1])
                times.append(ts)
        except:
            pass
 
    return times
 
def augment():
    f = open(sys.argv[1]).read()
    rawLines = f.split('\r\n')
 
    out = []
    t0 = None
    last = 0
    for line in rawLines:
        if "Pulled" in line:
            chewed = [int(line.split()[5]), int(line.split()[7])]
            if not t0: t0 = chewed[1]
            tm = chewed[1] - t0
            out.append("%s %d" % (line, (tm - last)))
            last = tm
        else:
            out.append(line)
    print "\n".join(out)
 
def chew():
    f = open(sys.argv[1]).read()
    rawLines = f.split('\n')
    lines = [x for x in rawLines if "Pulled" in x]
 
    sidx = lines[0].split().index("Pulled")
    print "sidx", sidx
    chewed = [[int(x.split()[sidx + 2]), int(x.split()[sidx + 4])] for x in lines]
 
    t0 = chewed[0][1]
    tLast = chewed[-1][1]
    chewed = [[x[1] - t0, x[0]] for x in chewed]
 
    totalTime = tLast - t0
    bytes = sum(x[1] for x in chewed)
    print "total time", totalTime, "bytes", bytes, "rate", bytes * 1000 / totalTime
 
    buckets = {}
    for x in chewed:
        bucket = x[0] / 1000
        bytes = x[1]
        if bucket in buckets:
            buckets[bucket] += bytes
        else:
            buckets[bucket] = bytes
 
    top = max(buckets.keys())
    for x in range(top):
        if x not in buckets.keys():
            buckets[x] = 0
 
    # smooth
    window = [0 for x in range(5)]
 
    for x in range(len(buckets.items())):
        window[x % len(window)] = buckets.items()[x][1]
        print "%s\t%s" % (buckets.items()[x][0], sum(window) / len(window))
 
def main():
    chew()
 
if __name__ == '__main__':
    main()