Changeset baacaea316cff470f3fe11e52a833ef4a51afe74

Show
Ignore:
Timestamp:
15/06/06 23:22:35 (2 years ago)
Author:
Clément Stenac <zorglub@videolan.org>
git-committer:
Clément Stenac <zorglub@videolan.org> 1150406555 +0000
git-parent:

[7a6b8a51f8b06684d32ba3a4985230363c32d8b0]

git-author:
Clément Stenac <zorglub@videolan.org> 1150406555 +0000
Message:

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

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • include/main.h

    r86b94ec rbaacaea  
    5757    /* Do stats ? - We keep this boolean to avoid unneeded lookups */ 
    5858    vlc_bool_t             b_stats; 
    59     stats_handler_t       *p_stats; 
     59    vlc_mutex_t            timer_lock; 
     60    int                    i_timers; 
     61    counter_t            **pp_timers; 
    6062 
    6163    /* Arch-specific variables */ 
  • include/vlc_httpd.h

    re611fda rbaacaea  
    7777    int         i_port; 
    7878    int         *fd; 
     79 
     80    /* Statistics */ 
     81    counter_t *p_active_counter; 
     82    counter_t *p_total_counter; 
    7983 
    8084    vlc_mutex_t lock; 
  • include/vlc_input.h

    rc9c85be rbaacaea  
    422422    input_source_t **slave; 
    423423 
     424    /* Stats counters */ 
     425    struct { 
     426        counter_t *p_read_packets; 
     427        counter_t *p_read_bytes; 
     428        counter_t *p_input_bitrate; 
     429        counter_t *p_demux_read; 
     430        counter_t *p_demux_bitrate; 
     431        counter_t *p_decoded_audio; 
     432        counter_t *p_decoded_video; 
     433        counter_t *p_decoded_sub; 
     434        counter_t *p_sout_sent_packets; 
     435        counter_t *p_sout_sent_bytes; 
     436        counter_t *p_sout_send_bitrate; 
     437        counter_t *p_played_abuffers; 
     438        counter_t *p_lost_abuffers; 
     439        counter_t *p_displayed_pictures; 
     440        counter_t *p_lost_pictures; 
     441        vlc_mutex_t counters_lock; 
     442    } counters; 
     443 
    424444    /* Buffer of pending actions */ 
    425445    vlc_mutex_t lock_control; 
  • include/vlc_messages.h

    r8e7484b rbaacaea  
    229229struct counter_t 
    230230{ 
    231     /* The list is *NOT* sorted at the moment, it could be ... */ 
    232     uint64_t            i_index; 
     231    unsigned int        i_id; 
    233232    char              * psz_name; 
    234233    int                 i_type; 
     
    268267}; 
    269268 
    270 struct stats_handler_t 
    271 
    272     VLC_COMMON_MEMBERS 
    273  
    274     int                 i_counters; 
    275     counter_t         **pp_counters; 
    276 }; 
    277  
    278 VLC_EXPORT( void, stats_HandlerDestroy, (stats_handler_t*) ); 
    279  
    280 #define stats_Update(a,b,c,d) __stats_Update( VLC_OBJECT( a ), b, c, d ) 
    281 VLC_EXPORT( int, __stats_Update, (vlc_object_t*, unsigned int, vlc_value_t, vlc_value_t *) ); 
    282 #define stats_Create(a,b,c,d,e) __stats_Create( VLC_OBJECT(a), b, c, d,e ) 
    283 VLC_EXPORT( int, __stats_Create, (vlc_object_t*, const char *, unsigned int, int, int) ); 
    284 #define stats_Get(a,b,c,d) __stats_Get( VLC_OBJECT(a), b, c, d ) 
    285 VLC_EXPORT( int, __stats_Get, (vlc_object_t*, int, unsigned int, vlc_value_t*) ); 
    286 #define stats_CounterGet(a,b,c) __stats_CounterGet( VLC_OBJECT(a), b, c ) 
    287 VLC_EXPORT( counter_t*, __stats_CounterGet, (vlc_object_t*, int, unsigned int ) ); 
    288  
    289 #define stats_GetInteger(a,b,c,d) __stats_GetInteger( VLC_OBJECT(a), b, c, d ) 
    290 static inline int __stats_GetInteger( vlc_object_t *p_obj, int i_id, 
    291                                       unsigned int i_counter, int *value ) 
     269#define stats_Update(a,b,c) __stats_Update( VLC_OBJECT(a), b, c ) 
     270VLC_EXPORT( int, __stats_Update, (vlc_object_t*, counter_t *, vlc_value_t, vlc_value_t *) ); 
     271#define stats_CounterCreate(a,b,c) __stats_CounterCreate( VLC_OBJECT(a), b, c ) 
     272VLC_EXPORT( counter_t *, __stats_CounterCreate, (vlc_object_t*, int, int) ); 
     273#define stats_Get(a,b,c) __stats_Get( VLC_OBJECT(a), b, c) 
     274VLC_EXPORT( int, __stats_Get, (vlc_object_t*, counter_t *, vlc_value_t*) ); 
     275 
     276VLC_EXPORT (void, stats_CounterClean, (counter_t * ) ); 
     277 
     278#define stats_GetInteger(a,b,c) __stats_GetInteger( VLC_OBJECT(a), b, c ) 
     279static inline int __stats_GetInteger( vlc_object_t *p_obj, counter_t *p_counter, 
     280                                      int *value ) 
    292281{ 
    293282    int i_ret; 
    294283    vlc_value_t val; val.i_int = 0; 
    295     i_ret = __stats_Get( p_obj, i_id, i_counter, &val ); 
     284    i_ret = __stats_Get( p_obj, p_counter, &val ); 
    296285    *value = val.i_int; 
    297286    return i_ret; 
    298287} 
    299288 
    300 #define stats_GetFloat(a,b,c,d) __stats_GetFloat( VLC_OBJECT(a), b, c, d
    301 static inline int __stats_GetFloat( vlc_object_t *p_obj, int i_id
    302                                     unsigned int i_counter, float *value ) 
    303 { 
    304    int i_ret; 
     289#define stats_GetFloat(a,b,c) __stats_GetFloat( VLC_OBJECT(a), b, c
     290static inline int __stats_GetFloat( vlc_object_t *p_obj, counter_t *p_counter
     291                                    float *value ) 
     292{ 
     293    int i_ret; 
    305294    vlc_value_t val; val.f_float = 0.0; 
    306     i_ret = __stats_Get( p_obj, i_id, i_counter, &val ); 
     295    i_ret = __stats_Get( p_obj, p_counter, &val ); 
    307296    *value = val.f_float; 
    308297    return i_ret; 
    309298} 
    310299#define stats_UpdateInteger(a,b,c,d) __stats_UpdateInteger( VLC_OBJECT(a),b,c,d ) 
    311 static inline int __stats_UpdateInteger( vlc_object_t *p_obj, 
    312                                          unsigned int i_counter, int i, 
    313                                          int *pi_new ) 
     300static inline int __stats_UpdateInteger( vlc_object_t *p_obj,counter_t *p_co, 
     301                                         int i, int *pi_new ) 
    314302{ 
    315303    int i_ret; 
     
    317305    vlc_value_t new_val; new_val.i_int = 0; 
    318306    val.i_int = i; 
    319     i_ret = __stats_Update( p_obj, i_counter, val , &new_val ); 
     307    i_ret = __stats_Update( p_obj, p_co, val, &new_val ); 
    320308    if( pi_new ) 
    321309        *pi_new = new_val.i_int; 
     
    323311} 
    324312#define stats_UpdateFloat(a,b,c,d) __stats_UpdateFloat( VLC_OBJECT(a),b,c,d ) 
    325 static inline int __stats_UpdateFloat( vlc_object_t *p_obj, 
    326                                        unsigned int i_counter, float f, 
    327                                        float *pf_new ) 
     313static inline int __stats_UpdateFloat( vlc_object_t *p_obj, counter_t *p_co, 
     314                                       float f, float *pf_new ) 
    328315{ 
    329316    vlc_value_t val; 
     
    331318    vlc_value_t new_val;new_val.f_float = 0.0; 
    332319    val.f_float = f; 
    333     i_ret =  __stats_Update( p_obj, i_counter, val, &new_val ); 
     320    i_ret =  __stats_Update( p_obj, p_co, val, &new_val ); 
    334321    if( pf_new ) 
    335322        *pf_new = new_val.f_float; 
     
    414401VLC_EXPORT( void,__stats_TimerDump, (vlc_object_t*, unsigned int) ); 
    415402VLC_EXPORT( void,__stats_TimersDumpAll, (vlc_object_t*) ); 
     403#define stats_TimersClean(a) __stats_TimersClean( VLC_OBJECT(a) ) 
     404VLC_EXPORT( void, __stats_TimersClean, (vlc_object_t * ) ); 
  • include/vlc_symbols.h

    rc9c85be rbaacaea  
    439439    void (*__intf_UserProgressUpdate_inner) (vlc_object_t*, int, const char*, float); 
    440440    void (*__intf_UserHide_inner) (vlc_object_t *, int); 
    441     int (*__stats_Create_inner) (vlc_object_t*, const char *, unsigned int, int, int)
    442     int (*__stats_Update_inner) (vlc_object_t*, unsigned int, vlc_value_t, vlc_value_t *); 
    443     int (*__stats_Get_inner) (vlc_object_t*, int, unsigned int, vlc_value_t*); 
     441    void *__stats_Create_deprecated
     442    int (*__stats_Update_inner) (vlc_object_t*, counter_t *, vlc_value_t, vlc_value_t *); 
     443    int (*__stats_Get_inner) (vlc_object_t*, counter_t *, vlc_value_t*); 
    444444    void (*stats_ComputeInputStats_inner) (input_thread_t*, input_stats_t*); 
    445445    void (*stats_DumpInputStats_inner) (input_stats_t *); 
    446446    void (*stats_ReinitInputStats_inner) (input_stats_t *); 
    447     counter_t* (*__stats_CounterGet_inner) (vlc_object_t*, int, unsigned int); 
    448447    void *__stats_CounterGet_deprecated; 
    449448    input_thread_t * (*__input_CreateThread2_inner) (vlc_object_t *, input_item_t *, char *); 
    450     void (*stats_HandlerDestroy_inner) (stats_handler_t*)
     449    void *stats_HandlerDestroy_deprecated
    451450    vlc_t * (*vlc_current_object_inner) (int); 
    452451    void (*__var_OptionParse_inner) (vlc_object_t *, const char *); 
     
    515514    void (*playlist_NodesCreateForSD_inner) (playlist_t *, char *, playlist_item_t **, playlist_item_t **); 
    516515    vlc_bool_t (*input_AddSubtitles_inner) (input_thread_t *, char *, vlc_bool_t); 
     516    counter_t * (*__stats_CounterCreate_inner) (vlc_object_t*, int, int); 
     517    void *stats_TimerClean_deprecated; 
     518    void *stats_TimersClean_deprecated; 
     519    void (*__stats_TimersClean_inner) (vlc_object_t *); 
    517520}; 
    518521# if defined (__PLUGIN__) 
     
    910913#  define __intf_UserProgressUpdate (p_symbols)->__intf_UserProgressUpdate_inner 
    911914#  define __intf_UserHide (p_symbols)->__intf_UserHide_inner 
    912 #  define __stats_Create (p_symbols)->__stats_Create_inner 
    913915#  define __stats_Update (p_symbols)->__stats_Update_inner 
    914916#  define __stats_Get (p_symbols)->__stats_Get_inner 
     
    916918#  define stats_DumpInputStats (p_symbols)->stats_DumpInputStats_inner 
    917919#  define stats_ReinitInputStats (p_symbols)->stats_ReinitInputStats_inner 
    918 #  define __stats_CounterGet (p_symbols)->__stats_CounterGet_inner 
    919920#  define __input_CreateThread2 (p_symbols)->__input_CreateThread2_inner 
    920 #  define stats_HandlerDestroy (p_symbols)->stats_HandlerDestroy_inner 
    921921#  define vlc_current_object (p_symbols)->vlc_current_object_inner 
    922922#  define __var_OptionParse (p_symbols)->__var_OptionParse_inner 
     
    983983#  define playlist_NodesCreateForSD (p_symbols)->playlist_NodesCreateForSD_inner 
    984984#  define input_AddSubtitles (p_symbols)->input_AddSubtitles_inner 
     985#  define __stats_CounterCreate (p_symbols)->__stats_CounterCreate_inner 
     986#  define __stats_TimersClean (p_symbols)->__stats_TimersClean_inner 
    985987# elif defined (HAVE_DYNAMIC_PLUGINS) && !defined (__BUILTIN__) 
    986988/****************************************************************** 
     
    13811383    ((p_symbols)->__intf_UserProgressUpdate_inner) = __intf_UserProgressUpdate; \ 
    13821384    ((p_symbols)->__intf_UserHide_inner) = __intf_UserHide; \ 
    1383     ((p_symbols)->__stats_Create_inner) = __stats_Create; \ 
    13841385    ((p_symbols)->__stats_Update_inner) = __stats_Update; \ 
    13851386    ((p_symbols)->__stats_Get_inner) = __stats_Get; \ 
     
    13871388    ((p_symbols)->stats_DumpInputStats_inner) = stats_DumpInputStats; \ 
    13881389    ((p_symbols)->stats_ReinitInputStats_inner) = stats_ReinitInputStats; \ 
    1389     ((p_symbols)->__stats_CounterGet_inner) = __stats_CounterGet; \ 
    13901390    ((p_symbols)->__input_CreateThread2_inner) = __input_CreateThread2; \ 
    1391     ((p_symbols)->stats_HandlerDestroy_inner) = stats_HandlerDestroy; \ 
    13921391    ((p_symbols)->vlc_current_object_inner) = vlc_current_object; \ 
    13931392    ((p_symbols)->__var_OptionParse_inner) = __var_OptionParse; \ 
     
    14541453    ((p_symbols)->playlist_NodesCreateForSD_inner) = playlist_NodesCreateForSD; \ 
    14551454    ((p_symbols)->input_AddSubtitles_inner) = input_AddSubtitles; \ 
     1455    ((p_symbols)->__stats_CounterCreate_inner) = __stats_CounterCreate; \ 
     1456    ((p_symbols)->__stats_TimersClean_inner) = __stats_TimersClean; \ 
    14561457    (p_symbols)->net_ConvertIPv4_deprecated = NULL; \ 
    14571458    (p_symbols)->__playlist_ItemCopy_deprecated = NULL; \ 
     
    14801481    (p_symbols)->playlist_Move_deprecated = NULL; \ 
    14811482    (p_symbols)->playlist_NodeRemoveParent_deprecated = NULL; \ 
     1483    (p_symbols)->__stats_Create_deprecated = NULL; \ 
    14821484    (p_symbols)->__stats_CounterGet_deprecated = NULL; \ 
     1485    (p_symbols)->stats_HandlerDestroy_deprecated = NULL; \ 
    14831486    (p_symbols)->__stats_TimerDumpAll_deprecated = NULL; \ 
    14841487    (p_symbols)->playlist_ItemNewFromInput_deprecated = NULL; \ 
     1488    (p_symbols)->stats_TimerClean_deprecated = NULL; \ 
     1489    (p_symbols)->stats_TimersClean_deprecated = NULL; \ 
    14851490 
    14861491# endif /* __PLUGIN__ */ 
  • src/audio_output/dec.c

    r0b44cb9 rbaacaea  
    313313        if( p_input->p_input_thread ) 
    314314        { 
    315             stats_UpdateInteger( p_input->p_input_thread, STATS_LOST_ABUFFERS, 1, 
    316                                  NULL ); 
     315            vlc_mutex_lock( &p_input->p_input_thread->counters.counters_lock); 
     316            stats_UpdateInteger( p_aout, 
     317                           p_input->p_input_thread->counters.p_lost_abuffers, 
     318                           1, NULL ); 
     319            vlc_mutex_unlock( &p_input->p_input_thread->counters.counters_lock); 
    317320        } 
    318321        aout_BufferFree( p_buffer ); 
     
    368371    if( p_input->p_input_thread ) 
    369372    { 
    370         stats_UpdateInteger( p_input->p_input_thread, 
    371                              STATS_PLAYED_ABUFFERS, 1, NULL ); 
     373        vlc_mutex_lock( &p_input->p_input_thread->counters.counters_lock); 
     374        stats_UpdateInteger( p_aout, 
     375                             p_input->p_input_thread->counters.p_lost_abuffers, 
     376                             1, NULL ); 
     377        vlc_mutex_unlock( &p_input->p_input_thread->counters.counters_lock); 
    372378    } 
    373379    vlc_mutex_unlock( &p_aout->mixer_lock ); 
  • src/audio_output/input.c

    r470b47f rbaacaea  
    450450        if( p_input->p_input_thread ) 
    451451        { 
    452             stats_UpdateInteger( p_input->p_input_thread, STATS_LOST_ABUFFERS, 1, 
    453                                  NULL ); 
     452            vlc_mutex_lock( &p_input->p_input_thread->counters.counters_lock); 
     453            stats_UpdateInteger( p_aout, p_input->p_input_thread->counters.p_lost_abuffers, 1, NULL ); 
     454            vlc_mutex_unlock( &p_input->p_input_thread->counters.counters_lock); 
    454455        } 
    455456    } 
     
    463464        if( p_input->p_input_thread ) 
    464465        { 
    465             stats_UpdateInteger( p_input->p_input_thread, STATS_LOST_ABUFFERS, 
    466                                  1, NULL ); 
     466            vlc_mutex_lock( &p_input->p_input_thread->counters.counters_lock); 
     467            stats_UpdateInteger( p_aout, p_input->p_input_thread->counters.p_lost_abuffers, 1, NULL ); 
     468            vlc_mutex_unlock( &p_input->p_input_thread->counters.counters_lock); 
    467469        } 
    468470        aout_BufferFree( p_buffer ); 
     
    505507        if( p_input->p_input_thread ) 
    506508        { 
    507             stats_UpdateInteger( p_input->p_input_thread, STATS_LOST_ABUFFERS, 
    508                                  1, NULL ); 
     509            vlc_mutex_lock( &p_input->p_input_thread->counters.counters_lock); 
     510            stats_UpdateInteger( p_aout, p_input->p_input_thread->counters.p_lost_abuffers, 1, NULL ); 
     511            vlc_mutex_unlock( &p_input->p_input_thread->counters.counters_lock); 
    509512        } 
    510513        return 0; 
  • src/input/decoder.c

    r2ef372c rbaacaea  
    430430    vlc_object_attach( p_dec, p_input ); 
    431431 
    432     stats_Create( p_dec->p_parent, "decoded_audio", STATS_DECODED_AUDIO, 
    433                   VLC_VAR_INTEGER, STATS_COUNTER ); 
    434     stats_Create( p_dec->p_parent, "decoded_video", STATS_DECODED_VIDEO, 
    435                   VLC_VAR_INTEGER, STATS_COUNTER ); 
    436     stats_Create( p_dec->p_parent, "decoded_sub", STATS_DECODED_SUB, 
    437                   VLC_VAR_INTEGER, STATS_COUNTER ); 
    438432    /* Find a suitable decoder/packetizer module */ 
    439433    if( i_object_type == VLC_OBJECT_DECODER ) 
     
    628622                                                       &p_packetized_block )) ) 
    629623                    { 
    630                         stats_UpdateInteger( p_dec->p_parent, 
    631                                              STATS_DECODED_AUDIO, 1, NULL ); 
    632                         /* FIXME the best would be to handle the case start_date < preroll < end_date 
     624                        input_thread_t *p_i =(input_thread_t*)(p_dec->p_parent); 
     625                        vlc_mutex_lock( &p_i->counters.counters_lock ); 
     626                        stats_UpdateInteger( p_dec, 
     627                               p_i->counters.p_decoded_audio, 1, NULL ); 
     628                        vlc_mutex_unlock( &p_i->counters.counters_lock ); 
     629 
     630                        /* FIXME the best would be to handle the case 
     631                         * start_date < preroll < end_date 
    633632                         * but that's not easy with non raw audio stream */ 
    634633                        if( p_dec->p_owner->i_preroll_end > 0 && 
     
    653652        else while( (p_aout_buf = p_dec->pf_decode_audio( p_dec, &p_block )) ) 
    654653        { 
    655             stats_UpdateInteger( p_dec->p_parent, STATS_DECODED_AUDIO, 1, NULL ); 
     654            input_thread_t *p_i = (input_thread_t*)(p_dec->p_parent); 
     655            vlc_mutex_lock( &p_i->counters.counters_lock ); 
     656            stats_UpdateInteger( p_dec, 
     657                               p_i->counters.p_decoded_audio, 1, NULL ); 
     658            vlc_mutex_unlock( &p_i->counters.counters_lock ); 
     659 
    656660            if( p_dec->p_owner->i_preroll_end > 0 && 
    657661                p_aout_buf->start_date < p_dec->p_owner->i_preroll_end ) 
     
    699703                                                       &p_packetized_block )) ) 
    700704                    { 
    701                         stats_UpdateInteger( p_dec->p_parent, STATS_DECODED_VIDEO, 
    702                                                              1, NULL ); 
     705                        input_thread_t *p_i =(input_thread_t*)(p_dec->p_parent); 
     706                        vlc_mutex_lock( &p_i->counters.counters_lock ); 
     707                        stats_UpdateInteger( p_dec, 
     708                               p_i->counters.p_decoded_video, 1, NULL ); 
     709                        vlc_mutex_unlock( &p_i->counters.counters_lock ); 
     710 
    703711                        if( p_dec->p_owner->i_preroll_end > 0 && 
    704712                            p_pic->date < p_dec->p_owner->i_preroll_end ) 
     
    721729        else while( (p_pic = p_dec->pf_decode_video( p_dec, &p_block )) ) 
    722730        { 
    723             stats_UpdateInteger( p_dec->p_parent, STATS_DECODED_VIDEO, 1 , NULL); 
     731            input_thread_t *p_i = (input_thread_t*)(p_dec->p_parent); 
     732            vlc_mutex_lock( &p_i->counters.counters_lock ); 
     733            stats_UpdateInteger( p_dec, 
     734                               p_i->counters.p_decoded_video, 1, NULL ); 
     735            vlc_mutex_unlock( &p_i->counters.counters_lock ); 
     736 
    724737            if( p_dec->p_owner->i_preroll_end > 0 && 
    725738                p_pic->date < p_dec->p_owner->i_preroll_end ) 
     
    741754        while( (p_spu = p_dec->pf_decode_sub( p_dec, &p_block ) ) ) 
    742755        { 
    743             stats_UpdateInteger( p_dec->p_parent, STATS_DECODED_SUB, 1 , NULL); 
     756            input_thread_t *p_i = (input_thread_t*)(p_dec->p_parent); 
     757            vlc_mutex_lock( &p_i->counters.counters_lock ); 
     758            stats_UpdateInteger( p_dec, 
     759                               p_i->counters.p_decoded_sub, 1, NULL ); 
     760            vlc_mutex_unlock( &p_i->counters.counters_lock ); 
     761 
    744762            if( p_dec->p_owner->i_preroll_end > 0 && 
    745763                p_spu->i_start < p_dec->p_owner->i_preroll_end && 
  • src/input/es_out.c

    red0b72e rbaacaea  
    10261026    if( p_input->p_libvlc->b_stats ) 
    10271027    { 
    1028         stats_UpdateInteger( p_input, STATS_DEMUX_READ, p_block->i_buffer, 
    1029                              &i_total ); 
    1030         stats_UpdateFloat( p_input , STATS_DEMUX_BITRATE, (float)i_total, NULL ); 
     1028        vlc_mutex_lock( &p_input->counters.counters_lock ); 
     1029        stats_UpdateInteger( p_input, p_input->counters.p_demux_read, 
     1030                             p_block->i_buffer, &i_total ); 
     1031        stats_UpdateFloat( p_input , p_input->counters.p_demux_bitrate, 
     1032                           (float)i_total, NULL ); 
     1033        vlc_mutex_unlock( &p_input->counters.counters_lock ); 
    10311034    } 
    10321035 
  • src/input/input.c

    r188a9ba rbaacaea  
    680680    { 
    681681        /* Prepare statistics */ 
    682         counter_t *p_counter; 
    683         stats_Create( p_input, "read_bytes", STATS_READ_BYTES, 
    684                       VLC_VAR_INTEGER, STATS_COUNTER ); 
    685         stats_Create( p_input, "read_packets", STATS_READ_PACKETS, 
    686                       VLC_VAR_INTEGER, STATS_COUNTER ); 
    687         stats_Create( p_input, "demux_read", STATS_DEMUX_READ, 
    688                       VLC_VAR_INTEGER, STATS_COUNTER ); 
    689         stats_Create( p_input, "input_bitrate", STATS_INPUT_BITRATE, 
    690                       VLC_VAR_FLOAT, STATS_DERIVATIVE ); 
    691         stats_Create( p_input, "demux_bitrate", STATS_DEMUX_BITRATE, 
    692                       VLC_VAR_FLOAT,  STATS_DERIVATIVE ); 
    693  
    694         p_counter = stats_CounterGet( p_input, p_input->i_object_id, 
    695                                       STATS_INPUT_BITRATE ); 
    696         if( p_counter ) p_counter->update_interval = 1000000; 
    697         p_counter = stats_CounterGet( p_input, p_input->i_object_id, 
    698                                       STATS_DEMUX_BITRATE ); 
    699         if( p_counter ) p_counter->update_interval = 1000000; 
    700  
    701         stats_Create( p_input, "played_abuffers", STATS_PLAYED_ABUFFERS, 
    702                       VLC_VAR_INTEGER, STATS_COUNTER ); 
    703         stats_Create( p_input, "lost_abuffers", STATS_LOST_ABUFFERS, 
    704                       VLC_VAR_INTEGER, STATS_COUNTER ); 
     682#define INIT_COUNTER( p, type, compute ) p_input->counters.p_##p = \ 
     683     stats_CounterCreate( p_input, VLC_VAR_##type, STATS_##compute); 
     684 
     685        INIT_COUNTER( read_bytes, INTEGER, COUNTER ); 
     686        INIT_COUNTER( read_packets, INTEGER, COUNTER ); 
     687        INIT_COUNTER( demux_read, INTEGER, COUNTER ); 
     688        INIT_COUNTER( input_bitrate, FLOAT, DERIVATIVE ); 
     689        INIT_COUNTER( demux_bitrate, FLOAT, DERIVATIVE ); 
     690        INIT_COUNTER( played_abuffers, INTEGER, COUNTER ); 
     691        INIT_COUNTER( lost_abuffers, INTEGER, COUNTER ); 
     692        INIT_COUNTER( displayed_pictures, INTEGER, COUNTER ); 
     693        INIT_COUNTER( lost_pictures, INTEGER, COUNTER ); 
     694        INIT_COUNTER( decoded_audio, INTEGER, COUNTER ); 
     695        INIT_COUNTER( decoded_video, INTEGER, COUNTER ); 
     696        INIT_COUNTER( decoded_sub, INTEGER, COUNTER ); 
     697        p_input->counters.p_sout_send_bitrate = NULL; 
     698        p_input->counters.p_sout_sent_packets = NULL; 
     699        p_input->counters.p_sout_sent_bytes = NULL; 
     700        p_input->counters.p_demux_bitrate->update_interval = 1000000; 
     701        p_input->counters.p_input_bitrate->update_interval = 1000000; 
     702        vlc_mutex_init( p_input, &p_input->counters.counters_lock ); 
    705703 
    706704        /* handle sout */ 
     
    716714                return VLC_EGENERIC; 
    717715            } 
     716            INIT_COUNTER( sout_sent_packets, INTEGER, COUNTER ); 
     717            INIT_COUNTER (sout_sent_bytes, INTEGER, COUNTER ); 
     718            INIT_COUNTER( sout_send_bitrate, FLOAT, DERIVATIVE ); 
     719            p_input->counters.p_sout_send_bitrate->update_interval = 1000000; 
    718720        } 
    719721        free( psz ); 
     
    11061108        input_EsOutDelete( p_input->p_es_out ); 
    11071109 
     1110#define CL_CO( c ) stats_CounterClean( p_input->counters.p_##c ) 
     1111 
     1112        CL_CO( read_bytes ); 
     1113        CL_CO( read_packets ); 
     1114        CL_CO( demux_read ); 
     1115        CL_CO( input_bitrate ); 
     1116        CL_CO( demux_bitrate ); 
     1117        CL_CO( played_abuffers ); 
     1118        CL_CO( lost_abuffers ); 
     1119        CL_CO( displayed_pictures ); 
     1120        CL_CO( lost_pictures ); 
     1121        CL_CO( decoded_audio) ; 
     1122        CL_CO( decoded_video ); 
     1123        CL_CO( decoded_sub) ; 
     1124        CL_CO( read_bytes ); 
     1125 
    11081126    /* Close optional stream output instance */ 
    11091127    if( p_input->p_sout ) 
     
    11121130            vlc_object_find( p_input, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE ); 
    11131131        vlc_value_t keep; 
     1132 
     1133        CL_CO( sout_sent_packets ); 
     1134        CL_CO( sout_sent_bytes ); 
     1135        CL_CO( sout_send_bitrate ); 
    11141136 
    11151137        if( var_Get( p_input, "sout-keep", &keep ) >= 0 && keep.b_bool && p_pl ) 
     
    11291151    } 
    11301152 
     1153#undef CL_CO 
    11311154    /* Tell we're dead */ 
    11321155    p_input->b_dead = VLC_TRUE; 
  • src/input/stream.c

    r8cbf9ec rbaacaea  
    2525#include <vlc/vlc.h> 
    2626#include <vlc/input.h> 
     27#include <assert.h> 
    2728 
    2829#include "input_internal.h" 
     
    15781579    int i_total; 
    15791580 
     1581    input_thread_t *p_input = (input_thread_t *)s->p_parent->p_parent ; 
     1582    assert( p_input ); 
     1583 
    15801584    if( !p_sys->i_list ) 
    15811585    { 
    15821586        i_read = p_access->pf_read( p_access, p_read, i_read ); 
    1583         stats_UpdateInteger( s->p_parent->p_parent , STATS_READ_BYTES, i_read, 
     1587        vlc_mutex_lock( &p_input->counters.counters_lock ); 
     1588        stats_UpdateInteger( s, p_input->counters.p_read_bytes, i_read, 
    15841589                             &i_total ); 
    1585         stats_UpdateFloat( s->p_parent->p_parent , STATS_INPUT_BITRATE
     1590        stats_UpdateFloat( s, p_input->counters.p_input_bitrate
    15861591                           (float)i_total, NULL ); 
    1587         stats_UpdateInteger( s->p_parent->p_parent , STATS_READ_PACKETS, 1, 
    1588                              NULL ); 
     1592        stats_UpdateInteger( s, p_input->counters.p_read_packets, 1, NULL ); 
     1593        vlc_mutex_unlock( &p_input->counters.counters_lock ); 
    15891594        return i_read; 
    15901595    } 
     
    16151620 
    16161621    /* Update read bytes in input */ 
    1617     stats_UpdateInteger( s->p_parent->p_parent ,  STATS_READ_BYTES, i_read, 
    1618                          &i_total ); 
    1619     stats_UpdateFloat( s->p_parent->p_parent ,  STATS_INPUT_BITRATE, 
    1620                       (float)i_total, NULL ); 
    1621     stats_UpdateInteger( s->p_parent->p_parent ,  STATS_READ_PACKETS, 1, NULL ); 
     1622    vlc_mutex_lock( &p_input->counters.counters_lock ); 
     1623    stats_UpdateInteger( s, p_input->counters.p_read_bytes, i_read, &i_total ); 
     1624    stats_UpdateFloat( s, p_input->counters.p_input_bitrate, 
     1625                       (float)i_total, NULL ); 
     1626    stats_UpdateInteger( s, p_input->counters.p_read_packets, 1, NULL ); 
     1627    vlc_mutex_unlock( &p_input->counters.counters_lock ); 
    16221628    return i_read; 
    16231629} 
     
    16311637    int i_total; 
    16321638 
     1639    input_thread_t *p_input = (input_thread_t *)s->p_parent->p_parent ; 
     1640    assert( p_input ); 
     1641 
    16331642    if( !p_sys->i_list ) 
    16341643    { 
     
    16371646        if( p_block && p_access->p_libvlc->b_stats ) 
    16381647        { 
    1639             stats_UpdateInteger( s->p_parent->p_parent,  STATS_READ_BYTES, 
     1648            vlc_mutex_lock( &p_input->counters.counters_lock ); 
     1649            stats_UpdateInteger( s, p_input->counters.p_read_bytes, 
    16401650                                 p_block->i_buffer, &i_total ); 
    1641             stats_UpdateFloat( s->p_parent->p_parent ,  STATS_INPUT_BITRATE
     1651            stats_UpdateFloat( s, p_input->counters.p_input_bitrate
    16421652                              (float)i_total, NULL ); 
    1643             stats_UpdateInteger( s->p_parent->p_parent ,  STATS_READ_PACKETS, 1, NULL ); 
     1653            stats_UpdateInteger( s, p_input->counters.p_read_packets, 1, NULL ); 
     1654            vlc_mutex_unlock( &p_input->counters.counters_lock ); 
    16441655        } 
    16451656        return p_block; 
     
    16721683    if( p_block ) 
    16731684    { 
    1674         stats_UpdateInteger( s->p_parent->p_parent,  STATS_READ_BYTES, 
     1685        vlc_mutex_lock( &p_input->counters.counters_lock ); 
     1686        stats_UpdateInteger( s, p_input->counters.p_read_bytes, 
    16751687                             p_block->i_buffer, &i_total ); 
    1676         stats_UpdateFloat( s->p_parent->p_parent ,  STATS_INPUT_BITRATE
     1688        stats_UpdateFloat( s, p_input->counters.p_input_bitrate
    16771689                          (float)i_total, NULL ); 
    1678         stats_UpdateInteger( s->p_parent->p_parent ,  STATS_READ_PACKETS
     1690        stats_UpdateInteger( s, p_input->counters.p_read_packets
    16791691                             1 , NULL); 
    1680     } 
    1681  
     1692        vlc_mutex_unlock( &p_input->counters.counters_lock ); 
     1693    } 
    16821694    return p_block; 
    16831695} 
  • src/libvlc.c

    r4896c11 rbaacaea  
    687687 
    688688    libvlc.b_stats = config_GetInt( p_vlc, "stats" ); 
    689     libvlc.p_stats = NULL; 
     689    libvlc.i_timers = 0; 
     690    libvlc.pp_timers = NULL; 
     691    vlc_mutex_init( p_vlc, &libvlc.timer_lock ); 
    690692 
    691693    /* 
     
    888890    aout_instance_t    * p_aout; 
    889891    announce_handler_t * p_announce; 
    890     stats_handler_t    * p_stats; 
    891892    vlc_t *p_vlc = vlc_current_object( i_object ); 
    892893 
     
    943944    } 
    944945 
    945     while( ( p_stats = vlc_object_find( p_vlc, VLC_OBJECT_STATS, FIND_CHILD) )) 
    946     { 
    947         stats_TimersDumpAll( p_vlc ); 
    948         stats_HandlerDestroy( p_stats ); 
    949         vlc_object_detach( (vlc_object_t*) p_stats ); 
    950         vlc_object_release( (vlc_object_t *)p_stats ); 
    951         // TODO: Delete it 
    952     } 
     946    stats_TimersDumpAll( p_vlc ); 
     947    stats_TimersClean( p_vlc ); 
    953948 
    954949    /* 
  • src/misc/objects.c

    r8ab353b rbaacaea  
    217217            psz_type = "osd menu"; 
    218218            break; 
    219         case VLC_OBJECT_STATS: 
    220             i_size = sizeof( stats_handler_t ); 
    221             psz_type = "statistics"; 
    222             break; 
    223219        default: 
    224220            i_size = i_type > (int)sizeof(vlc_object_t) 
  • src/misc/stats.c

    re444bfd rbaacaea  
    3333 * Local prototypes 
    3434 *****************************************************************************/ 
    35 static counter_t *GetCounter( stats_handler_t *p_handler, int i_object_id, 
    36                               unsigned int i_counter ); 
    37 static int stats_CounterUpdate( stats_handler_t *p_handler, 
    38                                 counter_t *p_counter, 
    39                                 vlc_value_t val, vlc_value_t * ); 
    40 static stats_handler_t* stats_HandlerCreate( vlc_object_t *p_this ); 
    41 static stats_handler_t *stats_HandlerGet( vlc_object_t *p_this ); 
    42  
     35static int CounterUpdate( vlc_object_t *p_this, 
     36                          counter_t *p_counter, 
     37                          vlc_value_t val, vlc_value_t * ); 
    4338static void TimerDump( vlc_object_t *p_this, counter_t *p_counter, vlc_bool_t); 
    4439 
     
    4843 
    4944/** 
    50  * Cleanup statistics handler stuff 
    51  * \param p_stats the handler to clean 
    52  * \return nothing 
    53  */ 
    54 void stats_HandlerDestroy( stats_handler_t *p_stats ) 
    55 { 
    56     int i; 
    57     for ( i =  p_stats->i_counters - 1 ; i >= 0 ; i-- ) 
    58     { 
    59         int j; 
    60         counter_t *p_counter = p_stats->pp_counters[i]; 
    61  
    62         for( j = p_counter->i_samples -1; j >= 0 ; j-- ) 
    63         { 
    64             counter_sample_t *p_sample = p_counter->pp_samples[j]; 
    65             REMOVE_ELEM( p_counter->pp_samples, p_counter->i_samples, j ); 
    66             free( p_sample ); 
    67         } 
    68         free( p_counter->psz_name ); 
    69         REMOVE_ELEM( p_stats->pp_counters, p_stats->i_counters, i ); 
    70         free( p_counter ); 
    71     } 
    72 } 
    73  
    74 /** 
    7545 * Create a statistics counter 
    76  * \param p_this the object for which to create the counter 
    77  * \param psz_name the name 
     46 * \param p_this a VLC object 
    7847 * \param i_type the type of stored data. One of VLC_VAR_STRING, 
    7948 * VLC_VAR_INTEGER, VLC_VAR_FLOAT 
     
    8352 * (keep a time derivative of the value) 
    8453 */ 
    85 int __stats_Create( vlc_object_t *p_this, const char *psz_name, unsigned int i_id
    86                     int i_type, int i_compute_type ) 
     54counter_t * __stats_CounterCreate( vlc_object_t *p_this
     55                                   int i_type, int i_compute_type ) 
    8756{ 
    8857    counter_t *p_counter; 
    89     stats_handler_t *p_handler; 
    90  
    91     if( !p_this->p_libvlc->b_stats ) return VLC_EGENERIC; 
    92  
    93     p_handler = stats_HandlerGet( p_this ); 
    94     if( !p_handler ) return VLC_ENOMEM; 
    95  
    96     vlc_mutex_lock( &p_handler->object_lock ); 
     58    if( !p_this->p_libvlc->b_stats ) return NULL; 
    9759 
    9860    p_counter = (counter_t*) malloc( sizeof( counter_t ) ) ; 
    9961 
    100     p_counter->psz_name = strdup( psz_name ); 
    101     p_counter->i_index = ((uint64_t)p_this->i_object_id << 32 ) + i_id; 
    10262    p_counter->i_compute_type = i_compute_type; 
    10363    p_counter->i_type = i_type; 
    10464    p_counter->i_samples = 0; 
    10565    p_counter->pp_samples = NULL; 
     66    p_counter->psz_name = NULL; 
    10667 
    10768    p_counter->update_interval = 0; 
    10869    p_counter->last_update = 0; 
    10970 
    110     INSERT_ELEM( p_handler->pp_counters, p_handler->i_counters, 
    111                  p_handler->i_counters, p_counter ); 
    112  
    113     vlc_mutex_unlock( &p_handler->object_lock ); 
    114     vlc_object_release( p_handler ); 
    115  
    116     return VLC_SUCCESS; 
     71    return p_counter; 
    11772} 
    11873 
    11974/** Update a counter element with new values 
    120  * \param p_this the object in which to update 
    121  * \param psz_name the nam
     75 * \param p_this a VLC object 
     76 * \param p_counter the counter to updat
    12277 * \param val the vlc_value union containing the new value to aggregate. For 
    12378 * more information on how data is aggregated, \see __stats_Create 
     79 * \param val_new a pointer that will be filled with new data 
    12480 */ 
    125 int __stats_Update( vlc_object_t *p_this, unsigned int i_counter, 
     81int __stats_Update( vlc_object_t *p_this, counter_t *p_counter, 
    12682                    vlc_value_t val, vlc_value_t *val_new ) 
    12783{ 
    128     int i_ret; 
    129     counter_t *p_counter; 
    130     stats_handler_t *p_handler; 
    131  
    13284    if( !p_this->p_libvlc->b_stats ) return VLC_EGENERIC; 
    133  
    134     /* Get stats handler singleton */ 
    135     p_handler = stats_HandlerGet( p_this ); 
    136     if( !p_handler ) return VLC_ENOMEM; 
    137  
    138     vlc_mutex_lock( &p_handler->object_lock ); 
    139     /* Look for existing element */ 
    140     p_counter = GetCounter( p_handler, p_this->i_object_id, i_counter ); 
    141     if( !p_counter ) 
    142     { 
    143         vlc_mutex_unlock( &p_handler->object_lock ); 
    144         vlc_object_release( p_handler ); 
    145         return VLC_ENOOBJ; 
    146     } 
    147  
    148     i_ret = stats_CounterUpdate( p_handler, p_counter, val, val_new ); 
    149     vlc_mutex_unlock( &p_handler->object_lock ); 
    150     vlc_object_release( p_handler ); 
    151  
    152     return i_ret; 
     85    return CounterUpdate( p_this, p_counter, val, val_new ); 
    15386} 
    15487 
    15588/** Get the aggregated value for a counter 
    15689 * \param p_this an object 
    157  * \param i_object_id the object id from which we want the data 
    158  * \param psz_name the name of the couner 
     90 * \param p_counter the counter 
    15991 * \param val a pointer to an initialized vlc_value union. It will contain the 
    16092 * retrieved value 
    16193 * \return an error code 
    16294 */ 
    163 int __stats_Get( vlc_object_t *p_this, int i_object_id, 
    164                  unsigned int i_counter, vlc_value_t *val ) 
    165 
    166     counter_t *p_counter; 
    167     stats_handler_t *p_handler; 
    168  
     95int __stats_Get( vlc_object_t *p_this, counter_t *p_counter, vlc_value_t *val ) 
     96
    16997    if( !p_this->p_libvlc->b_stats ) return VLC_EGENERIC; 
    17098 
    171     /* Get stats handler singleton */ 
    172     p_handler = stats_HandlerGet( p_this ); 
    173     if( !p_handler ) return VLC_ENOMEM; 
    174     vlc_mutex_lock( &p_handler->object_lock ); 
    175  
    176     /* Look for existing element */ 
    177     p_counter = GetCounter( p_handler, i_object_id, i_counter ); 
    178     if( !p_counter ) 
    179     { 
    180         vlc_mutex_unlock( &p_handler->object_lock ); 
    181         vlc_object_release( p_handler ); 
    182         val->i_int = val->f_float = 0.0; 
    183         return VLC_ENOOBJ; 
    184     } 
    185  
    18699    if( p_counter->i_samples == 0 ) 
    187100    { 
    188         vlc_mutex_unlock( &p_handler->object_lock );