Lluís Vilanova | b1bae81 | 2013-03-05 14:47:38 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Interface for configuring and controlling the state of tracing events. |
| 3 | * |
Lluís Vilanova | 17f7ac7 | 2016-07-11 12:53:24 +0200 | [diff] [blame] | 4 | * Copyright (C) 2011-2016 Lluís Vilanova <vilanova@ac.upc.edu> |
Lluís Vilanova | b1bae81 | 2013-03-05 14:47:38 +0100 | [diff] [blame] | 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 | |
Lluís Vilanova | 4815185 | 2016-07-11 12:53:41 +0200 | [diff] [blame] | 13 | #include <stddef.h> /* size_t */ |
| 14 | |
| 15 | #include "qom/cpu.h" |
| 16 | |
| 17 | |
Paolo Bonzini | 43b48cf | 2015-10-28 07:06:26 +0100 | [diff] [blame] | 18 | extern int trace_events_enabled_count; |
Lluís Vilanova | b1bae81 | 2013-03-05 14:47:38 +0100 | [diff] [blame] | 19 | |
| 20 | |
Lluís Vilanova | b1bae81 | 2013-03-05 14:47:38 +0100 | [diff] [blame] | 21 | static inline bool trace_event_is_pattern(const char *str) |
| 22 | { |
| 23 | assert(str != NULL); |
| 24 | return strchr(str, '*') != NULL; |
| 25 | } |
| 26 | |
Daniel P. Berrange | ef4c9fc | 2016-10-04 14:35:49 +0100 | [diff] [blame] | 27 | static inline uint32_t trace_event_get_id(TraceEvent *ev) |
Lluís Vilanova | b1bae81 | 2013-03-05 14:47:38 +0100 | [diff] [blame] | 28 | { |
| 29 | assert(ev != NULL); |
| 30 | return ev->id; |
| 31 | } |
| 32 | |
Daniel P. Berrange | ef4c9fc | 2016-10-04 14:35:49 +0100 | [diff] [blame] | 33 | static inline uint32_t trace_event_get_vcpu_id(TraceEvent *ev) |
Lluís Vilanova | 17f7ac7 | 2016-07-11 12:53:24 +0200 | [diff] [blame] | 34 | { |
| 35 | return ev->vcpu_id; |
| 36 | } |
| 37 | |
| 38 | static inline bool trace_event_is_vcpu(TraceEvent *ev) |
| 39 | { |
Daniel P. Berrange | ef4c9fc | 2016-10-04 14:35:49 +0100 | [diff] [blame] | 40 | return ev->vcpu_id != TRACE_VCPU_EVENT_NONE; |
Lluís Vilanova | 17f7ac7 | 2016-07-11 12:53:24 +0200 | [diff] [blame] | 41 | } |
| 42 | |
Lluís Vilanova | b1bae81 | 2013-03-05 14:47:38 +0100 | [diff] [blame] | 43 | static inline const char * trace_event_get_name(TraceEvent *ev) |
| 44 | { |
| 45 | assert(ev != NULL); |
| 46 | return ev->name; |
| 47 | } |
| 48 | |
| 49 | static inline bool trace_event_get_state_static(TraceEvent *ev) |
| 50 | { |
| 51 | assert(ev != NULL); |
| 52 | return ev->sstate; |
| 53 | } |
| 54 | |
Daniel P. Berrange | 9397740 | 2016-10-04 14:35:45 +0100 | [diff] [blame] | 55 | /* it's on fast path, avoid consistency checks (asserts) */ |
| 56 | #define trace_event_get_state_dynamic_by_id(id) \ |
| 57 | (unlikely(trace_events_enabled_count) && _ ## id ## _DSTATE) |
Paolo Bonzini | 585ec72 | 2015-10-28 07:06:27 +0100 | [diff] [blame] | 58 | |
Lluís Vilanova | b1bae81 | 2013-03-05 14:47:38 +0100 | [diff] [blame] | 59 | static inline bool trace_event_get_state_dynamic(TraceEvent *ev) |
| 60 | { |
Daniel P. Berrange | 9397740 | 2016-10-04 14:35:45 +0100 | [diff] [blame] | 61 | return unlikely(trace_events_enabled_count) && *ev->dstate; |
Lluís Vilanova | b1bae81 | 2013-03-05 14:47:38 +0100 | [diff] [blame] | 62 | } |
| 63 | |
Daniel P. Berrange | ef4c9fc | 2016-10-04 14:35:49 +0100 | [diff] [blame] | 64 | static inline bool |
| 65 | trace_event_get_vcpu_state_dynamic_by_vcpu_id(CPUState *vcpu, |
| 66 | uint32_t vcpu_id) |
Lluís Vilanova | b1bae81 | 2013-03-05 14:47:38 +0100 | [diff] [blame] | 67 | { |
Lluís Vilanova | 4815185 | 2016-07-11 12:53:41 +0200 | [diff] [blame] | 68 | /* it's on fast path, avoid consistency checks (asserts) */ |
| 69 | if (unlikely(trace_events_enabled_count)) { |
Daniel P. Berrange | ef4c9fc | 2016-10-04 14:35:49 +0100 | [diff] [blame] | 70 | return test_bit(vcpu_id, vcpu->trace_dstate); |
Lluís Vilanova | 4815185 | 2016-07-11 12:53:41 +0200 | [diff] [blame] | 71 | } else { |
| 72 | return false; |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | static inline bool trace_event_get_vcpu_state_dynamic(CPUState *vcpu, |
| 77 | TraceEvent *ev) |
| 78 | { |
Daniel P. Berrange | ef4c9fc | 2016-10-04 14:35:49 +0100 | [diff] [blame] | 79 | uint32_t vcpu_id; |
Lluís Vilanova | 4815185 | 2016-07-11 12:53:41 +0200 | [diff] [blame] | 80 | assert(trace_event_is_vcpu(ev)); |
Daniel P. Berrange | ef4c9fc | 2016-10-04 14:35:49 +0100 | [diff] [blame] | 81 | vcpu_id = trace_event_get_vcpu_id(ev); |
| 82 | return trace_event_get_vcpu_state_dynamic_by_vcpu_id(vcpu, vcpu_id); |
Lluís Vilanova | b1bae81 | 2013-03-05 14:47:38 +0100 | [diff] [blame] | 83 | } |
| 84 | |
Daniel P. Berrange | fe4db84 | 2016-10-04 14:35:52 +0100 | [diff] [blame^] | 85 | |
| 86 | void trace_event_register_group(TraceEvent **events); |
| 87 | |
Markus Armbruster | 175de52 | 2016-06-29 15:29:06 +0200 | [diff] [blame] | 88 | #endif /* TRACE__CONTROL_INTERNAL_H */ |