1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/media/test/graph_latency.py Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,104 @@ 1.4 +#!/usr/bin/env python 1.5 +# graph_latency.py - graph media latency 1.6 +# 1.7 +# This Source Code Form is subject to the terms of the Mozilla Public 1.8 +# License, v. 2.0. If a copy of the MPL was not distributed with this 1.9 +# file, You can obtain one at http://mozilla.org/MPL/2.0/. 1.10 + 1.11 +# needs matplotlib (sudo aptitude install python-matplotlib) 1.12 + 1.13 +import matplotlib.pyplot as plt 1.14 +from matplotlib import rc 1.15 +import sys 1.16 +from pprint import pprint 1.17 +import re 1.18 + 1.19 + 1.20 +# FIX! needs to be sum of a single mediastreamtrack and any output overhead for it 1.21 +# So there is one sum per MST 1.22 +def compute_sum(data): 1.23 + 'Compute the sum for each timestamp. This expects the output of parse_data.' 1.24 + last_values = {} 1.25 + out = ([],[]) 1.26 + 1.27 + for i in data: 1.28 + if i[0] not in last_values.keys(): 1.29 + last_values[i[0]] = 0 1.30 + last_values[i[0]] = float(i[3]) 1.31 + print last_values 1.32 + out[0].append(i[2]) 1.33 + out[1].append(sum(last_values.values())) 1.34 + return out 1.35 + 1.36 + 1.37 +def clean_data(raw_data): 1.38 + ''' 1.39 + Remove the PR_LOG cruft at the beginning of each line and returns a list of 1.40 + tuple. 1.41 + ''' 1.42 + out = [] 1.43 + for line in raw_data: 1.44 + match = re.match(r'(.*)#(.*)', line) 1.45 + if match: 1.46 + continue 1.47 + else: 1.48 + out.append(line.split(": ")[1]) 1.49 + return out 1.50 + 1.51 +# returns a list of tuples 1.52 +def parse_data(raw_lines): 1.53 + ''' 1.54 + Split each line by , and put every bit in a tuple. 1.55 + ''' 1.56 + out = [] 1.57 + for line in raw_lines: 1.58 + out.append(line.split(',')) 1.59 + return out 1.60 + 1.61 +if len(sys.argv) == 3: 1.62 + name = sys.argv[1] 1.63 + channels = int(sys.argv[2]) 1.64 +else: 1.65 + print sys.argv[0] + "latency_log" 1.66 + 1.67 +try: 1.68 + f = open(sys.argv[1]) 1.69 +except: 1.70 + print "cannot open " + name 1.71 + 1.72 +raw_lines = f.readlines() 1.73 +lines = clean_data(raw_lines) 1.74 +data = parse_data(lines) 1.75 + 1.76 +final_data = {} 1.77 + 1.78 +for tupl in data: 1.79 + name = tupl[0] 1.80 + if tupl[1] != 0: 1.81 + name = name+tupl[1] 1.82 + if name not in final_data.keys(): 1.83 + final_data[name] = ([], []) 1.84 +# sanity-check values 1.85 + if float(tupl[3]) < 10*1000: 1.86 + final_data[name][0].append(float(tupl[2])) 1.87 + final_data[name][1].append(float(tupl[3])) 1.88 + 1.89 +#overall = compute_sum(data) 1.90 +#final_data["overall"] = overall 1.91 + 1.92 +pprint(final_data) 1.93 + 1.94 +fig = plt.figure() 1.95 +for i in final_data.keys(): 1.96 + plt.plot(final_data[i][0], final_data[i][1], label=i) 1.97 + 1.98 +plt.legend() 1.99 +plt.suptitle("Latency in ms (y-axis) against time in ms (x-axis).") 1.100 + 1.101 +size = fig.get_size_inches() 1.102 +# make it gigantic so we can see things. sometimes, if the graph is too big, 1.103 +# this errors. reduce the factor so it stays under 2**15. 1.104 +fig.set_size_inches((size[0]*10, size[1]*2)) 1.105 +name = sys.argv[1][:-4] + ".pdf" 1.106 +fig.savefig(name) 1.107 +