Commit 26d5b738 authored by Clément Stenac's avatar Clément Stenac

* Avoid useless stats_Get calls

* Reduce vlc_object_find calls
parent f8cac3e1
......@@ -4,6 +4,7 @@ Changes between 0.8.4a and 0.8.5-svn (not yet released):
--------------------------------------------------------
Core support:
* Statistics collection (bitrates, packets, connections, ...)
Input:
* Initial support for RTSP-over-HTTP (to allow NAT traversal)
......@@ -49,11 +50,9 @@ OS X Port:
* Root wrapper to avoid running VLC as root
Developers:
* New libvlc API (not finished yet)
* Java bindings
Changes between 0.8.4 and 0.8.4a:
---------------------------------
......
......@@ -62,6 +62,7 @@ struct libvlc_t
/* Do stats ? - We keep this boolean to avoid unneeded lookups */
vlc_bool_t b_stats;
stats_handler_t *p_stats;
/* Arch-specific variables */
#if !defined( WIN32 )
......
......@@ -249,8 +249,8 @@ struct stats_handler_t
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*, const char *, 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*, const char *, vlc_value_t, vlc_value_t *) );
#define stats_Create( a,b,c,d ) __stats_Create( VLC_OBJECT(a), b, c, d )
VLC_EXPORT( int, __stats_Create, (vlc_object_t*, const char *, int, int) );
#define stats_Get( a,b,c,d ) __stats_Create( VLC_OBJECT(a), b, c, d )
......@@ -277,21 +277,31 @@ static inline int __stats_GetFloat( vlc_object_t *p_obj, int i_id,
*value = val.f_float;
return i_ret;
}
#define stats_UpdateInteger( a,b,c ) __stats_UpdateInteger( VLC_OBJECT(a),b,c )
#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,
const char *psz_name, int i )
const char *psz_name, int i, int *pi_new )
{
int i_ret;
vlc_value_t val;
vlc_value_t new_val;
val.i_int = i;
return __stats_Update( p_obj, psz_name, val );
i_ret = __stats_Update( p_obj, psz_name, val , &new_val );
if( pi_new )
*pi_new = new_val.i_int;
return i_ret;
}
#define stats_UpdateFloat( a,b,c ) __stats_UpdateFloat( VLC_OBJECT(a),b,c )
#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,
const char *psz_name, float f )
const char *psz_name, float f, float *pf_new )
{
vlc_value_t val;
int i_ret;
vlc_value_t new_val;
val.f_float = f;
return __stats_Update( p_obj, psz_name, val );
i_ret = __stats_Update( p_obj, psz_name, val, &new_val );
if( pf_new )
*pf_new = new_val.f_float;
return i_ret;
}
/******************
......
......@@ -124,7 +124,7 @@ void vlm_MessageDelete (vlm_message_t *);
void vout_SynchroDecode (vout_synchro_t *);
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);
int __stats_Update (vlc_object_t*, const char *, vlc_value_t);
int __stats_Update (vlc_object_t*, const char *, vlc_value_t, vlc_value_t *);
int __stats_Get (vlc_object_t*, int, const char *, vlc_value_t*);
char* httpd_ClientIP (httpd_client_t *cl, char *psz_ip);
int __intf_UserProgress (vlc_object_t*, const char*, const char*, float);
......@@ -897,7 +897,7 @@ struct module_symbols_t
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 *, int, int);
int (*__stats_Update_inner) (vlc_object_t*, const char *, vlc_value_t);
int (*__stats_Update_inner) (vlc_object_t*, const char *, vlc_value_t, vlc_value_t *);
int (*__stats_Get_inner) (vlc_object_t*, int, const char *, vlc_value_t*);
void (*stats_ComputeInputStats_inner) (input_thread_t*, input_stats_t*);
void (*stats_DumpInputStats_inner) (input_stats_t *);
......
......@@ -1328,7 +1328,7 @@ static int transcode_audio_process( sout_stream_t *p_stream,
while( (p_audio_buf = id->p_decoder->pf_decode_audio( id->p_decoder,
&in )) )
{
stats_UpdateInteger( p_stream->p_parent->p_parent, "decoded_audio", 1 );
stats_UpdateInteger( p_stream->p_parent->p_parent, "decoded_audio", 1, NULL );
if( p_sys->b_master_sync )
{
mtime_t i_dts = date_Get( &id->interpolated_pts ) + 1;
......@@ -1731,7 +1731,7 @@ static int transcode_video_process( sout_stream_t *p_stream,
while( (p_pic = id->p_decoder->pf_decode_video( id->p_decoder, &in )) )
{
subpicture_t *p_subpic = 0;
stats_UpdateInteger( p_stream->p_parent->p_parent, "decoded_video", 1 );
stats_UpdateInteger( p_stream->p_parent->p_parent, "decoded_video", 1, NULL );
if( p_stream->p_sout->i_out_pace_nocontrol && p_sys->b_hurry_up )
{
......
......@@ -312,7 +312,8 @@ 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, "lost_abuffers", 1 );
stats_UpdateInteger( p_input->p_input_thread, "lost_abuffers", 1,
NULL );
}
aout_BufferFree( p_buffer );
return -1;
......@@ -367,7 +368,7 @@ int aout_DecPlay( aout_instance_t * p_aout, aout_input_t * p_input,
if( p_input->p_input_thread )
{
stats_UpdateInteger( p_input->p_input_thread,
"played_abuffers", 1 );
"played_abuffers", 1, NULL );
}
vlc_mutex_unlock( &p_aout->mixer_lock );
......
......@@ -447,7 +447,8 @@ 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, "lost_abuffers", 1 );
stats_UpdateInteger( p_input->p_input_thread, "lost_abuffers", 1,
NULL );
}
}
......@@ -459,7 +460,8 @@ 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, "lost_abuffers", 1 );
stats_UpdateInteger( p_input->p_input_thread, "lost_abuffers", 1,
NULL );
}
aout_BufferFree( p_buffer );
p_input->i_resampling_type = AOUT_RESAMPLING_NONE;
......@@ -500,7 +502,8 @@ 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, "lost_abuffers", 1 );
stats_UpdateInteger( p_input->p_input_thread, "lost_abuffers", 1,
NULL );
}
return 0;
}
......
......@@ -627,7 +627,7 @@ 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, "decoded_audio", 1 );
stats_UpdateInteger( p_dec->p_parent, "decoded_audio", 1, NULL );
/* 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 &&
......@@ -651,7 +651,7 @@ 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, "decoded_audio", 1 );
stats_UpdateInteger( p_dec->p_parent, "decoded_audio", 1, NULL );
if( p_dec->p_owner->i_preroll_end > 0 &&
p_aout_buf->start_date < p_dec->p_owner->i_preroll_end )
{
......@@ -698,7 +698,7 @@ static int DecoderDecode( decoder_t *p_dec, block_t *p_block )
&p_packetized_block )) )
{
stats_UpdateInteger( p_dec->p_parent, "decoded_video",
1 );
1, NULL );
if( p_dec->p_owner->i_preroll_end > 0 &&
p_pic->date < p_dec->p_owner->i_preroll_end )
{
......@@ -719,7 +719,7 @@ 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, "decoded_video", 1 );
stats_UpdateInteger( p_dec->p_parent, "decoded_video", 1 , NULL);
if( p_dec->p_owner->i_preroll_end > 0 &&
p_pic->date < p_dec->p_owner->i_preroll_end )
{
......@@ -739,7 +739,7 @@ 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, "decoded_sub", 1 );
stats_UpdateInteger( p_dec->p_parent, "decoded_sub", 1 , NULL);
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 ) )
......
......@@ -1033,10 +1033,9 @@ 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, "demux_read", p_block->i_buffer );
stats_GetInteger( p_input, p_input->i_object_id, "demux_read",
&i_total );
stats_UpdateFloat( p_input , "demux_bitrate", (float)i_total );
stats_UpdateInteger( p_input, "demux_read", p_block->i_buffer,
&i_total );
stats_UpdateFloat( p_input , "demux_bitrate", (float)i_total, NULL );
}
/* Mark preroll blocks */
......
......@@ -1580,12 +1580,11 @@ static int AReadStream( stream_t *s, void *p_read, int i_read )
if( !p_sys->i_list )
{
i_read = p_access->pf_read( p_access, p_read, i_read );
stats_UpdateInteger( s->p_parent->p_parent , "read_bytes", i_read );
stats_GetInteger( s, s->p_parent->p_parent->i_object_id,
"read_bytes", &i_total );
stats_UpdateInteger( s->p_parent->p_parent , "read_bytes", i_read,
&i_total );
stats_UpdateFloat( s->p_parent->p_parent , "input_bitrate",
(float)i_total );
stats_UpdateInteger( s->p_parent->p_parent , "read_packets", 1 );
(float)i_total, NULL );
stats_UpdateInteger( s->p_parent->p_parent , "read_packets", 1, NULL );
return i_read;
}
......@@ -1614,12 +1613,11 @@ static int AReadStream( stream_t *s, void *p_read, int i_read )
}
/* Update read bytes in input */
stats_UpdateInteger( s->p_parent->p_parent , "read_bytes", i_read );
stats_GetInteger( s, s->p_parent->p_parent->i_object_id,
"read_bytes", &i_total );
stats_UpdateInteger( s->p_parent->p_parent , "read_bytes", i_read,
&i_total );
stats_UpdateFloat( s->p_parent->p_parent , "input_bitrate",
(float)i_total );
stats_UpdateInteger( s->p_parent->p_parent , "read_packets", 1 );
(float)i_total, NULL );
stats_UpdateInteger( s->p_parent->p_parent , "read_packets", 1, NULL );
return i_read;
}
......@@ -1638,12 +1636,10 @@ static block_t *AReadBlock( stream_t *s, vlc_bool_t *pb_eof )
if( p_block && p_access->p_libvlc->b_stats )
{
stats_UpdateInteger( s->p_parent->p_parent, "read_bytes",
p_block->i_buffer );
stats_GetInteger( s, s->p_parent->p_parent->i_object_id,
"read_bytes", &i_total );
p_block->i_buffer, &i_total );
stats_UpdateFloat( s->p_parent->p_parent , "input_bitrate",
(float)i_total );
stats_UpdateInteger( s->p_parent->p_parent , "read_packets", 1 );
(float)i_total, NULL );
stats_UpdateInteger( s->p_parent->p_parent , "read_packets", 1, NULL );
}
return p_block;
}
......@@ -1675,12 +1671,10 @@ static block_t *AReadBlock( stream_t *s, vlc_bool_t *pb_eof )
if( p_block )
{
stats_UpdateInteger( s->p_parent->p_parent, "read_bytes",
p_block->i_buffer );
stats_GetInteger( s, s->p_parent->p_parent->i_object_id,
"read_bytes", &i_total );
p_block->i_buffer, &i_total );
stats_UpdateFloat( s->p_parent->p_parent , "input_bitrate",
(float)i_total );
stats_UpdateInteger( s->p_parent->p_parent , "read_packets", 1 );
(float)i_total, NULL );
stats_UpdateInteger( s->p_parent->p_parent , "read_packets", 1 , NULL);
}
return p_block;
......
......@@ -691,6 +691,7 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
}
libvlc.b_stats = config_GetInt( p_vlc, "stats" );
libvlc.p_stats = NULL;
/*
* Initialize hotkey handling
......
......@@ -218,7 +218,7 @@ static uint64_t HashString( const char *psz_string, int i_id )
i_hash ^= i_hash >> 8;
}
i_hash += ( i_id << 32 );
i_hash += ( (uint64_t)i_id << 32 );
return i_hash;
}
......@@ -36,7 +36,7 @@ static counter_t *GetCounter( stats_handler_t *p_handler, int i_object_id,
const char *psz_name );
static int stats_CounterUpdate( stats_handler_t *p_handler,
counter_t *p_counter,
vlc_value_t val );
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 );
......@@ -126,7 +126,7 @@ int __stats_Create( vlc_object_t *p_this, const char *psz_name, int i_type,
* more information on how data is aggregated, \see __stats_Create
*/
int __stats_Update( vlc_object_t *p_this, const char *psz_name,
vlc_value_t val )
vlc_value_t val, vlc_value_t *val_new )
{
int i_ret;
counter_t *p_counter;
......@@ -151,7 +151,7 @@ int __stats_Update( vlc_object_t *p_this, const char *psz_name,
return VLC_ENOOBJ;
}
i_ret = stats_CounterUpdate( p_handler, p_counter, val );
i_ret = stats_CounterUpdate( p_handler, p_counter, val, val_new );
vlc_mutex_unlock( &p_handler->object_lock );
return i_ret;
......@@ -492,7 +492,7 @@ void __stats_TimersDumpAll( vlc_object_t *p_obj )
*/
static int stats_CounterUpdate( stats_handler_t *p_handler,
counter_t *p_counter,
vlc_value_t val )
vlc_value_t val, vlc_value_t *new_val )
{
switch( p_counter->i_compute_type )
{
......@@ -544,6 +544,7 @@ static int stats_CounterUpdate( stats_handler_t *p_handler,
free( p_counter->pp_samples[0]->value.psz_string );
}
p_counter->pp_samples[0]->value = val;
*new_val = p_counter->pp_samples[0]->value;
}
}
break;
......@@ -596,9 +597,14 @@ static int stats_CounterUpdate( stats_handler_t *p_handler,
switch( p_counter->i_type )
{
case VLC_VAR_INTEGER:
case VLC_VAR_FLOAT:
p_counter->pp_samples[0]->value.i_int += val.i_int;
if( new_val )
new_val->i_int = p_counter->pp_samples[0]->value.i_int;
break;
case VLC_VAR_FLOAT:
p_counter->pp_samples[0]->value.f_float += val.f_float;
if( new_val )
new_val->f_float = p_counter->pp_samples[0]->value.f_float;
default:
msg_Err( p_handler, "Trying to increment invalid variable %s",
p_counter->psz_name );
......@@ -621,9 +627,7 @@ static counter_t *GetCounter( stats_handler_t *p_handler, int i_object_id,
static stats_handler_t *stats_HandlerGet( vlc_object_t *p_this )
{
stats_handler_t *p_handler = (stats_handler_t*)
vlc_object_find( p_this->p_vlc, VLC_OBJECT_STATS,
FIND_ANYWHERE );
stats_handler_t *p_handler = p_this->p_libvlc->p_stats;
if( !p_handler )
{
p_handler = stats_HandlerCreate( p_this );
......@@ -631,8 +635,8 @@ static stats_handler_t *stats_HandlerGet( vlc_object_t *p_this )
{
return NULL;
}
vlc_object_yield( p_handler );
}
vlc_object_yield( p_handler );
return p_handler;
}
......@@ -657,11 +661,13 @@ static stats_handler_t* stats_HandlerCreate( vlc_object_t *p_this )
return NULL;
}
p_handler->i_counters = 0;
p_handler->p_counters = (hashtable_entry_t *) malloc( 5 * sizeof( variable_t ) );
p_handler->p_counters = (hashtable_entry_t *) malloc( 4 * sizeof( variable_t ) );
/// \bug is it p_vlc or p_libvlc ?
vlc_object_attach( p_handler, p_this->p_vlc );
p_this->p_libvlc->p_stats = p_handler;
return p_handler;
}
......
......@@ -2106,7 +2106,7 @@ static void httpd_HostThread( httpd_host_t *host )
cl->i_activity_date+cl->i_activity_timeout < mdate()) ) ) )
{
httpd_ClientClean( cl );
stats_UpdateInteger( host, "active_connections", -1 );
stats_UpdateInteger( host, "active_connections", -1, NULL );
TAB_REMOVE( host->i_client, host->client, cl );
free( cl );
i_client--;
......@@ -2560,8 +2560,10 @@ static void httpd_HostThread( httpd_host_t *host )
if( fd >= 0 )
{
httpd_client_t *cl;
stats_UpdateInteger( host, "client_connections", 1 );
stats_UpdateInteger( host, "active_connections", 1 );
stats_UpdateInteger( host, "client_connections", 1,
NULL );
stats_UpdateInteger( host, "active_connections", 1,
NULL );
cl = httpd_ClientNew( fd, &sock, i_sock_size, p_tls );
p_tls = NULL;
vlc_mutex_lock( &host->lock );
......
......@@ -381,14 +381,11 @@ int sout_AccessOutWrite( sout_access_out_t *p_access, block_t *p_buffer )
FIND_PARENT );
if( p_input )
{
stats_UpdateInteger( p_input, "sout_sent_packets", 10 );
stats_UpdateInteger( p_input, "sout_sent_packets", 10, NULL );
stats_UpdateInteger( p_input, "sout_sent_bytes",
p_access->i_sent_bytes );
stats_GetInteger( p_input,
p_access->p_parent->p_parent->i_object_id,
"sout_sent_bytes", &i_total );
stats_UpdateFloat( p_input, "sout_send_bitrate", (float)i_total );
p_access->i_sent_bytes, &i_total );
stats_UpdateFloat( p_input, "sout_send_bitrate", (float)i_total,
NULL );
p_access->i_sent_bytes = 0;
vlc_object_release( p_input );
}
......
......@@ -814,7 +814,7 @@ static void RunThread( vout_thread_t *p_vout)
}
msg_Warn( p_vout, "late picture skipped ("I64Fd")",
current_date - display_date );
stats_UpdateInteger( p_vout, "lost_pictures", 1 );
stats_UpdateInteger( p_vout, "lost_pictures", 1 , NULL);
vlc_mutex_unlock( &p_vout->picture_lock );
continue;
......@@ -837,7 +837,7 @@ static void RunThread( vout_thread_t *p_vout)
p_picture->i_status = DESTROYED_PICTURE;
p_vout->i_heap_size--;
}
stats_UpdateInteger( p_vout, "lost_pictures", 1 );
stats_UpdateInteger( p_vout, "lost_pictures", 1, NULL );
msg_Warn( p_vout, "vout warning: early picture skipped "
"("I64Fd")", display_date - current_date
- p_vout->i_pts_delay );
......@@ -895,7 +895,7 @@ static void RunThread( vout_thread_t *p_vout)
/*
* Perform rendering
*/
stats_UpdateInteger( p_vout, "displayed_pictures", 1 );
stats_UpdateInteger( p_vout, "displayed_pictures", 1, NULL );
p_directbuffer = vout_RenderPicture( p_vout, p_picture, p_subpic );
/*
......
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