content/media/test/graph_latency.py

Fri, 16 Jan 2015 04:50:19 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 04:50:19 +0100
branch
TOR_BUG_9701
changeset 13
44a2da4a2ab2
permissions
-rw-r--r--

Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32

michael@0 1 #!/usr/bin/env python
michael@0 2 # graph_latency.py - graph media latency
michael@0 3 #
michael@0 4 # This Source Code Form is subject to the terms of the Mozilla Public
michael@0 5 # License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 6 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
michael@0 7
michael@0 8 # needs matplotlib (sudo aptitude install python-matplotlib)
michael@0 9
michael@0 10 import matplotlib.pyplot as plt
michael@0 11 from matplotlib import rc
michael@0 12 import sys
michael@0 13 from pprint import pprint
michael@0 14 import re
michael@0 15
michael@0 16
michael@0 17 # FIX! needs to be sum of a single mediastreamtrack and any output overhead for it
michael@0 18 # So there is one sum per MST
michael@0 19 def compute_sum(data):
michael@0 20 'Compute the sum for each timestamp. This expects the output of parse_data.'
michael@0 21 last_values = {}
michael@0 22 out = ([],[])
michael@0 23
michael@0 24 for i in data:
michael@0 25 if i[0] not in last_values.keys():
michael@0 26 last_values[i[0]] = 0
michael@0 27 last_values[i[0]] = float(i[3])
michael@0 28 print last_values
michael@0 29 out[0].append(i[2])
michael@0 30 out[1].append(sum(last_values.values()))
michael@0 31 return out
michael@0 32
michael@0 33
michael@0 34 def clean_data(raw_data):
michael@0 35 '''
michael@0 36 Remove the PR_LOG cruft at the beginning of each line and returns a list of
michael@0 37 tuple.
michael@0 38 '''
michael@0 39 out = []
michael@0 40 for line in raw_data:
michael@0 41 match = re.match(r'(.*)#(.*)', line)
michael@0 42 if match:
michael@0 43 continue
michael@0 44 else:
michael@0 45 out.append(line.split(": ")[1])
michael@0 46 return out
michael@0 47
michael@0 48 # returns a list of tuples
michael@0 49 def parse_data(raw_lines):
michael@0 50 '''
michael@0 51 Split each line by , and put every bit in a tuple.
michael@0 52 '''
michael@0 53 out = []
michael@0 54 for line in raw_lines:
michael@0 55 out.append(line.split(','))
michael@0 56 return out
michael@0 57
michael@0 58 if len(sys.argv) == 3:
michael@0 59 name = sys.argv[1]
michael@0 60 channels = int(sys.argv[2])
michael@0 61 else:
michael@0 62 print sys.argv[0] + "latency_log"
michael@0 63
michael@0 64 try:
michael@0 65 f = open(sys.argv[1])
michael@0 66 except:
michael@0 67 print "cannot open " + name
michael@0 68
michael@0 69 raw_lines = f.readlines()
michael@0 70 lines = clean_data(raw_lines)
michael@0 71 data = parse_data(lines)
michael@0 72
michael@0 73 final_data = {}
michael@0 74
michael@0 75 for tupl in data:
michael@0 76 name = tupl[0]
michael@0 77 if tupl[1] != 0:
michael@0 78 name = name+tupl[1]
michael@0 79 if name not in final_data.keys():
michael@0 80 final_data[name] = ([], [])
michael@0 81 # sanity-check values
michael@0 82 if float(tupl[3]) < 10*1000:
michael@0 83 final_data[name][0].append(float(tupl[2]))
michael@0 84 final_data[name][1].append(float(tupl[3]))
michael@0 85
michael@0 86 #overall = compute_sum(data)
michael@0 87 #final_data["overall"] = overall
michael@0 88
michael@0 89 pprint(final_data)
michael@0 90
michael@0 91 fig = plt.figure()
michael@0 92 for i in final_data.keys():
michael@0 93 plt.plot(final_data[i][0], final_data[i][1], label=i)
michael@0 94
michael@0 95 plt.legend()
michael@0 96 plt.suptitle("Latency in ms (y-axis) against time in ms (x-axis).")
michael@0 97
michael@0 98 size = fig.get_size_inches()
michael@0 99 # make it gigantic so we can see things. sometimes, if the graph is too big,
michael@0 100 # this errors. reduce the factor so it stays under 2**15.
michael@0 101 fig.set_size_inches((size[0]*10, size[1]*2))
michael@0 102 name = sys.argv[1][:-4] + ".pdf"
michael@0 103 fig.savefig(name)
michael@0 104

mercurial