Selaa lähdekoodia

trace: count number of enabled events

This lets trace_event_get_state_dynamic quickly return false.  Right
now there is hardly any benefit because there are also many assertions
and indirections, but the next patch will streamline all of this.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Paolo Bonzini 9 vuotta sitten
vanhempi
commit
43b48cfc3e
2 muutettua tiedostoa jossa 5 lisäystä ja 1 poistoa
  1. 3 1
      trace/control-internal.h
  2. 2 0
      trace/control.c

+ 3 - 1
trace/control-internal.h

@@ -14,6 +14,7 @@
 
 
 
 
 extern TraceEvent trace_events[];
 extern TraceEvent trace_events[];
+extern int trace_events_enabled_count;
 
 
 
 
 static inline TraceEventID trace_event_count(void)
 static inline TraceEventID trace_event_count(void)
@@ -54,13 +55,14 @@ static inline bool trace_event_get_state_static(TraceEvent *ev)
 static inline bool trace_event_get_state_dynamic(TraceEvent *ev)
 static inline bool trace_event_get_state_dynamic(TraceEvent *ev)
 {
 {
     assert(ev != NULL);
     assert(ev != NULL);
-    return ev->dstate;
+    return unlikely(trace_events_enabled_count) && ev->dstate;
 }
 }
 
 
 static inline void trace_event_set_state_dynamic(TraceEvent *ev, bool state)
 static inline void trace_event_set_state_dynamic(TraceEvent *ev, bool state)
 {
 {
     assert(ev != NULL);
     assert(ev != NULL);
     assert(trace_event_get_state_static(ev));
     assert(trace_event_get_state_static(ev));
+    trace_events_enabled_count += state - ev->dstate;
     ev->dstate = state;
     ev->dstate = state;
 }
 }
 
 

+ 2 - 0
trace/control.c

@@ -16,6 +16,8 @@
 #endif
 #endif
 #include "qemu/error-report.h"
 #include "qemu/error-report.h"
 
 
+int trace_events_enabled_count;
+
 TraceEvent *trace_event_name(const char *name)
 TraceEvent *trace_event_name(const char *name)
 {
 {
     assert(name != NULL);
     assert(name != NULL);