1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-27 09:32:40 +00:00
mpv/common/msg.h
wm4 9dba2a52db 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.
2014-04-17 21:47:00 +02:00

88 lines
3.3 KiB
C

/*
* This file is part of MPlayer.
*
* MPlayer is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* MPlayer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef MPLAYER_MP_MSG_H
#define MPLAYER_MP_MSG_H
#include <stdarg.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdint.h>
#include "compat/compiler.h"
struct mp_log;
// A mp_log instance that never outputs anything.
extern struct mp_log *const mp_null_log;
// Verbosity levels.
enum {
MSGL_FATAL, // will exit/abort (note: msg.c doesn't exit or abort)
MSGL_ERR, // continues
MSGL_WARN, // only warning
MSGL_INFO, // -quiet
MSGL_STATUS, // exclusively for the playback status line
MSGL_V, // -v
MSGL_DEBUG, // -v -v
MSGL_TRACE, // -v -v -v
MSGL_STATS, // dumping fine grained stats (--dump-stats)
MSGL_SMODE, // old slave mode (-identify)
MSGL_MAX = MSGL_SMODE,
};
struct mp_log *mp_log_new(void *talloc_ctx, struct mp_log *parent,
const char *name);
void mp_msg(struct mp_log *log, int lev, const char *format, ...)
PRINTF_ATTRIBUTE(3, 4);
void mp_msg_va(struct mp_log *log, int lev, const char *format, va_list va);
bool mp_msg_test(struct mp_log *log, int lev);
// Convenience macros.
#define mp_fatal(log, ...) mp_msg(log, MSGL_FATAL, __VA_ARGS__)
#define mp_err(log, ...) mp_msg(log, MSGL_ERR, __VA_ARGS__)
#define mp_warn(log, ...) mp_msg(log, MSGL_WARN, __VA_ARGS__)
#define mp_info(log, ...) mp_msg(log, MSGL_INFO, __VA_ARGS__)
#define mp_verbose(log, ...) mp_msg(log, MSGL_V, __VA_ARGS__)
#define mp_dbg(log, ...) mp_msg(log, MSGL_DEBUG, __VA_ARGS__)
#define mp_trace(log, ...) mp_msg(log, MSGL_TRACE, __VA_ARGS__)
// Convenience macros, typically called with a pointer to a context struct
// as first argument, which has a "struct mp_log *log;" member.
#define MP_MSG(obj, lev, ...) mp_msg((obj)->log, lev, __VA_ARGS__)
#define MP_FATAL(obj, ...) MP_MSG(obj, MSGL_FATAL, __VA_ARGS__)
#define MP_ERR(obj, ...) MP_MSG(obj, MSGL_ERR, __VA_ARGS__)
#define MP_WARN(obj, ...) MP_MSG(obj, MSGL_WARN, __VA_ARGS__)
#define MP_INFO(obj, ...) MP_MSG(obj, MSGL_INFO, __VA_ARGS__)
#define MP_VERBOSE(obj, ...) MP_MSG(obj, MSGL_V, __VA_ARGS__)
#define MP_DBG(obj, ...) MP_MSG(obj, MSGL_DEBUG, __VA_ARGS__)
#define MP_TRACE(obj, ...) MP_MSG(obj, MSGL_TRACE, __VA_ARGS__)
#define MP_SMODE(obj, ...) MP_MSG(obj, MSGL_SMODE, __VA_ARGS__)
// This is a bit special. See TOOLS/stats-conv.py what rules text passed
// to these functions should follow. Also see --dump-stats.
#define mp_stats(obj, ...) mp_msg(obj, MSGL_STATS, __VA_ARGS__)
#define MP_STATS(obj, ...) MP_MSG(obj, MSGL_STATS, __VA_ARGS__)
#endif /* MPLAYER_MP_MSG_H */