| 1 | #ifndef BABELTRACE_PLUGINS_TEXT_DETAILS_DETAILS_H |
| 2 | #define BABELTRACE_PLUGINS_TEXT_DETAILS_DETAILS_H |
| 3 | |
| 4 | /* |
| 5 | * Copyright 2019 Philippe Proulx <pproulx@efficios.com> |
| 6 | * |
| 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 8 | * of this software and associated documentation files (the "Software"), to deal |
| 9 | * in the Software without restriction, including without limitation the rights |
| 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 11 | * copies of the Software, and to permit persons to whom the Software is |
| 12 | * furnished to do so, subject to the following conditions: |
| 13 | * |
| 14 | * The above copyright notice and this permission notice shall be included in |
| 15 | * all copies or substantial portions of the Software. |
| 16 | * |
| 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 23 | * SOFTWARE. |
| 24 | */ |
| 25 | |
| 26 | #include <glib.h> |
| 27 | #include <babeltrace2/babeltrace.h> |
| 28 | #include <stdbool.h> |
| 29 | |
| 30 | /* |
| 31 | * This structure contains a hash table which maps trace IR stream class |
| 32 | * and event class addresses to whether or not they have been printed |
| 33 | * already during the lifetime of the component. |
| 34 | * |
| 35 | * It is safe to keep the addresses (weak references) in this hash table |
| 36 | * as long as the trace class to which the structure is associated |
| 37 | * exists because it's not possible to remove stream classes from a |
| 38 | * trace class and event classes from a stream class. |
| 39 | */ |
| 40 | struct details_trace_class_meta { |
| 41 | /* |
| 42 | * Stream class or event class address (`const void *`) -> |
| 43 | * `guint` (as a pointer) |
| 44 | * |
| 45 | * This acts as a set in fact; we don't care about the values, |
| 46 | * but we put 1 so that we can use g_hash_table_lookup() to know |
| 47 | * whether or not the hash table contains a given key |
| 48 | * (g_hash_table_lookup() returns `NULL` when not found, but |
| 49 | * also when the value is `NULL`). |
| 50 | */ |
| 51 | GHashTable *objects; |
| 52 | |
| 53 | /* |
| 54 | * Trace class destruction listener ID (`UINT64_C(-1)` if |
| 55 | * there's no listener ID. |
| 56 | */ |
| 57 | bt_listener_id tc_destruction_listener_id; |
| 58 | }; |
| 59 | |
| 60 | /* |
| 61 | * An entry of the `traces` hash table of a |
| 62 | * `struct details_comp` structure. |
| 63 | */ |
| 64 | struct details_trace { |
| 65 | /* Unique ID of this trace within the lifetime of the component */ |
| 66 | uint64_t unique_id; |
| 67 | |
| 68 | /* |
| 69 | * Trace destruction listener ID (`UINT64_C(-1)` if there's no |
| 70 | * listener ID. |
| 71 | */ |
| 72 | bt_listener_id trace_destruction_listener_id; |
| 73 | }; |
| 74 | |
| 75 | /* A `sink.text.details` component */ |
| 76 | struct details_comp { |
| 77 | bt_logging_level log_level; |
| 78 | bt_self_component *self_comp; |
| 79 | |
| 80 | /* Component's configuration */ |
| 81 | struct { |
| 82 | /* Write metadata objects */ |
| 83 | bool with_meta; |
| 84 | |
| 85 | /* |
| 86 | * Compact mode: each line is a single message, and |
| 87 | * there are no extended message properties and |
| 88 | * event/packet fields. `with_meta` can still be true in |
| 89 | * compact mode, printing the full metadata objects, but |
| 90 | * making the messages compact. |
| 91 | */ |
| 92 | bool compact; |
| 93 | |
| 94 | /* Colorize output */ |
| 95 | bool with_color; |
| 96 | |
| 97 | /* Write message's time */ |
| 98 | bool with_time; |
| 99 | |
| 100 | /* Write trace's name */ |
| 101 | bool with_trace_name; |
| 102 | |
| 103 | /* Write stream class's name */ |
| 104 | bool with_stream_class_name; |
| 105 | |
| 106 | /* Write stream's name */ |
| 107 | bool with_stream_name; |
| 108 | |
| 109 | /* Write UUID */ |
| 110 | bool with_uuid; |
| 111 | } cfg; |
| 112 | |
| 113 | /* |
| 114 | * `const bt_trace_class *` (weak) -> |
| 115 | * `struct details_trace_class_meta *` (owned by this) |
| 116 | * |
| 117 | * The key (trace class object) is weak. An entry is added, if |
| 118 | * `cfg.with_meta` above is true, when first encountering a |
| 119 | * trace class. An entry is removed when a trace class is |
| 120 | * destroyed or when the component is finalized. |
| 121 | */ |
| 122 | GHashTable *meta; |
| 123 | |
| 124 | /* |
| 125 | * `const bt_trace *` (weak) -> |
| 126 | * `struct details_trace *` (owner by this) |
| 127 | * |
| 128 | * This hash table associates a trace object to a unique ID |
| 129 | * within the lifetime of this component. This is used to easily |
| 130 | * follow the messages of a given trace/stream when reading the |
| 131 | * text output of the component. We cannot use the actual stream |
| 132 | * ID properties for this because many streams can share the |
| 133 | * same ID (with different stream classes or different traces). |
| 134 | * |
| 135 | * When adding an entry, the unique ID to use is |
| 136 | * `next_unique_trace_id`. |
| 137 | * |
| 138 | * An entry is added when first encountering a trace. An entry |
| 139 | * is removed when a trace is destroyed or when the component is |
| 140 | * finalized. |
| 141 | */ |
| 142 | GHashTable *traces; |
| 143 | uint32_t next_unique_trace_id; |
| 144 | |
| 145 | /* Upstream message iterator */ |
| 146 | bt_self_component_port_input_message_iterator *msg_iter; |
| 147 | |
| 148 | /* |
| 149 | * True if this component printed something. This is used to |
| 150 | * prepend a newline to the next message string instead of |
| 151 | * appending it so that the last printed message is not followed |
| 152 | * with an empty line. |
| 153 | */ |
| 154 | bool printed_something; |
| 155 | |
| 156 | /* Current message's output buffer */ |
| 157 | GString *str; |
| 158 | }; |
| 159 | |
| 160 | BT_HIDDEN |
| 161 | bt_component_class_init_method_status details_init( |
| 162 | bt_self_component_sink *component, |
| 163 | const bt_value *params, void *init_method_data); |
| 164 | |
| 165 | BT_HIDDEN |
| 166 | void details_finalize(bt_self_component_sink *component); |
| 167 | |
| 168 | BT_HIDDEN |
| 169 | bt_component_class_sink_graph_is_configured_method_status details_graph_is_configured( |
| 170 | bt_self_component_sink *comp); |
| 171 | |
| 172 | BT_HIDDEN |
| 173 | bt_component_class_sink_consume_method_status details_consume(bt_self_component_sink *component); |
| 174 | |
| 175 | BT_HIDDEN |
| 176 | void details_destroy_details_trace_class_meta( |
| 177 | struct details_trace_class_meta *details_trace_class_meta); |
| 178 | |
| 179 | BT_HIDDEN |
| 180 | struct details_trace_class_meta *details_create_details_trace_class_meta(void); |
| 181 | |
| 182 | #endif /* BABELTRACE_PLUGINS_TEXT_DETAILS_DETAILS_H */ |