]> git.proxmox.com Git - mirror_qemu.git/blame - trace/control-internal.h
qcow2: Inform block layer about discard boundaries
[mirror_qemu.git] / trace / control-internal.h
CommitLineData
b1bae816
LV
1/*
2 * Interface for configuring and controlling the state of tracing events.
3 *
17f7ac75 4 * Copyright (C) 2011-2016 Lluís Vilanova <vilanova@ac.upc.edu>
b1bae816
LV
5 *
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#ifndef TRACE__CONTROL_INTERNAL_H
11#define TRACE__CONTROL_INTERNAL_H
12
48151859
LV
13#include <stddef.h> /* size_t */
14
15#include "qom/cpu.h"
16
17
b1bae816 18extern TraceEvent trace_events[];
48151859 19extern uint16_t trace_events_dstate[];
43b48cfc 20extern int trace_events_enabled_count;
b1bae816
LV
21
22
84f3fe1b 23static inline TraceEventID trace_event_count(void)
b1bae816 24{
84f3fe1b 25 return TRACE_EVENT_COUNT;
b1bae816
LV
26}
27
84f3fe1b 28static inline TraceEvent *trace_event_id(TraceEventID id)
b1bae816 29{
84f3fe1b
PM
30 assert(id < trace_event_count());
31 return &trace_events[id];
b1bae816
LV
32}
33
34static inline bool trace_event_is_pattern(const char *str)
35{
36 assert(str != NULL);
37 return strchr(str, '*') != NULL;
38}
39
40static inline TraceEventID trace_event_get_id(TraceEvent *ev)
41{
42 assert(ev != NULL);
43 return ev->id;
44}
45
17f7ac75
LV
46static inline TraceEventVCPUID trace_event_get_vcpu_id(TraceEvent *ev)
47{
48 return ev->vcpu_id;
49}
50
51static inline bool trace_event_is_vcpu(TraceEvent *ev)
52{
53 return ev->vcpu_id != TRACE_VCPU_EVENT_COUNT;
54}
55
b1bae816
LV
56static inline const char * trace_event_get_name(TraceEvent *ev)
57{
58 assert(ev != NULL);
59 return ev->name;
60}
61
62static inline bool trace_event_get_state_static(TraceEvent *ev)
63{
64 assert(ev != NULL);
65 return ev->sstate;
66}
67
e1d6e0a4 68static inline bool trace_event_get_state_dynamic_by_id(TraceEventID id)
585ec727 69{
e1d6e0a4 70 /* it's on fast path, avoid consistency checks (asserts) */
585ec727
PB
71 return unlikely(trace_events_enabled_count) && trace_events_dstate[id];
72}
73
b1bae816
LV
74static inline bool trace_event_get_state_dynamic(TraceEvent *ev)
75{
e1d6e0a4
LV
76 TraceEventID id;
77 assert(trace_event_get_state_static(ev));
78 id = trace_event_get_id(ev);
585ec727 79 return trace_event_get_state_dynamic_by_id(id);
b1bae816
LV
80}
81
48151859
LV
82static inline bool trace_event_get_vcpu_state_dynamic_by_vcpu_id(CPUState *vcpu,
83 TraceEventVCPUID id)
b1bae816 84{
48151859
LV
85 /* it's on fast path, avoid consistency checks (asserts) */
86 if (unlikely(trace_events_enabled_count)) {
87 return test_bit(id, vcpu->trace_dstate);
88 } else {
89 return false;
90 }
91}
92
93static inline bool trace_event_get_vcpu_state_dynamic(CPUState *vcpu,
94 TraceEvent *ev)
95{
96 TraceEventVCPUID id;
97 assert(trace_event_is_vcpu(ev));
98 id = trace_event_get_vcpu_id(ev);
99 return trace_event_get_vcpu_state_dynamic_by_vcpu_id(vcpu, id);
b1bae816
LV
100}
101
175de524 102#endif /* TRACE__CONTROL_INTERNAL_H */