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

Misc stats work (Refs:#473)

parent 8ea1f624
...@@ -64,6 +64,8 @@ struct input_item_t ...@@ -64,6 +64,8 @@ struct input_item_t
vlc_bool_t b_fixed_name; /**< Can the interface change the name ?*/ vlc_bool_t b_fixed_name; /**< Can the interface change the name ?*/
input_stats_t *p_stats; /**< Statistics */
vlc_mutex_t lock; /**< Item cannot be changed without this lock */ vlc_mutex_t lock; /**< Item cannot be changed without this lock */
}; };
...@@ -91,6 +93,10 @@ static inline void vlc_input_item_Init( vlc_object_t *p_o, input_item_t *p_i ) ...@@ -91,6 +93,10 @@ static inline void vlc_input_item_Init( vlc_object_t *p_o, input_item_t *p_i )
p_i->es = 0; p_i->es = 0;
p_i->i_type = ITEM_TYPE_UNKNOWN; p_i->i_type = ITEM_TYPE_UNKNOWN;
p_i->b_fixed_name = VLC_TRUE; p_i->b_fixed_name = VLC_TRUE;
p_i->p_stats = (input_stats_t*) malloc( sizeof( input_stats_t ) );
vlc_mutex_init( p_o, &p_i->p_stats->lock );
vlc_mutex_init( p_o, &p_i->lock ); vlc_mutex_init( p_o, &p_i->lock );
} }
......
...@@ -25,6 +25,10 @@ ...@@ -25,6 +25,10 @@
*****************************************************************************/ *****************************************************************************/
#include <stdarg.h> #include <stdarg.h>
int vlc_mutex_lock( vlc_mutex_t * ) ;
int vlc_mutex_unlock( vlc_mutex_t * ) ;
/** /**
* \defgroup messages Messages * \defgroup messages Messages
* This library provides basic functions for threads to interact with user * This library provides basic functions for threads to interact with user
...@@ -239,7 +243,20 @@ struct stats_handler_t ...@@ -239,7 +243,20 @@ struct stats_handler_t
VLC_EXPORT( int, __stats_Update, (vlc_object_t*, char *, vlc_value_t) ); VLC_EXPORT( int, __stats_Update, (vlc_object_t*, char *, vlc_value_t) );
#define stats_Create( a,b,c,d ) __stats_Create( VLC_OBJECT(a), b, c, d ) #define stats_Create( a,b,c,d ) __stats_Create( VLC_OBJECT(a), b, c, d )
VLC_EXPORT( int, __stats_Create, (vlc_object_t*, char *, int, int) ); VLC_EXPORT( int, __stats_Create, (vlc_object_t*, char *, int, int) );
#define stats_Get( a,b,c,d ) __stats_Create( VLC_OBJECT(a), b, c, d )
VLC_EXPORT( int, __stats_Get, (vlc_object_t*, int, char *, vlc_value_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,
char *psz_name, int *value )
{
vlc_value_t val;
int i_ret = __stats_Get( p_obj, i_id, psz_name, &val );
*value = val.i_int;
return i_ret;
}
#define stats_UpdateInteger( a,b,c ) __stats_UpdateInteger( VLC_OBJECT(a),b,c )
static inline int __stats_UpdateInteger( vlc_object_t *p_obj, char *psz_name, static inline int __stats_UpdateInteger( vlc_object_t *p_obj, char *psz_name,
int i ) int i )
{ {
...@@ -247,11 +264,13 @@ static inline int __stats_UpdateInteger( vlc_object_t *p_obj, char *psz_name, ...@@ -247,11 +264,13 @@ static inline int __stats_UpdateInteger( vlc_object_t *p_obj, char *psz_name,
val.i_int = i; val.i_int = i;
return __stats_Update( p_obj, psz_name, val ); return __stats_Update( p_obj, psz_name, val );
} }
#define stats_UpdateInteger( a,b,c ) __stats_UpdateInteger( VLC_OBJECT(a),b,c )
struct input_stats_t struct input_stats_t
{ {
vlc_mutex_t lock;
/* Input */ /* Input */
int i_read_packets; int i_read_packets;
int i_read_bytes; int i_read_bytes;
...@@ -265,3 +284,7 @@ struct input_stats_t ...@@ -265,3 +284,7 @@ struct input_stats_t
int i_displayed_pictures; int i_displayed_pictures;
int i_lost_pictures; int i_lost_pictures;
}; };
VLC_EXPORT( void, stats_ComputeInputStats, (input_thread_t*, input_stats_t*) );
VLC_EXPORT( void, stats_ReinitInputStats, (input_stats_t *) );
VLC_EXPORT( void, stats_DumpInputStats, (input_stats_t *) );
...@@ -29,6 +29,7 @@ void vlm_MediaDelete (vlm_t *, vlm_media_t *, const char *); ...@@ -29,6 +29,7 @@ void vlm_MediaDelete (vlm_t *, vlm_media_t *, const char *);
int __var_Destroy (vlc_object_t *, const char *); int __var_Destroy (vlc_object_t *, const char *);
int playlist_ItemSetDuration (playlist_item_t *, mtime_t); int playlist_ItemSetDuration (playlist_item_t *, mtime_t);
void aout_Delete (aout_instance_t *); void aout_Delete (aout_instance_t *);
void stats_ComputeInputStats (input_thread_t*, input_stats_t*);
int playlist_Control (playlist_t *, int, ...); int playlist_Control (playlist_t *, int, ...);
vlc_acl_t * __ACL_Create (vlc_object_t *p_this, vlc_bool_t b_allow); vlc_acl_t * __ACL_Create (vlc_object_t *p_this, vlc_bool_t b_allow);
playlist_item_t * playlist_ItemGetByPos (playlist_t *, int); playlist_item_t * playlist_ItemGetByPos (playlist_t *, int);
...@@ -120,6 +121,7 @@ void vout_SynchroDecode (vout_synchro_t *); ...@@ -120,6 +121,7 @@ void vout_SynchroDecode (vout_synchro_t *);
int playlist_Delete (playlist_t *, int); int playlist_Delete (playlist_t *, int);
void aout_FiltersPlay (aout_instance_t * p_aout, aout_filter_t ** pp_filters, int i_nb_filters, aout_buffer_t ** pp_input_buffer); void aout_FiltersPlay (aout_instance_t * p_aout, aout_filter_t ** pp_filters, int i_nb_filters, aout_buffer_t ** pp_input_buffer);
int __stats_Update (vlc_object_t*, char *, vlc_value_t); int __stats_Update (vlc_object_t*, char *, vlc_value_t);
int __stats_Get (vlc_object_t*, int, char *, vlc_value_t*);
char* httpd_ClientIP (httpd_client_t *cl, char *psz_ip); char* httpd_ClientIP (httpd_client_t *cl, char *psz_ip);
int __intf_UserProgress (vlc_object_t*, const char*, const char*, float); int __intf_UserProgress (vlc_object_t*, const char*, const char*, float);
void httpd_FileDelete (httpd_file_t *); void httpd_FileDelete (httpd_file_t *);
...@@ -241,6 +243,7 @@ int osd_ConfigLoader (vlc_object_t *, const char *, osd_menu_t **); ...@@ -241,6 +243,7 @@ int osd_ConfigLoader (vlc_object_t *, const char *, osd_menu_t **);
int aout_Restart (aout_instance_t * p_aout); int aout_Restart (aout_instance_t * p_aout);
void * __vlc_object_create (vlc_object_t *, int); void * __vlc_object_create (vlc_object_t *, int);
int __aout_VolumeInfos (vlc_object_t *, audio_volume_t *); int __aout_VolumeInfos (vlc_object_t *, audio_volume_t *);
void stats_DumpInputStats (input_stats_t *);
const iso639_lang_t * GetLang_2T (const char *); const iso639_lang_t * GetLang_2T (const char *);
int __intf_Interact (vlc_object_t *,interaction_dialog_t *); int __intf_Interact (vlc_object_t *,interaction_dialog_t *);
int playlist_NodeAddItem (playlist_t *, playlist_item_t *,int,playlist_item_t *,int , int); int playlist_NodeAddItem (playlist_t *, playlist_item_t *,int,playlist_item_t *,int , int);
...@@ -251,6 +254,7 @@ int playlist_LockControl (playlist_t *, int, ...); ...@@ -251,6 +254,7 @@ int playlist_LockControl (playlist_t *, int, ...);
vlc_bool_t vlc_current_charset (char **); vlc_bool_t vlc_current_charset (char **);
char * __net_Gets (vlc_object_t *p_this, int fd, v_socket_t *); char * __net_Gets (vlc_object_t *p_this, int fd, v_socket_t *);
void aout_DateMove (audio_date_t *, mtime_t); void aout_DateMove (audio_date_t *, mtime_t);
void stats_ReinitInputStats (input_stats_t *);
void sout_MuxDelete (sout_mux_t *); void sout_MuxDelete (sout_mux_t *);
void vout_InitFormat (video_frame_format_t *, uint32_t, int, int, int); void vout_InitFormat (video_frame_format_t *, uint32_t, int, int, int);
void vout_UnlinkPicture (vout_thread_t *, picture_t *); void vout_UnlinkPicture (vout_thread_t *, picture_t *);
...@@ -873,6 +877,10 @@ struct module_symbols_t ...@@ -873,6 +877,10 @@ struct module_symbols_t
void (*__intf_UserHide_inner) (vlc_object_t *, int); void (*__intf_UserHide_inner) (vlc_object_t *, int);
int (*__stats_Create_inner) (vlc_object_t*, char *, int, int); int (*__stats_Create_inner) (vlc_object_t*, char *, int, int);
int (*__stats_Update_inner) (vlc_object_t*, char *, vlc_value_t); int (*__stats_Update_inner) (vlc_object_t*, char *, vlc_value_t);
int (*__stats_Get_inner) (vlc_object_t*, int, char *, 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 *);
}; };
# if defined (__PLUGIN__) # if defined (__PLUGIN__)
# define aout_FiltersCreatePipeline (p_symbols)->aout_FiltersCreatePipeline_inner # define aout_FiltersCreatePipeline (p_symbols)->aout_FiltersCreatePipeline_inner
...@@ -1295,6 +1303,10 @@ struct module_symbols_t ...@@ -1295,6 +1303,10 @@ struct module_symbols_t
# define __intf_UserHide (p_symbols)->__intf_UserHide_inner # define __intf_UserHide (p_symbols)->__intf_UserHide_inner
# define __stats_Create (p_symbols)->__stats_Create_inner # define __stats_Create (p_symbols)->__stats_Create_inner
# define __stats_Update (p_symbols)->__stats_Update_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
# elif defined (HAVE_DYNAMIC_PLUGINS) && !defined (__BUILTIN__) # elif defined (HAVE_DYNAMIC_PLUGINS) && !defined (__BUILTIN__)
/****************************************************************** /******************************************************************
* STORE_SYMBOLS: store VLC APIs into p_symbols for plugin access. * STORE_SYMBOLS: store VLC APIs into p_symbols for plugin access.
...@@ -1720,6 +1732,10 @@ struct module_symbols_t ...@@ -1720,6 +1732,10 @@ struct module_symbols_t
((p_symbols)->__intf_UserHide_inner) = __intf_UserHide; \ ((p_symbols)->__intf_UserHide_inner) = __intf_UserHide; \
((p_symbols)->__stats_Create_inner) = __stats_Create; \ ((p_symbols)->__stats_Create_inner) = __stats_Create; \
((p_symbols)->__stats_Update_inner) = __stats_Update; \ ((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)->net_ConvertIPv4_deprecated = NULL; \ (p_symbols)->net_ConvertIPv4_deprecated = NULL; \
# endif /* __PLUGIN__ */ # endif /* __PLUGIN__ */
......
...@@ -150,6 +150,8 @@ static input_thread_t *Create( vlc_object_t *p_parent, input_item_t *p_item, ...@@ -150,6 +150,8 @@ static input_thread_t *Create( vlc_object_t *p_parent, input_item_t *p_item,
p_input->input.b_eof = VLC_FALSE; p_input->input.b_eof = VLC_FALSE;
p_input->input.i_cr_average = 0; p_input->input.i_cr_average = 0;
stats_ReinitInputStats( p_item->p_stats );
/* No slave */ /* No slave */
p_input->i_slave = 0; p_input->i_slave = 0;
p_input->slave = NULL; p_input->slave = NULL;
...@@ -673,8 +675,9 @@ static int Init( input_thread_t * p_input, vlc_bool_t b_quick ) ...@@ -673,8 +675,9 @@ static int Init( input_thread_t * p_input, vlc_bool_t b_quick )
if( !b_quick ) if( !b_quick )
{ {
stats_Create( p_input, "read_bytes", VLC_VAR_INTEGER, STATS_COUNTER ); stats_Create( p_input, "read_bytes", VLC_VAR_INTEGER, STATS_COUNTER );
stats_Create( p_input, "read_packets", VLC_VAR_INTEGER, STATS_COUNTER );
stats_Create( p_input, "input_bitrate", VLC_VAR_FLOAT, stats_Create( p_input, "input_bitrate", VLC_VAR_FLOAT,
STATS_DERIVATIVE ); STATS_DERIVATIVE );
psz = var_GetString( p_input, "sout" ); psz = var_GetString( p_input, "sout" );
if( *psz && strncasecmp( p_input->input.p_item->psz_uri, "vlc:", 4 ) ) if( *psz && strncasecmp( p_input->input.p_item->psz_uri, "vlc:", 4 ) )
{ {
......
...@@ -1569,6 +1569,9 @@ static int AReadStream( stream_t *s, void *p_read, int i_read ) ...@@ -1569,6 +1569,9 @@ static int AReadStream( stream_t *s, void *p_read, int i_read )
if( !p_sys->i_list ) if( !p_sys->i_list )
{ {
i_read = p_access->pf_read( p_access, p_read, i_read ); i_read = p_access->pf_read( p_access, p_read, i_read );
stats_UpdateInteger( s->p_parent->p_parent , "read_bytes", i_read );
stats_UpdateInteger( s->p_parent->p_parent , "input_bitrate", i_read );
stats_UpdateInteger( s->p_parent->p_parent , "read_packets", 1 );
return i_read; return i_read;
} }
...@@ -1597,8 +1600,9 @@ static int AReadStream( stream_t *s, void *p_read, int i_read ) ...@@ -1597,8 +1600,9 @@ static int AReadStream( stream_t *s, void *p_read, int i_read )
} }
/* Update read bytes in input */ /* Update read bytes in input */
stats_UpdateInteger( s->p_parent, "read_bytes", i_read ); stats_UpdateInteger( s->p_parent->p_parent , "read_bytes", i_read );
stats_UpdateInteger( s->p_parent->p_parent , "input_bitrate", i_read );
stats_UpdateInteger( s->p_parent->p_parent , "read_packets", 1 );
return i_read; return i_read;
} }
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include <stdio.h> /* required */ #include <stdio.h> /* required */
#include <vlc/vlc.h> #include <vlc/vlc.h>
#include <vlc_input.h>
/***************************************************************************** /*****************************************************************************
* Local prototypes * Local prototypes
...@@ -48,6 +49,9 @@ int __stats_Create( vlc_object_t *p_this, char *psz_name, int i_type, ...@@ -48,6 +49,9 @@ int __stats_Create( vlc_object_t *p_this, char *psz_name, int i_type,
{ {
counter_t *p_counter; counter_t *p_counter;
stats_handler_t *p_handler = stats_HandlerGet( p_this ); stats_handler_t *p_handler = stats_HandlerGet( p_this );
if( !p_handler ) return VLC_ENOMEM;
vlc_mutex_lock( &p_handler->object_lock );
p_counter = (counter_t*) malloc( sizeof( counter_t ) ) ; p_counter = (counter_t*) malloc( sizeof( counter_t ) ) ;
...@@ -63,6 +67,8 @@ int __stats_Create( vlc_object_t *p_this, char *psz_name, int i_type, ...@@ -63,6 +67,8 @@ int __stats_Create( vlc_object_t *p_this, char *psz_name, int i_type,
p_handler->i_counters, p_handler->i_counters,
p_counter ); p_counter );
vlc_mutex_unlock( &p_handler->object_lock );
return VLC_SUCCESS; return VLC_SUCCESS;
} }
...@@ -70,24 +76,106 @@ int __stats_Create( vlc_object_t *p_this, char *psz_name, int i_type, ...@@ -70,24 +76,106 @@ int __stats_Create( vlc_object_t *p_this, char *psz_name, int i_type,
int __stats_Update( vlc_object_t *p_this, char *psz_name, vlc_value_t val ) int __stats_Update( vlc_object_t *p_this, char *psz_name, vlc_value_t val )
{ {
int i_ret;
counter_t *p_counter; counter_t *p_counter;
/* Get stats handler singleton */ /* Get stats handler singleton */
stats_handler_t *p_handler = stats_HandlerGet( p_this ); stats_handler_t *p_handler = stats_HandlerGet( p_this );
if( !p_handler ) return VLC_ENOMEM; if( !p_handler ) return VLC_ENOMEM;
vlc_mutex_lock( &p_handler->object_lock );
/* Look for existing element */ /* Look for existing element */
p_counter = stats_GetCounter( p_handler, p_this->i_object_id, p_counter = stats_GetCounter( p_handler, p_this->i_object_id,
psz_name ); psz_name );
if( !p_counter ) if( !p_counter )
{ {
vlc_mutex_unlock( &p_handler->object_lock );
vlc_object_release( p_handler ); vlc_object_release( p_handler );
return VLC_ENOOBJ; return VLC_ENOOBJ;
} }
return stats_CounterUpdate( p_handler, p_counter, val ); i_ret = stats_CounterUpdate( p_handler, p_counter, val );
vlc_mutex_unlock( &p_handler->object_lock );
return i_ret;
}
int __stats_Get( vlc_object_t *p_this, int i_object_id, char *psz_name, vlc_value_t *val )
{
counter_t *p_counter;
/* Get stats handler singleton */
stats_handler_t *p_handler = stats_HandlerGet( p_this );
if( !p_handler ) return VLC_ENOMEM;
vlc_mutex_lock( &p_handler->object_lock );
/* Look for existing element */
p_counter = stats_GetCounter( p_handler, i_object_id,
psz_name );
if( !p_counter )
{
vlc_mutex_unlock( &p_handler->object_lock );
vlc_object_release( p_handler );
return VLC_ENOOBJ;
}
if( p_counter->i_samples == 0 )
{
vlc_mutex_unlock( &p_handler->object_lock );
return VLC_EGENERIC;
}
/* FIXME: Does not work for all types, maybe */
*val = p_counter->pp_samples[0]->value;
vlc_object_release( p_handler );
vlc_mutex_unlock( &p_handler->object_lock );
return VLC_SUCCESS;;
} }
void stats_ComputeInputStats( input_thread_t *p_input,
input_stats_t *p_stats )
{
vlc_mutex_lock( &p_stats->lock );
/* read_packets and read_bytes are common to all streams */
stats_GetInteger( p_input, p_input->i_object_id, "read_packets",
&p_stats->i_read_packets );
stats_GetInteger( p_input, p_input->i_object_id, "read_bytes",
&p_stats->i_read_bytes );
vlc_mutex_unlock( &p_stats->lock );
}
void stats_ReinitInputStats( input_stats_t *p_stats )
{
p_stats->i_read_packets = p_stats->i_read_bytes =
p_stats->f_last_bitrate = p_stats->f_average_bitrate =
p_stats->i_displayed_pictures = p_stats->i_lost_pictures = 0;
}
void stats_DumpInputStats( input_stats_t *p_stats )
{
vlc_mutex_lock( &p_stats->lock );
fprintf( stderr, "Read packets : %i (%i bytes)\n",
p_stats->i_read_packets, p_stats->i_read_bytes );
vlc_mutex_unlock( &p_stats->lock );
}
/********************************************************************
* Following functions are local
********************************************************************/
/**
* Update a statistics counter, according to its type
* If needed, perform a bit of computation (derivative, mostly)
* This function must be entered with stats handler lock
* \param p_handler stats handler singleton
* \param p_counter the counter to update
* \param val the "new" value
* \return an error code
*/
static int stats_CounterUpdate( stats_handler_t *p_handler, static int stats_CounterUpdate( stats_handler_t *p_handler,
counter_t *p_counter, counter_t *p_counter,
vlc_value_t val ) vlc_value_t val )
...@@ -244,12 +332,3 @@ static stats_handler_t* stats_HandlerCreate( vlc_object_t *p_this ) ...@@ -244,12 +332,3 @@ static stats_handler_t* stats_HandlerCreate( vlc_object_t *p_this )
} }
void stats_ComputeInputStats( input_thread_t *p_input,
input_stats_t *p_stats )
{
int i;
/* read_packets and read_bytes are common to all streams */
//p_stats->i_read_packets = stats_GetInteger( p_input, "read_packets" );
// p_stats->i_read_bytes = stats_GetInteger( p_input, "read_bytes" );
}
...@@ -63,6 +63,8 @@ playlist_item_t * playlist_ItemNewWithType( vlc_object_t *p_obj, ...@@ -63,6 +63,8 @@ playlist_item_t * playlist_ItemNewWithType( vlc_object_t *p_obj,
memset( p_item, 0, sizeof( playlist_item_t ) ); memset( p_item, 0, sizeof( playlist_item_t ) );
vlc_input_item_Init( p_obj, &p_item->input );
p_item->input.psz_uri = strdup( psz_uri ); p_item->input.psz_uri = strdup( psz_uri );
if( psz_name != NULL ) p_item->input.psz_name = strdup( psz_name ); if( psz_name != NULL ) p_item->input.psz_name = strdup( psz_name );
......
...@@ -618,6 +618,9 @@ static void RunThread ( playlist_t *p_playlist ) ...@@ -618,6 +618,9 @@ static void RunThread ( playlist_t *p_playlist )
/* If there is an input, check that it doesn't need to die. */ /* If there is an input, check that it doesn't need to die. */
if( p_playlist->p_input ) if( p_playlist->p_input )
{ {
stats_ComputeInputStats( p_playlist->p_input,
p_playlist->p_input->input.p_item->p_stats );
/* This input is dead. Remove it ! */ /* This input is dead. Remove it ! */
if( p_playlist->p_input->b_dead ) if( p_playlist->p_input->b_dead )
{ {
......
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