michael@0: #!/usr/bin/env python michael@0: # graph_latency.py - graph media latency michael@0: # michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: # needs matplotlib (sudo aptitude install python-matplotlib) michael@0: michael@0: import matplotlib.pyplot as plt michael@0: from matplotlib import rc michael@0: import sys michael@0: from pprint import pprint michael@0: import re michael@0: michael@0: michael@0: # FIX! needs to be sum of a single mediastreamtrack and any output overhead for it michael@0: # So there is one sum per MST michael@0: def compute_sum(data): michael@0: 'Compute the sum for each timestamp. This expects the output of parse_data.' michael@0: last_values = {} michael@0: out = ([],[]) michael@0: michael@0: for i in data: michael@0: if i[0] not in last_values.keys(): michael@0: last_values[i[0]] = 0 michael@0: last_values[i[0]] = float(i[3]) michael@0: print last_values michael@0: out[0].append(i[2]) michael@0: out[1].append(sum(last_values.values())) michael@0: return out michael@0: michael@0: michael@0: def clean_data(raw_data): michael@0: ''' michael@0: Remove the PR_LOG cruft at the beginning of each line and returns a list of michael@0: tuple. michael@0: ''' michael@0: out = [] michael@0: for line in raw_data: michael@0: match = re.match(r'(.*)#(.*)', line) michael@0: if match: michael@0: continue michael@0: else: michael@0: out.append(line.split(": ")[1]) michael@0: return out michael@0: michael@0: # returns a list of tuples michael@0: def parse_data(raw_lines): michael@0: ''' michael@0: Split each line by , and put every bit in a tuple. michael@0: ''' michael@0: out = [] michael@0: for line in raw_lines: michael@0: out.append(line.split(',')) michael@0: return out michael@0: michael@0: if len(sys.argv) == 3: michael@0: name = sys.argv[1] michael@0: channels = int(sys.argv[2]) michael@0: else: michael@0: print sys.argv[0] + "latency_log" michael@0: michael@0: try: michael@0: f = open(sys.argv[1]) michael@0: except: michael@0: print "cannot open " + name michael@0: michael@0: raw_lines = f.readlines() michael@0: lines = clean_data(raw_lines) michael@0: data = parse_data(lines) michael@0: michael@0: final_data = {} michael@0: michael@0: for tupl in data: michael@0: name = tupl[0] michael@0: if tupl[1] != 0: michael@0: name = name+tupl[1] michael@0: if name not in final_data.keys(): michael@0: final_data[name] = ([], []) michael@0: # sanity-check values michael@0: if float(tupl[3]) < 10*1000: michael@0: final_data[name][0].append(float(tupl[2])) michael@0: final_data[name][1].append(float(tupl[3])) michael@0: michael@0: #overall = compute_sum(data) michael@0: #final_data["overall"] = overall michael@0: michael@0: pprint(final_data) michael@0: michael@0: fig = plt.figure() michael@0: for i in final_data.keys(): michael@0: plt.plot(final_data[i][0], final_data[i][1], label=i) michael@0: michael@0: plt.legend() michael@0: plt.suptitle("Latency in ms (y-axis) against time in ms (x-axis).") michael@0: michael@0: size = fig.get_size_inches() michael@0: # make it gigantic so we can see things. sometimes, if the graph is too big, michael@0: # this errors. reduce the factor so it stays under 2**15. michael@0: fig.set_size_inches((size[0]*10, size[1]*2)) michael@0: name = sys.argv[1][:-4] + ".pdf" michael@0: fig.savefig(name) michael@0: