Debian Codegraph @

tools/ffmpeg/retry_crashed.py

raw symbols SCIP
1 """
2 Usage
3
4 retry_crashed.py [--clean] [max_retries]
5
6 Inspects the raw data collected to get the list of samples that crashed the last
7 time they were played.
8 Then it replays those samples, recording new raw data for them.
9
10 The process is repeated until all samples has a recording with no crashes or
11 the still crashing samples were played 'max_tries' times in this command run.
12
13 A configuration must be active, see command configure.py
14
15 Besides the updated debug recordings, a state is build and saved:
16 total_retries: total retries attempted, including previous runs
17 sometimes_crashed: list of samples that crashed one time but later completed a play
18 always_crashed: list of samples that always crashed
19
20 Options:
21 --clean: discards crash data collected in a previous run
22 max_retries: defaults to 5
23 """
24 import os
25 import sys
26
27 import fs
28 from pyglet.media import instrumentation as ins
29 import mpexceptions
30 import playmany
31
32
33 def main(clean, max_retries):
34 try:
35 pathserv = fs.get_path_info_for_active_session()
36 except mpexceptions.ExceptionUndefinedSamplesDir:
37 print("The env var 'pyglet_mp_samples_dir' is not defined.")
38 return 1
39 except mpexceptions.ExceptionNoSessionIsActive:
40 print("*** Error, no session active.")
41 return 1
42
43 if clean:
44 crashes_light_file = pathserv.special_raw_filename("crashes_light")
45 if os.path.isfile(crashes_light_file):
46 os.unlink(crashes_light_file)
47
48 retry_crashed(pathserv, max_retries)
49 return 0
50
51
52 def retry_crashed(pathserv, max_retries=5):
53 crashes_light_file = pathserv.special_raw_filename("crashes_light")
54 if os.path.isfile(crashes_light_file):
55 total_retries, sometimes_crashed, still_crashing = fs.pickle_load(crashes_light_file)
56 samples_to_consider = still_crashing
57 else:
58 total_retries, sometimes_crashed = 0, set()
59 playlist_gen = pathserv.session_playlist_generator()
60 samples_to_consider = [s for s, f in playlist_gen]
61
62 cnt_retries = 0
63 while 1:
64 still_crashing = set()
65 for sample in samples_to_consider:
66 if sample_crashed(pathserv, sample):
67 sometimes_crashed.add(sample)
68 still_crashing.add(sample)
69 fs.pickle_save((total_retries, sometimes_crashed, still_crashing), crashes_light_file)
70
71 if cnt_retries >= max_retries or len(still_crashing) == 0:
72 break
73 samples_to_consider = still_crashing
74 playlist = pathserv.playlist_generator_from_samples_iterable(samples_to_consider)
75 playmany.core_play_many(pathserv, playlist)
76 cnt_retries += 1
77 total_retries += 1
78
79
80 def sample_crashed(pathserv, sample):
81 dbg_file = pathserv.dbg_filename(sample)
82 log_entries = fs.pickle_load(dbg_file)
83 return ins.crash_detected(log_entries)
84
85
86 def sysargs_to_mainargs():
87 """builds main args from sys.argv"""
88 if len(sys.argv) > 1 and sys.argv[1].startswith("--help"):
89 print(__doc__)
90 sys.exit(1)
91
92 if len(sys.argv) > 1 and sys.argv[1] == "--clean":
93 sys.argv.pop(1)
94 clean = True
95 else:
96 clean = False
97
98 if len(sys.argv) > 1:
99 max_retries = int(sys.argv[1])
100 else:
101 max_retries = 5
102
103 return clean, max_retries
104
105 if __name__ == "__main__":
106 clean, max_retries = sysargs_to_mainargs()
107 main(clean, max_retries)