]> git.proxmox.com Git - mirror_qemu.git/blobdiff - trace/control.c
Move include qemu/option.h from qemu-common.h to actual users
[mirror_qemu.git] / trace / control.c
index a2313273d8808ef413116be4ab270adf8ab7528d..e40cfca775ee36e45d31319ad672fd829a833769 100644 (file)
@@ -10,6 +10,7 @@
 #include "qemu/osdep.h"
 #include "trace/control.h"
 #include "qemu/help_option.h"
+#include "qemu/option.h"
 #ifdef CONFIG_TRACE_SIMPLE
 #include "trace/simple.h"
 #endif
@@ -26,6 +27,7 @@
 #include "qemu/error-report.h"
 #include "qemu/config-file.h"
 #include "monitor/monitor.h"
+#include "trace-root.h"
 
 int trace_events_enabled_count;
 
@@ -35,6 +37,8 @@ typedef struct TraceEventGroup {
 
 static TraceEventGroup *event_groups;
 static size_t nevent_groups;
+static uint32_t next_id;
+static uint32_t next_vcpu_id;
 
 QemuOptsList qemu_trace_opts = {
     .name = "trace",
@@ -59,6 +63,20 @@ QemuOptsList qemu_trace_opts = {
 
 void trace_event_register_group(TraceEvent **events)
 {
+    size_t i;
+    for (i = 0; events[i] != NULL; i++) {
+        events[i]->id = next_id++;
+        if (events[i]->vcpu_id == TRACE_VCPU_EVENT_NONE) {
+            continue;
+        }
+
+        if (likely(next_vcpu_id < CPU_TRACE_DSTATE_MAX_EVENTS)) {
+            events[i]->vcpu_id = next_vcpu_id++;
+        } else {
+            warn_report("too many vcpu trace events; dropping '%s'",
+                        events[i]->name);
+        }
+    }
     event_groups = g_renew(TraceEventGroup, event_groups, nevent_groups + 1);
     event_groups[nevent_groups].events = events;
     nevent_groups++;
@@ -161,8 +179,8 @@ static void do_trace_enable_events(const char *line_buf)
     while ((ev = trace_event_iter_next(&iter)) != NULL) {
         if (!trace_event_get_state_static(ev)) {
             if (!is_pattern) {
-                error_report("WARNING: trace event '%s' is not traceable",
-                             line_ptr);
+                warn_report("trace event '%s' is not traceable",
+                            line_ptr);
                 return;
             }
             continue;
@@ -176,8 +194,8 @@ static void do_trace_enable_events(const char *line_buf)
     }
 
     if (!is_pattern) {
-        error_report("WARNING: trace event '%s' does not exist",
-                     line_ptr);
+        warn_report("trace event '%s' does not exist",
+                    line_ptr);
     }
 }
 
@@ -250,6 +268,24 @@ void trace_init_file(const char *file)
 #endif
 }
 
+void trace_fini_vcpu(CPUState *vcpu)
+{
+    TraceEventIter iter;
+    TraceEvent *ev;
+
+    trace_guest_cpu_exit(vcpu);
+
+    trace_event_iter_init(&iter, NULL);
+    while ((ev = trace_event_iter_next(&iter)) != NULL) {
+        if (trace_event_is_vcpu(ev) &&
+            trace_event_get_state_static(ev) &&
+            trace_event_get_vcpu_state_dynamic(vcpu, ev)) {
+            /* must disable to affect the global counter */
+            trace_event_set_vcpu_state_dynamic(vcpu, ev, false);
+        }
+    }
+}
+
 bool trace_init_backends(void)
 {
 #ifdef CONFIG_TRACE_SIMPLE
@@ -290,3 +326,8 @@ char *trace_opt_parse(const char *optarg)
 
     return trace_file;
 }
+
+uint32_t trace_get_vcpu_event_count(void)
+{
+    return next_vcpu_id;
+}