vlc | branch: master | Rémi Denis-Courmont <[email protected]> | Mon Dec 11 20:52:03 2017 +0200| [d67fd22472b073e551c991a0ab52c35139adfc67] | committer: Rémi Denis-Courmont
stats: simplify > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=d67fd22472b073e551c991a0ab52c35139adfc67 --- src/input/access.c | 4 ++-- src/input/es_out.c | 2 +- src/input/input.c | 11 +++++------ src/input/stats.c | 54 ++++++++++++++++++++---------------------------------- src/libvlc.h | 9 ++------- 5 files changed, 30 insertions(+), 50 deletions(-) diff --git a/src/input/access.c b/src/input/access.c index 6ae4aea35a..de2f223c4b 100644 --- a/src/input/access.c +++ b/src/input/access.c @@ -203,7 +203,7 @@ static block_t *AStreamReadBlock(stream_t *s, bool *restrict eof) vlc_mutex_lock(&input_priv(input)->counters.counters_lock); total = (input_priv(input)->counters.read_bytes += block->i_buffer); - stats_Update(input_priv(input)->counters.p_input_bitrate, total, NULL); + stats_Update(input_priv(input)->counters.p_input_bitrate, total); input_priv(input)->counters.read_packets++; vlc_mutex_unlock(&input_priv(input)->counters.counters_lock); } @@ -230,7 +230,7 @@ static ssize_t AStreamReadStream(stream_t *s, void *buf, size_t len) vlc_mutex_lock(&input_priv(input)->counters.counters_lock); total = (input_priv(input)->counters.read_bytes += val); - stats_Update(input_priv(input)->counters.p_input_bitrate, total, NULL); + stats_Update(input_priv(input)->counters.p_input_bitrate, total); input_priv(input)->counters.read_packets++; vlc_mutex_unlock(&input_priv(input)->counters.counters_lock); } diff --git a/src/input/es_out.c b/src/input/es_out.c index ff7f3586e9..c6e87ed8d3 100644 --- a/src/input/es_out.c +++ b/src/input/es_out.c @@ -2048,7 +2048,7 @@ static int EsOutSend( es_out_t *out, es_out_id_t *es, block_t *p_block ) vlc_mutex_lock( &input_priv(p_input)->counters.counters_lock ); i_total = (input_priv(p_input)->counters.demux_read += p_block->i_buffer); - stats_Update( input_priv(p_input)->counters.p_demux_bitrate, i_total, NULL ); + stats_Update( input_priv(p_input)->counters.p_demux_bitrate, i_total ); /* Update number of corrupted data packats */ if( p_block->i_flags & BLOCK_FLAG_CORRUPTED ) diff --git a/src/input/input.c b/src/input/input.c index 5ed1abad76..ed6a6eb9d1 100644 --- a/src/input/input.c +++ b/src/input/input.c @@ -810,16 +810,15 @@ static void InitStatistics( input_thread_t *p_input ) if( priv->b_preparsing ) return; /* Prepare statistics */ -#define INIT_COUNTER( c, compute ) free( priv->counters.p_##c ); \ - priv->counters.p_##c = \ - stats_CounterCreate( STATS_##compute); +#define INIT_COUNTER( c ) free( priv->counters.p_##c ); \ + priv->counters.p_##c = stats_CounterCreate( ); if( libvlc_stats( p_input ) ) { priv->counters.read_bytes = 0; priv->counters.read_packets = 0; priv->counters.demux_read = 0; - INIT_COUNTER( input_bitrate, DERIVATIVE ); - INIT_COUNTER( demux_bitrate, DERIVATIVE ); + INIT_COUNTER( input_bitrate ); + INIT_COUNTER( demux_bitrate ); priv->counters.demux_corrupted = 0; priv->counters.demux_discontinuity = 0; priv->counters.played_abuffers = 0; @@ -866,7 +865,7 @@ static int InitSout( input_thread_t * p_input ) } if( libvlc_stats( p_input ) ) { - INIT_COUNTER( sout_send_bitrate, DERIVATIVE ); + INIT_COUNTER( sout_send_bitrate ); } } else diff --git a/src/input/stats.c b/src/input/stats.c index 87d6fd8b2f..9a21f250f3 100644 --- a/src/input/stats.c +++ b/src/input/stats.c @@ -36,7 +36,6 @@ typedef struct counter_sample_t struct counter_t { - int i_compute_type; int i_samples; counter_sample_t ** pp_samples; @@ -45,17 +44,12 @@ struct counter_t /** * Create a statistics counter - * \param i_compute_type the aggregation type. One of STATS_LAST (always - * keep the last value), STATS_COUNTER (increment by the passed value), - * STATS_MAX (keep the maximum passed value), STATS_MIN, or STATS_DERIVATIVE - * (keep a time derivative of the value) */ -counter_t * stats_CounterCreate( int i_compute_type ) +counter_t * stats_CounterCreate( void ) { counter_t *p_counter = (counter_t*) malloc( sizeof( counter_t ) ) ; if( !p_counter ) return NULL; - p_counter->i_compute_type = i_compute_type; p_counter->i_samples = 0; p_counter->pp_samples = NULL; @@ -161,38 +155,30 @@ void stats_CounterClean( counter_t *p_c ) * \param p_counter the counter to update * \param val the vlc_value union containing the new value to aggregate. For * more information on how data is aggregated, \see stats_Create - * \param val_new a pointer that will be filled with new data */ -void stats_Update( counter_t *p_counter, uint64_t val, uint64_t *new_val ) +void stats_Update( counter_t *p_counter, uint64_t val ) { if( !p_counter ) return; - switch( p_counter->i_compute_type ) - { - case STATS_DERIVATIVE: + counter_sample_t *p_new, *p_old; + mtime_t now = mdate(); + if( now - p_counter->last_update < CLOCK_FREQ ) + return; + p_counter->last_update = now; + /* Insert the new one at the beginning */ + p_new = malloc( sizeof( counter_sample_t ) ); + if (unlikely(p_new == NULL)) + return; /* NOTE: Losing sample here */ + + p_new->value = val; + p_new->date = p_counter->last_update; + TAB_INSERT(p_counter->i_samples, p_counter->pp_samples, p_new, 0); + + if( p_counter->i_samples == 3 ) { - counter_sample_t *p_new, *p_old; - mtime_t now = mdate(); - if( now - p_counter->last_update < CLOCK_FREQ ) - return; - p_counter->last_update = now; - /* Insert the new one at the beginning */ - p_new = (counter_sample_t*)malloc( sizeof( counter_sample_t ) ); - if (unlikely(p_new == NULL)) - return; /* NOTE: Losing sample here */ - - p_new->value = val; - p_new->date = p_counter->last_update; - TAB_INSERT(p_counter->i_samples, p_counter->pp_samples, p_new, 0); - - if( p_counter->i_samples == 3 ) - { - p_old = p_counter->pp_samples[2]; - TAB_ERASE(p_counter->i_samples, p_counter->pp_samples, 2); - free( p_old ); - } - break; - } + p_old = p_counter->pp_samples[2]; + TAB_ERASE(p_counter->i_samples, p_counter->pp_samples, 2); + free( p_old ); } } diff --git a/src/libvlc.h b/src/libvlc.h index 68a01595c6..34ce312df8 100644 --- a/src/libvlc.h +++ b/src/libvlc.h @@ -213,15 +213,10 @@ void var_OptionParse (vlc_object_t *, const char *, bool trusted); /* * Stats stuff */ -enum -{ - STATS_DERIVATIVE, -}; - typedef struct counter_t counter_t; -counter_t * stats_CounterCreate (int); -void stats_Update (counter_t *, uint64_t, uint64_t *); +counter_t * stats_CounterCreate(void); +void stats_Update(counter_t *, uint64_t); void stats_CounterClean (counter_t * ); void stats_ComputeInputStats(input_thread_t*, input_stats_t*); _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
