| 1 |
import os |
| 2 |
|
| 3 |
import fs |
| 4 |
from pyglet.media import instrumentation as ins |
| 5 |
import mpexceptions |
| 6 |
|
| 7 |
|
| 8 |
def render_event(events_definition, state, fn_prefix): |
| 9 |
evname = state["evname"] |
| 10 |
ev_description = events_definition[evname] |
| 11 |
parts = [fn_prefix(state)] |
| 12 |
parts.append(ev_description["desc"]) |
| 13 |
for name in ev_description["update_names"]: |
| 14 |
if name == "evname": |
| 15 |
continue |
| 16 |
parts.append(" %s: %s" % (name, state[name])) |
| 17 |
extra_names = ev_description["other_fields"] |
| 18 |
if extra_names: |
| 19 |
parts.append(' ;') |
| 20 |
for name in extra_names: |
| 21 |
parts.append(" %s: %s" % (name, state[name])) |
| 22 |
text = "".join(parts) |
| 23 |
return text |
| 24 |
|
| 25 |
|
| 26 |
def rpt_all(log_entries, events_definition=ins.mp_events): |
| 27 |
no_indent = {"crash", "mp.im", "p.P._sp", "p.P.sk", "p.P.ut.1.0", "p.P.oe"} |
| 28 |
fn_prefix = lambda st: "" if st["evname"] in no_indent else " " |
| 29 |
mp_states = ins.MediaPlayerStateIterator(log_entries, events_definition) |
| 30 |
parts = [] |
| 31 |
for mp in mp_states: |
| 32 |
s = "%4d " % mp["frame_num"] + render_event(events_definition, mp, fn_prefix) |
| 33 |
parts.append(s) |
| 34 |
text = "\n".join(parts) |
| 35 |
return text |
| 36 |
|
| 37 |
|
| 38 |
def rpt_anomalies(log_entries, events_definition=ins.mp_events): |
| 39 |
allow = {"crash", "mp.im", "p.P.sk", "p.P.ut.1.3", "p.P.ut.1.4", |
| 40 |
"p.P.ut.1.5", "p.P.ut.1.7", "p.P.ut.1.8", "p.P.oe"} |
| 41 |
mp_states = ins.MediaPlayerStateIterator(log_entries, events_definition) |
| 42 |
fn_prefix = lambda st: "%4d " % st["frame_num"] |
| 43 |
parts = [] |
| 44 |
for st in mp_states: |
| 45 |
if st["evname"] == "p.P.ut.1.9": |
| 46 |
if st["rescheduling_time"] < 0: |
| 47 |
parts.append("%4d !!! Scheduling in the past, reschedulling_time: %f" % |
| 48 |
(st["frame_num"], st["rescheduling_time"])) |
| 49 |
elif st["evname"] in allow: |
| 50 |
parts.append(render_event(events_definition, st, fn_prefix)) |
| 51 |
text = "\n".join(parts) |
| 52 |
return text |
| 53 |
|
| 54 |
|
| 55 |
def rpt_counter(log_entries, events_definition=ins.mp_events): |
| 56 |
count_bads = ins.CountBads(events_definition, ins.mp_bads) |
| 57 |
counters = count_bads.count_bads(log_entries) |
| 58 |
text = format_anomalies_counter(count_bads.anomalies_description, counters) |
| 59 |
return text |
| 60 |
|
| 61 |
|
| 62 |
def format_anomalies_counter(anomalies_description, counters, sample=None): |
| 63 |
parts = [] |
| 64 |
fmt = "%4d %s" |
| 65 |
for anomaly in counters: |
| 66 |
if counters[anomaly]: |
| 67 |
desc = anomalies_description[anomaly] |
| 68 |
parts.append(fmt % (counters[anomaly], desc)) |
| 69 |
if parts: |
| 70 |
parts_sorted = sorted(parts, key=lambda e: e[4:]) |
| 71 |
text = "\n".join(parts_sorted) |
| 72 |
text = ("Counts of anomalies\n" + |
| 73 |
"qtty anomaly\n" + text) |
| 74 |
else: |
| 75 |
text = "No anomalies detected." |
| 76 |
if sample is not None: |
| 77 |
text = "Sample: %s\n" % sample + text |
| 78 |
return text |
| 79 |
|
| 80 |
|
| 81 |
def fragment_crash_retries(pathserv): |
| 82 |
crashes_light_file = pathserv.special_raw_filename("crashes_light") |
| 83 |
if not os.path.isfile(crashes_light_file): |
| 84 |
text = "No crash info available, please run retry_crashes.py" |
| 85 |
return text |
| 86 |
total_retries, sometimes_crashed, still_crashing = fs.pickle_load(crashes_light_file) |
| 87 |
if len(sometimes_crashed) == 0: |
| 88 |
text = "No sample crashed the player." |
| 89 |
return text |
| 90 |
parts = [] |
| 91 |
if still_crashing: |
| 92 |
parts.append("Samples that crashed in any one of the %d attempts to play" % (total_retries + 1)) |
| 93 |
sorted_keys = sorted(still_crashing) |
| 94 |
for sample in sorted_keys: |
| 95 |
parts.append(sample) |
| 96 |
|
| 97 |
if still_crashing and sometimes_crashed: |
| 98 |
parts.append("") |
| 99 |
|
| 100 |
if sometimes_crashed: |
| 101 |
parts.append("Samples that crashed but finally played entirelly") |
| 102 |
finally_played = sometimes_crashed - still_crashing |
| 103 |
if finally_played: |
| 104 |
sorted_keys = sorted(finally_played) |
| 105 |
for sample in sorted_keys: |
| 106 |
parts.append(sample) |
| 107 |
else: |
| 108 |
parts.append("<none>") |
| 109 |
|
| 110 |
text = "\n".join(parts) |
| 111 |
return text |
| 112 |
|
| 113 |
|
| 114 |
available_reports = { |
| 115 |
|
| 116 |
"anomalies": (rpt_anomalies, "Start, end and interesting events"), |
| 117 |
"all": (rpt_all, "All data is exposed as text"), |
| 118 |
"counter": (rpt_counter, "How many occurrences of each defect") |
| 119 |
} |
| 120 |
|
| 121 |
|
| 122 |
def available_reports_description(line_prefix): |
| 123 |
d = available_reports |
| 124 |
lines = ["%s%s: %s" % (line_prefix, k, d[k][1]) for k in d] |
| 125 |
lines.sort() |
| 126 |
text = "\n".join(lines) |
| 127 |
return text |
| 128 |
|
| 129 |
|
| 130 |
def report_by_name(name): |
| 131 |
try: |
| 132 |
fn_report = available_reports[name][0] |
| 133 |
except KeyError: |
| 134 |
raise mpexceptions.ExceptionUnknownReport(name) |
| 135 |
return fn_report |
| 136 |
|
| 137 |
|
| 138 |
def report_session_comparison(session_comparison_data): |
| 139 |
sd = session_comparison_data |
| 140 |
header = "crashes | Defects per sample | session" |
| 141 |
fmt = "%7d | %18.3f | %s" |
| 142 |
parts = [header] |
| 143 |
|
| 144 |
cnt_crashes = len(sd.overall_counters.crashed_samples) |
| 145 |
score = sd.overall_counters.defects_per_sample() |
| 146 |
session = sd.overall_counters.pathserv.session |
| 147 |
parts.append(fmt % (cnt_crashes, score, session)) |
| 148 |
|
| 149 |
cnt_crashes_o = len(sd.overall_counters.crashed_samples) |
| 150 |
score_o = sd.overall_counters_o.defects_per_sample() |
| 151 |
session_o = sd.overall_counters_o.pathserv.session |
| 152 |
parts.append(fmt % (cnt_crashes_o, score_o, session_o)) |
| 153 |
|
| 154 |
parts.append("") |
| 155 |
c = sd.confidence_guess() |
| 156 |
parts.append("Confidence guess, from 1(highest) to 0(lowest): %.2f" % c) |
| 157 |
|
| 158 |
parts.append("") |
| 159 |
parts.append("Summary samples ignored for scores") |
| 160 |
parts.append("qtty | reason") |
| 161 |
|
| 162 |
n = len(sd.samples - sd.common_samples) |
| 163 |
parts.append("%4d only on playlist session '%s'" % (n, session)) |
| 164 |
n = len(sd.other_samples - sd.common_samples) |
| 165 |
parts.append("%4d only on playlist session '%s'" % (n, session_o)) |
| 166 |
|
| 167 |
n = len(sd.overall_counters.no_dbg_samples & sd.overall_counters_other.no_dbg_samples) |
| 168 |
parts.append("%4d no .dbg in both sessions" % n) |
| 169 |
n = len(sd.overall_counters.no_dbg_samples - sd.overall_counters_other.no_dbg_samples) |
| 170 |
parts.append("%4d .dbg missing only on session '%s'" % (n, session)) |
| 171 |
n = len(sd.overall_counters_other.no_dbg_samples - sd.overall_counters.no_dbg_samples) |
| 172 |
parts.append("%4d .dbg missing only on session '%s'" % (n, session_o)) |
| 173 |
|
| 174 |
n = len(sd.overall_counters.crashed_samples & sd.overall_counters_other.crashed_samples) |
| 175 |
parts.append("%4d crashed in both sessions" % n) |
| 176 |
n = len(sd.overall_counters.crashed_samples - sd.overall_counters_other.crashed_samples) |
| 177 |
parts.append("%4d crashed only on session '%s'" % (n, session)) |
| 178 |
n = len(sd.overall_counters_other.crashed_samples - sd.overall_counters.crashed_samples) |
| 179 |
parts.append("%4d crashed only on session '%s'" % (n, session_o)) |
| 180 |
|
| 181 |
text = "\n".join(parts) |
| 182 |
return text |