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

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

mercurial