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 | 5b80827 | 2014-05-27 15:02:14 +0200 | [diff] [blame] | 4 | * Copyright (C) 2011-2014 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 | |
| 13 | #include <string.h> |
| 14 | |
| 15 | |
| 16 | extern TraceEvent trace_events[]; |
Paolo Bonzini | 43b48cf | 2015-10-28 07:06:26 +0100 | [diff] [blame^] | 17 | extern int trace_events_enabled_count; |
Lluís Vilanova | b1bae81 | 2013-03-05 14:47:38 +0100 | [diff] [blame] | 18 | |
| 19 | |
Peter Maydell | 84f3fe1 | 2014-02-20 19:44:25 +0000 | [diff] [blame] | 20 | static inline TraceEventID trace_event_count(void) |
| 21 | { |
| 22 | return TRACE_EVENT_COUNT; |
| 23 | } |
| 24 | |
Lluís Vilanova | b1bae81 | 2013-03-05 14:47:38 +0100 | [diff] [blame] | 25 | static inline TraceEvent *trace_event_id(TraceEventID id) |
| 26 | { |
| 27 | assert(id < trace_event_count()); |
| 28 | return &trace_events[id]; |
| 29 | } |
| 30 | |
Lluís Vilanova | b1bae81 | 2013-03-05 14:47:38 +0100 | [diff] [blame] | 31 | static inline bool trace_event_is_pattern(const char *str) |
| 32 | { |
| 33 | assert(str != NULL); |
| 34 | return strchr(str, '*') != NULL; |
| 35 | } |
| 36 | |
| 37 | static inline TraceEventID trace_event_get_id(TraceEvent *ev) |
| 38 | { |
| 39 | assert(ev != NULL); |
| 40 | return ev->id; |
| 41 | } |
| 42 | |
| 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 | |
| 55 | static inline bool trace_event_get_state_dynamic(TraceEvent *ev) |
| 56 | { |
| 57 | assert(ev != NULL); |
Paolo Bonzini | 43b48cf | 2015-10-28 07:06:26 +0100 | [diff] [blame^] | 58 | return unlikely(trace_events_enabled_count) && ev->dstate; |
Lluís Vilanova | b1bae81 | 2013-03-05 14:47:38 +0100 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | static inline void trace_event_set_state_dynamic(TraceEvent *ev, bool state) |
| 62 | { |
| 63 | assert(ev != NULL); |
| 64 | assert(trace_event_get_state_static(ev)); |
Paolo Bonzini | 43b48cf | 2015-10-28 07:06:26 +0100 | [diff] [blame^] | 65 | trace_events_enabled_count += state - ev->dstate; |
Lluís Vilanova | 5b80827 | 2014-05-27 15:02:14 +0200 | [diff] [blame] | 66 | ev->dstate = state; |
Lluís Vilanova | b1bae81 | 2013-03-05 14:47:38 +0100 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | #endif /* TRACE__CONTROL_INTERNAL_H */ |