Commit baacaea3 authored by Clément Stenac's avatar Clément Stenac

Partial rewrite of stats to avoid lookups (Closes:#693)

parent 7a6b8a51
......@@ -56,7 +56,9 @@ struct libvlc_t
/* Do stats ? - We keep this boolean to avoid unneeded lookups */
vlc_bool_t b_stats;
stats_handler_t *p_stats;
vlc_mutex_t timer_lock;
int i_timers;
counter_t **pp_timers;
/* Arch-specific variables */
#if !defined( WIN32 )
......
......@@ -77,6 +77,10 @@ struct httpd_host_t
int i_port;
int *fd;
/* Statistics */
counter_t *p_active_counter;
counter_t *p_total_counter;
vlc_mutex_t lock;
/* all registered url (becarefull that 2 httpd_url_t could point at the same url)
......
......@@ -421,6 +421,26 @@ struct input_thread_t
int i_slave;
input_source_t **slave;
/* Stats counters */
struct {
counter_t *p_read_packets;
counter_t *p_read_bytes;
counter_t *p_input_bitrate;
counter_t *p_demux_read;
counter_t *p_demux_bitrate;
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;
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;
vlc_mutex_t counters_lock;
} counters;
/* Buffer of pending actions */
vlc_mutex_t lock_control;
int i_control;
......
......@@ -228,8 +228,7 @@ struct counter_sample_t
struct counter_t
{
/* The list is *NOT* sorted at the moment, it could be ... */
uint64_t i_index;
unsigned int i_id;
char * psz_name;
int i_type;
int i_compute_type;
......@@ -267,70 +266,58 @@ enum
STATS_TIMER_SKINS_PLAYTREE_IMAGE,
};
struct stats_handler_t
{
VLC_COMMON_MEMBERS
int i_counters;
counter_t **pp_counters;
};
VLC_EXPORT( void, stats_HandlerDestroy, (stats_handler_t*) );
#define stats_Update(a,b,c) __stats_Update( VLC_OBJECT(a), b, c )
VLC_EXPORT( int, __stats_Update, (vlc_object_t*, counter_t *, vlc_value_t, vlc_value_t *) );
#define stats_CounterCreate(a,b,c) __stats_CounterCreate( VLC_OBJECT(a), b, c )
VLC_EXPORT( counter_t *, __stats_CounterCreate, (vlc_object_t*, int, int) );
#define stats_Get(a,b,c) __stats_Get( VLC_OBJECT(a), b, c)
VLC_EXPORT( int, __stats_Get, (vlc_object_t*, counter_t *, vlc_value_t*) );
#define stats_Update(a,b,c,d) __stats_Update( VLC_OBJECT( a ), b, c, d )
VLC_EXPORT( int, __stats_Update, (vlc_object_t*, unsigned int, vlc_value_t, vlc_value_t *) );
#define stats_Create(a,b,c,d,e) __stats_Create( VLC_OBJECT(a), b, c, d,e )
VLC_EXPORT( int, __stats_Create, (vlc_object_t*, const char *, unsigned int, int, int) );
#define stats_Get(a,b,c,d) __stats_Get( VLC_OBJECT(a), b, c, d )
VLC_EXPORT( int, __stats_Get, (vlc_object_t*, int, unsigned int, vlc_value_t*) );
#define stats_CounterGet(a,b,c) __stats_CounterGet( VLC_OBJECT(a), b, c )
VLC_EXPORT( counter_t*, __stats_CounterGet, (vlc_object_t*, int, unsigned int ) );
VLC_EXPORT (void, stats_CounterClean, (counter_t * ) );
#define stats_GetInteger(a,b,c,d) __stats_GetInteger( VLC_OBJECT(a), b, c, d )
static inline int __stats_GetInteger( vlc_object_t *p_obj, int i_id,
unsigned int i_counter, int *value )
#define stats_GetInteger(a,b,c) __stats_GetInteger( VLC_OBJECT(a), b, c )
static inline int __stats_GetInteger( vlc_object_t *p_obj, counter_t *p_counter,
int *value )
{
int i_ret;
vlc_value_t val; val.i_int = 0;
i_ret = __stats_Get( p_obj, i_id, i_counter, &val );
i_ret = __stats_Get( p_obj, p_counter, &val );
*value = val.i_int;
return i_ret;
}
#define stats_GetFloat(a,b,c,d) __stats_GetFloat( VLC_OBJECT(a), b, c, d )
static inline int __stats_GetFloat( vlc_object_t *p_obj, int i_id,
unsigned int i_counter, float *value )
#define stats_GetFloat(a,b,c) __stats_GetFloat( VLC_OBJECT(a), b, c )
static inline int __stats_GetFloat( vlc_object_t *p_obj, counter_t *p_counter,
float *value )
{
int i_ret;
vlc_value_t val; val.f_float = 0.0;
i_ret = __stats_Get( p_obj, i_id, i_counter, &val );
i_ret = __stats_Get( p_obj, p_counter, &val );
*value = val.f_float;
return i_ret;
}
#define stats_UpdateInteger(a,b,c,d) __stats_UpdateInteger( VLC_OBJECT(a),b,c,d )
static inline int __stats_UpdateInteger( vlc_object_t *p_obj,
unsigned int i_counter, int i,
int *pi_new )
static inline int __stats_UpdateInteger( vlc_object_t *p_obj,counter_t *p_co,
int i, int *pi_new )
{
int i_ret;
vlc_value_t val;
vlc_value_t new_val; new_val.i_int = 0;
val.i_int = i;
i_ret = __stats_Update( p_obj, i_counter, val , &new_val );
i_ret = __stats_Update( p_obj, p_co, val, &new_val );
if( pi_new )
*pi_new = new_val.i_int;
return i_ret;
}
#define stats_UpdateFloat(a,b,c,d) __stats_UpdateFloat( VLC_OBJECT(a),b,c,d )
static inline int __stats_UpdateFloat( vlc_object_t *p_obj,
unsigned int i_counter, float f,
float *pf_new )
static inline int __stats_UpdateFloat( vlc_object_t *p_obj, counter_t *p_co,
float f, float *pf_new )
{
vlc_value_t val;
int i_ret;
vlc_value_t new_val;new_val.f_float = 0.0;
val.f_float = f;
i_ret = __stats_Update( p_obj, i_counter, val, &new_val );
i_ret = __stats_Update( p_obj, p_co, val, &new_val );
if( pf_new )
*pf_new = new_val.f_float;
return i_ret;
......@@ -413,3 +400,5 @@ VLC_EXPORT( void,__stats_TimerStart, (vlc_object_t*, const char *, unsigned int
VLC_EXPORT( void,__stats_TimerStop, (vlc_object_t*, unsigned int) );
VLC_EXPORT( void,__stats_TimerDump, (vlc_object_t*, unsigned int) );
VLC_EXPORT( void,__stats_TimersDumpAll, (vlc_object_t*) );
#define stats_TimersClean(a) __stats_TimersClean( VLC_OBJECT(a) )
VLC_EXPORT( void, __stats_TimersClean, (vlc_object_t * ) );
......@@ -438,16 +438,15 @@ struct module_symbols_t
int (*__intf_UserProgress_inner) (vlc_object_t*, const char*, const char*, float);
void (*__intf_UserProgressUpdate_inner) (vlc_object_t*, int, const char*, float);
void (*__intf_UserHide_inner) (vlc_object_t *, int);
int (*__stats_Create_inner) (vlc_object_t*, const char *, unsigned int, int, int);
int (*__stats_Update_inner) (vlc_object_t*, unsigned int, vlc_value_t, vlc_value_t *);
int (*__stats_Get_inner) (vlc_object_t*, int, unsigned int, vlc_value_t*);
void *__stats_Create_deprecated;
int (*__stats_Update_inner) (vlc_object_t*, counter_t *, vlc_value_t, vlc_value_t *);
int (*__stats_Get_inner) (vlc_object_t*, counter_t *, vlc_value_t*);
void (*stats_ComputeInputStats_inner) (input_thread_t*, input_stats_t*);
void (*stats_DumpInputStats_inner) (input_stats_t *);
void (*stats_ReinitInputStats_inner) (input_stats_t *);
counter_t* (*__stats_CounterGet_inner) (vlc_object_t*, int, unsigned int);
void *__stats_CounterGet_deprecated;
input_thread_t * (*__input_CreateThread2_inner) (vlc_object_t *, input_item_t *, char *);
void (*stats_HandlerDestroy_inner) (stats_handler_t*);
void *stats_HandlerDestroy_deprecated;
vlc_t * (*vlc_current_object_inner) (int);
void (*__var_OptionParse_inner) (vlc_object_t *, const char *);
void *__stats_TimerDumpAll_deprecated;
......@@ -514,6 +513,10 @@ struct module_symbols_t
int (*__intf_UserStringInput_inner) (vlc_object_t*, const char*, const char*, char **);
void (*playlist_NodesCreateForSD_inner) (playlist_t *, char *, playlist_item_t **, playlist_item_t **);
vlc_bool_t (*input_AddSubtitles_inner) (input_thread_t *, char *, vlc_bool_t);
counter_t * (*__stats_CounterCreate_inner) (vlc_object_t*, int, int);
void *stats_TimerClean_deprecated;
void *stats_TimersClean_deprecated;
void (*__stats_TimersClean_inner) (vlc_object_t *);
};
# if defined (__PLUGIN__)
# define aout_FiltersCreatePipeline (p_symbols)->aout_FiltersCreatePipeline_inner
......@@ -909,15 +912,12 @@ struct module_symbols_t
# define __intf_UserProgress (p_symbols)->__intf_UserProgress_inner
# define __intf_UserProgressUpdate (p_symbols)->__intf_UserProgressUpdate_inner
# define __intf_UserHide (p_symbols)->__intf_UserHide_inner
# define __stats_Create (p_symbols)->__stats_Create_inner
# define __stats_Update (p_symbols)->__stats_Update_inner
# define __stats_Get (p_symbols)->__stats_Get_inner
# define stats_ComputeInputStats (p_symbols)->stats_ComputeInputStats_inner
# define stats_DumpInputStats (p_symbols)->stats_DumpInputStats_inner
# define stats_ReinitInputStats (p_symbols)->stats_ReinitInputStats_inner
# define __stats_CounterGet (p_symbols)->__stats_CounterGet_inner
# define __input_CreateThread2 (p_symbols)->__input_CreateThread2_inner
# define stats_HandlerDestroy (p_symbols)->stats_HandlerDestroy_inner
# define vlc_current_object (p_symbols)->vlc_current_object_inner
# define __var_OptionParse (p_symbols)->__var_OptionParse_inner
# define __stats_TimerDump (p_symbols)->__stats_TimerDump_inner
......@@ -982,6 +982,8 @@ struct module_symbols_t
# define __intf_UserStringInput (p_symbols)->__intf_UserStringInput_inner
# define playlist_NodesCreateForSD (p_symbols)->playlist_NodesCreateForSD_inner
# define input_AddSubtitles (p_symbols)->input_AddSubtitles_inner
# define __stats_CounterCreate (p_symbols)->__stats_CounterCreate_inner
# define __stats_TimersClean (p_symbols)->__stats_TimersClean_inner
# elif defined (HAVE_DYNAMIC_PLUGINS) && !defined (__BUILTIN__)
/******************************************************************
* STORE_SYMBOLS: store VLC APIs into p_symbols for plugin access.
......@@ -1380,15 +1382,12 @@ struct module_symbols_t
((p_symbols)->__intf_UserProgress_inner) = __intf_UserProgress; \
((p_symbols)->__intf_UserProgressUpdate_inner) = __intf_UserProgressUpdate; \
((p_symbols)->__intf_UserHide_inner) = __intf_UserHide; \
((p_symbols)->__stats_Create_inner) = __stats_Create; \
((p_symbols)->__stats_Update_inner) = __stats_Update; \
((p_symbols)->__stats_Get_inner) = __stats_Get; \
((p_symbols)->stats_ComputeInputStats_inner) = stats_ComputeInputStats; \
((p_symbols)->stats_DumpInputStats_inner) = stats_DumpInputStats; \
((p_symbols)->stats_ReinitInputStats_inner) = stats_ReinitInputStats; \
((p_symbols)->__stats_CounterGet_inner) = __stats_CounterGet; \
((p_symbols)->__input_CreateThread2_inner) = __input_CreateThread2; \
((p_symbols)->stats_HandlerDestroy_inner) = stats_HandlerDestroy; \
((p_symbols)->vlc_current_object_inner) = vlc_current_object; \
((p_symbols)->__var_OptionParse_inner) = __var_OptionParse; \
((p_symbols)->__stats_TimerDump_inner) = __stats_TimerDump; \
......@@ -1453,6 +1452,8 @@ struct module_symbols_t
((p_symbols)->__intf_UserStringInput_inner) = __intf_UserStringInput; \
((p_symbols)->playlist_NodesCreateForSD_inner) = playlist_NodesCreateForSD; \
((p_symbols)->input_AddSubtitles_inner) = input_AddSubtitles; \
((p_symbols)->__stats_CounterCreate_inner) = __stats_CounterCreate; \
((p_symbols)->__stats_TimersClean_inner) = __stats_TimersClean; \
(p_symbols)->net_ConvertIPv4_deprecated = NULL; \
(p_symbols)->__playlist_ItemCopy_deprecated = NULL; \
(p_symbols)->playlist_ItemAddParent_deprecated = NULL; \
......@@ -1479,9 +1480,13 @@ struct module_symbols_t
(p_symbols)->playlist_Sort_deprecated = NULL; \
(p_symbols)->playlist_Move_deprecated = NULL; \
(p_symbols)->playlist_NodeRemoveParent_deprecated = NULL; \
(p_symbols)->__stats_Create_deprecated = NULL; \
(p_symbols)->__stats_CounterGet_deprecated = NULL; \
(p_symbols)->stats_HandlerDestroy_deprecated = NULL; \
(p_symbols)->__stats_TimerDumpAll_deprecated = NULL; \
(p_symbols)->playlist_ItemNewFromInput_deprecated = NULL; \
(p_symbols)->stats_TimerClean_deprecated = NULL; \
(p_symbols)->stats_TimersClean_deprecated = NULL; \
# endif /* __PLUGIN__ */
#endif /* __VLC_SYMBOLS_H */
......@@ -312,8 +312,11 @@ int aout_DecPlay( aout_instance_t * p_aout, aout_input_t * p_input,
p_buffer->start_date - mdate());
if( p_input->p_input_thread )
{
stats_UpdateInteger( p_input->p_input_thread, STATS_LOST_ABUFFERS, 1,
NULL );
vlc_mutex_lock( &p_input->p_input_thread->counters.counters_lock);
stats_UpdateInteger( p_aout,
p_input->p_input_thread->counters.p_lost_abuffers,
1, NULL );
vlc_mutex_unlock( &p_input->p_input_thread->counters.counters_lock);
}
aout_BufferFree( p_buffer );
return -1;
......@@ -367,8 +370,11 @@ int aout_DecPlay( aout_instance_t * p_aout, aout_input_t * p_input,
aout_MixerRun( p_aout );
if( p_input->p_input_thread )
{
stats_UpdateInteger( p_input->p_input_thread,
STATS_PLAYED_ABUFFERS, 1, NULL );
vlc_mutex_lock( &p_input->p_input_thread->counters.counters_lock);
stats_UpdateInteger( p_aout,
p_input->p_input_thread->counters.p_lost_abuffers,
1, NULL );
vlc_mutex_unlock( &p_input->p_input_thread->counters.counters_lock);
}
vlc_mutex_unlock( &p_aout->mixer_lock );
......
......@@ -449,8 +449,9 @@ int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
start_date = 0;
if( p_input->p_input_thread )
{
stats_UpdateInteger( p_input->p_input_thread, STATS_LOST_ABUFFERS, 1,
NULL );
vlc_mutex_lock( &p_input->p_input_thread->counters.counters_lock);
stats_UpdateInteger( p_aout, p_input->p_input_thread->counters.p_lost_abuffers, 1, NULL );
vlc_mutex_unlock( &p_input->p_input_thread->counters.counters_lock);
}
}
......@@ -462,8 +463,9 @@ int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
mdate() - p_buffer->start_date );
if( p_input->p_input_thread )
{
stats_UpdateInteger( p_input->p_input_thread, STATS_LOST_ABUFFERS,
1, NULL );
vlc_mutex_lock( &p_input->p_input_thread->counters.counters_lock);
stats_UpdateInteger( p_aout, p_input->p_input_thread->counters.p_lost_abuffers, 1, NULL );
vlc_mutex_unlock( &p_input->p_input_thread->counters.counters_lock);
}
aout_BufferFree( p_buffer );
p_input->i_resampling_type = AOUT_RESAMPLING_NONE;
......@@ -504,8 +506,9 @@ int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
aout_BufferFree( p_buffer );
if( p_input->p_input_thread )
{
stats_UpdateInteger( p_input->p_input_thread, STATS_LOST_ABUFFERS,
1, NULL );
vlc_mutex_lock( &p_input->p_input_thread->counters.counters_lock);
stats_UpdateInteger( p_aout, p_input->p_input_thread->counters.p_lost_abuffers, 1, NULL );
vlc_mutex_unlock( &p_input->p_input_thread->counters.counters_lock);
}
return 0;
}
......
......@@ -429,12 +429,6 @@ static decoder_t * CreateDecoder( input_thread_t *p_input,
vlc_object_attach( p_dec, p_input );
stats_Create( p_dec->p_parent, "decoded_audio", STATS_DECODED_AUDIO,
VLC_VAR_INTEGER, STATS_COUNTER );
stats_Create( p_dec->p_parent, "decoded_video", STATS_DECODED_VIDEO,
VLC_VAR_INTEGER, STATS_COUNTER );
stats_Create( p_dec->p_parent, "decoded_sub", STATS_DECODED_SUB,
VLC_VAR_INTEGER, STATS_COUNTER );
/* Find a suitable decoder/packetizer module */
if( i_object_type == VLC_OBJECT_DECODER )
p_dec->p_module = module_Need( p_dec, "decoder", "$codec", 0 );
......@@ -627,9 +621,14 @@ static int DecoderDecode( decoder_t *p_dec, block_t *p_block )
while( (p_aout_buf = p_dec->pf_decode_audio( p_dec,
&p_packetized_block )) )
{
stats_UpdateInteger( p_dec->p_parent,
STATS_DECODED_AUDIO, 1, NULL );
/* FIXME the best would be to handle the case start_date < preroll < end_date
input_thread_t *p_i =(input_thread_t*)(p_dec->p_parent);
vlc_mutex_lock( &p_i->counters.counters_lock );
stats_UpdateInteger( p_dec,
p_i->counters.p_decoded_audio, 1, NULL );
vlc_mutex_unlock( &p_i->counters.counters_lock );
/* FIXME the best would be to handle the case
* start_date < preroll < end_date
* but that's not easy with non raw audio stream */
if( p_dec->p_owner->i_preroll_end > 0 &&
p_aout_buf->start_date < p_dec->p_owner->i_preroll_end )
......@@ -652,7 +651,12 @@ static int DecoderDecode( decoder_t *p_dec, block_t *p_block )
}
else while( (p_aout_buf = p_dec->pf_decode_audio( p_dec, &p_block )) )
{
stats_UpdateInteger( p_dec->p_parent, STATS_DECODED_AUDIO, 1, NULL );
input_thread_t *p_i = (input_thread_t*)(p_dec->p_parent);
vlc_mutex_lock( &p_i->counters.counters_lock );
stats_UpdateInteger( p_dec,
p_i->counters.p_decoded_audio, 1, NULL );
vlc_mutex_unlock( &p_i->counters.counters_lock );
if( p_dec->p_owner->i_preroll_end > 0 &&
p_aout_buf->start_date < p_dec->p_owner->i_preroll_end )
{
......@@ -698,8 +702,12 @@ static int DecoderDecode( decoder_t *p_dec, block_t *p_block )
while( (p_pic = p_dec->pf_decode_video( p_dec,
&p_packetized_block )) )
{
stats_UpdateInteger( p_dec->p_parent, STATS_DECODED_VIDEO,
1, NULL );
input_thread_t *p_i =(input_thread_t*)(p_dec->p_parent);
vlc_mutex_lock( &p_i->counters.counters_lock );
stats_UpdateInteger( p_dec,
p_i->counters.p_decoded_video, 1, NULL );
vlc_mutex_unlock( &p_i->counters.counters_lock );
if( p_dec->p_owner->i_preroll_end > 0 &&
p_pic->date < p_dec->p_owner->i_preroll_end )
{
......@@ -720,7 +728,12 @@ static int DecoderDecode( decoder_t *p_dec, block_t *p_block )
}
else while( (p_pic = p_dec->pf_decode_video( p_dec, &p_block )) )
{
stats_UpdateInteger( p_dec->p_parent, STATS_DECODED_VIDEO, 1 , NULL);
input_thread_t *p_i = (input_thread_t*)(p_dec->p_parent);
vlc_mutex_lock( &p_i->counters.counters_lock );
stats_UpdateInteger( p_dec,
p_i->counters.p_decoded_video, 1, NULL );
vlc_mutex_unlock( &p_i->counters.counters_lock );
if( p_dec->p_owner->i_preroll_end > 0 &&
p_pic->date < p_dec->p_owner->i_preroll_end )
{
......@@ -740,7 +753,12 @@ static int DecoderDecode( decoder_t *p_dec, block_t *p_block )
subpicture_t *p_spu;
while( (p_spu = p_dec->pf_decode_sub( p_dec, &p_block ) ) )
{
stats_UpdateInteger( p_dec->p_parent, STATS_DECODED_SUB, 1 , NULL);
input_thread_t *p_i = (input_thread_t*)(p_dec->p_parent);
vlc_mutex_lock( &p_i->counters.counters_lock );
stats_UpdateInteger( p_dec,
p_i->counters.p_decoded_sub, 1, NULL );
vlc_mutex_unlock( &p_i->counters.counters_lock );
if( p_dec->p_owner->i_preroll_end > 0 &&
p_spu->i_start < p_dec->p_owner->i_preroll_end &&
( p_spu->i_stop <= 0 || p_spu->i_stop <= p_dec->p_owner->i_preroll_end ) )
......
......@@ -1025,9 +1025,12 @@ static int EsOutSend( es_out_t *out, es_out_id_t *es, block_t *p_block )
if( p_input->p_libvlc->b_stats )
{
stats_UpdateInteger( p_input, STATS_DEMUX_READ, p_block->i_buffer,
&i_total );
stats_UpdateFloat( p_input , STATS_DEMUX_BITRATE, (float)i_total, NULL );
vlc_mutex_lock( &p_input->counters.counters_lock );
stats_UpdateInteger( p_input, p_input->counters.p_demux_read,
p_block->i_buffer, &i_total );
stats_UpdateFloat( p_input , p_input->counters.p_demux_bitrate,
(float)i_total, NULL );
vlc_mutex_unlock( &p_input->counters.counters_lock );
}
/* Mark preroll blocks */
......
......@@ -679,29 +679,27 @@ static int Init( input_thread_t * p_input, vlc_bool_t b_quick )
if( !b_quick )
{
/* Prepare statistics */
counter_t *p_counter;
stats_Create( p_input, "read_bytes", STATS_READ_BYTES,
VLC_VAR_INTEGER, STATS_COUNTER );
stats_Create( p_input, "read_packets", STATS_READ_PACKETS,
VLC_VAR_INTEGER, STATS_COUNTER );
stats_Create( p_input, "demux_read", STATS_DEMUX_READ,
VLC_VAR_INTEGER, STATS_COUNTER );
stats_Create( p_input, "input_bitrate", STATS_INPUT_BITRATE,
VLC_VAR_FLOAT, STATS_DERIVATIVE );
stats_Create( p_input, "demux_bitrate", STATS_DEMUX_BITRATE,
VLC_VAR_FLOAT, STATS_DERIVATIVE );
p_counter = stats_CounterGet( p_input, p_input->i_object_id,
STATS_INPUT_BITRATE );
if( p_counter ) p_counter->update_interval = 1000000;
p_counter = stats_CounterGet( p_input, p_input->i_object_id,
STATS_DEMUX_BITRATE );
if( p_counter ) p_counter->update_interval = 1000000;
stats_Create( p_input, "played_abuffers", STATS_PLAYED_ABUFFERS,
VLC_VAR_INTEGER, STATS_COUNTER );
stats_Create( p_input, "lost_abuffers", STATS_LOST_ABUFFERS,
VLC_VAR_INTEGER, STATS_COUNTER );
#define INIT_COUNTER( p, type, compute ) p_input->counters.p_##p = \
stats_CounterCreate( p_input, VLC_VAR_##type, STATS_##compute);
INIT_COUNTER( read_bytes, INTEGER, COUNTER );
INIT_COUNTER( read_packets, INTEGER, COUNTER );
INIT_COUNTER( demux_read, INTEGER, COUNTER );
INIT_COUNTER( input_bitrate, FLOAT, DERIVATIVE );
INIT_COUNTER( demux_bitrate, FLOAT, DERIVATIVE );
INIT_COUNTER( played_abuffers, INTEGER, COUNTER );
INIT_COUNTER( lost_abuffers, INTEGER, COUNTER );
INIT_COUNTER( displayed_pictures, INTEGER, COUNTER );
INIT_COUNTER( lost_pictures, INTEGER, COUNTER );
INIT_COUNTER( decoded_audio, INTEGER, COUNTER );
INIT_COUNTER( decoded_video, INTEGER, COUNTER );
INIT_COUNTER( decoded_sub, INTEGER, COUNTER );
p_input->counters.p_sout_send_bitrate = NULL;
p_input->counters.p_sout_sent_packets = NULL;
p_input->counters.p_sout_sent_bytes = NULL;
p_input->counters.p_demux_bitrate->update_interval = 1000000;
p_input->counters.p_input_bitrate->update_interval = 1000000;
vlc_mutex_init( p_input, &p_input->counters.counters_lock );
/* handle sout */
psz = var_GetString( p_input, "sout" );
......@@ -715,6 +713,10 @@ static int Init( input_thread_t * p_input, vlc_bool_t b_quick )
free( psz );
return VLC_EGENERIC;
}
INIT_COUNTER( sout_sent_packets, INTEGER, COUNTER );
INIT_COUNTER (sout_sent_bytes, INTEGER, COUNTER );
INIT_COUNTER( sout_send_bitrate, FLOAT, DERIVATIVE );
p_input->counters.p_sout_send_bitrate->update_interval = 1000000;
}
free( psz );
}
......@@ -1105,6 +1107,22 @@ static void End( input_thread_t * p_input )
if( p_input->p_es_out )
input_EsOutDelete( p_input->p_es_out );
#define CL_CO( c ) stats_CounterClean( p_input->counters.p_##c )
CL_CO( read_bytes );
CL_CO( read_packets );
CL_CO( demux_read );
CL_CO( input_bitrate );
CL_CO( demux_bitrate );
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) ;
CL_CO( read_bytes );
/* Close optional stream output instance */
if( p_input->p_sout )
{
......@@ -1112,6 +1130,10 @@ static void End( input_thread_t * p_input )
vlc_object_find( p_input, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
vlc_value_t keep;
CL_CO( sout_sent_packets );
CL_CO( sout_sent_bytes );
CL_CO( sout_send_bitrate );
if( var_Get( p_input, "sout-keep", &keep ) >= 0 && keep.b_bool && p_pl )
{
/* attach sout to the playlist */
......@@ -1128,6 +1150,7 @@ static void End( input_thread_t * p_input )
vlc_object_release( p_pl );
}
#undef CL_CO
/* Tell we're dead */
p_input->b_dead = VLC_TRUE;
}
......
......@@ -24,6 +24,7 @@
#include <stdlib.h>
#include <vlc/vlc.h>
#include <vlc/input.h>
#include <assert.h>
#include "input_internal.h"
......@@ -1577,15 +1578,19 @@ static int AReadStream( stream_t *s, void *p_read, int i_read )
int i_read_orig = i_read;
int i_total;
input_thread_t *p_input = (input_thread_t *)s->p_parent->p_parent ;
assert( p_input );
if( !p_sys->i_list )
{
i_read = p_access->pf_read( p_access, p_read, i_read );
stats_UpdateInteger( s->p_parent->p_parent , STATS_READ_BYTES, i_read,
vlc_mutex_lock( &p_input->counters.counters_lock );
stats_UpdateInteger( s, p_input->counters.p_read_bytes, i_read,
&i_total );
stats_UpdateFloat( s->p_parent->p_parent , STATS_INPUT_BITRATE,
stats_UpdateFloat( s, p_input->counters.p_input_bitrate,
(float)i_total, NULL );
stats_UpdateInteger( s->p_parent->p_parent , STATS_READ_PACKETS, 1,
NULL );
stats_UpdateInteger( s, p_input->counters.p_read_packets, 1, NULL );
vlc_mutex_unlock( &p_input->counters.counters_lock );
return i_read;
}
......@@ -1614,11 +1619,12 @@ static int AReadStream( stream_t *s, void *p_read, int i_read )
}
/* Update read bytes in input */
stats_UpdateInteger( s->p_parent->p_parent , STATS_READ_BYTES, i_read,
&i_total );
stats_UpdateFloat( s->p_parent->p_parent , STATS_INPUT_BITRATE,
vlc_mutex_lock( &p_input->counters.counters_lock );
stats_UpdateInteger( s, p_input->counters.p_read_bytes, i_read, &i_total );
stats_UpdateFloat( s, p_input->counters.p_input_bitrate,
(float)i_total, NULL );
stats_UpdateInteger( s->p_parent->p_parent , STATS_READ_PACKETS, 1, NULL );
stats_UpdateInteger( s, p_input->counters.p_read_packets, 1, NULL );
vlc_mutex_unlock( &p_input->counters.counters_lock );
return i_read;
}
......@@ -1630,17 +1636,22 @@ static block_t *AReadBlock( stream_t *s, vlc_bool_t *pb_eof )
vlc_bool_t b_eof;
int i_total;
input_thread_t *p_input = (input_thread_t *)s->p_parent->p_parent ;
assert( p_input );
if( !p_sys->i_list )
{
p_block = p_access->pf_block( p_access );
if( pb_eof ) *pb_eof = p_access->info.b_eof;
if( p_block && p_access->p_libvlc->b_stats )
{
stats_UpdateInteger( s->p_parent->p_parent, STATS_READ_BYTES,
vlc_mutex_lock( &p_input->counters.counters_lock );
stats_UpdateInteger( s, p_input->counters.p_read_bytes,
p_block->i_buffer, &i_total );
stats_UpdateFloat( s->p_parent->p_parent , STATS_INPUT_BITRATE,
stats_UpdateFloat( s, p_input->counters.p_input_bitrate,
(float)i_total, NULL );
stats_UpdateInteger( s->p_parent->p_parent , STATS_READ_PACKETS, 1, NULL );
stats_UpdateInteger( s, p_input->counters.p_read_packets, 1, NULL );
vlc_mutex_unlock( &p_input->counters.counters_lock );
}
return p_block;
}
......@@ -1671,14 +1682,15 @@ static block_t *AReadBlock( stream_t *s, vlc_bool_t *pb_eof )
}
if( p_block )
{
stats_UpdateInteger( s->p_parent->p_parent, STATS_READ_BYTES,
vlc_mutex_lock( &p_input->counters.counters_lock );
stats_UpdateInteger( s, p_input->counters.p_read_bytes,
p_block->i_buffer, &i_total );
stats_UpdateFloat( s->p_parent->p_parent , STATS_INPUT_BITRATE,
stats_UpdateFloat( s, p_input->counters.p_input_bitrate,
(float)i_total, NULL );
stats_UpdateInteger( s->p_parent->p_parent , STATS_READ_PACKETS,
stats_UpdateInteger( s, p_input->counters.p_read_packets,
1 , NULL);
vlc_mutex_unlock( &p_input->counters.counters_lock );
}
return p_block;
}
......
......@@ -686,7 +686,9 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
}
libvlc.b_stats = config_GetInt( p_vlc, "stats" );
libvlc.p_stats = NULL;
libvlc.i_timers = 0;
libvlc.pp_timers = NULL;
vlc_mutex_init( p_vlc, &libvlc.timer_lock );
/*
* Initialize hotkey handling
......@@ -887,7 +889,6 @@ int VLC_CleanUp( int i_object )
vout_thread_t * p_vout;
aout_instance_t * p_aout;
announce_handler_t * p_announce;
stats_handler_t * p_stats;
vlc_t *p_vlc = vlc_current_object( i_object );
/* Check that the handle is valid */
......@@ -942,14 +943,8 @@ int VLC_CleanUp( int i_object )
aout_Delete( p_aout );
}
while( ( p_stats = vlc_object_find( p_vlc, VLC_OBJECT_STATS, FIND_CHILD) ))
{
stats_TimersDumpAll( p_vlc );
stats_HandlerDestroy( p_stats );
vlc_object_detach( (vlc_object_t*) p_stats );
vlc_object_release( (vlc_object_t *)p_stats );
// TODO: Delete it
}
stats_TimersClean( p_vlc );
/*
* Free announce handler(s?)
......
......@@ -216,10 +216,6 @@ void * __vlc_object_create( vlc_object_t *p_this, int i_type )
i_size = sizeof( osd_menu_t );
psz_type = "osd menu";
break;
case VLC_OBJECT_STATS:
i_size = sizeof( stats_handler_t );
psz_type = "statistics";
break;
default:
i_size = i_type > (int)sizeof(vlc_object_t)
? i_type : (int)sizeof(vlc_object_t);
......
......@@ -32,49 +32,18 @@
/*****************************************************************************
* Local prototypes
*****************************************************************************/
static counter_t *GetCounter( stats_handler_t *p_handler, int i_object_id,
unsigned int i_counter );
static int stats_CounterUpdate( stats_handler_t *p_handler,
static int CounterUpdate( vlc_object_t *p_this,
counter_t *p_counter,
vlc_value_t val, vlc_value_t * );
static stats_handler_t* stats_HandlerCreate( vlc_object_t *p_this );
static stats_handler_t *stats_HandlerGet( vlc_object_t *p_this );
static void TimerDump( vlc_object_t *p_this, counter_t *p_counter, vlc_bool_t);
/*****************************************************************************
* Exported functions
*****************************************************************************/
/**
* Cleanup statistics handler stuff
* \param p_stats the handler to clean
* \return nothing
*/
void stats_HandlerDestroy( stats_handler_t *p_stats )
{
int i;
for ( i = p_stats->i_counters - 1 ; i >= 0 ; i-- )
{
int j;
counter_t *p_counter = p_stats->pp_counters[i];
for( j = p_counter->i_samples -1; j >= 0 ; j-- )
{
counter_sample_t *p_sample = p_counter->pp_samples[j];
REMOVE_ELEM( p_counter->pp_samples, p_counter->i_samples, j );
free( p_sample );
}
free( p_counter->psz_name );
REMOVE_ELEM( p_stats->pp_counters, p_stats->i_counters, i );
free( p_counter );
}
}
/**
* Create a statistics counter
* \param p_this the object for which to create the counter
* \param psz_name the name
* \param p_this a VLC object
* \param i_type the type of stored data. One of VLC_VAR_STRING,
* VLC_VAR_INTEGER, VLC_VAR_FLOAT
* \param i_compute_type the aggregation type. One of STATS_LAST (always
......@@ -82,111 +51,53 @@ void stats_HandlerDestroy( stats_handler_t *p_stats )
* STATS_MAX (keep the maximum passed value), STATS_MIN, or STATS_DERIVATIVE
* (keep a time derivative of the value)
*/
int __stats_Create( vlc_object_t *p_this, const char *psz_name, unsigned int i_id,
counter_t * __stats_CounterCreate( vlc_object_t *p_this,
<