-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot-delays.py
100 lines (81 loc) · 4.24 KB
/
plot-delays.py
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
88
89
90
91
92
93
94
95
96
97
98
99
100
import os
import sys
import re
import numpy as np
import directory_traversal_helper
import plotting_helper
def main():
if len( sys.argv ) is not 2:
raise ValueError("Usage: python plot-inter-frame-delay.py frame_stats_directory")
frame_stats_directory = sys.argv[1]
_, dataset_title = os.path.split(os.path.abspath(frame_stats_directory))
inter_frame_delays_list = []
resume_delays_list = []
rebuffering_ratios = []
num_files_parsed = 0
for f, _ in directory_traversal_helper.get_files_matching_regex(frame_stats_directory, "frame-stats.dat"):
print("parsing " + f)
num_files_parsed += 1
with open(f) as frame_stats_file:
total_playback_time = 0
rebuffering_time = 0
first_line = True
for line in frame_stats_file:
if first_line:
string_match = re.search("first chunk request logged on server at ([0-9]+\.[0-9]+)", line)
if string_match is None:
print("Failed to parse chunk request time from first line: " + line)
previous_system_time = float(string_match.group(1))
previous_frame_shown = -100
first_line = False
continue
string_match = re.search("displayed at system time ([0-9\.]+) ", line)
if string_match is None:
print("Failed to parse system time from: " + line)
system_time = float(string_match.group(1))
string_match = re.search("which is frame ([0-9]+)", line)
if string_match is None:
print("Failed to parse frame number from: " + line)
frame_shown = int(string_match.group(1))
time_since_last_frame = system_time - previous_system_time
assert(time_since_last_frame > -1)
# make sure time is non-decreasing (this shows up a couple times probably because of NTP,
# also for first frame display time with margin of error from first chunk request)
if time_since_last_frame < 0:
time_since_last_frame = 0
if (frame_shown - previous_frame_shown) > 24: # consider a seek if move forward >1s in video, this also includes first frame played
resume_delays_list.append(time_since_last_frame)
else:
inter_frame_delays_list.append(time_since_last_frame)
total_playback_time += time_since_last_frame
if time_since_last_frame > .1:
rebuffering_time += time_since_last_frame
previous_system_time = system_time
previous_frame_shown = frame_shown
rebuffering_ratios.append(rebuffering_time / total_playback_time)
if num_files_parsed is 0:
raise ValueError("Found no frame-stats.dat files to parse")
else:
print("Finished parsing " + str(num_files_parsed) + " files")
total_playback_time = sum( inter_frame_delays_list )
xvals = np.sort( inter_frame_delays_list )
yvals = []
subtotal_playback_time = total_playback_time
for ifd in xvals:
subtotal_playback_time -= ifd
yvals.append(subtotal_playback_time / total_playback_time)
(xvals, yvals) = plotting_helper.downsample_cumulative_y((xvals, yvals))
filename = dataset_title + "-proportional-playback.dat"
plotting_helper.write_points_to_file(xvals, yvals, dataset_title, filename)
(xvals, yvals) = plotting_helper.downsample_cumulative_y(plotting_helper.get_cdf(inter_frame_delays_list))
yvals = 1-np.array(yvals) # CCDF
filename = dataset_title + "-inter-frame-delays-ccdf.dat"
plotting_helper.write_points_to_file(xvals, yvals, dataset_title, filename)
(xvals, yvals) = plotting_helper.get_cdf( resume_delays_list )
filename = dataset_title + "-resume-delays-cdf.dat"
plotting_helper.write_points_to_file(xvals, yvals, dataset_title, filename)
(xvals, yvals) = plotting_helper.get_cdf( rebuffering_ratios )
filename = dataset_title + "-rebuffering-ratios-cdf.dat"
plotting_helper.write_points_to_file(xvals, yvals, dataset_title, filename)
if __name__ == '__main__':
main()