forked from mozilla/mozperftest-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_side_by_side.py
963 lines (841 loc) · 30.4 KB
/
generate_side_by_side.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
#!/usr/bin/python3
"""
Used to produce comparisons of browsertime videos between a base
and a new revision.
"""
import argparse
import cv2
import gc
import numpy as np
import os
import pathlib
import json
import shutil
import subprocess
from matplotlib import pyplot as plt
from scipy.stats import spearmanr
from sys import stdout
from time import sleep
try:
from urllib.parse import urlencode
from urllib.request import urlopen, urlretrieve
except ImportError:
from urllib import urlencode, urlretrieve
from urllib2 import urlopen
from artifact_downloader import artifact_downloader
from task_processor import get_task_data_paths, match_vismets_with_videos, sorted_nicely
TASK_IDS = (
"https://firefox-ci-tc.services.mozilla.com/api/index/v1/tasks/"
+ "gecko.v2.{}.revision.{}.taskgraph"
)
TASK_INFO = "https://firefox-ci-tc.services.mozilla.com/api/queue/v1/task/{}"
def side_by_side_parser():
parser = argparse.ArgumentParser(
"This tool can be used to generate a side-by-side visualization of two videos. "
"When using this tool, make sure that the `--test-name` is an exact match, i.e. "
"if you are comparing the task `test-linux64-shippable-qr/opt-browsertime-tp6-firefox-linkedin-e10s` "
"between two revisions, then use `browsertime-tp6-firefox-linkedin-e10s` as the suite name "
"and `test-linux64-shippable-qr/opt` as the platform."
)
parser.add_argument(
"--base-revision",
type=str,
required=True,
help="The base revision to compare a new revision to.",
)
parser.add_argument(
"--base-branch",
type=str,
default="autoland",
help="Branch to search for the base revision.",
)
parser.add_argument(
"--new-revision",
type=str,
required=True,
help="The base revision to compare a new revision to.",
)
parser.add_argument(
"--new-branch",
type=str,
default="autoland",
help="Branch to search for the new revision.",
)
parser.add_argument(
"--test-name",
"--base-test-name",
type=str,
required=True,
dest="test_name",
help="The name of the test task to get videos from.",
)
parser.add_argument(
"--new-test-name",
type=str,
default=None,
help="The name of the test task to get videos from in the new revision.",
)
parser.add_argument(
"--platform",
"--base-platform",
type=str,
required=True,
dest="platform",
help="Platform to return results for.",
)
parser.add_argument(
"--new-platform",
type=str,
default=None,
help="Platform to return results for in the new revision.",
)
parser.add_argument(
"--overwrite",
action="store_true",
default=False,
help="If set, the downloaded task group data will be deleted before "
+ "it gets re-downloaded.",
)
parser.add_argument(
"--cold",
action="store_true",
default=False,
help="If set, we'll only look at cold pageload tests.",
)
parser.add_argument(
"--warm",
action="store_true",
default=False,
help="If set, we'll only look at warm pageload tests.",
)
parser.add_argument(
"--most-similar",
action="store_true",
default=False,
help="If set, we'll search for a video pairing that is the most similar.",
)
parser.add_argument(
"--search-crons",
action="store_true",
default=False,
help="If set, we will search for the tasks within the cron jobs as well. ",
)
parser.add_argument(
"--skip-download",
action="store_true",
default=False,
help="If set, we won't try to download artifacts again and we'll "
+ "try using what already exists in the output folder.",
)
parser.add_argument(
"--output",
type=str,
default=os.getcwd(),
help="This is where the data will be saved. Defaults to CWD. "
+ "You can include a name for the file here, otherwise it will "
+ "default to side-by-side.mp4.",
)
parser.add_argument(
"--metric",
type=str,
default="speedindex",
help="Metric to use for side-by-side comparison.",
)
parser.add_argument(
"--vismetPath",
type=str,
default=False,
help="Paths to visualmetrics.py for step chart generation.",
)
parser.add_argument(
"--original",
action="store_true",
default=False,
help="If set, use the original videos in the side-by-side instead "
+ "of the postprocessed videos.",
)
parser.add_argument(
"--skip-slow-gif",
action="store_true",
default=False,
help="If set, the slow-motion GIFs won't be produced.",
)
return parser
def write_same_line(x, sleep_time=0.0001):
stdout.write("\r%s" % str(x))
stdout.flush()
sleep(sleep_time)
def finish_same_line():
stdout.write("\r \r\n")
def get_json(url, params=None):
if params is not None:
url += "?" + urlencode(params)
r = urlopen(url).read().decode("utf-8")
return json.loads(r)
def find_task_group_id(revision, branch, search_crons=False):
# Find the task IDs from this revision first
task_ids_url = TASK_IDS.format(branch, revision)
print("Downloading task ids from: %s" % task_ids_url)
task_ids_data = get_json(task_ids_url)
if "tasks" not in task_ids_data or len(task_ids_data["tasks"]) == 0:
raise Exception("Cannot find any task IDs for %s!" % revision)
task_group_ids = []
for task in task_ids_data["tasks"]:
# Only find the task group ID for the decision task if we
# don't need to search for cron tasks
if not search_crons and not task["namespace"].endswith("decision"):
continue
task_group_url = TASK_INFO.format(task["taskId"])
print("Downloading task group id from: %s" % task_group_url)
task_info = get_json(task_group_url)
task_group_ids.append(task_info["taskGroupId"])
return task_group_ids
def find_videos(artifact_dir, original=False):
# Find the cold/warm browsertime.json files
cold_path = ""
warm_path = ""
for path in pathlib.Path(artifact_dir).rglob("*-browsertime.json"):
if "cold" in str(path):
cold_path = path
elif "warm" in str(path):
warm_path = path
if not cold_path:
raise Exception("Cannot find a browsertime.json file for the cold pageloads.")
if not warm_path:
raise Exception("Cannot find a browsertime.json file for the warm pageloads.")
with cold_path.open() as f:
cold_data = json.load(f)
with warm_path.open() as f:
warm_data = json.load(f)
return {
"cold": [
str(pathlib.Path(cold_path.parents[0], file)).replace(
".mp4", "-original.mp4"
)
if original
else str(pathlib.Path(cold_path.parents[0], file))
for file in cold_data[0]["files"]["video"]
],
"warm": [
str(pathlib.Path(warm_path.parents[0], file)).replace(
".mp4", "-original.mp4"
)
if original
else str(pathlib.Path(warm_path.parents[0], file))
for file in warm_data[0]["files"]["video"]
],
}
def find_videos_with_retriggers(artifact_dirs, original=False):
results = {"cold": [], "warm": []}
for artifact_dir in artifact_dirs:
videos = find_videos(artifact_dir, original=original)
results["cold"].extend(videos["cold"])
results["warm"].extend(videos["warm"])
return results
def get_similarity(
old_videos_info, new_videos_info, output, prefix="", most_similar=False
):
"""Calculates a similarity score for two groupings of videos.
The technique works as follows:
2. For each UxV video pairings, build a cross-correlation matrix:
1. Get each of the videos and calculate their histograms
across the full videos.
2. Calculate the correlation coefficient between these two.
3. Average the cross-correlation matrix to obtain the score.
Args:
old_videos: List of old videos.
new_videos: List of new videos (from this task).
output: Location to output videos with low similarity scores.
prefix: Prefix a string to the output.
Returns:
A dictionary containing the worst pairing and the 3D similarity score.
"""
def _get_frames(video):
"""Gets all frames from a video into a list."""
allframes = []
orange_pixind = 0
orange_frameind = 0
frame_count = 0
check_for_orange = True
while video.isOpened():
ret, frame = video.read()
if ret:
# Convert to gray to simplify the process
allframes.append(cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY))
# Check if it's orange still
if check_for_orange:
frame = allframes[-1]
histo, _, _ = plt.hist(np.asarray(frame).flatten(), bins=255)
maxi = np.argmax(histo)
if not orange_pixind:
if maxi > 130:
continue
orange_pixind = maxi
elif maxi == orange_pixind:
orange_frameind = frame_count
else:
check_for_orange = False
frame_count += 1
else:
video.release()
break
return allframes[orange_frameind:], orange_frameind
nhists = []
old_videos = [entry["data"] for entry in old_videos_info]
new_videos = [entry["data"] for entry in new_videos_info]
new_orange_frameinds = []
old_orange_frameinds = []
total_vids = min(len(old_videos), len(new_videos))
xcorr = np.zeros((total_vids, total_vids))
for i in range(total_vids):
datao, old_orange_frameind = _get_frames(old_videos[i])
datao = np.asarray(datao)
old_orange_frameinds.append(old_orange_frameind)
histo, _, _ = plt.hist(datao.flatten(), bins=255)
plt.clf()
gc.collect()
for j in range(total_vids):
write_same_line("Comparing old video %s to new video %s" % (i + 1, j + 1))
if i == 0:
# Only calculate the histograms once; it takes time
datan, new_orange_frameind = _get_frames(new_videos[j])
datan = np.asarray(datan)
new_orange_frameinds.append(new_orange_frameind)
histn, _, _ = plt.hist(datan.flatten(), bins=255)
plt.clf()
gc.collect()
nhists.append(histn)
else:
histn = nhists[j]
rho, _ = spearmanr(histo, histn)
xcorr[i, j] = rho
finish_same_line()
similarity = np.nanmean(xcorr)
print("Average 3D similarity: %s" % str(np.round(similarity, 5)))
if most_similar:
inds = np.unravel_index(np.argmax(xcorr, axis=None), xcorr.shape)
else:
inds = np.unravel_index(np.argmin(xcorr, axis=None), xcorr.shape)
oldvid = old_videos_info[inds[0]]["path"]
oldvidnewpath = str(pathlib.Path(output, "%sold_video.mp4" % prefix))
shutil.copyfile(oldvid, oldvidnewpath)
newvid = new_videos_info[inds[1]]["path"]
newvidnewpath = str(pathlib.Path(output, "%snew_video.mp4" % prefix))
shutil.copyfile(newvid, newvidnewpath)
return {
"sim3": np.round(similarity, 5),
"oldvid": oldvidnewpath,
"oldvid_ind": old_orange_frameinds[inds[0]],
"newvid": newvidnewpath,
"newvid_ind": new_orange_frameinds[inds[1]],
}
def find_lowest_similarity(base_videos, new_videos, output, prefix, most_similar=False):
def _open_data(file):
return cv2.VideoCapture(str(file))
return get_similarity(
[{"data": _open_data(str(f)), "path": str(f)} for f in base_videos],
[{"data": _open_data(str(f)), "path": str(f)} for f in new_videos],
output,
prefix,
most_similar=most_similar,
)
def open_and_organize_perfherder(files, metric):
def _open_perfherder(filen):
with open(filen) as f:
return json.load(f)
res = {"cold": [], "warm": []}
for filen in files:
data = _open_perfherder(filen)
for suite in data["suites"]:
pl_type = "warm"
if "cold" in suite["extraOptions"]:
pl_type = "cold"
for subtest in suite["subtests"]:
if subtest["name"].lower() != metric.lower():
continue
# Each entry here will be a single retrigger of
# the test for the requested metric (ordered
# based on the `files` ordering)
res[pl_type].append(subtest)
return res
def generate_step_chart(oldvid, newvid, vismetPath, prefix, metric, output):
print("Generating step chart for %s" % metric)
oldvid_metrics = json.loads(
subprocess.check_output(
[
"python",
vismetPath,
"--orange",
"--perceptual",
"--contentful",
"--force",
"--renderignore",
"5",
"--json",
"--viewport",
"--video",
oldvid,
]
)
)
newvid_metrics = json.loads(
subprocess.check_output(
[
"python",
vismetPath,
"--orange",
"--perceptual",
"--contentful",
"--force",
"--renderignore",
"5",
"--json",
"--viewport",
"--video",
newvid,
]
)
)
if metric.lower() == "perceptualspeedindex":
progress = "PerceptualSpeedIndexProgress"
metricName = "PerceptualSpeedIndex"
elif metric.lower() == "contentfulspeedindex":
progress = "ContentfulSpeedIndexProgress"
metricName = "ContentfulSpeedIndex"
else:
progress = "VisualProgress"
metricName = "SpeedIndex"
x = []
y = []
for pt in oldvid_metrics[progress].split(","):
x_val, y_val = pt.split("=")
x.append(int(x_val))
y.append(int(y_val))
plt.step(x, y, label="Before (%d)" % oldvid_metrics[metricName])
x = []
y = []
for pt in newvid_metrics[progress].split(","):
x_val, y_val = pt.split("=")
x.append(int(x_val))
y.append(int(y_val))
plt.step(x, y, label="After (%d)" % newvid_metrics[metricName])
plt.legend(loc="lower right")
plt.title("%s %s" % (prefix.rstrip("_"), metricName))
plt.savefig(str(output / "%s-%s-step.png" % (prefix.rstrip("_"), metric)))
plt.clf()
def find_closest_videos(
base_videos, base_vismet, new_videos, new_vismet, output, prefix, metric
):
base_btime_id = ""
base_min_idx = None
# Recalculate median for all values, then find the new video
# by searching in the list for it (use index) to determine
# the matching video.
replicates = []
for retrigger in base_vismet:
replicates.extend(retrigger["replicates"])
median_value = np.median(replicates)
# Find the video which most closely matches the average
diff = [abs(replicate - median_value) for replicate in replicates]
min_diff = min(diff)
base_min_idx = diff.index(min_diff)
print(
"BASE: metric=%s prefix=%s mean=%d closest=%d index=%d"
% (
metric,
prefix,
median_value,
min_diff,
base_min_idx,
)
)
replicates = []
for retrigger in new_vismet:
replicates.extend(retrigger["replicates"])
median_value = np.median(replicates)
# Find the video which most closely matches the average
diff = [abs(replicate - median_value) for replicate in replicates]
min_diff = min(diff)
new_min_idx = diff.index(min_diff)
print(
"NEW: metric=%s prefix=%s mean=%d closest=%d index=%d"
% (
metric,
prefix,
median_value,
min_diff,
new_min_idx,
)
)
oldvid = base_videos[base_min_idx]
oldvidnewpath = str(pathlib.Path(output, "%sold_video.mp4" % prefix))
shutil.copyfile(oldvid, oldvidnewpath)
newvid = new_videos[new_min_idx]
newvidnewpath = str(pathlib.Path(output, "%snew_video.mp4" % prefix))
shutil.copyfile(newvid, newvidnewpath)
if args.vismetPath:
generate_step_chart(oldvid, newvid, args.vismetPath, prefix, metric, output)
# The index values used here are for frame selection during video editing.
# We use 0 to select all frames.
return {
"oldvid": oldvidnewpath,
"oldvid_ind": 0,
"newvid": newvidnewpath,
"newvid_ind": 0,
}
def build_side_by_side(base_video, new_video, base_ind, new_ind, output_dir, filename):
before_vid = pathlib.Path(output_dir, "before.mp4")
after_vid = pathlib.Path(output_dir, "after.mp4")
before_cut_vid = pathlib.Path(output_dir, "before-cut.mp4")
after_cut_vid = pathlib.Path(output_dir, "after-cut.mp4")
before_rs_vid = pathlib.Path(output_dir, "before-rs.mp4")
after_rs_vid = pathlib.Path(output_dir, "after-rs.mp4")
for apath in (
before_vid,
after_vid,
before_cut_vid,
after_cut_vid,
before_rs_vid,
after_rs_vid,
):
if apath.exists():
apath.unlink()
overlay_text = (
"fps=fps=60,drawtext=text={}\\\\ :fontsize=(h/20):fontcolor=black:y=10:"
+ "timecode=00\\\\:00\\\\:00\\\\:00:rate=60*1000/1001:fontcolor=white:x=(w-tw)/2:"
+ "y=10:box=1:boxcolor=0x00000000@1[vid]"
)
common_options = [
"-map",
"[vid]",
"-c:v",
"libx264",
"-crf",
"18",
"-preset",
"veryfast",
]
# Cut the videos
subprocess.check_output(
["ffmpeg", "-i", str(base_video), "-vf", "select=gt(n\\,%s)" % base_ind]
+ [str(before_cut_vid)]
)
subprocess.check_output(
["ffmpeg", "-i", str(new_video), "-vf", "select=gt(n\\,%s)" % new_ind]
+ [str(after_cut_vid)]
)
# Resample
subprocess.check_output(
["ffmpeg", "-i", str(before_cut_vid), "-filter:v", "fps=fps=60"]
+ [str(before_rs_vid)]
)
subprocess.check_output(
["ffmpeg", "-i", str(after_cut_vid), "-filter:v", "fps=fps=60"]
+ [str(after_rs_vid)]
)
# Generate the before and after videos
subprocess.check_output(
[
"ffmpeg",
"-i",
str(before_rs_vid),
"-filter_complex",
overlay_text.format("BEFORE"),
]
+ common_options
+ [str(before_vid)]
)
subprocess.check_output(
[
"ffmpeg",
"-i",
str(after_rs_vid),
"-filter_complex",
overlay_text.format("AFTER"),
]
+ common_options
+ [str(after_vid)]
)
subprocess.check_output(
[
"ffmpeg",
"-i",
str(before_vid),
"-i",
str(after_vid),
"-filter_complex",
"[0:v]pad=iw*2:ih[int];[int][1:v]overlay=W/2:0[vid]",
]
+ common_options
+ [str(pathlib.Path(output_dir, filename))]
)
def convert_mp4_to_gif(path_to_mp4, path_to_gif, slow_motion=False):
path_to_gif = str(path_to_gif)
fps = 30
# Use slow motion for more subtle differences
if slow_motion:
fps = 100
path_to_gif = path_to_gif.replace(".gif", "-slow-motion.gif")
# Generate palette for a better quality
subprocess.check_output(
[
"ffmpeg",
"-i",
str(path_to_mp4),
"-vf",
f"fps={fps},scale=1024:-1:flags=lanczos,palettegen",
"-y",
]
+ [path_to_gif.replace(".gif", "-palette.gif")]
)
subprocess.check_output(
[
"ffmpeg",
"-i",
str(path_to_mp4),
"-i",
path_to_gif.replace(".gif", "-palette.gif"),
"-filter_complex",
f"fps={fps},scale=1024:-1:flags=lanczos[x];[x][1:v]paletteuse",
"-loop",
"-1",
]
+ [str(path_to_gif)]
)
subprocess.check_output(["rm", path_to_gif.replace(".gif", "-palette.gif")])
return str(path_to_gif)
if __name__ == "__main__":
args = side_by_side_parser().parse_args()
overwrite = args.overwrite
if shutil.which("ffmpeg") is None:
raise Exception(
"Cannot find ffmpeg in path! Please install it before continuing."
)
if "vismet-" in args.platform:
args.platform = args.platform.replace("vismet-", "")
if not args.test_name.endswith("-e10s"):
args.test_name += "-e10s"
print(
"Vismet tasks do not contain browsertime video recordings."
+ "We'll assume you meant this platform: %s" % args.platform
)
if args.vismetPath and not pathlib.Path(args.vismetPath).exists():
raise Exception("Cannot find the vismet script at: %s" % args.vismetPath)
if args.metric != "similarity" and args.skip_download:
print(
"WARNING: Downloads will not be skipped as you are using something other "
"than the similarity metric (only supported for this metric)."
)
# Parse the given output argument
filename = "side-by-side.mp4"
output = pathlib.Path(args.output)
if output.exists() and output.is_file():
print("Deleting existing output file...")
output.unlink()
elif not output.suffixes:
output.mkdir(parents=True, exist_ok=True)
else:
filename = output.name
output = output.parents[0]
output.mkdir(parents=True, exist_ok=True)
# Make sure we remove the old side-by-side visualization
# for the FFMPEG operations
cold_path = pathlib.Path(output, "cold-" + filename)
warm_path = pathlib.Path(output, "warm-" + filename)
if cold_path.exists():
cold_path.unlink()
if warm_path.exists():
warm_path.unlink()
# Get the task group IDs for the revisions
base_revision_ids = find_task_group_id(
args.base_revision, args.base_branch, search_crons=args.search_crons
)
new_revision_ids = find_task_group_id(
args.new_revision, args.new_branch, search_crons=args.search_crons
)
base_task_dirs = [pathlib.Path(output, revid) for revid in base_revision_ids]
new_task_dirs = [pathlib.Path(output, revid) for revid in new_revision_ids]
if overwrite:
for task_dir in base_task_dirs + new_task_dirs:
if task_dir.exists():
print("Removing existing task group folder: %s" % str(task_dir))
shutil.rmtree(str(task_dir))
def _search_for_paths(rev_ids, artifact, open_data=False):
found_paths = []
for rev_id in rev_ids:
if found_paths:
break
# Get the paths to the directory holding the artifacts, the 0
# index is because we are only looking at one suite here.
found_paths = list(
get_task_data_paths(rev_id, str(output), artifact=artifact).values()
)[0]
return found_paths
# Setup the vismet version of the platform and test names
vismet_platform = args.platform.replace("test-", "test-vismet-")
test_no_e10s = args.test_name.replace("-e10s", "")
# Download the artifacts
if not args.skip_download:
base_paths = []
for base_revision_id in base_revision_ids:
if base_paths:
break
artifact_downloader(
base_revision_id,
output_dir=str(output),
test_suites=[args.test_name],
platform=args.platform,
artifact_to_get=["browsertime-results", "perfherder-data"],
unzip_artifact=True,
download_failures=False,
ingest_continue=False,
)
base_paths = _search_for_paths([base_revision_id], "browsertime-results")
base_vismet = _search_for_paths([base_revision_id], "perfherder-data")
new_paths = []
for new_revision_id in new_revision_ids:
if new_paths:
break
artifact_downloader(
new_revision_id,
output_dir=str(output),
test_suites=[args.new_test_name or args.test_name],
platform=args.new_platform or args.platform,
artifact_to_get=["browsertime-results", "perfherder-data"],
unzip_artifact=True,
download_failures=False,
ingest_continue=False,
)
new_paths = _search_for_paths([new_revision_id], "browsertime-results")
new_vismet = _search_for_paths([new_revision_id], "perfherder-data")
else:
base_paths = _search_for_paths(base_revision_ids, "browsertime-results")
base_vismet = _search_for_paths(base_revision_ids, "perfherder-data")
new_paths = _search_for_paths(new_revision_ids, "browsertime-results")
new_vismet = _search_for_paths(new_revision_ids, "perfherder-data")
# Make sure we only downloaded one task
failure_msg = (
"Not enough artifacts downloaded for %s, can't compare! "
+ "Found paths: %s \nTry using --search-crons if you are sure the task exists."
)
if not base_paths:
raise Exception(failure_msg % (args.base_revision, base_paths))
if not new_paths:
raise Exception(failure_msg % (args.new_revision, new_paths))
# Gather the videos and split them between warm and cold
base_videos = find_videos_with_retriggers(base_paths, original=args.original)
new_videos = find_videos_with_retriggers(new_paths, original=args.original)
# If we are looking at something other than similarity,
# prepare the data for this (open, and split between
# cold and warm)
if args.metric != "similarity":
print("Opening, and organizing perfherder data...")
org_base_vismet = open_and_organize_perfherder(base_vismet, args.metric)
org_new_vismet = open_and_organize_perfherder(new_vismet, args.metric)
if (not org_new_vismet["cold"] and not org_new_vismet["warm"]) or (
not org_base_vismet["cold"] and not org_base_vismet["warm"]
):
raise Exception("Could not find any data with the metric: %s" % args.metric)
run_cold = args.cold
run_warm = args.warm
if not args.cold and not args.warm:
run_cold = True
run_warm = True
# Find the worst video pairing for cold and warm
print("Starting comparisons, this may take a few minutes")
if run_cold:
print("Running comparison for cold pageloads...")
if args.metric == "similarity":
cold_pairing = find_lowest_similarity(
base_videos["cold"],
new_videos["cold"],
str(output),
"cold_",
most_similar=args.most_similar,
)
else:
cold_pairing = find_closest_videos(
base_videos["cold"],
org_base_vismet["cold"],
new_videos["cold"],
org_new_vismet["cold"],
str(output),
"cold_",
args.metric,
)
if run_warm:
gc.collect()
print("Running comparison for warm pageloads...")
if args.metric == "similarity":
warm_pairing = find_lowest_similarity(
base_videos["warm"],
new_videos["warm"],
str(output),
"warm_",
most_similar=args.most_similar,
)
else:
warm_pairing = find_closest_videos(
base_videos["warm"],
org_base_vismet["warm"],
new_videos["warm"],
org_new_vismet["warm"],
str(output),
"warm_",
args.metric,
)
# Build up the side-by-side comparisons now
if run_cold:
output_name = str(pathlib.Path(output, "cold-" + filename))
build_side_by_side(
cold_pairing["oldvid"],
cold_pairing["newvid"],
cold_pairing["oldvid_ind"],
cold_pairing["newvid_ind"],
output,
"cold-" + filename,
)
print("Successfully built a side-by-side cold comparison: %s" % output_name)
gif_output_name = pathlib.Path(
output, "cold-" + filename.replace(".mp4", ".gif")
)
gif_output_name = convert_mp4_to_gif(output_name, gif_output_name)
print(
"Successfully converted the side-by-side cold comparison to gif: %s"
% gif_output_name
)
if not args.skip_slow_gif:
gif_output_name = convert_mp4_to_gif(
output_name, gif_output_name, slow_motion=True
)
print(
"Successfully converted the side-by-side cold comparison to slow motion gif: %s"
% gif_output_name
)
if run_warm:
output_name = str(pathlib.Path(output, "warm-" + filename))
build_side_by_side(
warm_pairing["oldvid"],
warm_pairing["newvid"],
warm_pairing["oldvid_ind"],
warm_pairing["newvid_ind"],
output,
"warm-" + filename,
)
print("Successfully built a side-by-side warm comparison: %s" % output_name)
gif_output_name = pathlib.Path(
output, "warm-" + filename.replace(".mp4", ".gif")
)
gif_output_name = convert_mp4_to_gif(output_name, gif_output_name)
print(
"Successfully converted the side-by-side warm comparison to gif: %s"
% gif_output_name
)
if not args.skip_slow_gif:
gif_output_name = convert_mp4_to_gif(
output_name, gif_output_name, slow_motion=True
)
print(
"Successfully converted the side-by-side warm comparison to slow motion gif: %s"
% gif_output_name
)