[vlc-devel] commit: stats: Support per object timer. (and implement stats_TimerClean()) . (Pierre d'Herbemont )

git version control git at videolan.org
Tue Apr 15 19:39:59 CEST 2008


vlc | branch: master | Pierre d'Herbemont <pdherbemont at videolan.org> | Tue Apr 15 19:29:31 2008 +0200| [d52644844b16b544109bc95add4e0b213c01d909]

stats: Support per object timer. (and implement stats_TimerClean()).

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=d52644844b16b544109bc95add4e0b213c01d909
---

 include/vlc_messages.h |    8 ++++++--
 src/libvlc-common.c    |    2 +-
 src/misc/stats.c       |   32 +++++++++++++++++++++++++++-----
 3 files changed, 34 insertions(+), 8 deletions(-)

diff --git a/include/vlc_messages.h b/include/vlc_messages.h
index 64655d0..aa83521 100644
--- a/include/vlc_messages.h
+++ b/include/vlc_messages.h
@@ -195,6 +195,7 @@ struct counter_t
     unsigned int        i_id;
     char              * psz_name;
     int                 i_type;
+    void              * p_obj;
     int                 i_compute_type;
     int                 i_samples;
     counter_sample_t ** pp_samples;
@@ -370,7 +371,10 @@ 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 * ) );
+#define stats_TimersCleanAll(a) __stats_TimersCleanAll( VLC_OBJECT(a) )
+VLC_EXPORT( void, __stats_TimersCleanAll, (vlc_object_t * ) );
+
+#define stats_TimerClean(a,b) __stats_TimerClean( VLC_OBJECT(a), b )
+VLC_EXPORT( void, __stats_TimerClean, (vlc_object_t *, int ) );
 
 #endif
diff --git a/src/libvlc-common.c b/src/libvlc-common.c
index 96099a7..85b94e9 100644
--- a/src/libvlc-common.c
+++ b/src/libvlc-common.c
@@ -988,7 +988,7 @@ int libvlc_InternalCleanup( libvlc_int_t *p_libvlc )
     vlc_object_release( p_libvlc->p_interaction );
 
     stats_TimersDumpAll( p_libvlc );
-    stats_TimersClean( p_libvlc );
+    stats_TimersCleanAll( p_libvlc );
 
     /* Free announce handler(s?) */
     while( (p_announce = vlc_object_find( p_libvlc, VLC_OBJECT_ANNOUNCE,
diff --git a/src/misc/stats.c b/src/misc/stats.c
index 71e5c4b..7e967f9 100644
--- a/src/misc/stats.c
+++ b/src/misc/stats.c
@@ -142,6 +142,7 @@ int __stats_Get( vlc_object_t *p_this, counter_t *p_counter, vlc_value_t *val )
 
 input_stats_t *stats_NewInputStats( input_thread_t *p_input )
 {
+    (void)p_input;
     input_stats_t *p_stats = malloc( sizeof(input_stats_t) );
 
     if( !p_stats )
@@ -286,7 +287,8 @@ void __stats_TimerStart( vlc_object_t *p_obj, const char *psz_name,
 
     for( i = 0 ; i < p_obj->p_libvlc->i_timers; i++ )
     {
-        if( p_obj->p_libvlc->pp_timers[i]->i_id == i_id )
+        if( p_obj->p_libvlc->pp_timers[i]->i_id == i_id
+            && p_obj->p_libvlc->pp_timers[i]->p_obj == p_obj )
         {
             p_counter = p_obj->p_libvlc->pp_timers[i];
             break;
@@ -304,6 +306,7 @@ void __stats_TimerStart( vlc_object_t *p_obj, const char *psz_name,
         }
         p_counter->psz_name = strdup( psz_name );
         p_counter->i_id = i_id;
+        p_counter->p_obj = p_obj;
         INSERT_ELEM( p_obj->p_libvlc->pp_timers, p_obj->p_libvlc->i_timers,
                      p_obj->p_libvlc->i_timers, p_counter );
 
@@ -320,7 +323,7 @@ void __stats_TimerStart( vlc_object_t *p_obj, const char *psz_name,
     }
     if( p_counter->pp_samples[0]->value.b_bool == true )
     {
-        msg_Warn( p_obj, "timer %s was already started !", psz_name );
+        msg_Warn( p_obj, "timer '%s' was already started !", psz_name );
         vlc_mutex_unlock( &p_obj->p_libvlc->timer_lock );
         return;
     }
@@ -337,7 +340,8 @@ void __stats_TimerStop( vlc_object_t *p_obj, unsigned int i_id )
     vlc_mutex_lock( &p_obj->p_libvlc->timer_lock );
     for( i = 0 ; i < p_obj->p_libvlc->i_timers; i++ )
     {
-        if( p_obj->p_libvlc->pp_timers[i]->i_id == i_id )
+        if( p_obj->p_libvlc->pp_timers[i]->i_id == i_id
+            && p_obj->p_libvlc->pp_timers[i]->p_obj == p_obj )
         {
             p_counter = p_obj->p_libvlc->pp_timers[i];
             break;
@@ -364,7 +368,8 @@ void __stats_TimerDump( vlc_object_t *p_obj, unsigned int i_id )
     vlc_mutex_lock( &p_obj->p_libvlc->timer_lock );
     for( i = 0 ; i < p_obj->p_libvlc->i_timers; i++ )
     {
-        if( p_obj->p_libvlc->pp_timers[i]->i_id == i_id )
+        if( p_obj->p_libvlc->pp_timers[i]->i_id == i_id
+            && p_obj->p_libvlc->pp_timers[i]->p_obj == p_obj )
         {
             p_counter = p_obj->p_libvlc->pp_timers[i];
             break;
@@ -384,7 +389,24 @@ void __stats_TimersDumpAll( vlc_object_t *p_obj )
     vlc_mutex_unlock( &p_obj->p_libvlc->timer_lock );
 }
 
-void __stats_TimersClean( vlc_object_t *p_obj )
+void __stats_TimerClean( vlc_object_t *p_obj, int i_id )
+{
+    int i;
+    vlc_mutex_lock( &p_obj->p_libvlc->timer_lock );
+    for ( i = p_obj->p_libvlc->i_timers -1 ; i >= 0; i-- )
+    {
+        counter_t *p_counter = p_obj->p_libvlc->pp_timers[i];
+        if( p_counter->i_id == i_id && p_counter->p_obj == p_obj )
+        {
+            REMOVE_ELEM( p_obj->p_libvlc->pp_timers,
+                         p_obj->p_libvlc->i_timers, i );
+            stats_CounterClean( p_counter );
+        }
+    }
+    vlc_mutex_unlock( &p_obj->p_libvlc->timer_lock );
+}
+
+void __stats_TimersCleanAll( vlc_object_t *p_obj )
 {
     int i;
     vlc_mutex_lock( &p_obj->p_libvlc->timer_lock );




More information about the vlc-devel mailing list