mirror of
https://github.com/mpv-player/mpv
synced 2025-01-19 05:41:16 +00:00
player, stats: more silly debug stuff
In addition to stats.c being gross, I don't think master branch code should be littered with debug code. But it's a helpful abomination.
This commit is contained in:
parent
437a46d443
commit
a2846faa32
@ -45,6 +45,7 @@ enum val_type {
|
||||
VAL_UNSET = 0,
|
||||
VAL_STATIC,
|
||||
VAL_STATIC_SIZE,
|
||||
VAL_INC,
|
||||
VAL_TIME,
|
||||
VAL_THREAD_CPU_TIME,
|
||||
};
|
||||
@ -181,6 +182,10 @@ void stats_global_query(struct mpv_global *global, struct mpv_node *out)
|
||||
talloc_free(s);
|
||||
break;
|
||||
}
|
||||
case VAL_INC:
|
||||
add_stat(out, e, NULL, e->val_d, NULL);
|
||||
e->val_d = 0;
|
||||
break;
|
||||
case VAL_TIME: {
|
||||
double t_cpu = e->val_th / 1e6;
|
||||
add_stat(out, e, "cpu", t_cpu, mp_tprintf(80, "%.2f ms", t_cpu));
|
||||
@ -303,6 +308,17 @@ void stats_time_end(struct stats_ctx *ctx, const char *name)
|
||||
pthread_mutex_unlock(&ctx->base->lock);
|
||||
}
|
||||
|
||||
void stats_event(struct stats_ctx *ctx, const char *name)
|
||||
{
|
||||
if (!IS_ACTIVE(ctx))
|
||||
return;
|
||||
pthread_mutex_lock(&ctx->base->lock);
|
||||
struct stat_entry *e = find_entry(ctx, name);
|
||||
e->val_d += 1;
|
||||
e->type = VAL_INC;
|
||||
pthread_mutex_unlock(&ctx->base->lock);
|
||||
}
|
||||
|
||||
static void register_thread(struct stats_ctx *ctx, const char *name,
|
||||
enum val_type type)
|
||||
{
|
||||
|
@ -22,6 +22,9 @@ void stats_size_value(struct stats_ctx *ctx, const char *name, double val);
|
||||
void stats_time_start(struct stats_ctx *ctx, const char *name);
|
||||
void stats_time_end(struct stats_ctx *ctx, const char *name);
|
||||
|
||||
// Display number of events per poll period.
|
||||
void stats_event(struct stats_ctx *ctx, const char *name);
|
||||
|
||||
// Report the thread's CPU time. This needs to be called only once per thread.
|
||||
// The current thread is assumed to stay valid until the stats_ctx is destroyed
|
||||
// or stats_unregister_thread() is called, otherwise UB will occur.
|
||||
|
@ -240,6 +240,7 @@ typedef struct MPContext {
|
||||
struct mpv_global *global;
|
||||
struct MPOpts *opts;
|
||||
struct mp_log *log;
|
||||
struct stats_ctx *stats;
|
||||
struct m_config *mconfig;
|
||||
struct input_ctx *input;
|
||||
struct mp_client_api *clients;
|
||||
|
@ -1774,8 +1774,7 @@ struct playlist_entry *mp_next_file(struct MPContext *mpctx, int direction,
|
||||
// Return if all done.
|
||||
void mp_play_files(struct MPContext *mpctx)
|
||||
{
|
||||
struct stats_ctx *stats = stats_ctx_create(mpctx, mpctx->global, "main");
|
||||
stats_register_thread_cputime(stats, "thread");
|
||||
stats_register_thread_cputime(mpctx->stats, "thread");
|
||||
|
||||
// Wait for all scripts to load before possibly starting playback.
|
||||
if (!mp_clients_all_initialized(mpctx)) {
|
||||
|
@ -283,6 +283,8 @@ struct MPContext *mp_create(void)
|
||||
mpctx->log = mp_log_new(mpctx, mpctx->global->log, "!cplayer");
|
||||
mpctx->statusline = mp_log_new(mpctx, mpctx->log, "!statusline");
|
||||
|
||||
mpctx->stats = stats_ctx_create(mpctx, mpctx->global, "main");
|
||||
|
||||
// Create the config context and register the options
|
||||
mpctx->mconfig = m_config_new(mpctx, mpctx->log, &mp_opt_root);
|
||||
mpctx->opts = mpctx->mconfig->optstruct;
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include "common/common.h"
|
||||
#include "common/encode.h"
|
||||
#include "common/recorder.h"
|
||||
#include "common/stats.h"
|
||||
#include "filters/f_decoder_wrapper.h"
|
||||
#include "options/m_config_frontend.h"
|
||||
#include "options/m_property.h"
|
||||
@ -57,6 +58,8 @@ void mp_wait_events(struct MPContext *mpctx)
|
||||
{
|
||||
mp_client_send_property_changes(mpctx);
|
||||
|
||||
stats_event(mpctx->stats, "iterations");
|
||||
|
||||
bool sleeping = mpctx->sleeptime > 0;
|
||||
if (sleeping)
|
||||
MP_STATS(mpctx, "start sleep");
|
||||
|
Loading…
Reference in New Issue
Block a user