blob: 97f21e476d2d7d7d77748669978fe4ca6aa00271 [file] [log] [blame]
Lluís Vilanova48151852016-07-11 12:53:41 +02001/*
2 * Interface for configuring and controlling the state of tracing events.
3 *
Lluís Vilanovaf5956d72017-06-25 14:08:38 +03004 * Copyright (C) 2014-2017 Lluís Vilanova <vilanova@ac.upc.edu>
Lluís Vilanova48151852016-07-11 12:53:41 +02005 *
6 * This work is licensed under the terms of the GNU GPL, version 2 or later.
7 * See the COPYING file in the top-level directory.
8 */
9
10#include "qemu/osdep.h"
Jamie Iles370ed602023-04-27 03:09:24 +010011#include "qemu/lockable.h"
Lluís Vilanova48151852016-07-11 12:53:41 +020012#include "cpu.h"
Paolo Bonzini243af022020-02-04 12:20:10 +010013#include "trace/trace-root.h"
Lluís Vilanova48151852016-07-11 12:53:41 +020014#include "trace/control.h"
Lluís Vilanova48151852016-07-11 12:53:41 +020015
16
Lluís Vilanovaa4d50b12016-08-23 10:58:52 +020017void trace_event_set_state_dynamic_init(TraceEvent *ev, bool state)
18{
Lluís Vilanova8eb1b9d2016-08-23 10:58:58 +020019 bool state_pre;
Lluís Vilanovaa4d50b12016-08-23 10:58:52 +020020 assert(trace_event_get_state_static(ev));
Lluís Vilanova8eb1b9d2016-08-23 10:58:58 +020021 /*
22 * We ignore the "vcpu" property here, since no vCPUs have been created
23 * yet. Then dstate can only be 1 or 0.
24 */
Daniel P. Berrange93977402016-10-04 14:35:45 +010025 state_pre = *ev->dstate;
Lluís Vilanova8eb1b9d2016-08-23 10:58:58 +020026 if (state_pre != state) {
27 if (state) {
28 trace_events_enabled_count++;
Daniel P. Berrange93977402016-10-04 14:35:45 +010029 *ev->dstate = 1;
Lluís Vilanova8eb1b9d2016-08-23 10:58:58 +020030 } else {
31 trace_events_enabled_count--;
Daniel P. Berrange93977402016-10-04 14:35:45 +010032 *ev->dstate = 0;
Lluís Vilanova8eb1b9d2016-08-23 10:58:58 +020033 }
34 }
Lluís Vilanovaa4d50b12016-08-23 10:58:52 +020035}
36
Lluís Vilanova48151852016-07-11 12:53:41 +020037void trace_event_set_state_dynamic(TraceEvent *ev, bool state)
38{
Lluís Vilanova48151852016-07-11 12:53:41 +020039 assert(trace_event_get_state_static(ev));
Lluís Vilanova48151852016-07-11 12:53:41 +020040
Alex Bennée89aafcf2023-05-26 17:53:57 +010041 /*
42 * There is no longer a "vcpu" property, dstate can only be 1 or
43 * 0. With it, we haven't instantiated any vCPU yet, so we will
44 * set a global state instead, and trace_init_vcpu will reconcile
45 * it afterwards.
46 */
47 bool state_pre = *ev->dstate;
Lluís Vilanova48151852016-07-11 12:53:41 +020048 if (state_pre != state) {
49 if (state) {
50 trace_events_enabled_count++;
Alex Bennée89aafcf2023-05-26 17:53:57 +010051 *ev->dstate = 1;
Lluís Vilanova48151852016-07-11 12:53:41 +020052 } else {
53 trace_events_enabled_count--;
Alex Bennée89aafcf2023-05-26 17:53:57 +010054 *ev->dstate = 0;
Lluís Vilanova2bfe11c2016-09-19 14:55:07 +020055 }
56 }
57}