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 | b1bae81 | 2013-03-05 14:47:38 +0100 | [diff] [blame] | 13 | extern TraceEvent trace_events[]; |
Paolo Bonzini | 585ec72 | 2015-10-28 07:06:27 +0100 | [diff] [blame] | 14 | extern bool trace_events_dstate[]; |
Paolo Bonzini | 43b48cf | 2015-10-28 07:06:26 +0100 | [diff] [blame] | 15 | extern int trace_events_enabled_count; |
Lluís Vilanova | b1bae81 | 2013-03-05 14:47:38 +0100 | [diff] [blame] | 16 | |
| 17 | |
Peter Maydell | 84f3fe1 | 2014-02-20 19:44:25 +0000 | [diff] [blame] | 18 | static inline TraceEventID trace_event_count(void) |
| 19 | { |
| 20 | return TRACE_EVENT_COUNT; |
| 21 | } |
| 22 | |
Lluís Vilanova | b1bae81 | 2013-03-05 14:47:38 +0100 | [diff] [blame] | 23 | static inline TraceEvent *trace_event_id(TraceEventID id) |
| 24 | { |
| 25 | assert(id < trace_event_count()); |
| 26 | return &trace_events[id]; |
| 27 | } |
| 28 | |
Lluís Vilanova | b1bae81 | 2013-03-05 14:47:38 +0100 | [diff] [blame] | 29 | static inline bool trace_event_is_pattern(const char *str) |
| 30 | { |
| 31 | assert(str != NULL); |
| 32 | return strchr(str, '*') != NULL; |
| 33 | } |
| 34 | |
| 35 | static inline TraceEventID trace_event_get_id(TraceEvent *ev) |
| 36 | { |
| 37 | assert(ev != NULL); |
| 38 | return ev->id; |
| 39 | } |
| 40 | |
Lluís Vilanova | 17f7ac7 | 2016-07-11 12:53:24 +0200 | [diff] [blame^] | 41 | static inline TraceEventVCPUID trace_event_get_vcpu_id(TraceEvent *ev) |
| 42 | { |
| 43 | return ev->vcpu_id; |
| 44 | } |
| 45 | |
| 46 | static inline bool trace_event_is_vcpu(TraceEvent *ev) |
| 47 | { |
| 48 | return ev->vcpu_id != TRACE_VCPU_EVENT_COUNT; |
| 49 | } |
| 50 | |
Lluís Vilanova | b1bae81 | 2013-03-05 14:47:38 +0100 | [diff] [blame] | 51 | static inline const char * trace_event_get_name(TraceEvent *ev) |
| 52 | { |
| 53 | assert(ev != NULL); |
| 54 | return ev->name; |
| 55 | } |
| 56 | |
| 57 | static inline bool trace_event_get_state_static(TraceEvent *ev) |
| 58 | { |
| 59 | assert(ev != NULL); |
| 60 | return ev->sstate; |
| 61 | } |
| 62 | |
Paolo Bonzini | 585ec72 | 2015-10-28 07:06:27 +0100 | [diff] [blame] | 63 | static inline bool trace_event_get_state_dynamic_by_id(int id) |
| 64 | { |
| 65 | return unlikely(trace_events_enabled_count) && trace_events_dstate[id]; |
| 66 | } |
| 67 | |
Lluís Vilanova | b1bae81 | 2013-03-05 14:47:38 +0100 | [diff] [blame] | 68 | static inline bool trace_event_get_state_dynamic(TraceEvent *ev) |
| 69 | { |
Paolo Bonzini | 585ec72 | 2015-10-28 07:06:27 +0100 | [diff] [blame] | 70 | int id = trace_event_get_id(ev); |
| 71 | return trace_event_get_state_dynamic_by_id(id); |
Lluís Vilanova | b1bae81 | 2013-03-05 14:47:38 +0100 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | static inline void trace_event_set_state_dynamic(TraceEvent *ev, bool state) |
| 75 | { |
Paolo Bonzini | 585ec72 | 2015-10-28 07:06:27 +0100 | [diff] [blame] | 76 | int id = trace_event_get_id(ev); |
Lluís Vilanova | b1bae81 | 2013-03-05 14:47:38 +0100 | [diff] [blame] | 77 | assert(ev != NULL); |
| 78 | assert(trace_event_get_state_static(ev)); |
Paolo Bonzini | 585ec72 | 2015-10-28 07:06:27 +0100 | [diff] [blame] | 79 | trace_events_enabled_count += state - trace_events_dstate[id]; |
| 80 | trace_events_dstate[id] = state; |
Lluís Vilanova | b1bae81 | 2013-03-05 14:47:38 +0100 | [diff] [blame] | 81 | } |
| 82 | |
Markus Armbruster | 175de52 | 2016-06-29 15:29:06 +0200 | [diff] [blame] | 83 | #endif /* TRACE__CONTROL_INTERNAL_H */ |