diff options
author | wm4 <wm4@nowhere> | 2014-04-17 21:47:00 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2014-04-17 21:47:00 +0200 |
commit | 9dba2a52db2adb42e7c1a292625bd0114ce81969 (patch) | |
tree | 6ea6a9410a4741bbb8e2c2c4cfff39c0172c3425 /player | |
parent | 6c24a80009025cbaf1e71a753b7c5572ba89b71f (diff) | |
download | mpv-9dba2a52db2adb42e7c1a292625bd0114ce81969.tar.bz2 mpv-9dba2a52db2adb42e7c1a292625bd0114ce81969.tar.xz |
player: add a --dump-stats option
This collects statistics and other things. The option dumps raw data
into a file. A script to visualize this data is included too.
Litter some of the player code with calls that generate these
statistics.
In general, this will be helpful to debug timing dependent issues, such
as A/V sync problems. Normally, one could argue that this is the task of
a real profiler, but then we'd have a hard time to include extra
information like audio/video PTS differences. We could also just
hardcode all statistics collection and processing in the player code,
but then we'd end up with something like mplayer's status line, which
was cluttered and required a centralized approach (i.e. getting the data
to the status line; so it was all in mplayer.c). Some players can
visualize such statistics on OSD, but that sounds even more complicated.
So the approach added with this commit sounds sensible.
The stats-conv.py script is rather primitive at the moment and its
output is semi-ugly. It uses matplotlib, so it could probably be
extended to do a lot, so it's not a dead-end.
Diffstat (limited to 'player')
-rw-r--r-- | player/main.c | 8 | ||||
-rw-r--r-- | player/playloop.c | 19 |
2 files changed, 26 insertions, 1 deletions
diff --git a/player/main.c b/player/main.c index 3a6084658c..dc685b84f7 100644 --- a/player/main.c +++ b/player/main.c @@ -366,6 +366,12 @@ int mp_initialize(struct MPContext *mpctx) assert(!mpctx->initialized); + if (opts->dump_stats && opts->dump_stats[0]) { + if (mp_msg_open_stats_file(mpctx->global, opts->dump_stats) < 0) + MP_ERR(mpctx, "Failed to open stats file '%s'\n", opts->dump_stats); + } + MP_STATS(mpctx, "start init"); + if (mpctx->opts->use_terminal && !terminal_initialized) { terminal_initialized = true; terminal_init(); @@ -452,6 +458,8 @@ int mp_initialize(struct MPContext *mpctx) if (!mpctx->playlist->current) mpctx->playlist->current = mpctx->playlist->first; + MP_STATS(mpctx, "end init"); + return 0; } diff --git a/player/playloop.c b/player/playloop.c index 84da8d231a..2495579c39 100644 --- a/player/playloop.c +++ b/player/playloop.c @@ -1030,6 +1030,7 @@ void run_playloop(struct MPContext *mpctx) } mpctx->time_frame -= get_relative_time(mpctx); + double audio_pts = playing_audio_pts(mpctx); if (full_audio_buffers && !mpctx->restart_playback) { buffered_audio = ao_get_delay(mpctx->ao); MP_TRACE(mpctx, "audio delay=%f\n", buffered_audio); @@ -1076,14 +1077,21 @@ void run_playloop(struct MPContext *mpctx) //=================== FLIP PAGE (VIDEO BLT): ====================== + MP_STATS(mpctx, "vo draw frame"); + vo_new_frame_imminent(vo); mpctx->video_pts = mpctx->video_next_pts; mpctx->last_vo_pts = mpctx->video_pts; mpctx->playback_pts = mpctx->video_pts; + update_subtitles(mpctx); update_osd_msg(mpctx); + + MP_STATS(mpctx, "draw OSD"); draw_osd(mpctx); + MP_STATS(mpctx, "vo sleep"); + mpctx->time_frame -= get_relative_time(mpctx); mpctx->time_frame -= vo->flip_queue_offset; if (mpctx->time_frame > 0.001) @@ -1120,7 +1128,13 @@ void run_playloop(struct MPContext *mpctx) } if (mpctx->restart_playback) duration = -1; + + MP_STATS(mpctx, "start flip"); vo_flip_page(vo, pts_us | 1, duration); + MP_STATS(mpctx, "end flip"); + + if (audio_pts != MP_NOPTS_VALUE) + MP_STATS(mpctx, "value %f ptsdiff", mpctx->video_pts - audio_pts); mpctx->last_vo_flip_duration = (mp_time_us() - t2) * 0.000001; if (vo->driver->flip_page_timed) { @@ -1256,8 +1270,11 @@ void run_playloop(struct MPContext *mpctx) if (handle_osd_redraw(mpctx)) sleeptime = 0; } - if (sleeptime > 0) + if (sleeptime > 0) { + MP_STATS(mpctx, "start sleep"); mp_input_get_cmd(mpctx->input, sleeptime * 1000, true); + MP_STATS(mpctx, "end sleep"); + } } handle_metadata_update(mpctx); |