Debian Codegraph @

tools/ffmpeg/summarize.py

raw symbols SCIP
1 """
2 Usage
3
4 summarize.py
5
6 Summarizes the session info collected with playmany and retry_crashes
7
8 A configuration must be active, see command configure.py
9
10 If a playlist was provided at session creation, then only the samples in the
11 playlist will be played, otherwise all files in samples_dir.
12 """
13
14 import shutil
15 import sys
16
17 import extractors
18 import fs
19 from pyglet.media import instrumentation as ins
20 import mpexceptions
21 import report
22 import reports
23
24
25 def main():
26 try:
27 pathserv = fs.get_path_info_for_active_session()
28 except mpexceptions.ExceptionUndefinedSamplesDir:
29 print("The env var 'pyglet_mp_samples_dir' is not defined.")
30 return 1
31 except mpexceptions.ExceptionNoSessionIsActive:
32 print("*** Error, no session active.")
33 return 1
34
35 count_bads = ins.CountBads()
36
37 try:
38 summarize(pathserv, count_bads)
39 except mpexceptions.ExceptionAttemptToBrekReportsProtection:
40 print("*** Error, attempt to overwrite reports when protect_reports "
41 "is True.")
42 return 1
43 except mpexceptions.ExceptionNoDbgFilesPresent:
44 print("*** Error, no dbg files present; maybe playmany should be run?")
45 return 1
46 return 0
47
48
49 def summarize(pathserv, count_bads):
50 conf = fs.get_session_configuration(pathserv)
51 if conf["dev_debug"]:
52 pass
53 else:
54 if conf["protect_reports"]:
55 raise mpexceptions.ExceptionAttemptToBreakRawDataProtection()
56
57 session = pathserv.session
58 parts = ["Summary of media_player debug info for session: %s" % session]
59 filename = pathserv.special_raw_filename("samples_version")
60 try:
61 text = fs.txt_load(filename)
62 except Exception as ex:
63 print(ex)
64 print("*** Error, could not read dbg/_version.txt, "
65 "target dir probably not a session one.")
66 sys.exit(1)
67 parts.append("Samples version: %s" % text)
68
69 overall = extractors.single_session_overall_defect_counters(pathserv, count_bads.count_bads)
70
71 if len(overall.no_dbg_samples):
72 parts.append("Samples with no .dbg recording: %d" % len(overall.no_dbg_samples))
73 else:
74 parts.append("All samples have a .dbg recording.")
75
76 if len(overall.crashed_samples):
77 parts.append("Samples that always crashed: %d" % len(overall.crashed_samples))
78 else:
79 parts.append("All samples (finally) got a report with no crash.")
80
81 n = overall.total_relevant_samples()
82 parts.append("Relevant samples (all - no_dbg - crashed): %d" % n)
83
84 no_relevant_samples = (n == 0)
85 if no_relevant_samples:
86 parts.append("*** Error, no relevant samples remains to calculate"
87 " score.")
88 else:
89 parts.extend([
90 "Naive quality number (anomalies / samples): %f" % overall.defects_per_sample(),
91 "Relevant samples with perfect play: %d / %d" % (len(overall.perfect_play_samples), n),
92 "Relevant samples with anomalies : %d / %d" % (len(overall.counters_non_perfect_play_samples), n),
93 ""
94 ])
95
96 # include crash info collected by retry_crashed.py
97 text = reports.fragment_crash_retries(pathserv)
98 parts.append(text)
99 parts.append("")
100
101 # include count of defects for samples with anomalies but no crash
102 if len(overall.counters_non_perfect_play_samples):
103 parts.append("Per sample defects info (always crashed and perfect plays"
104 " not listed)\n")
105 for sample in sorted(overall.counters_non_perfect_play_samples.keys()):
106 counters = overall.counters_non_perfect_play_samples[sample]
107 text = reports.format_anomalies_counter(
108 count_bads.anomalies_description, counters, sample)
109 parts.append(text)
110 parts.append("")
111
112 # additionally emit reports 'anomalies' and 'all'
113 for sample in overall.counters_non_perfect_play_samples.keys():
114 report.report_sample(pathserv, sample, "anomalies")
115 report.report_sample(pathserv, sample, "all")
116
117 # appendix, list of samples without dbg
118 if len(overall.no_dbg_samples):
119 parts.append("Appendix, list of samples without dbg")
120 for s in overall.no_dbg_samples:
121 parts.append("\t%s" % s)
122 parts.append("")
123
124 text = "\n".join(parts)
125 filename_summary = pathserv.special_report_filename("summary")
126 fs.txt_save(text, filename_summary)
127
128 # output pyglet info as captured at session creation
129 src = pathserv.special_raw_filename("pyglet_info")
130 dst = pathserv.special_report_filename("pyglet_info")
131 shutil.copyfile(src, dst)
132 src = pathserv.special_raw_filename("pyglet_hg_revision")
133 dst = pathserv.special_report_filename("pyglet_hg_revision")
134 try:
135 shutil.copyfile(src, dst)
136 except Exception:
137 pass
138
139
140 def sysargs_to_mainargs():
141 """builds main args from sys.argv"""
142 if len(sys.argv) > 1 and sys.argv[1].startswith("--help"):
143 print(__doc__)
144 sys.exit(1)
145
146 if __name__ == '__main__':
147 main()