Debian Codegraph @

doc/internal/media_logging_manual.rst

raw
1 Media logging manual
2 ^^^^^^^^^^^^^^^^^^^^
3
4 Workflows
5 =========
6
7 User submitting debug info
8 --------------------------
9
10 Basically:
11
12 - get samples
13 - run a script
14 - submit that directory
15
16 This is detailed in ``tools/ffmpeg/readme_run_tests.txt``.
17
18 Changing code in pyglet ffmpeg subsystem
19 ----------------------------------------
20
21 Preparation like in readme_run_tests.txt, optionally install the library bokeh
22 (http://bokeh.pydata.org/en/latest/index.html) for visualization support.
23
24 The basic flow goes as:
25
26 - initialize the active session subsystem:
27 set environment variable ``pyglet_mp_samples_dir`` to the desired
28 samples_dir.
29 - record a session with the initial state::
30
31 configure.py new <session> [playlist]
32 run_test_suite.py
33
34 - Follow this workflow
35
36 .. code-block:: none
37
38 while True:
39 edit code
40 commit to hg
41 record a new session:
42 configure.py new <new session> [playlist]
43 run_test_suite.py
44 look at the last session reports in samples_dir/session/reports
45 especially 00_summary.txt, which shows defects stats and list condensed
46 info about any sample failing;
47 then to look more details look at the individual reports.
48 compare with prev sessions if desired:
49 compare.py <session1> <session2>
50
51 render additional reports:
52 report.py sample
53
54 or visualize the data collected with:
55 bokeh_timeline.py sample
56
57 if results are as wanted, break
58 done, you may want to delete sessions for intermediate commits
59
60 It is possible to return to a previous session to request additional reports::
61
62 configure.py activate <session>
63 report.py ...
64
65 You can list the known sessions for the current samples_dir with::
66
67 configure.py list
68
69 .. important::
70 All this debugging machinery depends on a detailed and accurate capture of
71 media_player related state, currently in examples/media_player.py and
72 pyglet.media.player.
73
74 Modifications in those modules may require matching modifications in
75 pyglet/media/sources/instrumentation.py, and further propagation to other
76 modules.
77
78
79 Changing the debug code for pyglet ffmpeg
80 -----------------------------------------
81
82 For initial debugging of debug code, where there are misspellings and trivial
83 errors to weed out, creating a new session for each run_test_suite.py run may
84 be inconvenient.
85
86 The flag ``dev_debug`` can be set to true in the session configuration file;
87 this will allow to rewrite the session.
88
89 Keep in mind that some raw data will be stale or misleading:
90
91 - The ones captured at session creation time (currently pyglet.info and
92 pyglet_changeset)
93 - The collected crashes info (new crashes will not be seen)
94 - If media_player.py crashes before doing any writing, the state recording
95 will be the previous recording.
96
97 The reports using that stale raw data will obviously report stale data.
98
99 So it is a good idea to switch to a normal workflow as soon as possible
100 (simply creating a new session and deleting the special session).
101
102
103 Session
104 =======
105
106 If ``playlist_file`` is not specified, then all files in samples_dir, except
107 for the files with extension ".dbg", ".htm", ".html", ".json", ".log", ".pkl",
108 ".py", ".txt" will make the implicit playlist; subdirectories of samples_dir
109 will **not** be explored.
110
111 If a ``playlist_file`` is specified, then it should contain one sample name
112 per line; a sanity check will be performed ensuring no blacklisted extension
113 is used, and that the sample exists in samples_dir.
114
115 Once the ``playlist_file`` is used in ``configure.py new`` a copy is written to
116 the session raw data directory, and this copy will be the authoritative
117 playlist for the session; ``playlist_file`` can be deleted if desired.
118
119 Specifying a playlist is useful in development to restrict the tests to
120 samples relevant to the feature or issue under work.
121
122 The session name will be used to create a samples_dir subdir to store the test
123 results, hence it should be different of previous sessions names, and it must
124 not contain slashes, ``/``, backslashes ``\`` or characters forbidden in
125 directory names.
126
127
128 Active session
129 ==============
130
131 Most commands and subcommands target the currently active session.
132
133 A session becomes active when
134
135 - a ``configure.py new session [playlist]`` is issued
136 - a ``configure.py activate session`` is issued
137
138 The current implementation relies in two pieces of data to determine the
139 active session
140
141 - the environment variable ``pyglet_mp_samples_dir`` specifies samples_dir,
142 the directory where all the media samples reside. Under the current
143 paths schema is also where session data will be stored, one subdir per
144 session.
145
146 - a file ``activation.json`` in samples_dir storing the name for the
147 current active session.
148
149 Notice that the second precludes running two commands in parallel targeting
150 two different sessions in the same sample_dir.
151
152 The concept of active session plus the enforced path schema avoids the need to
153 provide paths at each command invocation, making for less errors, easier docs
154 and less typing.
155
156
157 Commands Summary
158 ================
159
160 Primary commands
161 ----------------
162
163 They are the ones normally used by developers
164
165 ``configure.py``, ``mp.py`` : session creation, activation, protection, status
166 and list all.
167
168 ``run_test_suite.py`` : plays session's samples, reports results.
169
170 ``report.py`` : produces the specified report for the specified sample.
171
172 ``timeline.py`` : translates the event stream to a stream of ``media_player``
173 state, useful to pass to other software.
174
175 ``bokeh_timeline.py`` : visualization of data collected for the specified
176 sample.
177
178 Helper commands
179 ---------------
180
181 Somehow an artifact of ``run_test_suite.py`` development, can help in testing
182 the debugging subsystem. ``run_test_suite.py`` is basically ``playmany.py +
183 retry_crashed.py + summarize.py``. When trying to change ``run_test_suite.py``
184 it is easier to first adapt the relevant helper.
185
186 ``playmany.py`` : plays active session samples, recording media_player state
187 along the play.
188
189 ``retry_crashed.py`` : plays again samples that have been seen always
190 crashing, hoping to get a recording with no crash. Motivated by early tests on
191 Ubuntu, where sometimes (but not always) a sample will crash the media_player.
192
193 ``summarize.py`` : using the raw data produced by the two previous commands
194 elaborates some reports, aiming to give an idea of how well the run was and
195 what samples should be investigated.
196
197 Data directory layout
198 =====================
199
200 .. code-block:: none
201
202 samples_dir/ : directory where the samples live, also used to store
203 sessions data
204 <session name>/ : directory to store session info, one per session,
205 named as the session.
206 dbg/ : recording of media_player events captured while playing a
207 sample, one per sample, named as sample.dbg; additional
208 versioning info, other raw data collected.
209 _crashes_light.pkl : pickle with info for retry crashed
210 _pyglet_hg_revision.txt
211 _pyglet_info.txt
212 _samples_version.txt
213 _session_playlist.txt
214 <one .dbg file per sample in the session playlist, named sample.dbg>
215 reports/ : human readable reports rendered from the raw data (.txt),
216 visualizations (.html), intermediate data used by other
217 tools(.pkl)
218 configuration.json : session configuration info, mostly permissions
219 activation.json : holds the name of current active session
220 <sample> : one for each sample
221
222 A subdirectory of samples_dir is detected as a session dir if:
223
224 - it is a direct child of session dir
225 - it has a ``configuration.json`` file
226
227 policies:
228
229 - it should be hard to rewrite the .dbg files (recordings of media_player
230 states)
231 - think of dev analyzing data sent by an user.
232
233
234 Code Layout and conventions
235 ===========================
236
237 The emerging separation of responsibilities goes like
238
239 Scripts (commands)
240 ------------------
241
242 Structured as:
243
244 - uses ``if __main__`` idiom to allow use as module (testing, sharing)
245 - ``sysargs_to_mainargs()``: ``sys.argv`` translation to ``main`` params
246 - ``main(...)``
247
248 - params validation and translation to adequate code entities (uses
249 module ``fs``).
250 - translates exceptions to prints (uses module ``mpexceptions``)
251 - short chain of instantiations / function calls to accomplish the
252 command goals, no logic or calculations here.
253 - other functions and classes: code specific to this command, delegates as
254 much as possible to modules.
255
256 When two scripts use some related but not identical functionality, these parts
257 can be moved to another module. Example: at first ``summarize`` had the code to
258 collect defects stats, later, when ``compare`` was written, the module
259 ``extractors`` was added and the defect collection stats code moved to that
260 module.
261
262 If script B needs a subset of unchanged script A functionality, it imports A
263 and uses what it needs. Example is ``retry_crashed``, will call into
264 ``playmany``.
265
266 Because of the last point, some scripts will also be listed as modules.
267
268
269 Modules
270 -------
271
272
273 buffered_logger
274 _______________
275
276 Accumulation of debug events while playing media_player, saves when
277 sample's play ends
278
279
280 instrumentation
281 _______________
282
283 Defines the events that modify media_player state.
284 Defines which events are potential defects.
285 Gives the low level support to extract info from the recorded data.
286
287 For new code here, keep accepting and returning only data structures, no paths
288 or files.
289
290
291 fs
292 __
293
294 Path building for entities into a session directory should be delegated to
295 ``fs.PathServices``.
296 Session's creation, activation and management at start of ``fs``.
297 Versions capture are handled at start of module ``fs``.
298 Utility functions to load - save at the end of ``fs``.
299
300 While there isn't a ``Session`` object, in practice the code identifies and
301 provides access to a particular session data by handling a ``fs.PathServices``
302 instance.
303
304
305 extractors
306 __________
307
308 Analyzes a media_player recording to build specific info on behalf of
309 reporters. Uses ``instrumentation`` to get input data about the media_player
310 state sequence seen while playing a sample.
311 Defines object types to collect some specific info about a replay.
312
313
314 reports
315 _______
316
317 Formats as text info captured / generated elsewhere.
318
319
320 mpexceptions
321 ____________
322
323 Defines exceptions generated by code in the ffmpeg debug subsystem.
324
325
326 Scripts that also acts as modules
327 ---------------------------------
328
329 timeline
330 ________
331
332 Renders the media player's debug info to a format more suitable to postprocess
333 in a spreadsheets or other software, particularly to get a data visualization.
334 (used by ``bokeh_timeline.py``)
335
336 playmany
337 ________
338
339 Produces media_player debug recordings.
340 Runs python scripts as subprocesses with a timeout (used by retry_crashed.py).
341
342
343 Commands detailed
344 =================
345
346 bokeh_timeline.py
347 -----------------
348
349 Usage::
350
351 bokeh_timeline.py sample
352
353 Renders media player's internal state graphically using bokeh.
354
355 Arguments:
356
357 .. code-block:: none
358
359 sample: sample to report
360
361 The output will be written to session's output dir under
362 ``reports/sample.timeline.html``.
363
364 Notice the plot can be zoomed live with the mouse wheel, but you must click
365 the button that looks as a distorted **OP**; it also does pan with mouse drag.
366
367 Example::
368
369 bokeh_timeline.py small.mp4
370
371 will write the output to ``report/small.mp4.timeline.html``.
372
373
374 compare.py
375 ----------
376
377 Usage::
378
379 compare.py --reldir=relpath other_session
380
381 Builds a reports comparing the active session with other_session.
382
383 Outputs to ``samples_dir/relpath/comparison_<session>_<other_session>.txt``.
384
385
386 configure.py
387 ------------
388
389 Usage::
390
391 configure.py subcommand [args]
392
393 Subcommands:
394
395 .. code-block:: none
396
397 new session [playlist] : Creates a new session, sets it as the active one
398 activate session : activates a session
399 deactivate : no session will be active
400 protect [target]: forbids overwrite of session data
401 status : prints configuration for the active session
402 help [subcommand] : prints help for the given subcommand or topic
403 list : list all sessions associated the current samples_dir
404
405 Creates and manages pyglet media_player debug session configurations.
406
407 Most commands and subcommands need an environment variable
408 ``pyglet_mp_samples_dir`` to be set to the directory where the media samples
409 reside.
410
411 The configuration stores some values used when other commands are executed,
412 mostly protection status.
413
414 This command can be called both as ``configure.py`` or ``mp.py``, they do the
415 same.
416
417
418 mp.py
419 -----
420
421 alias for ``configure.py``
422
423
424 playmany.py
425 -----------
426
427 Usage::
428
429 playmany.py
430
431 Uses media_player to play a sequence of samples and record debug info.
432
433 A session must be active, see command ``configure.py``
434 If the active configuration has disallowed dbg overwrites it will do nothing.
435
436 If a playlist was provided at session creation, then only the samples in the
437 playlist will be played, otherwise all files in ``samples_dir``.
438
439
440 report.py
441 ---------
442
443 Usage::
444
445 report.py sample report_name
446
447 Generates a report from the debugging info recorded while playing sample.
448
449 Arguments:
450
451 .. code-block:: none
452
453 sample: sample to report
454 report_name: desired report, one of
455 "anomalies": Start, end and interesting events
456 "all": All data is exposed as text
457 "counter": How many occurrences of each defect
458
459 The report will be written to session's output dir under
460 ``reports/sample.report_name.txt``.
461
462 Example::
463
464 report anomalies small.mp4
465
466 will write the report *anomalies* to ``report/small.mp4.anomalies.txt``.
467
468 The authoritative list of reports available comes from
469 ``reports.available_reports``
470
471
472 retry_crashed.py
473 ----------------
474
475 Usage::
476
477 retry_crashed.py [--clean] [max_retries]
478
479 Inspects the raw data collected to get the list of samples that crashed the
480 last time they were played.
481 Then it replays those samples, recording new raw data for them.
482
483 The process is repeated until all samples has a recording with no crashes or
484 the still crashing samples were played ``max_tries`` times in this command
485 run.
486
487 Notice that only samples recorded as crashing in the last run are retried.
488
489 A configuration must be active, see command ``configure.py``.
490
491 Besides the updated debug recordings, a state is build and saved:
492
493 .. code-block:: none
494
495 total_retries: total retries attempted, including previous runs
496 sometimes_crashed: list of samples that crashed one time but later
497 completed a play
498 always_crashed: list of samples that always crashed
499
500 Options:
501
502 .. code-block:: none
503
504 --clean: discards crash data collected in a previous run
505 max_retries: defaults to 5
506
507
508 run_test_suite.py
509 -----------------
510
511 Usage::
512
513 run_test_suite.py [samples_dir]
514
515 Plays media samples with the pyglet media_player, recording debug information
516 for each sample played and writing reports about the data captured.
517
518 Arguments:
519
520 .. code-block:: none
521
522 samples_dir: directory with the media samples to play
523
524 If no samples_dir is provided the active session is the target.
525 If an explicit playlist was specified when creating the session, then only the
526 samples in the playlist will be played, otherwise all samples in samples_dir
527 will be played.
528
529 If sample_dir is provided, a session named ``testrun_00`` (``_01``, ``_02``,
530 ... if that name was taken) will be created, with no explicit playlist, and
531 then the command operates as in the previous case.
532
533 Output files will be into:
534
535 .. code-block:: none
536
537 samples_dir/session/dbg : binary capture of media_player events, other raw
538 data captured
539 samples_dir/session/reports : human readable reports
540
541 .. note::
542
543 This script will refuse to overwrite an existing ``test_run results``.
544
545 Output files will be into subdirectories:
546
547 ``samples_dir/test_run/dbg``
548
549 Each sample will generate a ``sample.dbg`` file storing the sequence of
550 player debug events seen while playing the sample.
551 It is simply a pickle of a list of tuples, each tuple an event.
552 There are not meant for direct human use, but to run some analyzers to
553 render useful reports.
554
555 A ``crash_retries.pkl`` file, a pickle of
556 ``(total_retries, sometimes_crashed, still_crashing) <-> (int, set, set)``.
557
558 A ``pyglet.info`` captured at session creation to track hw & sw.
559
560 A pyglet hg revision captured at session creation.
561
562 ``samples_dir/test_run/reports``
563
564 Human readable outputs, described in command ``summarize.py``
565
566 Later a user can generate visualizations and additional reports that will
567 be stored in this directory
568
569
570 summarize.py
571 ------------
572
573 Usage::
574
575 summarize.py
576
577 Summarizes the session info collected with ``playmany`` and ``retry_crashes``.
578
579 A configuration must be active, see command ``configure.py``.
580
581 If a playlist was provided at session creation, then only the samples in the
582 playlist will be played, otherwise all files in samples_dir.
583
584 Produces human readable reports, constructed from the .dbg files.
585
586 Output will be in
587
588 ``samples_dir/test_run/reports``
589
590 The files in that directory will be
591
592 ``00_summary.txt`` , which provides:
593
594 - basics defects stats over all samples
595 - a paragraph for each non perfect sample play with the count of each
596 anomaly observed
597
598 ``03_pyglet_info.txt`` , ``pyglet.info`` output giving OS, python version,
599 etc (as captured at session creation).
600
601 ``04_pyglet_hg_revision.txt`` , pyglet hg revision if running from a repo
602 clone, non written if no repo (as captured at session creation).
603
604 ``sample_name.all.txt`` and ``sample_name.anomalies.txt`` for each sample that
605 played non perfect.
606
607 ``sample_name.all.txt`` has all info in the ``sample_name.dbg`` in human
608 readable form, that is, the sequence of player's internal events along the
609 play.
610
611 ``sample_name.anomalies.txt`` is a reduced version of the ``.all``.
612 variant: normal events are not shown, only anomalies.
613
614
615 timeline.py
616 -----------
617
618 Usage::
619
620 timeline.py sample [output_format]
621
622 Renders the media player's debug info to a format more suitable to postprocess
623 in a spreadsheets or other software, particularly to get a data visualization.
624
625 See output details in the manual.
626
627 Arguments:
628
629 .. code-block:: none
630
631 sample: sample to report
632 output_format : one of { "csv", "pkl"}, by default saves as .pkl (pickle)
633
634 The output will be written to session's output dir under
635 ``reports/sample.timeline.[.pkl or .csv]``.
636
637 Example::
638
639 timeline.py small.mp4
640
641 will write the output to ``report/small.mp4.timeline.pkl``.
642
643 .. note::
644 ``.csv`` sample is currently not implemented.
645
646
647 Samples
648 =======
649
650 Samples should be small, at the moment I suggest an arbitrary 2MB 2 minutes
651 limit. The samples dir contains a ``_sources.txt`` which lists from where
652 each sample comes.
653
654 Caveat:
655
656 Samples are not 'certified to be compliant with the specification'.
657
658 When possible, samples should be played with non ffmpeg software for
659 incidental confirmation of well formed
660
661 ``*.mp4``, ``*.3gp`` played well with Windows Media Player for win7
662
663 ``*.ogv``, ``*. webm`` played well with Firefox 54.0
664
665 ``*.flv``, ``*.mkv`` played well with VLC Media player, but VLC uses
666 ffmpeg
667
668 Surely the samples set will be refined as time goes.
669
670
671 pycharm notes
672 =============
673
674 For ``examples/video_ffmpeg`` module visibility and code completion, that
675 directory should be a 'content root' in pycharm settings | 'project
676 structure'; as projects roots cannot nest, the pyglet working copy cannot be a
677 'content root', I removed it; I added also working_copy/pyglet as another
678 'content root' so pycharm plays well also en the library proper. This with
679 pycharm 2017.2