[vlc-commits] stats: replace counters with simple integers
Rémi Denis-Courmont
git at videolan.org
Mon Dec 11 21:02:19 CET 2017
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Dec 11 20:44:51 2017 +0200| [75f5ad27cd768605e03622435e97a15ff89b6bf8] | committer: Rémi Denis-Courmont
stats: replace counters with simple integers
In case you wondered how to over-engineer the integer addition.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=75f5ad27cd768605e03622435e97a15ff89b6bf8
---
src/input/access.c | 9 ++++---
src/input/decoder.c | 14 +++++------
src/input/es_out.c | 13 ++++-------
src/input/input.c | 58 +++++++++++-----------------------------------
src/input/input_internal.h | 28 +++++++++++-----------
src/input/stats.c | 52 +++++++++++------------------------------
src/libvlc.h | 1 -
7 files changed, 57 insertions(+), 118 deletions(-)
diff --git a/src/input/access.c b/src/input/access.c
index 2e7c1aea1d..6ae4aea35a 100644
--- a/src/input/access.c
+++ b/src/input/access.c
@@ -202,10 +202,9 @@ static block_t *AStreamReadBlock(stream_t *s, bool *restrict eof)
uint64_t total;
vlc_mutex_lock(&input_priv(input)->counters.counters_lock);
- stats_Update(input_priv(input)->counters.p_read_bytes,
- block->i_buffer, &total);
+ 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_read_packets, 1, NULL);
+ input_priv(input)->counters.read_packets++;
vlc_mutex_unlock(&input_priv(input)->counters.counters_lock);
}
@@ -230,9 +229,9 @@ static ssize_t AStreamReadStream(stream_t *s, void *buf, size_t len)
uint64_t total;
vlc_mutex_lock(&input_priv(input)->counters.counters_lock);
- stats_Update(input_priv(input)->counters.p_read_bytes, val, &total);
+ 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_read_packets, 1, NULL);
+ input_priv(input)->counters.read_packets++;
vlc_mutex_unlock(&input_priv(input)->counters.counters_lock);
}
diff --git a/src/input/decoder.c b/src/input/decoder.c
index a79891da55..1368fd30a4 100644
--- a/src/input/decoder.c
+++ b/src/input/decoder.c
@@ -1094,9 +1094,9 @@ static void DecoderUpdateStatVideo( decoder_owner_sys_t *p_owner,
}
vlc_mutex_lock( &input_priv(p_input)->counters.counters_lock );
- stats_Update( input_priv(p_input)->counters.p_decoded_video, decoded, NULL );
- stats_Update( input_priv(p_input)->counters.p_lost_pictures, lost , NULL);
- stats_Update( input_priv(p_input)->counters.p_displayed_pictures, displayed, NULL);
+ input_priv(p_input)->counters.decoded_video += decoded;
+ input_priv(p_input)->counters.lost_pictures += lost;
+ input_priv(p_input)->counters.displayed_pictures += displayed;
vlc_mutex_unlock( &input_priv(p_input)->counters.counters_lock );
}
@@ -1214,9 +1214,9 @@ static void DecoderUpdateStatAudio( decoder_owner_sys_t *p_owner,
}
vlc_mutex_lock( &input_priv(p_input)->counters.counters_lock);
- stats_Update( input_priv(p_input)->counters.p_lost_abuffers, lost, NULL );
- stats_Update( input_priv(p_input)->counters.p_played_abuffers, played, NULL );
- stats_Update( input_priv(p_input)->counters.p_decoded_audio, decoded, NULL );
+ input_priv(p_input)->counters.lost_abuffers += lost;
+ input_priv(p_input)->counters.played_abuffers += played;
+ input_priv(p_input)->counters.decoded_audio += decoded;
vlc_mutex_unlock( &input_priv(p_input)->counters.counters_lock);
}
@@ -1284,7 +1284,7 @@ static int DecoderQueueSpu( decoder_t *p_dec, subpicture_t *p_spu )
if( p_input != NULL )
{
vlc_mutex_lock( &input_priv(p_input)->counters.counters_lock );
- stats_Update( input_priv(p_input)->counters.p_decoded_sub, 1, NULL );
+ input_priv(p_input)->counters.decoded_sub++;
vlc_mutex_unlock( &input_priv(p_input)->counters.counters_lock );
}
diff --git a/src/input/es_out.c b/src/input/es_out.c
index c4a848d5e9..ff7f3586e9 100644
--- a/src/input/es_out.c
+++ b/src/input/es_out.c
@@ -2046,20 +2046,17 @@ static int EsOutSend( es_out_t *out, es_out_id_t *es, block_t *p_block )
uint64_t i_total;
vlc_mutex_lock( &input_priv(p_input)->counters.counters_lock );
- stats_Update( input_priv(p_input)->counters.p_demux_read,
- p_block->i_buffer, &i_total );
+ 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 );
/* Update number of corrupted data packats */
if( p_block->i_flags & BLOCK_FLAG_CORRUPTED )
- {
- stats_Update( input_priv(p_input)->counters.p_demux_corrupted, 1, NULL );
- }
+ input_priv(p_input)->counters.demux_corrupted++;
+
/* Update number of discontinuities */
if( p_block->i_flags & BLOCK_FLAG_DISCONTINUITY )
- {
- stats_Update( input_priv(p_input)->counters.p_demux_discontinuity, 1, NULL );
- }
+ input_priv(p_input)->counters.demux_discontinuity++;
vlc_mutex_unlock( &input_priv(p_input)->counters.counters_lock );
}
diff --git a/src/input/input.c b/src/input/input.c
index a515526271..5ed1abad76 100644
--- a/src/input/input.c
+++ b/src/input/input.c
@@ -815,23 +815,23 @@ static void InitStatistics( input_thread_t *p_input )
stats_CounterCreate( STATS_##compute);
if( libvlc_stats( p_input ) )
{
- INIT_COUNTER( read_bytes, COUNTER );
- INIT_COUNTER( read_packets, COUNTER );
- INIT_COUNTER( demux_read, COUNTER );
+ 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( demux_corrupted, COUNTER );
- INIT_COUNTER( demux_discontinuity, COUNTER );
- INIT_COUNTER( played_abuffers, COUNTER );
- INIT_COUNTER( lost_abuffers, COUNTER );
- INIT_COUNTER( displayed_pictures, COUNTER );
- INIT_COUNTER( lost_pictures, COUNTER );
- INIT_COUNTER( decoded_audio, COUNTER );
- INIT_COUNTER( decoded_video, COUNTER );
- INIT_COUNTER( decoded_sub, COUNTER );
+ priv->counters.demux_corrupted = 0;
+ priv->counters.demux_discontinuity = 0;
+ priv->counters.played_abuffers = 0;
+ priv->counters.lost_abuffers = 0;
+ priv->counters.displayed_pictures = 0;
+ priv->counters.lost_pictures = 0;
+ priv->counters.decoded_audio = 0;
+ priv->counters.decoded_video = 0;
+ priv->counters.decoded_sub = 0;
priv->counters.p_sout_send_bitrate = NULL;
- priv->counters.p_sout_sent_packets = NULL;
- priv->counters.p_sout_sent_bytes = NULL;
+ priv->counters.sout_sent_packets = 0;
+ priv->counters.sout_sent_bytes = 0;
}
}
@@ -866,8 +866,6 @@ static int InitSout( input_thread_t * p_input )
}
if( libvlc_stats( p_input ) )
{
- INIT_COUNTER( sout_sent_packets, COUNTER );
- INIT_COUNTER( sout_sent_bytes, COUNTER );
INIT_COUNTER( sout_send_bitrate, DERIVATIVE );
}
}
@@ -1422,25 +1420,11 @@ error:
#define EXIT_COUNTER( c ) do { if( input_priv(p_input)->counters.p_##c ) \
stats_CounterClean( input_priv(p_input)->counters.p_##c );\
input_priv(p_input)->counters.p_##c = NULL; } while(0)
- EXIT_COUNTER( read_bytes );
- EXIT_COUNTER( read_packets );
- EXIT_COUNTER( demux_read );
EXIT_COUNTER( input_bitrate );
EXIT_COUNTER( demux_bitrate );
- EXIT_COUNTER( demux_corrupted );
- EXIT_COUNTER( demux_discontinuity );
- EXIT_COUNTER( played_abuffers );
- EXIT_COUNTER( lost_abuffers );
- EXIT_COUNTER( displayed_pictures );
- EXIT_COUNTER( lost_pictures );
- EXIT_COUNTER( decoded_audio );
- EXIT_COUNTER( decoded_video );
- EXIT_COUNTER( decoded_sub );
if( input_priv(p_input)->p_sout )
{
- EXIT_COUNTER( sout_sent_packets );
- EXIT_COUNTER( sout_sent_bytes );
EXIT_COUNTER( sout_send_bitrate );
}
#undef EXIT_COUNTER
@@ -1498,27 +1482,13 @@ do { \
{
/* make sure we are up to date */
stats_ComputeInputStats( p_input, priv->p_item->p_stats );
- CL_CO( read_bytes );
- CL_CO( read_packets );
- CL_CO( demux_read );
CL_CO( input_bitrate );
CL_CO( demux_bitrate );
- CL_CO( demux_corrupted );
- CL_CO( demux_discontinuity );
- CL_CO( played_abuffers );
- CL_CO( lost_abuffers );
- CL_CO( displayed_pictures );
- CL_CO( lost_pictures );
- CL_CO( decoded_audio) ;
- CL_CO( decoded_video );
- CL_CO( decoded_sub) ;
}
/* Close optional stream output instance */
if( priv->p_sout )
{
- CL_CO( sout_sent_packets );
- CL_CO( sout_sent_bytes );
CL_CO( sout_send_bitrate );
}
#undef CL_CO
diff --git a/src/input/input_internal.h b/src/input/input_internal.h
index 9bf6dd072a..8419e7c81b 100644
--- a/src/input/input_internal.h
+++ b/src/input/input_internal.h
@@ -148,23 +148,23 @@ typedef struct input_thread_private_t
/* Stats counters */
struct {
- counter_t *p_read_packets;
- counter_t *p_read_bytes;
+ uintmax_t read_packets;
+ uintmax_t read_bytes;
counter_t *p_input_bitrate;
- counter_t *p_demux_read;
+ uintmax_t demux_read;
counter_t *p_demux_bitrate;
- counter_t *p_demux_corrupted;
- counter_t *p_demux_discontinuity;
- counter_t *p_decoded_audio;
- counter_t *p_decoded_video;
- counter_t *p_decoded_sub;
- counter_t *p_sout_sent_packets;
- counter_t *p_sout_sent_bytes;
+ uintmax_t demux_corrupted;
+ uintmax_t demux_discontinuity;
+ uintmax_t decoded_audio;
+ uintmax_t decoded_video;
+ uintmax_t decoded_sub;
+ uintmax_t sout_sent_packets;
+ uintmax_t sout_sent_bytes;
counter_t *p_sout_send_bitrate;
- counter_t *p_played_abuffers;
- counter_t *p_lost_abuffers;
- counter_t *p_displayed_pictures;
- counter_t *p_lost_pictures;
+ uintmax_t played_abuffers;
+ uintmax_t lost_abuffers;
+ uintmax_t displayed_pictures;
+ uintmax_t lost_pictures;
vlc_mutex_t counters_lock;
} counters;
diff --git a/src/input/stats.c b/src/input/stats.c
index e58322815e..87d6fd8b2f 100644
--- a/src/input/stats.c
+++ b/src/input/stats.c
@@ -64,13 +64,6 @@ counter_t * stats_CounterCreate( int i_compute_type )
return p_counter;
}
-static inline int64_t stats_GetTotal(const counter_t *counter)
-{
- if (counter == NULL || counter->i_samples == 0)
- return 0;
- return counter->pp_samples[0]->value;
-}
-
static inline float stats_GetRate(const counter_t *counter)
{
if (counter == NULL || counter->i_samples < 2)
@@ -104,33 +97,33 @@ void stats_ComputeInputStats(input_thread_t *input, input_stats_t *st)
vlc_mutex_lock(&st->lock);
/* Input */
- st->i_read_packets = stats_GetTotal(priv->counters.p_read_packets);
- st->i_read_bytes = stats_GetTotal(priv->counters.p_read_bytes);
+ st->i_read_packets = priv->counters.read_packets;
+ st->i_read_bytes = priv->counters.read_bytes;
st->f_input_bitrate = stats_GetRate(priv->counters.p_input_bitrate);
- st->i_demux_read_bytes = stats_GetTotal(priv->counters.p_demux_read);
+ st->i_demux_read_bytes = priv->counters.demux_read;
st->f_demux_bitrate = stats_GetRate(priv->counters.p_demux_bitrate);
- st->i_demux_corrupted = stats_GetTotal(priv->counters.p_demux_corrupted);
- st->i_demux_discontinuity = stats_GetTotal(priv->counters.p_demux_discontinuity);
+ st->i_demux_corrupted = priv->counters.demux_corrupted;
+ st->i_demux_discontinuity = priv->counters.demux_discontinuity;
/* Decoders */
- st->i_decoded_video = stats_GetTotal(priv->counters.p_decoded_video);
- st->i_decoded_audio = stats_GetTotal(priv->counters.p_decoded_audio);
+ st->i_decoded_video = priv->counters.decoded_video;
+ st->i_decoded_audio = priv->counters.decoded_audio;
/* Sout */
if (priv->counters.p_sout_send_bitrate)
{
- st->i_sent_packets = stats_GetTotal(priv->counters.p_sout_sent_packets);
- st->i_sent_bytes = stats_GetTotal(priv->counters.p_sout_sent_bytes);
+ st->i_sent_packets = priv->counters.sout_sent_packets;
+ st->i_sent_bytes = priv->counters.sout_sent_bytes;
st->f_send_bitrate = stats_GetRate(priv->counters.p_sout_send_bitrate);
}
/* Aout */
- st->i_played_abuffers = stats_GetTotal(priv->counters.p_played_abuffers);
- st->i_lost_abuffers = stats_GetTotal(priv->counters.p_lost_abuffers);
+ st->i_played_abuffers = priv->counters.played_abuffers;
+ st->i_lost_abuffers = priv->counters.lost_abuffers;
/* Vouts */
- st->i_displayed_pictures = stats_GetTotal(priv->counters.p_displayed_pictures);
- st->i_lost_pictures = stats_GetTotal(priv->counters.p_lost_pictures);
+ st->i_displayed_pictures = priv->counters.displayed_pictures;
+ st->i_lost_pictures = priv->counters.lost_pictures;
vlc_mutex_unlock(&st->lock);
vlc_mutex_unlock(&priv->counters.counters_lock);
@@ -201,24 +194,5 @@ void stats_Update( counter_t *p_counter, uint64_t val, uint64_t *new_val )
}
break;
}
- case STATS_COUNTER:
- if( p_counter->i_samples == 0 )
- {
- counter_sample_t *p_new = (counter_sample_t*)malloc(
- sizeof( counter_sample_t ) );
- if (unlikely(p_new == NULL))
- return; /* NOTE: Losing sample here */
-
- p_new->value = 0;
-
- TAB_APPEND(p_counter->i_samples, p_counter->pp_samples, p_new);
- }
- if( p_counter->i_samples == 1 )
- {
- p_counter->pp_samples[0]->value += val;
- if( new_val )
- *new_val = p_counter->pp_samples[0]->value;
- }
- break;
}
}
diff --git a/src/libvlc.h b/src/libvlc.h
index d55732cc33..68a01595c6 100644
--- a/src/libvlc.h
+++ b/src/libvlc.h
@@ -215,7 +215,6 @@ void var_OptionParse (vlc_object_t *, const char *, bool trusted);
*/
enum
{
- STATS_COUNTER,
STATS_DERIVATIVE,
};
More information about the vlc-commits
mailing list