Commit 8923568d authored by Clément Stenac's avatar Clément Stenac

Move stats stuff to the per-instance object

parent f485214f
...@@ -47,13 +47,6 @@ struct libvlc_global_data_t ...@@ -47,13 +47,6 @@ struct libvlc_global_data_t
msg_bank_t msg_bank; ///< The message bank msg_bank_t msg_bank; ///< The message bank
module_bank_t * p_module_bank; ///< The module bank module_bank_t * p_module_bank; ///< The module bank
vlc_bool_t b_stats; ///< Should we collect stats
/* Timers handling */
vlc_mutex_t timer_lock; ///< Lock to protect timers
int i_timers; ///< Number of timers
counter_t **pp_timers; ///< Array of all timers
intf_thread_t *p_probe; ///< Devices prober intf_thread_t *p_probe; ///< Devices prober
/* Arch-specific variables */ /* Arch-specific variables */
...@@ -98,8 +91,12 @@ struct libvlc_int_t ...@@ -98,8 +91,12 @@ struct libvlc_int_t
void* ( *pf_memcpy ) ( void *, const void *, size_t ); void* ( *pf_memcpy ) ( void *, const void *, size_t );
void* ( *pf_memset ) ( void *, int, size_t ); void* ( *pf_memset ) ( void *, int, size_t );
/* Shared data - these structures are accessed directly from p_vlc by /* Statistics */
* several modules */ vlc_bool_t b_stats; ///< Should we collect stats
/* Timers handling */
vlc_mutex_t timer_lock; ///< Lock to protect timers
int i_timers; ///< Number of timers
counter_t **pp_timers; ///< Array of all timers
/* Locks */ /* Locks */
vlc_mutex_t config_lock; /* lock for the config file */ vlc_mutex_t config_lock; /* lock for the config file */
......
...@@ -1026,7 +1026,7 @@ static int EsOutSend( es_out_t *out, es_out_id_t *es, block_t *p_block ) ...@@ -1026,7 +1026,7 @@ static int EsOutSend( es_out_t *out, es_out_id_t *es, block_t *p_block )
else else
i_delay = 0; i_delay = 0;
if( p_input->p_libvlc_global->b_stats ) if( p_input->p_libvlc->b_stats )
{ {
vlc_mutex_lock( &p_input->counters.counters_lock ); vlc_mutex_lock( &p_input->counters.counters_lock );
stats_UpdateInteger( p_input, p_input->counters.p_demux_read, stats_UpdateInteger( p_input, p_input->counters.p_demux_read,
......
...@@ -685,7 +685,7 @@ static int Init( input_thread_t * p_input, vlc_bool_t b_quick ) ...@@ -685,7 +685,7 @@ static int Init( input_thread_t * p_input, vlc_bool_t b_quick )
/* Prepare statistics */ /* Prepare statistics */
#define INIT_COUNTER( p, type, compute ) p_input->counters.p_##p = \ #define INIT_COUNTER( p, type, compute ) p_input->counters.p_##p = \
stats_CounterCreate( p_input, VLC_VAR_##type, STATS_##compute); stats_CounterCreate( p_input, VLC_VAR_##type, STATS_##compute);
if( p_input->p_libvlc_global->b_stats ) if( p_input->p_libvlc->b_stats )
{ {
INIT_COUNTER( read_bytes, INTEGER, COUNTER ); INIT_COUNTER( read_bytes, INTEGER, COUNTER );
INIT_COUNTER( read_packets, INTEGER, COUNTER ); INIT_COUNTER( read_packets, INTEGER, COUNTER );
...@@ -721,7 +721,7 @@ static int Init( input_thread_t * p_input, vlc_bool_t b_quick ) ...@@ -721,7 +721,7 @@ static int Init( input_thread_t * p_input, vlc_bool_t b_quick )
free( psz ); free( psz );
return VLC_EGENERIC; return VLC_EGENERIC;
} }
if( p_input->p_libvlc_global->b_stats ) if( p_input->p_libvlc->b_stats )
{ {
INIT_COUNTER( sout_sent_packets, INTEGER, COUNTER ); INIT_COUNTER( sout_sent_packets, INTEGER, COUNTER );
INIT_COUNTER (sout_sent_bytes, INTEGER, COUNTER ); INIT_COUNTER (sout_sent_bytes, INTEGER, COUNTER );
...@@ -1114,7 +1114,7 @@ static void End( input_thread_t * p_input ) ...@@ -1114,7 +1114,7 @@ static void End( input_thread_t * p_input )
input_EsOutDelete( p_input->p_es_out ); input_EsOutDelete( p_input->p_es_out );
#define CL_CO( c ) stats_CounterClean( p_input->counters.p_##c ); p_input->counters.p_##c = NULL; #define CL_CO( c ) stats_CounterClean( p_input->counters.p_##c ); p_input->counters.p_##c = NULL;
if( p_input->p_libvlc_global->b_stats ) if( p_input->p_libvlc->b_stats )
{ {
vlc_mutex_lock( &p_input->counters.counters_lock ); vlc_mutex_lock( &p_input->counters.counters_lock );
CL_CO( read_bytes ); CL_CO( read_bytes );
......
...@@ -1655,7 +1655,7 @@ static block_t *AReadBlock( stream_t *s, vlc_bool_t *pb_eof ) ...@@ -1655,7 +1655,7 @@ static block_t *AReadBlock( stream_t *s, vlc_bool_t *pb_eof )
{ {
p_block = p_access->pf_block( p_access ); p_block = p_access->pf_block( p_access );
if( pb_eof ) *pb_eof = p_access->info.b_eof; if( pb_eof ) *pb_eof = p_access->info.b_eof;
if( p_input && p_block && p_access->p_libvlc_global->b_stats ) if( p_input && p_block && p_access->p_libvlc->b_stats )
{ {
vlc_object_yield( p_input ); vlc_object_yield( p_input );
vlc_mutex_lock( &p_input->counters.counters_lock ); vlc_mutex_lock( &p_input->counters.counters_lock );
......
...@@ -714,10 +714,10 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] ) ...@@ -714,10 +714,10 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
p_libvlc->pf_memset = memset; p_libvlc->pf_memset = memset;
} }
libvlc_global.b_stats = config_GetInt( p_libvlc, "stats" ); p_libvlc->b_stats = config_GetInt( p_libvlc, "stats" );
libvlc_global.i_timers = 0; p_libvlc->i_timers = 0;
libvlc_global.pp_timers = NULL; p_libvlc->pp_timers = NULL;
vlc_mutex_init( p_libvlc, &libvlc_global.timer_lock ); vlc_mutex_init( p_libvlc, &p_libvlc->timer_lock );
/* /*
* Initialize hotkey handling * Initialize hotkey handling
......
...@@ -78,7 +78,7 @@ counter_t * __stats_CounterCreate( vlc_object_t *p_this, ...@@ -78,7 +78,7 @@ counter_t * __stats_CounterCreate( vlc_object_t *p_this,
int __stats_Update( vlc_object_t *p_this, counter_t *p_counter, int __stats_Update( vlc_object_t *p_this, counter_t *p_counter,
vlc_value_t val, vlc_value_t *val_new ) vlc_value_t val, vlc_value_t *val_new )
{ {
if( !p_this->p_libvlc_global->b_stats || !p_counter ) return VLC_EGENERIC; if( !p_this->p_libvlc->b_stats || !p_counter ) return VLC_EGENERIC;
return CounterUpdate( p_this, p_counter, val, val_new ); return CounterUpdate( p_this, p_counter, val, val_new );
} }
...@@ -91,7 +91,7 @@ int __stats_Update( vlc_object_t *p_this, counter_t *p_counter, ...@@ -91,7 +91,7 @@ int __stats_Update( vlc_object_t *p_this, counter_t *p_counter,
*/ */
int __stats_Get( vlc_object_t *p_this, counter_t *p_counter, vlc_value_t *val ) int __stats_Get( vlc_object_t *p_this, counter_t *p_counter, vlc_value_t *val )
{ {
if( !p_this->p_libvlc_global->b_stats || !p_counter || p_counter->i_samples == 0 ) if( !p_this->p_libvlc->b_stats || !p_counter || p_counter->i_samples == 0 )
{ {
val->i_int = val->f_float = 0.0; val->i_int = val->f_float = 0.0;
return VLC_EGENERIC; return VLC_EGENERIC;
...@@ -135,7 +135,7 @@ int __stats_Get( vlc_object_t *p_this, counter_t *p_counter, vlc_value_t *val ) ...@@ -135,7 +135,7 @@ int __stats_Get( vlc_object_t *p_this, counter_t *p_counter, vlc_value_t *val )
void stats_ComputeInputStats( input_thread_t *p_input, input_stats_t *p_stats ) void stats_ComputeInputStats( input_thread_t *p_input, input_stats_t *p_stats )
{ {
if( !p_input->p_libvlc_global->b_stats ) return; if( !p_input->p_libvlc->b_stats ) return;
vlc_mutex_lock( &p_input->counters.counters_lock ); vlc_mutex_lock( &p_input->counters.counters_lock );
vlc_mutex_lock( &p_stats->lock ); vlc_mutex_lock( &p_stats->lock );
...@@ -223,7 +223,7 @@ void __stats_ComputeGlobalStats( vlc_object_t *p_obj, global_stats_t *p_stats ) ...@@ -223,7 +223,7 @@ void __stats_ComputeGlobalStats( vlc_object_t *p_obj, global_stats_t *p_stats )
vlc_list_t *p_list; vlc_list_t *p_list;
int i_index; int i_index;
if( !p_obj->p_libvlc_global->b_stats ) return; if( !p_obj->p_libvlc->b_stats ) return;
vlc_mutex_lock( &p_stats->lock ); vlc_mutex_lock( &p_stats->lock );
...@@ -268,14 +268,14 @@ void __stats_TimerStart( vlc_object_t *p_obj, const char *psz_name, ...@@ -268,14 +268,14 @@ void __stats_TimerStart( vlc_object_t *p_obj, const char *psz_name,
{ {
int i; int i;
counter_t *p_counter = NULL; counter_t *p_counter = NULL;
if( !p_obj->p_libvlc_global->b_stats ) return; if( !p_obj->p_libvlc->b_stats ) return;
vlc_mutex_lock( &p_obj->p_libvlc_global->timer_lock ); vlc_mutex_lock( &p_obj->p_libvlc->timer_lock );
for( i = 0 ; i < p_obj->p_libvlc_global->i_timers; i++ ) for( i = 0 ; i < p_obj->p_libvlc->i_timers; i++ )
{ {
if( p_obj->p_libvlc_global->pp_timers[i]->i_id == i_id ) if( p_obj->p_libvlc->pp_timers[i]->i_id == i_id )
{ {
p_counter = p_obj->p_libvlc_global->pp_timers[i]; p_counter = p_obj->p_libvlc->pp_timers[i];
break; break;
} }
} }
...@@ -286,13 +286,13 @@ void __stats_TimerStart( vlc_object_t *p_obj, const char *psz_name, ...@@ -286,13 +286,13 @@ void __stats_TimerStart( vlc_object_t *p_obj, const char *psz_name,
STATS_TIMER ); STATS_TIMER );
if( !p_counter ) if( !p_counter )
{ {
vlc_mutex_unlock( &p_obj->p_libvlc_global->timer_lock ); vlc_mutex_unlock( &p_obj->p_libvlc->timer_lock );
return; return;
} }
p_counter->psz_name = strdup( psz_name ); p_counter->psz_name = strdup( psz_name );
p_counter->i_id = i_id; p_counter->i_id = i_id;
INSERT_ELEM( p_obj->p_libvlc_global->pp_timers, p_obj->p_libvlc_global->i_timers, INSERT_ELEM( p_obj->p_libvlc->pp_timers, p_obj->p_libvlc->i_timers,
p_obj->p_libvlc_global->i_timers, p_counter ); p_obj->p_libvlc->i_timers, p_counter );
/* 1st sample : if started: start_date, else last_time, b_started */ /* 1st sample : if started: start_date, else last_time, b_started */
p_sample = (counter_sample_t *)malloc( sizeof( counter_sample_t ) ); p_sample = (counter_sample_t *)malloc( sizeof( counter_sample_t ) );
...@@ -308,80 +308,80 @@ void __stats_TimerStart( vlc_object_t *p_obj, const char *psz_name, ...@@ -308,80 +308,80 @@ void __stats_TimerStart( vlc_object_t *p_obj, const char *psz_name,
if( p_counter->pp_samples[0]->value.b_bool == VLC_TRUE ) if( p_counter->pp_samples[0]->value.b_bool == VLC_TRUE )
{ {
msg_Warn( p_obj, "timer %s was already started !", psz_name ); msg_Warn( p_obj, "timer %s was already started !", psz_name );
vlc_mutex_unlock( &p_obj->p_libvlc_global->timer_lock ); vlc_mutex_unlock( &p_obj->p_libvlc->timer_lock );
return; return;
} }
p_counter->pp_samples[0]->value.b_bool = VLC_TRUE; p_counter->pp_samples[0]->value.b_bool = VLC_TRUE;
p_counter->pp_samples[0]->date = mdate(); p_counter->pp_samples[0]->date = mdate();
vlc_mutex_unlock( &p_obj->p_libvlc_global->timer_lock ); vlc_mutex_unlock( &p_obj->p_libvlc->timer_lock );
} }
void __stats_TimerStop( vlc_object_t *p_obj, unsigned int i_id ) void __stats_TimerStop( vlc_object_t *p_obj, unsigned int i_id )
{ {
counter_t *p_counter = NULL; counter_t *p_counter = NULL;
int i; int i;
if( !p_obj->p_libvlc_global->b_stats ) return; if( !p_obj->p_libvlc->b_stats ) return;
vlc_mutex_lock( &p_obj->p_libvlc_global->timer_lock ); vlc_mutex_lock( &p_obj->p_libvlc->timer_lock );
for( i = 0 ; i < p_obj->p_libvlc_global->i_timers; i++ ) for( i = 0 ; i < p_obj->p_libvlc->i_timers; i++ )
{ {
if( p_obj->p_libvlc_global->pp_timers[i]->i_id == i_id ) if( p_obj->p_libvlc->pp_timers[i]->i_id == i_id )
{ {
p_counter = p_obj->p_libvlc_global->pp_timers[i]; p_counter = p_obj->p_libvlc->pp_timers[i];
break; break;
} }
} }
if( !p_counter || p_counter->i_samples != 2 ) if( !p_counter || p_counter->i_samples != 2 )
{ {
msg_Err( p_obj, "timer does not exist" ); msg_Err( p_obj, "timer does not exist" );
vlc_mutex_unlock( &p_obj->p_libvlc_global->timer_lock ); vlc_mutex_unlock( &p_obj->p_libvlc->timer_lock );
return; return;
} }
p_counter->pp_samples[0]->value.b_bool = VLC_FALSE; p_counter->pp_samples[0]->value.b_bool = VLC_FALSE;
p_counter->pp_samples[1]->value.i_int += 1; p_counter->pp_samples[1]->value.i_int += 1;
p_counter->pp_samples[0]->date = mdate() - p_counter->pp_samples[0]->date; p_counter->pp_samples[0]->date = mdate() - p_counter->pp_samples[0]->date;
p_counter->pp_samples[1]->date += p_counter->pp_samples[0]->date; p_counter->pp_samples[1]->date += p_counter->pp_samples[0]->date;
vlc_mutex_unlock( &p_obj->p_libvlc_global->timer_lock ); vlc_mutex_unlock( &p_obj->p_libvlc->timer_lock );
} }
void __stats_TimerDump( vlc_object_t *p_obj, unsigned int i_id ) void __stats_TimerDump( vlc_object_t *p_obj, unsigned int i_id )
{ {
counter_t *p_counter = NULL; counter_t *p_counter = NULL;
int i; int i;
if( !p_obj->p_libvlc_global->b_stats ) return; if( !p_obj->p_libvlc->b_stats ) return;
vlc_mutex_lock( &p_obj->p_libvlc_global->timer_lock ); vlc_mutex_lock( &p_obj->p_libvlc->timer_lock );
for( i = 0 ; i < p_obj->p_libvlc_global->i_timers; i++ ) for( i = 0 ; i < p_obj->p_libvlc->i_timers; i++ )
{ {
if( p_obj->p_libvlc_global->pp_timers[i]->i_id == i_id ) if( p_obj->p_libvlc->pp_timers[i]->i_id == i_id )
{ {
p_counter = p_obj->p_libvlc_global->pp_timers[i]; p_counter = p_obj->p_libvlc->pp_timers[i];
break; break;
} }
} }
TimerDump( p_obj, p_counter, VLC_TRUE ); TimerDump( p_obj, p_counter, VLC_TRUE );
vlc_mutex_unlock( &p_obj->p_libvlc_global->timer_lock ); vlc_mutex_unlock( &p_obj->p_libvlc->timer_lock );
} }
void __stats_TimersDumpAll( vlc_object_t *p_obj ) void __stats_TimersDumpAll( vlc_object_t *p_obj )
{ {
int i; int i;
if( !p_obj->p_libvlc_global->b_stats ) return; if( !p_obj->p_libvlc->b_stats ) return;
vlc_mutex_lock( &p_obj->p_libvlc_global->timer_lock ); vlc_mutex_lock( &p_obj->p_libvlc->timer_lock );
for ( i = 0 ; i< p_obj->p_libvlc_global->i_timers ; i++ ) for ( i = 0 ; i< p_obj->p_libvlc->i_timers ; i++ )
TimerDump( p_obj, p_obj->p_libvlc_global->pp_timers[i], VLC_FALSE ); TimerDump( p_obj, p_obj->p_libvlc->pp_timers[i], VLC_FALSE );
vlc_mutex_unlock( &p_obj->p_libvlc_global->timer_lock ); vlc_mutex_unlock( &p_obj->p_libvlc->timer_lock );
} }
void __stats_TimersClean( vlc_object_t *p_obj ) void __stats_TimersClean( vlc_object_t *p_obj )
{ {
int i; int i;
vlc_mutex_lock( &p_obj->p_libvlc_global->timer_lock ); vlc_mutex_lock( &p_obj->p_libvlc->timer_lock );
for ( i = p_obj->p_libvlc_global->i_timers -1 ; i >= 0; i-- ) for ( i = p_obj->p_libvlc->i_timers -1 ; i >= 0; i-- )
{ {
counter_t *p_counter = p_obj->p_libvlc_global->pp_timers[i]; counter_t *p_counter = p_obj->p_libvlc->pp_timers[i];
REMOVE_ELEM( p_obj->p_libvlc_global->pp_timers, p_obj->p_libvlc_global->i_timers, i ); REMOVE_ELEM( p_obj->p_libvlc->pp_timers, p_obj->p_libvlc->i_timers, i );
stats_CounterClean( p_counter ); stats_CounterClean( p_counter );
} }
vlc_mutex_unlock( &p_obj->p_libvlc_global->timer_lock ); vlc_mutex_unlock( &p_obj->p_libvlc->timer_lock );
} }
void stats_CounterClean( counter_t *p_c ) void stats_CounterClean( counter_t *p_c )
......
...@@ -363,7 +363,7 @@ int sout_AccessOutWrite( sout_access_out_t *p_access, block_t *p_buffer ) ...@@ -363,7 +363,7 @@ int sout_AccessOutWrite( sout_access_out_t *p_access, block_t *p_buffer )
int i_total = 0; int i_total = 0;
p_access->i_writes++; p_access->i_writes++;
p_access->i_sent_bytes += p_buffer->i_buffer; p_access->i_sent_bytes += p_buffer->i_buffer;
if( p_access->p_libvlc_global->b_stats && p_access->i_writes % 30 == 0 ) if( p_access->p_libvlc->b_stats && p_access->i_writes % 30 == 0 )
{ {
/* Access_out -> sout_instance -> input_thread_t */ /* Access_out -> sout_instance -> input_thread_t */
input_thread_t *p_input = input_thread_t *p_input =
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment