From: Philippe Proulx Date: Tue, 31 Jul 2018 21:31:50 +0000 (-0400) Subject: lib: remove clock class priority map, use default clock value X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=e22b45d0f7d3ce1311bf96a930bc42326f555202 lib: remove clock class priority map, use default clock value This patch removes the concept (and associated files and functions) of clock class priority maps. We're setting plain clock values to objects which have a time (event, packet, some notifications) instead and using a _default_ clock value. This is an easier API, and after all, all we need is a clock value to sort notifications, not custom priorities assigned to clock classes. The purpose of the default clock value is to mux (sort) or trim notifications, and also to seek eventually. For an event object, the API is now: int bt_event_set_clock_value(struct bt_event *event, struct bt_clock_class *clock_class, uint64_t raw_value, bt_bool is_default); struct bt_clock_value *bt_event_borrow_default_clock_value( struct bt_event *event); As of this version, when calling bt_event_set_clock_value() (or any clock value setter), you must pass `BT_TRUE` as the `is_default` parameter. That is, individual objects support at most a single, default clock value. This is simpler now and can still change in the future. Like before this patch, clock value objects are unique, that is, you cannot get or put a clock value reference, but you can borrow it. You cannot set a clock value object's raw value directly (bt_clock_value_set_value()) anymore because this is done through specific clock value setter functions. Behind the scenes, all the objects with a clock value setter and borrower function use an internal clock value set object. This is an array of clock values with a pointer to the default one. Its API is: static inline int bt_clock_value_set_initialize(struct bt_clock_value_set *cv_set); static inline void bt_clock_value_set_reset(struct bt_clock_value_set *cv_set); static inline void bt_clock_value_set_finalize(struct bt_clock_value_set *cv_set); static inline int bt_clock_value_set_set_clock_value( struct bt_clock_value_set *cv_set, struct bt_clock_class *cc, uint64_t raw_value, bt_bool is_default); You can reset a clock value set if it's located within a resettable (poolable) object (e.g., event, packet). The `bt_packet` object now has two clock value sets: its beginning and end times. Although there is no developer mode check as of this patch, the beginning and end times must match the `timestamp_begin` and `timestamp_end` field values if they exist. The stream beginning and end notification APIs have clock value setter and borrower functions so that you can (optionally, if possible) indicate the beginning and end times of a stream. An `flt.utils.muxer` component now uses the default clock value of event and inactivity notifications to sort notifications. Discarded element (event, packet) notification types are removed because they rely on the clock class priority map concept too and we're about to remove them anyway and replace them with a new concept. Their usage is temporarily removed from specific plugin component classes (`src.text.pretty`, `sink.utils.counter`). Signed-off-by: Philippe Proulx --- diff --git a/include/Makefile.am b/include/Makefile.am index d9789fcf..5bb35abe 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -128,7 +128,6 @@ babeltraceplugininclude_HEADERS = \ # Graph, component, and notification API babeltracegraphincludedir = "$(includedir)/babeltrace/graph" babeltracegraphinclude_HEADERS = \ - babeltrace/graph/clock-class-priority-map.h \ babeltrace/graph/component-class-filter.h \ babeltrace/graph/component-class-sink.h \ babeltrace/graph/component-class-source.h \ @@ -140,8 +139,6 @@ babeltracegraphinclude_HEADERS = \ babeltrace/graph/component.h \ babeltrace/graph/connection.h \ babeltrace/graph/graph.h \ - babeltrace/graph/notification-discarded-events.h \ - babeltrace/graph/notification-discarded-packets.h \ babeltrace/graph/notification-event.h \ babeltrace/graph/notification-inactivity.h \ babeltrace/graph/notification-iterator.h \ @@ -210,6 +207,7 @@ noinst_HEADERS = \ babeltrace/ctf-ir/clock-class-internal.h \ babeltrace/ctf-ir/field-types-internal.h \ babeltrace/ctf-ir/clock-value-internal.h \ + babeltrace/ctf-ir/clock-value-set-internal.h \ babeltrace/ctf-ir/attributes-internal.h \ babeltrace/ctf-ir/stream-internal.h \ babeltrace/ctf-ir/resolve-internal.h \ @@ -228,7 +226,6 @@ noinst_HEADERS = \ babeltrace/graph/component-class-sink-colander-internal.h \ babeltrace/graph/notification-inactivity-internal.h \ babeltrace/graph/component-source-internal.h \ - babeltrace/graph/notification-discarded-elements-internal.h \ babeltrace/graph/notification-packet-internal.h \ babeltrace/graph/notification-iterator-internal.h \ babeltrace/graph/notification-internal.h \ @@ -236,7 +233,6 @@ noinst_HEADERS = \ babeltrace/graph/component-class-internal.h \ babeltrace/graph/component-sink-internal.h \ babeltrace/graph/port-internal.h \ - babeltrace/graph/clock-class-priority-map-internal.h \ babeltrace/list-internal.h \ version.h \ version.i diff --git a/include/babeltrace/babeltrace.h b/include/babeltrace/babeltrace.h index 181c0141..b208b8b0 100644 --- a/include/babeltrace/babeltrace.h +++ b/include/babeltrace/babeltrace.h @@ -72,7 +72,6 @@ #include /* Graph, component, and notification API */ -#include #include #include #include @@ -84,8 +83,6 @@ #include #include #include -#include -#include #include #include #include diff --git a/include/babeltrace/ctf-ir/clock-value-internal.h b/include/babeltrace/ctf-ir/clock-value-internal.h index 0f23181b..11b80a36 100644 --- a/include/babeltrace/ctf-ir/clock-value-internal.h +++ b/include/babeltrace/ctf-ir/clock-value-internal.h @@ -25,6 +25,7 @@ #include #include +#include #include #include @@ -63,6 +64,200 @@ void _bt_clock_value_set_is_frozen(struct bt_clock_value *clock_value, clock_value->frozen = is_frozen; } +static inline +uint64_t ns_from_value(uint64_t frequency, uint64_t value) +{ + uint64_t ns; + + if (frequency == UINT64_C(1000000000)) { + ns = value; + } else { + double dblres = ((1e9 * (double) value) / (double) frequency); + + if (dblres >= (double) UINT64_MAX) { + /* Overflows uint64_t */ + ns = -1ULL; + } else { + ns = (uint64_t) dblres; + } + } + + return ns; +} + +static inline +int ns_from_epoch(struct bt_clock_class *clock_class, uint64_t value, + int64_t *ns_from_epoch, bool *overflows) +{ + int ret = 0; + int64_t diff; + int64_t s_ns; + uint64_t u_ns; + uint64_t cycles; + + *overflows = false; + + /* Initialize nanosecond timestamp to clock's offset in seconds */ + if (clock_class->offset_s <= (INT64_MIN / INT64_C(1000000000)) || + clock_class->offset_s >= (INT64_MAX / INT64_C(1000000000))) { + /* + * Overflow: offset in seconds converted to nanoseconds + * is outside the int64_t range. + */ + *overflows = true; + goto end; + } + + *ns_from_epoch = clock_class->offset_s * INT64_C(1000000000); + + /* Add offset in cycles */ + if (clock_class->offset < 0) { + cycles = (uint64_t) -clock_class->offset; + } else { + cycles = (uint64_t) clock_class->offset; + } + + u_ns = ns_from_value(clock_class->frequency, cycles); + + if (u_ns == UINT64_C(-1) || u_ns >= INT64_MAX) { + /* + * Overflow: offset in cycles converted to nanoseconds + * is outside the int64_t range. + */ + *overflows = true; + goto end; + } + + s_ns = (int64_t) u_ns; + BT_ASSERT(s_ns >= 0); + + if (clock_class->offset < 0) { + if (*ns_from_epoch >= 0) { + /* + * Offset in cycles is negative so it must also + * be negative once converted to nanoseconds. + */ + s_ns = -s_ns; + goto offset_ok; + } + + diff = *ns_from_epoch - INT64_MIN; + + if (s_ns >= diff) { + /* + * Overflow: current timestamp in nanoseconds + * plus the offset in cycles converted to + * nanoseconds is outside the int64_t range. + */ + *overflows = true; + goto end; + } + + /* + * Offset in cycles is negative so it must also be + * negative once converted to nanoseconds. + */ + s_ns = -s_ns; + } else { + if (*ns_from_epoch <= 0) { + goto offset_ok; + } + + diff = INT64_MAX - *ns_from_epoch; + + if (s_ns >= diff) { + /* + * Overflow: current timestamp in nanoseconds + * plus the offset in cycles converted to + * nanoseconds is outside the int64_t range. + */ + *overflows = true; + goto end; + } + } + +offset_ok: + *ns_from_epoch += s_ns; + + /* Add clock value (cycles) */ + u_ns = ns_from_value(clock_class->frequency, value); + + if (u_ns == -1ULL || u_ns >= INT64_MAX) { + /* + * Overflow: value converted to nanoseconds is outside + * the int64_t range. + */ + *overflows = true; + goto end; + } + + s_ns = (int64_t) u_ns; + BT_ASSERT(s_ns >= 0); + + /* Clock value (cycles) is always positive */ + if (*ns_from_epoch <= 0) { + goto value_ok; + } + + diff = INT64_MAX - *ns_from_epoch; + + if (s_ns >= diff) { + /* + * Overflow: current timestamp in nanoseconds plus the + * clock value converted to nanoseconds is outside the + * int64_t range. + */ + *overflows = true; + goto end; + } + +value_ok: + *ns_from_epoch += s_ns; + +end: + if (*overflows) { + *ns_from_epoch = 0; + ret = -1; + } + + return ret; +} + +static inline +void set_ns_from_epoch(struct bt_clock_value *clock_value) +{ + (void) ns_from_epoch(clock_value->clock_class, + clock_value->value, &clock_value->ns_from_epoch, + &clock_value->ns_from_epoch_overflows); +} + +static inline +void bt_clock_value_set_raw_value(struct bt_clock_value *clock_value, + uint64_t cycles) +{ + BT_ASSERT(clock_value); + + clock_value->value = cycles; + set_ns_from_epoch(clock_value); + bt_clock_value_set(clock_value); +} + +static inline +int bt_clock_value_set_value_inline(struct bt_clock_value *clock_value, + uint64_t raw_value) +{ +#ifdef BT_ASSERT_PRE_NON_NULL + BT_ASSERT_PRE_NON_NULL(clock_value, "Clock value"); +#endif + +#ifdef BT_ASSERT_PRE_HOT + BT_ASSERT_PRE_HOT(clock_value, "Clock value", ": %!+k", clock_value); +#endif + + bt_clock_value_set_raw_value(clock_value, raw_value); + return 0; +} + #ifdef BT_DEV_MODE # define bt_clock_value_set_is_frozen _bt_clock_value_set_is_frozen #else diff --git a/include/babeltrace/ctf-ir/clock-value-set-internal.h b/include/babeltrace/ctf-ir/clock-value-set-internal.h new file mode 100644 index 00000000..c5a1ce57 --- /dev/null +++ b/include/babeltrace/ctf-ir/clock-value-set-internal.h @@ -0,0 +1,159 @@ +#ifndef BABELTRACE_GRAPH_CLOCK_VALUE_SET_H +#define BABELTRACE_GRAPH_CLOCK_VALUE_SET_H + +/* + * Copyright 2018 Philippe Proulx + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include +#include +#include +#include + +struct bt_clock_value_set { + /* Unique objects owned by this */ + GPtrArray *clock_values; + + /* Weak; points to one of the clock values above */ + struct bt_clock_value *default_cv; +}; + +static inline +int bt_clock_value_set_initialize(struct bt_clock_value_set *cv_set) +{ + int ret = 0; + + cv_set->clock_values = g_ptr_array_sized_new(1); + if (!cv_set->clock_values) { +#ifdef BT_LOGE_STR + BT_LOGE_STR("Failed to allocate one GPtrArray."); +#endif + + ret = -1; + goto end; + } + + cv_set->default_cv = NULL; + +end: + return ret; +} + +static inline +void bt_clock_value_set_reset(struct bt_clock_value_set *cv_set) +{ + uint64_t i; + + BT_ASSERT(cv_set); + BT_ASSERT(cv_set->clock_values); + + for (i = 0; i < cv_set->clock_values->len; i++) { + struct bt_clock_value *cv = cv_set->clock_values->pdata[i]; + + BT_ASSERT(cv); + bt_clock_value_reset(cv); + bt_clock_value_set_is_frozen(cv, false); + } + + cv_set->default_cv = NULL; +} + +static inline +void bt_clock_value_set_finalize(struct bt_clock_value_set *cv_set) +{ + uint64_t i; + + BT_ASSERT(cv_set); + + if (cv_set->clock_values) { + for (i = 0; i < cv_set->clock_values->len; i++) { + struct bt_clock_value *cv = + cv_set->clock_values->pdata[i]; + + BT_ASSERT(cv); + bt_clock_value_recycle(cv); + } + + g_ptr_array_free(cv_set->clock_values, TRUE); + } + + cv_set->default_cv = NULL; +} + +static inline +int bt_clock_value_set_set_clock_value( + struct bt_clock_value_set *cv_set, + struct bt_clock_class *cc, uint64_t raw_value, + bt_bool is_default) +{ + int ret = 0; + struct bt_clock_value *clock_value = NULL; + uint64_t i; + + BT_ASSERT(cv_set); + BT_ASSERT(cc); + + /* Check if we already have a value for this clock class */ + for (i = 0; i < cv_set->clock_values->len; i++) { + struct bt_clock_value *cv = cv_set->clock_values->pdata[i]; + + BT_ASSERT(cv); + + if (cv->clock_class == cc) { + clock_value = cv; + break; + } + } + + if (!clock_value) { + clock_value = bt_clock_value_create(cc); + if (!clock_value) { +#ifdef BT_LIB_LOGE + BT_LIB_LOGE("Cannot create a clock value from a clock class: " + "%![cc-]+K", cc); +#endif + + ret = -1; + goto end; + } + + g_ptr_array_add(cv_set->clock_values, clock_value); + } + +#ifdef BT_ASSERT_PRE_HOT + BT_ASSERT_PRE_HOT(clock_value, "Clock value", ": %!+k", clock_value); +#endif + + ret = bt_clock_value_set_value_inline(clock_value, raw_value); + if (ret) { + goto end; + } + + if (is_default) { + cv_set->default_cv = clock_value; + } + +end: + return ret; +} + +#endif /* BABELTRACE_GRAPH_CLOCK_VALUE_SET_H */ diff --git a/include/babeltrace/ctf-ir/clock-value.h b/include/babeltrace/ctf-ir/clock-value.h index 9fb152e8..19b9aec6 100644 --- a/include/babeltrace/ctf-ir/clock-value.h +++ b/include/babeltrace/ctf-ir/clock-value.h @@ -53,8 +53,6 @@ struct bt_clock_class *bt_clock_value_get_class( return bt_get(bt_clock_value_borrow_class(clock_value)); } -extern int bt_clock_value_set_value( - struct bt_clock_value *clock_value, uint64_t raw_value); extern int bt_clock_value_get_value( struct bt_clock_value *clock_value, uint64_t *raw_value); extern int bt_clock_value_get_value_ns_from_epoch( diff --git a/include/babeltrace/ctf-ir/event-class-internal.h b/include/babeltrace/ctf-ir/event-class-internal.h index 40df300c..404bcd75 100644 --- a/include/babeltrace/ctf-ir/event-class-internal.h +++ b/include/babeltrace/ctf-ir/event-class-internal.h @@ -102,10 +102,6 @@ int bt_event_class_common_validate_single_clock_class( struct bt_event_class_common *event_class, struct bt_clock_class **expected_clock_class); -BT_HIDDEN -int bt_event_class_update_event_pool_clock_values( - struct bt_event_class *event_class); - static inline const char *bt_event_class_common_get_name( struct bt_event_class_common *event_class) diff --git a/include/babeltrace/ctf-ir/event-internal.h b/include/babeltrace/ctf-ir/event-internal.h index 193a3813..f1d09205 100644 --- a/include/babeltrace/ctf-ir/event-internal.h +++ b/include/babeltrace/ctf-ir/event-internal.h @@ -38,7 +38,7 @@ #include #include #include -#include +#include #include #include #include @@ -59,9 +59,7 @@ struct bt_event_common { struct bt_event { struct bt_event_common common; - - /* Maps clock classes to bt_clock_value. */ - GHashTable *clock_values; + struct bt_clock_value_set cv_set; struct bt_packet *packet; }; @@ -86,7 +84,7 @@ void _bt_event_set_is_frozen(struct bt_event *event, bool is_frozen); #endif #define BT_ASSERT_PRE_EVENT_COMMON_HOT(_event, _name) \ - BT_ASSERT_PRE_HOT((_event), (_name), ": +%!+_e", (_event)) + BT_ASSERT_PRE_HOT((_event), (_name), ": %!+_e", (_event)) static inline struct bt_event_class_common *bt_event_common_borrow_class( @@ -256,9 +254,6 @@ BT_UNUSED static inline void _bt_event_reset_dev_mode(struct bt_event *event) { - GHashTableIter iter; - gpointer key, value; - BT_ASSERT(event); if (event->common.header_field) { @@ -286,15 +281,6 @@ void _bt_event_reset_dev_mode(struct bt_event *event) event->common.payload_field, false); bt_field_common_reset_recursive(event->common.payload_field); } - - g_hash_table_iter_init(&iter, event->clock_values); - while (g_hash_table_iter_next(&iter, &key, &value)) { - struct bt_clock_value *clock_value = value; - - BT_ASSERT(clock_value); - bt_clock_value_reset(clock_value); - bt_clock_value_set_is_frozen(clock_value, false); - } } #ifdef BT_DEV_MODE @@ -311,7 +297,7 @@ void bt_event_reset(struct bt_event *event) { BT_ASSERT(event); bt_event_set_is_frozen(event, false); - bt_event_reset_dev_mode(event); + bt_clock_value_set_reset(&event->cv_set); bt_object_put_no_null_check(&event->packet->base); event->packet = NULL; } diff --git a/include/babeltrace/ctf-ir/event.h b/include/babeltrace/ctf-ir/event.h index ababc8f0..44112125 100644 --- a/include/babeltrace/ctf-ir/event.h +++ b/include/babeltrace/ctf-ir/event.h @@ -33,6 +33,9 @@ /* For bt_get() */ #include +/* For bt_bool */ +#include + #include #include @@ -261,9 +264,12 @@ extern struct bt_field *bt_event_borrow_payload(struct bt_event *event); @{ */ -extern struct bt_clock_value *bt_event_borrow_clock_value( - struct bt_event *event, - struct bt_clock_class *clock_class); +extern int bt_event_set_clock_value(struct bt_event *event, + struct bt_clock_class *clock_class, uint64_t raw_value, + bt_bool is_default); + +extern struct bt_clock_value *bt_event_borrow_default_clock_value( + struct bt_event *event); /** @} */ diff --git a/include/babeltrace/ctf-ir/field-types-internal.h b/include/babeltrace/ctf-ir/field-types-internal.h index 3940b1d4..0b96007b 100644 --- a/include/babeltrace/ctf-ir/field-types-internal.h +++ b/include/babeltrace/ctf-ir/field-types-internal.h @@ -42,7 +42,7 @@ "%![ft-]+_F", bt_common_field_type_id_string(_type_id), (_ft)) #define BT_ASSERT_PRE_FT_HOT(_ft, _name) \ - BT_ASSERT_PRE_HOT((_ft), (_name), ": +%!+_F", (_ft)) + BT_ASSERT_PRE_HOT((_ft), (_name), ": %!+_F", (_ft)) #define BT_FIELD_TYPE_COMMON_STRUCTURE_FIELD_AT_INDEX(_ft, _index) \ (&g_array_index(((struct bt_field_type_common_structure *) (_ft))->fields, \ diff --git a/include/babeltrace/ctf-ir/fields-internal.h b/include/babeltrace/ctf-ir/fields-internal.h index d6da0a4a..b7aff55e 100644 --- a/include/babeltrace/ctf-ir/fields-internal.h +++ b/include/babeltrace/ctf-ir/fields-internal.h @@ -51,7 +51,7 @@ _name " is not set: %!+_f", (_field)) #define BT_ASSERT_PRE_FIELD_COMMON_HOT(_field, _name) \ - BT_ASSERT_PRE_HOT((_field), (_name), ": +%!+_f", (_field)) + BT_ASSERT_PRE_HOT((_field), (_name), ": %!+_f", (_field)) struct bt_field; struct bt_field_common; diff --git a/include/babeltrace/ctf-ir/packet-internal.h b/include/babeltrace/ctf-ir/packet-internal.h index 37aeab7b..206215bf 100644 --- a/include/babeltrace/ctf-ir/packet-internal.h +++ b/include/babeltrace/ctf-ir/packet-internal.h @@ -31,12 +31,15 @@ #include #include #include +#include struct bt_packet { struct bt_object base; struct bt_field_wrapper *header; struct bt_field_wrapper *context; struct bt_stream *stream; + struct bt_clock_value_set begin_cv_set; + struct bt_clock_value_set end_cv_set; int frozen; }; diff --git a/include/babeltrace/ctf-ir/packet.h b/include/babeltrace/ctf-ir/packet.h index e87a5f80..e8ebf879 100644 --- a/include/babeltrace/ctf-ir/packet.h +++ b/include/babeltrace/ctf-ir/packet.h @@ -28,10 +28,13 @@ * http://www.efficios.com/ctf */ +#include + /* For bt_get() */ #include -#include +/* For bt_bool */ +#include #ifdef __cplusplus extern "C" { @@ -100,6 +103,8 @@ struct bt_packet; struct bt_packet_header_field; struct bt_packet_context_field; struct bt_stream; +struct bt_clock_value; +struct bt_clock_class; /** @name Creation and parent access functions @@ -167,6 +172,20 @@ int bt_packet_move_context(struct bt_packet *packet, /** @} */ +extern int bt_packet_set_beginning_clock_value(struct bt_packet *packet, + struct bt_clock_class *clock_class, uint64_t raw_value, + bt_bool is_default); + +extern struct bt_clock_value *bt_packet_borrow_default_beginning_clock_value( + struct bt_packet *packet); + +extern int bt_packet_set_end_clock_value(struct bt_packet *packet, + struct bt_clock_class *clock_class, uint64_t raw_value, + bt_bool is_default); + +extern struct bt_clock_value *bt_packet_borrow_default_end_clock_value( + struct bt_packet *packet); + /** @} */ #ifdef __cplusplus diff --git a/include/babeltrace/graph/clock-class-priority-map-internal.h b/include/babeltrace/graph/clock-class-priority-map-internal.h deleted file mode 100644 index be6a9953..00000000 --- a/include/babeltrace/graph/clock-class-priority-map-internal.h +++ /dev/null @@ -1,66 +0,0 @@ -#ifndef BABELTRACE_GRAPH_CLOCK_CLASS_PRIORITY_MAP_INTERNAL_H -#define BABELTRACE_GRAPH_CLOCK_CLASS_PRIORITY_MAP_INTERNAL_H - -/* - * Copyright 2017 Philippe Proulx - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * The Common Trace Format (CTF) Specification is available at - * http://www.efficios.com/ctf - */ - -#include -#include -#include -#include -#include -#include -#include - -struct bt_clock_class_priority_map { - struct bt_object base; - - /* Array of struct bt_clock_class *, owned by this */ - GPtrArray *entries; - - /* struct bt_clock_class * (weak) to priority (uint64_t *) */ - GHashTable *prios; - - /* Clock class (weak) with the currently highest priority */ - struct bt_clock_class *highest_prio_cc; - - bt_bool frozen; -}; - -static inline -void _bt_clock_class_priority_map_freeze( - struct bt_clock_class_priority_map *cc_prio_map) -{ - BT_ASSERT(cc_prio_map); - cc_prio_map->frozen = BT_TRUE; -} - -#ifdef BT_DEV_MODE -# define bt_clock_class_priority_map_freeze _bt_clock_class_priority_map_freeze -#else -# define bt_clock_class_priority_map_freeze(_cc_prio_map) -#endif /* BT_DEV_MODE */ - -#endif /* BABELTRACE_GRAPH_CLOCK_CLASS_PRIORITY_MAP_INTERNAL_H */ diff --git a/include/babeltrace/graph/clock-class-priority-map.h b/include/babeltrace/graph/clock-class-priority-map.h deleted file mode 100644 index 93f05ab8..00000000 --- a/include/babeltrace/graph/clock-class-priority-map.h +++ /dev/null @@ -1,343 +0,0 @@ -#ifndef BABELTRACE_GRAPH_CLOCK_CLASS_PRIORITY_MAP_H -#define BABELTRACE_GRAPH_CLOCK_CLASS_PRIORITY_MAP_H - -/* - * Copyright 2017 Philippe Proulx - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * The Common Trace Format (CTF) Specification is available at - * http://www.efficios.com/ctf - */ - -/* For bt_get() */ -#include - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -struct bt_clock_class; - -/** -@defgroup graphclockclassprioritymap Clock class priority map -@ingroup graph -@brief Clock class priority map. - -@code -#include -@endcode - -A clock class priority map object associates -CTF IR clock classes to priorities. A clock class priority indicates -which clock class you should choose to sort notifications by time. - -You need a clock class priority map object when you create -an \link graphnotifevent event notification\endlink or -an \link graphnotifinactivity inactivity notification\endlink. - -A priority is a 64-bit unsigned integer. A lower value has a -\em higher priority. Multiple clock classes can have the same priority -within a given clock class priority map. - -The following functions can \em freeze clock class priority map objects: - -- bt_notification_event_create() freezes its clock class priority - map parameter. -- bt_notification_inactivity_create() freezes its clock class priority - map parameter. - -You cannot modify a frozen clock class priority map object: it is -considered immutable, except for \link refs reference counting\endlink. - -As with any Babeltrace object, clock class priority map objects have -reference -counts. See \ref refs to learn more about the reference counting -management of Babeltrace objects. - -@file -@brief Clock class priority map type and functions. -@sa graphclockclassprioritymap - -@addtogroup graphclockclassprioritymap -@{ -*/ - -/** -@struct bt_clock_class_priority_map -@brief A clock class priority map. -@sa graphclockclassprioritymap -*/ -struct bt_clock_class_priority_map; - -/** -@brief Creates an empty clock class priority map. - -@returns Created clock class priority map object, or \c NULL on error. - -@postsuccessrefcountret1 -*/ -extern struct bt_clock_class_priority_map *bt_clock_class_priority_map_create(void); - -/** -@brief Returns the number of CTF IR clock classes contained in the - clock class priority map \p clock_class_priority_map. - -@param[in] clock_class_priority_map Clock class priority map of - which to get the number of - clock classes. -@returns Number of clock classes contained - in \p clock_class_priority_map, - or a negative value on error. - -@prenotnull{clock_class_priority_map} -@postrefcountsame{clock_class_priority_map} -*/ -extern int64_t bt_clock_class_priority_map_get_clock_class_count( - struct bt_clock_class_priority_map *clock_class_priority_map); - -extern struct bt_clock_class * -bt_clock_class_priority_map_borrow_clock_class_by_index( - struct bt_clock_class_priority_map *clock_class_priority_map, - uint64_t index); - -/** -@brief Returns the CTF IR clock class at index \p index in the clock - class priority map \p clock_class_priority_map. - -@param[in] clock_class_priority_map Clock class priority map of which - to get the clock class at index - \p index. -@param[in] index Index of the clock class to find - in \p clock_class_priority_map. -@returns Clock class at index \p index in - \p clock_class_priority_map, - or \c NULL on error. - -@prenotnull{clock_class_priority_map} -@pre \p index is lesser than the number of clock classes contained in - the clock class priority map \p clock_class_priority_map (see - bt_clock_class_priority_map_get_clock_class_count()). -@postrefcountsame{clock_class_priority_map} - -@sa bt_clock_class_priority_map_get_clock_class_by_name(): Finds a clock - class by name in a given clock class priority map. -@sa bt_clock_class_priority_map_get_highest_priority_clock_class(): - Returns the clock class with the highest priority contained - in a given clock class priority map. -@sa bt_clock_class_priority_map_add_clock_class(): Adds a clock class - to a clock class priority map. -*/ -static inline -struct bt_clock_class * -bt_clock_class_priority_map_get_clock_class_by_index( - struct bt_clock_class_priority_map *clock_class_priority_map, - uint64_t index) -{ - return bt_get(bt_clock_class_priority_map_borrow_clock_class_by_index( - clock_class_priority_map, index)); -} - -extern struct bt_clock_class * -bt_clock_class_priority_map_borrow_clock_class_by_name( - struct bt_clock_class_priority_map *clock_class_priority_map, - const char *name); - -/** -@brief Returns the CTF IR clock class named \c name found in the clock - class priority map \p clock_class_priority_map. - -@param[in] clock_class_priority_map Clock class priority map of - which to get the clock class - named \p name. -@param[in] name Name of the clock class to find - in \p clock_class_priority_map. -@returns Clock class named \p name in - \p clock_class_priority_map, - or \c NULL on error. - -@prenotnull{clock_class_priority_map} -@prenotnull{name} -@postrefcountsame{clock_class_priority_map} -@postsuccessrefcountretinc - -@sa bt_clock_class_priority_map_get_clock_class_by_index(): Returns the clock - class contained in a given clock class priority map at - a given index. -@sa bt_clock_class_priority_map_get_highest_priority_clock_class(): - Returns the clock class with the highest priority contained in - a given clock class priority map. -@sa bt_clock_class_priority_map_add_clock_class(): Adds a clock class - to a clock class priority map. -*/ -static inline -struct bt_clock_class *bt_clock_class_priority_map_get_clock_class_by_name( - struct bt_clock_class_priority_map *clock_class_priority_map, - const char *name) -{ - return bt_get(bt_clock_class_priority_map_borrow_clock_class_by_name( - clock_class_priority_map, name)); -} - -extern struct bt_clock_class * -bt_clock_class_priority_map_borrow_highest_priority_clock_class( - struct bt_clock_class_priority_map *clock_class_priority_map); - -/** -@brief Returns the CTF IR clock class with the currently highest - priority within the clock class priority map - \p clock_class_priority_map. - -If multiple clock classes share the same highest priority in -\p clock_class_priority_map, you cannot deterministically know which one -this function returns. - -@param[in] clock_class_priority_map Clock class priority map of which - to get the clock class with the - highest priority. -@returns Clock class with the highest - priority within - \p clock_class_priority_map, or - \c NULL on error or if there are - no clock classes in - \p clock_class_priority_map. - -@prenotnull{clock_class_priority_map} -@postrefcountsame{clock_class_priority_map} -@postsuccessrefcountretinc - -@sa bt_clock_class_priority_map_get_clock_class_by_index(): Returns the clock - class contained in a given clock class priority map at - a given index. -@sa bt_clock_class_priority_map_get_clock_class_by_name(): Finds a - clock class by name in a given clock class priority map. -@sa bt_clock_class_priority_map_add_clock_class(): Adds a clock class - to a clock class priority map. -*/ -static inline -struct bt_clock_class * -bt_clock_class_priority_map_get_highest_priority_clock_class( - struct bt_clock_class_priority_map *clock_class_priority_map) -{ - return bt_get( - bt_clock_class_priority_map_borrow_highest_priority_clock_class( - clock_class_priority_map)); -} - -/** -@brief Returns the priority of the CTF IR clock class \p clock_class - contained within the clock class priority map - \p clock_class_priority_map. - -@param[in] clock_class_priority_map Clock class priority map - containing \p clock_class. -@param[in] clock_class Clock class of which to get the - priority. -@param[out] priority Returned priority of - \p clock_class within - \p clock_class_priority_map. -@returns 0 on success, or a negative - value on error. - -@prenotnull{clock_class_priority_map} -@prenotnull{clock_class} -@prenotnull{priority} -@pre \p clock_class is contained in \p clock_class_priority_map (was - previously added to \p clock_class_priority_map with - bt_clock_class_priority_map_add_clock_class()). -@postrefcountsame{clock_class_priority_map} -@postrefcountsame{clock_class} - -@sa bt_clock_class_priority_map_get_highest_priority_clock_class(): - Returns the clock class with the highest priority contained - in a given clock class priority map. -*/ -extern int bt_clock_class_priority_map_get_clock_class_priority( - struct bt_clock_class_priority_map *clock_class_priority_map, - struct bt_clock_class *clock_class, uint64_t *priority); - -/** -@brief Adds the CTF IR clock class \p clock_class to the clock class - priority map \p clock_class_priority_map with the - priority \p priority. - -You can call this function even if \p clock_class is frozen. - -A lower priority value means a \em higher priority. Multiple clock -classes can have the same priority within a given clock class priority -map. - -@param[in] clock_class_priority_map Clock class priority map to - which to add \p clock_class. -@param[in] clock_class Clock class to add to - \p clock_class_priority_map. -@param[in] priority Priority of \p clock_class within - \p clock_class_priority_map, - where a lower value means a - higher priority. -@returns 0 on success, or a negative - value on error. - -@prenotnull{clock_class_priority_map} -@prenotnull{clock_class} -@prehot{clock_class_priority_map} -@postrefcountsame{clock_class_priority_map} -@postsuccessrefcountinc{clock_class} - -@sa bt_clock_class_priority_map_get_clock_class_by_index(): Returns the clock - class contained in a given clock class priority map - at a given index. -@sa bt_clock_class_priority_map_get_clock_class_by_name(): Finds a - clock class by name in a given clock class priority map. -*/ -extern int bt_clock_class_priority_map_add_clock_class( - struct bt_clock_class_priority_map *clock_class_priority_map, - struct bt_clock_class *clock_class, uint64_t priority); - -/** -@brief Creates a copy of the clock class priority map - \p clock_class_priority_map. - -You can copy a frozen clock class priority map: the resulting copy is -not frozen. - -@param[in] clock_class_priority_map Clock class priority map to copy. -@returns Copy of \p clock_class_priority_map - on success, or a negative value - on error. - -@prenotnull{clock_class_priority_map} -@postrefcountsame{clock_class_priority_map} -@postsuccessrefcountret1 -@post On success, the returned clock class priority map - is not frozen. -*/ -extern struct bt_clock_class_priority_map *bt_clock_class_priority_map_copy( - struct bt_clock_class_priority_map *clock_class_priority_map); - -/** @} */ - -#ifdef __cplusplus -} -#endif - -#endif /* BABELTRACE_GRAPH_CLOCK_CLASS_PRIORITY_MAP_H */ diff --git a/include/babeltrace/graph/notification-discarded-elements-internal.h b/include/babeltrace/graph/notification-discarded-elements-internal.h deleted file mode 100644 index c5d1f0ea..00000000 --- a/include/babeltrace/graph/notification-discarded-elements-internal.h +++ /dev/null @@ -1,75 +0,0 @@ -#ifndef BABELTRACE_GRAPH_NOTIFICATION_DISCARDED_ELEMENTS_INTERNAL_H -#define BABELTRACE_GRAPH_NOTIFICATION_DISCARDED_ELEMENTS_INTERNAL_H - -/* - * Copyright 2017 Philippe Proulx - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include -#include -#include -#include -#include -#include - -struct bt_clock_class_priority_map; -struct bt_stream; - -struct bt_notification_discarded_elements { - struct bt_notification parent; - struct bt_stream *stream; - struct bt_clock_value *begin_clock_value; - struct bt_clock_value *end_clock_value; - int64_t count; -}; - -BT_HIDDEN -struct bt_notification *bt_notification_discarded_elements_create( - struct bt_graph *graph, - enum bt_notification_type type, - struct bt_stream *stream, - struct bt_clock_value *begin_clock_value, - struct bt_clock_value *end_clock_value, - uint64_t count); - -BT_HIDDEN -struct bt_stream *bt_notification_discarded_elements_borrow_stream( - enum bt_notification_type type, - struct bt_notification *notification); - -BT_HIDDEN -struct bt_clock_value * -bt_notification_discarded_elements_borrow_begin_clock_value( - enum bt_notification_type type, - struct bt_notification *notification); - -BT_HIDDEN -struct bt_clock_value * -bt_notification_discarded_elements_borrow_end_clock_value( - enum bt_notification_type type, - struct bt_notification *notification); - -BT_HIDDEN -int64_t bt_notification_discarded_elements_get_count( - enum bt_notification_type type, - struct bt_notification *notification); - -#endif /* BABELTRACE_GRAPH_NOTIFICATION_DISCARDED_ELEMENTS_INTERNAL_H */ diff --git a/include/babeltrace/graph/notification-discarded-events.h b/include/babeltrace/graph/notification-discarded-events.h deleted file mode 100644 index 90108820..00000000 --- a/include/babeltrace/graph/notification-discarded-events.h +++ /dev/null @@ -1,84 +0,0 @@ -#ifndef BABELTRACE_GRAPH_NOTIFICATION_DISCARDED_EVENTS_H -#define BABELTRACE_GRAPH_NOTIFICATION_DISCARDED_EVENTS_H - -/* - * Copyright 2017 Philippe Proulx - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -/* For bt_get() */ -#include - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -struct bt_notification; -struct bt_clock_class_priority_map; -struct bt_clock_class; -struct bt_stream; - -extern struct bt_clock_value * -bt_notification_discarded_events_borrow_begin_clock_value( - struct bt_notification *notification); - -static inline -struct bt_clock_value * -bt_notification_discarded_events_get_begin_clock_value( - struct bt_notification *notification) -{ - return bt_get(bt_notification_discarded_events_borrow_begin_clock_value( - notification)); -} - -extern struct bt_clock_value * -bt_notification_discarded_events_borrow_end_clock_value( - struct bt_notification *notification); - -static inline -struct bt_clock_value * -bt_notification_discarded_events_get_end_clock_value( - struct bt_notification *notification) -{ - return bt_get(bt_notification_discarded_events_borrow_end_clock_value( - notification)); -} - -extern int64_t bt_notification_discarded_events_get_count( - struct bt_notification *notification); - -extern struct bt_stream *bt_notification_discarded_events_borrow_stream( - struct bt_notification *notification); - -static inline -struct bt_stream *bt_notification_discarded_events_get_stream( - struct bt_notification *notification) -{ - return bt_get(bt_notification_discarded_events_borrow_stream( - notification)); -} - -#ifdef __cplusplus -} -#endif - -#endif /* BABELTRACE_GRAPH_NOTIFICATION_DISCARDED_EVENTS_H */ diff --git a/include/babeltrace/graph/notification-discarded-packets.h b/include/babeltrace/graph/notification-discarded-packets.h deleted file mode 100644 index 1627f249..00000000 --- a/include/babeltrace/graph/notification-discarded-packets.h +++ /dev/null @@ -1,85 +0,0 @@ -#ifndef BABELTRACE_GRAPH_NOTIFICATION_DISCARDED_PACKETS_H -#define BABELTRACE_GRAPH_NOTIFICATION_DISCARDED_PACKETS_H - -/* - * Copyright 2017 Philippe Proulx - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -/* For bt_get() */ -#include - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -struct bt_notification; -struct bt_clock_class_priority_map; -struct bt_clock_class; -struct bt_stream; - -extern struct bt_clock_value * -bt_notification_discarded_packets_borrow_begin_clock_value( - struct bt_notification *notification); - -static inline -struct bt_clock_value * -bt_notification_discarded_packets_get_begin_clock_value( - struct bt_notification *notification) -{ - return bt_get( - bt_notification_discarded_packets_borrow_begin_clock_value( - notification)); -} - -extern struct bt_clock_value * -bt_notification_discarded_packets_borrow_end_clock_value( - struct bt_notification *notification); - -static inline -struct bt_clock_value * -bt_notification_discarded_packets_get_end_clock_value( - struct bt_notification *notification) -{ - return bt_get(bt_notification_discarded_packets_borrow_end_clock_value( - notification)); -} - -extern int64_t bt_notification_discarded_packets_get_count( - struct bt_notification *notification); - -extern struct bt_stream *bt_notification_discarded_packets_borrow_stream( - struct bt_notification *notification); - -static inline -struct bt_stream *bt_notification_discarded_packets_get_stream( - struct bt_notification *notification) -{ - return bt_get(bt_notification_discarded_packets_borrow_stream( - notification)); -} - -#ifdef __cplusplus -} -#endif - -#endif /* BABELTRACE_GRAPH_NOTIFICATION_DISCARDED_PACKETS_H */ diff --git a/include/babeltrace/graph/notification-event-internal.h b/include/babeltrace/graph/notification-event-internal.h index 436477b3..83a02069 100644 --- a/include/babeltrace/graph/notification-event-internal.h +++ b/include/babeltrace/graph/notification-event-internal.h @@ -31,7 +31,6 @@ #include #include #include -#include #include #ifdef __cplusplus @@ -41,7 +40,6 @@ extern "C" { struct bt_notification_event { struct bt_notification parent; struct bt_event *event; - struct bt_clock_class_priority_map *cc_prio_map; }; BT_HIDDEN diff --git a/include/babeltrace/graph/notification-event.h b/include/babeltrace/graph/notification-event.h index ab8a6606..07559581 100644 --- a/include/babeltrace/graph/notification-event.h +++ b/include/babeltrace/graph/notification-event.h @@ -37,30 +37,14 @@ extern "C" { struct bt_notification; struct bt_event; struct bt_event_class; -struct bt_clock_class_priority_map; extern struct bt_notification *bt_notification_event_create(struct bt_graph *graph, - struct bt_event_class *event_class, - struct bt_packet *packet, - struct bt_clock_class_priority_map *clock_class_priority_map); + struct bt_event_class *event_class, struct bt_packet *packet); extern struct bt_event *bt_notification_event_borrow_event( struct bt_notification *notification); -extern struct bt_clock_class_priority_map * -bt_notification_event_borrow_clock_class_priority_map( - struct bt_notification *notification); - -static inline -struct bt_clock_class_priority_map * -bt_notification_event_get_clock_class_priority_map( - struct bt_notification *notification) -{ - return bt_get(bt_notification_event_borrow_clock_class_priority_map( - notification)); -} - #ifdef __cplusplus } #endif diff --git a/include/babeltrace/graph/notification-inactivity-internal.h b/include/babeltrace/graph/notification-inactivity-internal.h index 62fba00e..ccc32965 100644 --- a/include/babeltrace/graph/notification-inactivity-internal.h +++ b/include/babeltrace/graph/notification-inactivity-internal.h @@ -24,13 +24,12 @@ */ #include - -struct bt_clock_class_priority_map; +#include +#include struct bt_notification_inactivity { struct bt_notification parent; - struct bt_clock_class_priority_map *cc_prio_map; - GHashTable *clock_values; + struct bt_clock_value_set cv_set; }; #endif /* BABELTRACE_GRAPH_NOTIFICATION_INACTIVITY_INTERNAL_H */ diff --git a/include/babeltrace/graph/notification-inactivity.h b/include/babeltrace/graph/notification-inactivity.h index c530660c..e2466187 100644 --- a/include/babeltrace/graph/notification-inactivity.h +++ b/include/babeltrace/graph/notification-inactivity.h @@ -23,39 +23,30 @@ * SOFTWARE. */ -/* For bt_get() */ -#include +#include + +/* For bt_bool */ +#include #ifdef __cplusplus extern "C" { #endif struct bt_notification; -struct bt_clock_class_priority_map; +struct bt_clock_value; struct bt_clock_class; extern struct bt_notification *bt_notification_inactivity_create( - struct bt_graph *graph, - struct bt_clock_class_priority_map *clock_class_priority_map); - -extern struct bt_clock_class_priority_map * -bt_notification_inactivity_borrow_clock_class_priority_map( - struct bt_notification *notification); + struct bt_graph *graph); -static inline -struct bt_clock_class_priority_map * -bt_notification_inactivity_get_clock_class_priority_map( - struct bt_notification *notification) -{ - return bt_get( - bt_notification_inactivity_borrow_clock_class_priority_map( - notification)); -} +extern int bt_notification_inactivity_set_clock_value( + struct bt_notification *notif, + struct bt_clock_class *clock_class, uint64_t raw_value, + bt_bool is_default); -extern struct bt_clock_value *bt_notification_inactivity_borrow_clock_value( - struct bt_notification *notification, - struct bt_clock_class *clock_class); +extern struct bt_clock_value *bt_notification_inactivity_borrow_default_clock_value( + struct bt_notification *notif); #ifdef __cplusplus } diff --git a/include/babeltrace/graph/notification-internal.h b/include/babeltrace/graph/notification-internal.h index 5b7ce539..206c110b 100644 --- a/include/babeltrace/graph/notification-internal.h +++ b/include/babeltrace/graph/notification-internal.h @@ -131,10 +131,6 @@ const char *bt_notification_type_string(enum bt_notification_type type) return "BT_NOTIFICATION_TYPE_PACKET_BEGIN"; case BT_NOTIFICATION_TYPE_PACKET_END: return "BT_NOTIFICATION_TYPE_PACKET_END"; - case BT_NOTIFICATION_TYPE_DISCARDED_EVENTS: - return "BT_NOTIFICATION_TYPE_DISCARDED_EVENTS"; - case BT_NOTIFICATION_TYPE_DISCARDED_PACKETS: - return "BT_NOTIFICATION_TYPE_DISCARDED_PACKETS"; default: return "(unknown)"; } diff --git a/include/babeltrace/graph/notification-stream-internal.h b/include/babeltrace/graph/notification-stream-internal.h index 708d0fae..f34ef510 100644 --- a/include/babeltrace/graph/notification-stream-internal.h +++ b/include/babeltrace/graph/notification-stream-internal.h @@ -30,16 +30,19 @@ #include #include #include +#include #include struct bt_notification_stream_begin { struct bt_notification parent; struct bt_stream *stream; + struct bt_clock_value_set cv_set; }; struct bt_notification_stream_end { struct bt_notification parent; struct bt_stream *stream; + struct bt_clock_value_set cv_set; }; #endif /* BABELTRACE_GRAPH_NOTIFICATION_STREAM_INTERNAL_H */ diff --git a/include/babeltrace/graph/notification-stream.h b/include/babeltrace/graph/notification-stream.h index e016117a..963a95ce 100644 --- a/include/babeltrace/graph/notification-stream.h +++ b/include/babeltrace/graph/notification-stream.h @@ -27,14 +27,21 @@ * SOFTWARE. */ +#include + /* For bt_get() */ #include +/* For bt_bool */ +#include + #ifdef __cplusplus extern "C" { #endif struct bt_notification; +struct bt_clock_class; +struct bt_clock_value; struct bt_stream; extern @@ -57,6 +64,14 @@ struct bt_stream *bt_notification_stream_begin_get_stream( return bt_get(bt_notification_stream_begin_borrow_stream(notification)); } +extern int bt_notification_stream_begin_set_clock_value( + struct bt_notification *notif, + struct bt_clock_class *clock_class, uint64_t raw_value, + bt_bool is_default); + +extern struct bt_clock_value *bt_notification_stream_begin_borrow_default_clock_value( + struct bt_notification *notif); + extern struct bt_stream *bt_notification_stream_end_borrow_stream( struct bt_notification *notification); @@ -67,6 +82,14 @@ struct bt_stream *bt_notification_stream_end_get_stream( return bt_get(bt_notification_stream_end_borrow_stream(notification)); } +extern int bt_notification_stream_end_set_clock_value( + struct bt_notification *notif, + struct bt_clock_class *clock_class, uint64_t raw_value, + bt_bool is_default); + +extern struct bt_clock_value *bt_notification_stream_end_borrow_default_clock_value( + struct bt_notification *notif); + #ifdef __cplusplus } #endif diff --git a/include/babeltrace/graph/notification.h b/include/babeltrace/graph/notification.h index 1f8b7a31..198485b4 100644 --- a/include/babeltrace/graph/notification.h +++ b/include/babeltrace/graph/notification.h @@ -46,8 +46,6 @@ enum bt_notification_type { BT_NOTIFICATION_TYPE_STREAM_END = 3, BT_NOTIFICATION_TYPE_PACKET_BEGIN = 4, BT_NOTIFICATION_TYPE_PACKET_END = 5, - BT_NOTIFICATION_TYPE_DISCARDED_EVENTS = 6, - BT_NOTIFICATION_TYPE_DISCARDED_PACKETS = 7, BT_NOTIFICATION_TYPE_NR, /* Not part of ABI. */ }; diff --git a/lib/ctf-ir/clock-class.c b/lib/ctf-ir/clock-class.c index 5872ef83..88bee776 100644 --- a/lib/ctf-ir/clock-class.c +++ b/lib/ctf-ir/clock-class.c @@ -531,27 +531,6 @@ end: return ret; } -static inline -uint64_t ns_from_value(uint64_t frequency, uint64_t value) -{ - uint64_t ns; - - if (frequency == UINT64_C(1000000000)) { - ns = value; - } else { - double dblres = ((1e9 * (double) value) / (double) frequency); - - if (dblres >= (double) UINT64_MAX) { - /* Overflows uint64_t */ - ns = -1ULL; - } else { - ns = (uint64_t) dblres; - } - } - - return ns; -} - BT_HIDDEN void bt_clock_class_freeze(struct bt_clock_class *clock_class) { @@ -596,152 +575,6 @@ void bt_clock_value_destroy(struct bt_clock_value *clock_value) g_free(clock_value); } -static inline -int ns_from_epoch(struct bt_clock_class *clock_class, uint64_t value, - int64_t *ns_from_epoch, bool *overflows) -{ - int ret = 0; - int64_t diff; - int64_t s_ns; - uint64_t u_ns; - uint64_t cycles; - - *overflows = false; - - /* Initialize nanosecond timestamp to clock's offset in seconds */ - if (clock_class->offset_s <= (INT64_MIN / INT64_C(1000000000)) || - clock_class->offset_s >= (INT64_MAX / INT64_C(1000000000))) { - /* - * Overflow: offset in seconds converted to nanoseconds - * is outside the int64_t range. - */ - *overflows = true; - goto end; - } - - *ns_from_epoch = clock_class->offset_s * INT64_C(1000000000); - - /* Add offset in cycles */ - if (clock_class->offset < 0) { - cycles = (uint64_t) -clock_class->offset; - } else { - cycles = (uint64_t) clock_class->offset; - } - - u_ns = ns_from_value(clock_class->frequency, cycles); - - if (u_ns == UINT64_C(-1) || u_ns >= INT64_MAX) { - /* - * Overflow: offset in cycles converted to nanoseconds - * is outside the int64_t range. - */ - *overflows = true; - goto end; - } - - s_ns = (int64_t) u_ns; - BT_ASSERT(s_ns >= 0); - - if (clock_class->offset < 0) { - if (*ns_from_epoch >= 0) { - /* - * Offset in cycles is negative so it must also - * be negative once converted to nanoseconds. - */ - s_ns = -s_ns; - goto offset_ok; - } - - diff = *ns_from_epoch - INT64_MIN; - - if (s_ns >= diff) { - /* - * Overflow: current timestamp in nanoseconds - * plus the offset in cycles converted to - * nanoseconds is outside the int64_t range. - */ - *overflows = true; - goto end; - } - - /* - * Offset in cycles is negative so it must also be - * negative once converted to nanoseconds. - */ - s_ns = -s_ns; - } else { - if (*ns_from_epoch <= 0) { - goto offset_ok; - } - - diff = INT64_MAX - *ns_from_epoch; - - if (s_ns >= diff) { - /* - * Overflow: current timestamp in nanoseconds - * plus the offset in cycles converted to - * nanoseconds is outside the int64_t range. - */ - *overflows = true; - goto end; - } - } - -offset_ok: - *ns_from_epoch += s_ns; - - /* Add clock value (cycles) */ - u_ns = ns_from_value(clock_class->frequency, value); - - if (u_ns == -1ULL || u_ns >= INT64_MAX) { - /* - * Overflow: value converted to nanoseconds is outside - * the int64_t range. - */ - *overflows = true; - goto end; - } - - s_ns = (int64_t) u_ns; - BT_ASSERT(s_ns >= 0); - - /* Clock value (cycles) is always positive */ - if (*ns_from_epoch <= 0) { - goto value_ok; - } - - diff = INT64_MAX - *ns_from_epoch; - - if (s_ns >= diff) { - /* - * Overflow: current timestamp in nanoseconds plus the - * clock value converted to nanoseconds is outside the - * int64_t range. - */ - *overflows = true; - goto end; - } - -value_ok: - *ns_from_epoch += s_ns; - -end: - if (*overflows) { - *ns_from_epoch = 0; - ret = -1; - } - - return ret; -} - -static -void set_ns_from_epoch(struct bt_clock_value *clock_value) -{ - (void) ns_from_epoch(clock_value->clock_class, - clock_value->value, &clock_value->ns_from_epoch, - &clock_value->ns_from_epoch_overflows); -} - static struct bt_clock_value *bt_clock_value_new(struct bt_clock_class *clock_class) { @@ -842,26 +675,6 @@ void bt_clock_value_recycle(struct bt_clock_value *clock_value) bt_put(clock_class); } -BT_HIDDEN -void bt_clock_value_set_raw_value(struct bt_clock_value *clock_value, - uint64_t cycles) -{ - BT_ASSERT(clock_value); - - clock_value->value = cycles; - set_ns_from_epoch(clock_value); - bt_clock_value_set(clock_value); -} - -int bt_clock_value_set_value(struct bt_clock_value *clock_value, - uint64_t raw_value) -{ - BT_ASSERT_PRE_NON_NULL(clock_value, "Clock value"); - BT_ASSERT_PRE_HOT(clock_value, "Clock value", ": %!+k", clock_value); - bt_clock_value_set_raw_value(clock_value, raw_value); - return 0; -} - int bt_clock_value_get_value(struct bt_clock_value *clock_value, uint64_t *raw_value) { diff --git a/lib/ctf-ir/event-class.c b/lib/ctf-ir/event-class.c index a387b38a..a6295cbe 100644 --- a/lib/ctf-ir/event-class.c +++ b/lib/ctf-ir/event-class.c @@ -325,43 +325,3 @@ int bt_event_class_common_validate_single_clock_class( end: return ret; } - -BT_HIDDEN -int bt_event_class_update_event_pool_clock_values( - struct bt_event_class *event_class) -{ - int ret = 0; - uint64_t i; - struct bt_stream_class *stream_class = - bt_event_class_borrow_stream_class(event_class); - - BT_ASSERT(stream_class->common.clock_class); - - for (i = 0; i < event_class->event_pool.size; i++) { - struct bt_clock_value *cv; - struct bt_event *event = - event_class->event_pool.objects->pdata[i]; - - BT_ASSERT(event); - - cv = g_hash_table_lookup(event->clock_values, - stream_class->common.clock_class); - if (cv) { - continue; - } - - cv = bt_clock_value_create(stream_class->common.clock_class); - if (!cv) { - BT_LIB_LOGE("Cannot create clock value from clock class: " - "%![cc-]+K", stream_class->common.clock_class); - ret = -1; - goto end; - } - - g_hash_table_insert(event->clock_values, - stream_class->common.clock_class, cv); - } - -end: - return ret; -} diff --git a/lib/ctf-ir/event.c b/lib/ctf-ir/event.c index ea552727..9337c4b3 100644 --- a/lib/ctf-ir/event.c +++ b/lib/ctf-ir/event.c @@ -591,26 +591,11 @@ struct bt_event *bt_event_new(struct bt_event_class *event_class) goto error; } - event->clock_values = g_hash_table_new_full(g_direct_hash, - g_direct_equal, NULL, - (GDestroyNotify) bt_clock_value_recycle); - BT_ASSERT(event->clock_values); stream_class = bt_event_class_borrow_stream_class(event_class); BT_ASSERT(stream_class); - - if (stream_class->common.clock_class) { - struct bt_clock_value *clock_value; - - clock_value = bt_clock_value_create( - stream_class->common.clock_class); - if (!clock_value) { - BT_LIB_LOGE("Cannot create clock value from clock class: " - "%![cc-]+K", stream_class->common.clock_class); - goto error; - } - - g_hash_table_insert(event->clock_values, - stream_class->common.clock_class, clock_value); + ret = bt_clock_value_set_initialize(&event->cv_set); + if (ret) { + goto error; } goto end; @@ -688,32 +673,36 @@ void bt_event_destroy(struct bt_event *event) bt_event_common_finalize((void *) event, (void *) bt_field_destroy_recursive, (void *) release_event_header_field); - g_hash_table_destroy(event->clock_values); + bt_clock_value_set_finalize(&event->cv_set); BT_LOGD_STR("Putting event's packet."); bt_put(event->packet); g_free(event); } -struct bt_clock_value *bt_event_borrow_clock_value( - struct bt_event *event, struct bt_clock_class *clock_class) +int bt_event_set_clock_value(struct bt_event *event, + struct bt_clock_class *clock_class, uint64_t raw_value, + bt_bool is_default) +{ + BT_ASSERT_PRE_NON_NULL(event, "Event"); + BT_ASSERT_PRE_NON_NULL(clock_class, "Clock class"); + BT_ASSERT_PRE_HOT(BT_TO_COMMON(event), "Event", ": %!+e", event); + BT_ASSERT_PRE(is_default, + "You can only set a default clock value as of this version."); + return bt_clock_value_set_set_clock_value(&event->cv_set, clock_class, + raw_value, is_default); +} + +struct bt_clock_value *bt_event_borrow_default_clock_value( + struct bt_event *event) { struct bt_clock_value *clock_value = NULL; BT_ASSERT_PRE_NON_NULL(event, "Event"); - BT_ASSERT_PRE_NON_NULL(clock_class, "Clock class"); - clock_value = g_hash_table_lookup(event->clock_values, clock_class); + clock_value = event->cv_set.default_cv; if (!clock_value) { - BT_LOGV("No clock value associated to the given clock class: " - "event-addr=%p, event-class-name=\"%s\", " - "event-class-id=%" PRId64 ", clock-class-addr=%p, " - "clock-class-name=\"%s\"", event, - bt_event_class_common_get_name(event->common.class), - bt_event_class_common_get_id(event->common.class), - clock_class, bt_clock_class_get_name(clock_class)); - goto end; + BT_LIB_LOGV("No default clock value: %![event-]+e", event); } -end: return clock_value; } @@ -752,7 +741,7 @@ int bt_event_move_header(struct bt_event *event, BT_ASSERT_PRE_NON_NULL(event, "Event"); BT_ASSERT_PRE_NON_NULL(field_wrapper, "Header field"); - BT_ASSERT_PRE_HOT(BT_TO_COMMON(event), "Event", ": +%!+e", event); + BT_ASSERT_PRE_HOT(BT_TO_COMMON(event), "Event", ": %!+e", event); stream_class = bt_event_class_borrow_stream_class( bt_event_borrow_class(event)); BT_ASSERT_PRE(stream_class->common.event_header_field_type, diff --git a/lib/ctf-ir/packet.c b/lib/ctf-ir/packet.c index 7df3d32e..ad09416b 100644 --- a/lib/ctf-ir/packet.c +++ b/lib/ctf-ir/packet.c @@ -102,6 +102,9 @@ void bt_packet_reset(struct bt_packet *packet) (void *) packet->context->field, false); bt_field_reset_recursive((void *) packet->context->field); } + + bt_clock_value_set_reset(&packet->begin_cv_set); + bt_clock_value_set_reset(&packet->end_cv_set); } static @@ -193,6 +196,8 @@ void bt_packet_destroy(struct bt_packet *packet) } } + bt_clock_value_set_finalize(&packet->begin_cv_set); + bt_clock_value_set_finalize(&packet->end_cv_set); BT_LOGD_STR("Putting packet's stream."); bt_put(packet->stream); g_free(packet); @@ -253,6 +258,16 @@ struct bt_packet *bt_packet_new(struct bt_stream *stream) } } + if (bt_clock_value_set_initialize(&packet->begin_cv_set)) { + BT_PUT(packet); + goto end; + } + + if (bt_clock_value_set_initialize(&packet->end_cv_set)) { + BT_PUT(packet); + goto end; + } + BT_LOGD("Created packet object: addr=%p", packet); end: @@ -291,7 +306,7 @@ int bt_packet_move_header(struct bt_packet *packet, BT_ASSERT_PRE_NON_NULL(packet, "Event"); BT_ASSERT_PRE_NON_NULL(field_wrapper, "Header field"); - BT_ASSERT_PRE_HOT(packet, "Packet", ": +%!+a", packet); + BT_ASSERT_PRE_HOT(packet, "Packet", ": %!+a", packet); trace = bt_stream_class_borrow_trace( bt_stream_borrow_class(packet->stream)); BT_ASSERT_PRE(trace->common.packet_header_field_type, @@ -317,7 +332,7 @@ int bt_packet_move_context(struct bt_packet *packet, BT_ASSERT_PRE_NON_NULL(packet, "Event"); BT_ASSERT_PRE_NON_NULL(field_wrapper, "Context field"); - BT_ASSERT_PRE_HOT(packet, "Packet", ": +%!+a", packet); + BT_ASSERT_PRE_HOT(packet, "Packet", ": %!+a", packet); stream_class = bt_stream_borrow_class(packet->stream); BT_ASSERT_PRE(stream_class->common.packet_context_field_type, "Stream class has no packet context field type: %!+S", @@ -333,3 +348,57 @@ int bt_packet_move_context(struct bt_packet *packet, packet->context = field_wrapper; return 0; } + +int bt_packet_set_beginning_clock_value(struct bt_packet *packet, + struct bt_clock_class *clock_class, uint64_t raw_value, + bt_bool is_default) +{ + BT_ASSERT_PRE_NON_NULL(packet, "Packet"); + BT_ASSERT_PRE_NON_NULL(clock_class, "Clock class"); + BT_ASSERT_PRE_HOT(packet, "Packet", ": %!+a", packet); + BT_ASSERT_PRE(is_default, + "You can only set a default clock value as of this version."); + return bt_clock_value_set_set_clock_value(&packet->begin_cv_set, + clock_class, raw_value, is_default); +} + +struct bt_clock_value *bt_packet_borrow_default_begin_clock_value( + struct bt_packet *packet) +{ + struct bt_clock_value *clock_value = NULL; + + BT_ASSERT_PRE_NON_NULL(packet, "Packet"); + clock_value = packet->begin_cv_set.default_cv; + if (!clock_value) { + BT_LIB_LOGV("No default clock value: %![packet-]+a", packet); + } + + return clock_value; +} + +int bt_packet_set_end_clock_value(struct bt_packet *packet, + struct bt_clock_class *clock_class, uint64_t raw_value, + bt_bool is_default) +{ + BT_ASSERT_PRE_NON_NULL(packet, "Packet"); + BT_ASSERT_PRE_NON_NULL(clock_class, "Clock class"); + BT_ASSERT_PRE_HOT(packet, "Packet", ": %!+a", packet); + BT_ASSERT_PRE(is_default, + "You can only set a default clock value as of this version."); + return bt_clock_value_set_set_clock_value(&packet->end_cv_set, + clock_class, raw_value, is_default); +} + +struct bt_clock_value *bt_packet_borrow_default_end_clock_value( + struct bt_packet *packet) +{ + struct bt_clock_value *clock_value = NULL; + + BT_ASSERT_PRE_NON_NULL(packet, "Packet"); + clock_value = packet->end_cv_set.default_cv; + if (!clock_value) { + BT_LIB_LOGV("No default clock value: %![packet-]+a", packet); + } + + return clock_value; +} diff --git a/lib/ctf-ir/stream-class.c b/lib/ctf-ir/stream-class.c index 52a5ed6d..03d8ce8f 100644 --- a/lib/ctf-ir/stream-class.c +++ b/lib/ctf-ir/stream-class.c @@ -572,14 +572,11 @@ end: return ret; } -int bt_stream_class_add_event_class( - struct bt_stream_class *stream_class, +int bt_stream_class_add_event_class(struct bt_stream_class *stream_class, struct bt_event_class *event_class) { struct bt_trace *trace; int ret = 0; - uint64_t i; - struct bt_clock_class *old_clock_class; if (!stream_class) { BT_LOGW("Invalid parameter: stream class is NULL: " @@ -588,7 +585,6 @@ int bt_stream_class_add_event_class( goto end; } - old_clock_class = stream_class->common.clock_class; trace = BT_FROM_COMMON(bt_stream_class_common_borrow_trace( BT_TO_COMMON(stream_class))); if (trace && trace->is_static) { @@ -614,28 +610,6 @@ int bt_stream_class_add_event_class( (void) bt_trace_object_modification(&obj, trace); } - if (!old_clock_class && stream_class->common.clock_class) { - /* - * Adding this event class updated the stream class's - * single clock class: make sure all the events which - * exist in event pools have an existing clock value for - * this clock class so that any created event object in - * the future (from a pool or not) has this clock value - * available. - */ - for (i = 0; i < stream_class->common.event_classes->len; i++) { - struct bt_event_class *event_class = - stream_class->common.event_classes->pdata[i]; - - BT_ASSERT(event_class); - ret = bt_event_class_update_event_pool_clock_values( - event_class); - if (ret) { - goto end; - } - } - } - end: return ret; } diff --git a/lib/graph/Makefile.am b/lib/graph/Makefile.am index 4e608569..3dcf50dd 100644 --- a/lib/graph/Makefile.am +++ b/lib/graph/Makefile.am @@ -4,7 +4,6 @@ noinst_LTLIBRARIES = libgraph.la # Graph library libgraph_la_SOURCES = \ - clock-class-priority-map.c \ component.c \ component-class.c \ graph.c \ diff --git a/lib/graph/clock-class-priority-map.c b/lib/graph/clock-class-priority-map.c deleted file mode 100644 index e8f9654b..00000000 --- a/lib/graph/clock-class-priority-map.c +++ /dev/null @@ -1,311 +0,0 @@ -/* - * clock-class-priority-map.c - * - * Copyright 2017 Philippe Proulx - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#define BT_LOG_TAG "CC-PRIO-MAP" -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -static -void bt_clock_class_priority_map_destroy(struct bt_object *obj) -{ - struct bt_clock_class_priority_map *cc_prio_map = (void *) obj; - - BT_LOGD("Destroying component class priority map object: addr=%p", - cc_prio_map); - - if (cc_prio_map->entries) { - BT_LOGD("Putting clock classes."); - g_ptr_array_free(cc_prio_map->entries, TRUE); - } - - if (cc_prio_map->prios) { - g_hash_table_destroy(cc_prio_map->prios); - } - - g_free(cc_prio_map); -} - -struct bt_clock_class_priority_map *bt_clock_class_priority_map_create() -{ - struct bt_clock_class_priority_map *cc_prio_map = NULL; - - BT_LOGD_STR("Creating clock class priority map object."); - - cc_prio_map = g_new0(struct bt_clock_class_priority_map, 1); - if (!cc_prio_map) { - BT_LOGE_STR("Failed to allocate one clock class priority map."); - goto error; - } - - bt_object_init_shared(&cc_prio_map->base, - bt_clock_class_priority_map_destroy); - cc_prio_map->entries = g_ptr_array_new_with_free_func( - (GDestroyNotify) bt_put); - if (!cc_prio_map->entries) { - BT_LOGE_STR("Failed to allocate a GPtrArray."); - goto error; - } - - cc_prio_map->prios = g_hash_table_new_full(g_direct_hash, - g_direct_equal, NULL, (GDestroyNotify) g_free); - if (!cc_prio_map->entries) { - BT_LOGE_STR("Failed to allocate a GHashTable."); - goto error; - } - - BT_LOGD("Created clock class priority map object: addr=%p", - cc_prio_map); - goto end; - -error: - BT_PUT(cc_prio_map); - -end: - return cc_prio_map; -} - -int64_t bt_clock_class_priority_map_get_clock_class_count( - struct bt_clock_class_priority_map *cc_prio_map) -{ - BT_ASSERT_PRE_NON_NULL(cc_prio_map, "Clock class priority map"); - return (int64_t) cc_prio_map->entries->len; -} - -struct bt_clock_class *bt_clock_class_priority_map_borrow_clock_class_by_index( - struct bt_clock_class_priority_map *cc_prio_map, - uint64_t index) -{ - BT_ASSERT_PRE_NON_NULL(cc_prio_map, "Clock class priority map"); - BT_ASSERT_PRE(index < cc_prio_map->entries->len, - "Index is out of bounds: index=%" PRIu64 ", count=%" PRIu64, - index, cc_prio_map->entries->len); - return g_ptr_array_index(cc_prio_map->entries, index); -} - -struct bt_clock_class *bt_clock_class_priority_map_borrow_clock_class_by_name( - struct bt_clock_class_priority_map *cc_prio_map, - const char *name) -{ - size_t i; - struct bt_clock_class *clock_class = NULL; - - BT_ASSERT_PRE_NON_NULL(cc_prio_map, "Clock class priority map"); - BT_ASSERT_PRE_NON_NULL(name, "Name"); - - for (i = 0; i < cc_prio_map->entries->len; i++) { - struct bt_clock_class *cur_cc = - g_ptr_array_index(cc_prio_map->entries, i); - const char *cur_cc_name = - bt_clock_class_get_name(cur_cc); - - BT_ASSERT(cur_cc_name); - - if (strcmp(cur_cc_name, name) == 0) { - clock_class = cur_cc; - goto end; - } - } - -end: - return clock_class; -} - - -struct clock_class_prio { - uint64_t prio; - struct bt_clock_class *clock_class; -}; - -static -void current_highest_prio_gh_func(gpointer key, gpointer value, - gpointer user_data) -{ - struct clock_class_prio *func_data = user_data; - uint64_t *prio = value; - - if (*prio <= func_data->prio) { - func_data->prio = *prio; - func_data->clock_class = key; - } -} - -static -struct clock_class_prio bt_clock_class_priority_map_current_highest_prio( - struct bt_clock_class_priority_map *cc_prio_map) -{ - struct clock_class_prio func_data = { - .prio = -1ULL, - .clock_class = NULL, - }; - - g_hash_table_foreach(cc_prio_map->prios, current_highest_prio_gh_func, - &func_data); - return func_data; -} - -struct bt_clock_class * -bt_clock_class_priority_map_borrow_highest_priority_clock_class( - struct bt_clock_class_priority_map *cc_prio_map) -{ - BT_ASSERT_PRE_NON_NULL(cc_prio_map, "Clock class priority map"); - return cc_prio_map->highest_prio_cc; -} - -int bt_clock_class_priority_map_get_clock_class_priority( - struct bt_clock_class_priority_map *cc_prio_map, - struct bt_clock_class *clock_class, uint64_t *priority) -{ - int ret = 0; - uint64_t *prio; - - BT_ASSERT_PRE_NON_NULL(cc_prio_map, "Clock class priority map"); - BT_ASSERT_PRE_NON_NULL(clock_class, "Clock class"); - BT_ASSERT_PRE_NON_NULL(priority, "Priority"); - prio = g_hash_table_lookup(cc_prio_map->prios, clock_class); - if (!prio) { - BT_LOGV("Clock class does not exist in clock class priority map: " - "cc-prio-map-addr=%p, clock-class-addr=%p, " - "clock-class-name=\"%s\"", - cc_prio_map, clock_class, - bt_clock_class_get_name(clock_class)); - ret = -1; - goto end; - } - - *priority = *prio; - -end: - return ret; -} - -int bt_clock_class_priority_map_add_clock_class( - struct bt_clock_class_priority_map *cc_prio_map, - struct bt_clock_class *clock_class, uint64_t priority) -{ - int ret = 0; - uint64_t *prio_ptr = NULL; - struct clock_class_prio cc_prio; - - // FIXME when available: check - // bt_clock_class_is_valid(clock_class) - BT_ASSERT_PRE_NON_NULL(cc_prio_map, "Clock class priority map"); - BT_ASSERT_PRE_NON_NULL(clock_class, "Clock class"); - BT_ASSERT_PRE_HOT(cc_prio_map, "Clock class priority map", ""); - - /* Check for existing clock class */ - prio_ptr = g_hash_table_lookup(cc_prio_map->prios, clock_class); - if (prio_ptr) { - *prio_ptr = priority; - prio_ptr = NULL; - goto set_highest_prio; - } - - prio_ptr = g_new(uint64_t, 1); - if (!prio_ptr) { - BT_LOGE_STR("Failed to allocate a uint64_t."); - ret = -1; - goto end; - } - - *prio_ptr = priority; - bt_get(clock_class); - g_ptr_array_add(cc_prio_map->entries, clock_class); - g_hash_table_insert(cc_prio_map->prios, clock_class, prio_ptr); - prio_ptr = NULL; - -set_highest_prio: - cc_prio = bt_clock_class_priority_map_current_highest_prio( - cc_prio_map); - BT_ASSERT(cc_prio.clock_class); - cc_prio_map->highest_prio_cc = cc_prio.clock_class; - BT_LOGV("Added clock class to clock class priority map: " - "cc-prio-map-addr=%p, added-clock-class-addr=%p, " - "added-clock-class-name=\"%s\", " - "highest-prio-clock-class-addr=%p, " - "highest-prio-clock-class-name=\"%s\"", - cc_prio_map, clock_class, - bt_clock_class_get_name(clock_class), - cc_prio.clock_class, - bt_clock_class_get_name(cc_prio.clock_class)); - -end: - g_free(prio_ptr); - - return ret; -} - -struct bt_clock_class_priority_map *bt_clock_class_priority_map_copy( - struct bt_clock_class_priority_map *orig_cc_prio_map) -{ - struct bt_clock_class_priority_map *cc_prio_map; - size_t i; - - cc_prio_map = bt_clock_class_priority_map_create(); - if (!cc_prio_map) { - BT_LOGE_STR("Cannot create empty clock class priority map."); - goto error; - } - - for (i = 0; i < orig_cc_prio_map->entries->len; i++) { - struct bt_clock_class *clock_class = - g_ptr_array_index(orig_cc_prio_map->entries, i); - uint64_t *prio = g_hash_table_lookup(orig_cc_prio_map->prios, - clock_class); - int ret = bt_clock_class_priority_map_add_clock_class( - cc_prio_map, clock_class, *prio); - - if (ret) { - BT_LOGE("Cannot add clock class to clock class priority map copy: " - "cc-prio-map-copy-addr=%p, clock-class-addr=%p, " - "clock-class-name=\"%s\"", - cc_prio_map, clock_class, - bt_clock_class_get_name(clock_class)); - goto error; - } - } - - cc_prio_map->highest_prio_cc = orig_cc_prio_map->highest_prio_cc; - BT_LOGD("Copied clock class priority map: " - "original-addr=%p, copy-addr=%p", - orig_cc_prio_map, cc_prio_map); - goto end; - -error: - BT_PUT(cc_prio_map); - -end: - return cc_prio_map; -} diff --git a/lib/graph/iterator.c b/lib/graph/iterator.c index 0deb40c7..fcc00100 100644 --- a/lib/graph/iterator.c +++ b/lib/graph/iterator.c @@ -53,7 +53,6 @@ #include #include #include -#include #include #include #include @@ -69,16 +68,9 @@ */ #define NOTIF_BATCH_SIZE 15 -struct discarded_elements_state { - struct bt_clock_value *cur_begin; - uint64_t cur_count; -}; - struct stream_state { struct bt_stream *stream; /* owned by this */ struct bt_packet *cur_packet; /* owned by this */ - struct discarded_elements_state discarded_packets_state; - struct discarded_elements_state discarded_events_state; uint64_t expected_notif_seq_num; bt_bool is_ended; }; @@ -96,8 +88,6 @@ void destroy_stream_state(struct stream_state *stream_state) bt_put(stream_state->cur_packet); BT_LOGV_STR("Putting stream state's stream."); bt_put(stream_state->stream); - bt_put(stream_state->discarded_packets_state.cur_begin); - bt_put(stream_state->discarded_events_state.cur_begin); g_free(stream_state); } @@ -112,15 +102,6 @@ struct stream_state *create_stream_state(struct bt_stream *stream) goto end; } - /* - * The packet index is a monotonic counter which may not start - * at 0 at the beginning of the stream. We therefore need to - * have an internal object initial state of -1ULL to distinguish - * between initial state and having seen a packet with - * the sequence number 0. - */ - stream_state->discarded_packets_state.cur_count = -1ULL; - /* * We keep a reference to the stream until we know it's ended. */ diff --git a/lib/graph/notification/Makefile.am b/lib/graph/notification/Makefile.am index 2c837b10..dc253eb8 100644 --- a/lib/graph/notification/Makefile.am +++ b/lib/graph/notification/Makefile.am @@ -5,7 +5,4 @@ libgraph_notification_la_SOURCES = \ packet.c \ event.c \ stream.c \ - inactivity.c \ - discarded-events.c \ - discarded-packets.c \ - discarded-elements.c + inactivity.c diff --git a/lib/graph/notification/discarded-elements.c b/lib/graph/notification/discarded-elements.c deleted file mode 100644 index 0dfd7579..00000000 --- a/lib/graph/notification/discarded-elements.c +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright 2017 Philippe Proulx - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#define BT_LOG_TAG "NOTIF-DISCARDED" -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -static -void bt_notification_discarded_elements_destroy(struct bt_object *obj) -{ - struct bt_notification_discarded_elements *notification = - (struct bt_notification_discarded_elements *) obj; - - BT_LOGD("Destroying discarded elements notification: addr=%p", - notification); - BT_LOGD_STR("Putting stream."); - bt_put(notification->stream); - BT_LOGD_STR("Putting beginning clock value."); - bt_put(notification->begin_clock_value); - BT_LOGD_STR("Putting end clock value."); - bt_put(notification->end_clock_value); - g_free(notification); -} - -BT_HIDDEN -struct bt_notification *bt_notification_discarded_elements_create( - struct bt_graph *graph, - enum bt_notification_type type, - struct bt_stream *stream, - struct bt_clock_value *begin_clock_value, - struct bt_clock_value *end_clock_value, - uint64_t count) -{ - struct bt_notification_discarded_elements *notification; - struct bt_notification *ret_notif = NULL; - - BT_ASSERT_PRE_NON_NULL(stream, "Stream"); - BT_LOGD("Creating discarded elements notification object: " - "type=%s, stream-addr=%p, stream-name=\"%s\", " - "begin-clock-value-addr=%p, end-clock-value-addr=%p, " - "count=%" PRIu64, - bt_notification_type_string(type), stream, - bt_stream_get_name(stream), begin_clock_value, - end_clock_value, count); - notification = g_new0(struct bt_notification_discarded_elements, 1); - if (!notification) { - BT_LOGE_STR("Failed to allocate one discarded elements notification."); - goto error; - } - - bt_notification_init(¬ification->parent, type, - bt_notification_discarded_elements_destroy, NULL); - ret_notif = ¬ification->parent; - notification->stream = bt_get(stream); - notification->begin_clock_value = bt_get(begin_clock_value); - notification->end_clock_value = bt_get(end_clock_value); - notification->count = (int64_t) count; - BT_LOGD("Created discarded elements notification object: " - "type=%s, stream-addr=%p, stream-name=\"%s\", " - "begin-clock-value-addr=%p, end-clock-value-addr=%p, " - "count=%" PRIu64 ", addr=%p", - bt_notification_type_string(type), stream, - bt_stream_get_name(stream), begin_clock_value, - end_clock_value, count, ret_notif); - goto end; - -error: - BT_PUT(ret_notif); - -end: - return ret_notif; -} - -BT_HIDDEN -struct bt_clock_value * -bt_notification_discarded_elements_borrow_begin_clock_value( - enum bt_notification_type type, - struct bt_notification *notification) -{ - struct bt_notification_discarded_elements *discarded_elems_notif; - - BT_ASSERT_PRE_NON_NULL(notification, "Notification"); - BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, type); - discarded_elems_notif = container_of(notification, - struct bt_notification_discarded_elements, parent); - return discarded_elems_notif->begin_clock_value; -} - -BT_HIDDEN -struct bt_clock_value * -bt_notification_discarded_elements_borrow_end_clock_value( - enum bt_notification_type type, - struct bt_notification *notification) -{ - struct bt_notification_discarded_elements *discarded_elems_notif; - - BT_ASSERT_PRE_NON_NULL(notification, "Notification"); - BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, type); - discarded_elems_notif = container_of(notification, - struct bt_notification_discarded_elements, parent); - return discarded_elems_notif->end_clock_value; -} - -BT_HIDDEN -int64_t bt_notification_discarded_elements_get_count( - enum bt_notification_type type, - struct bt_notification *notification) -{ - struct bt_notification_discarded_elements *discarded_elems_notif; - - BT_ASSERT_PRE_NON_NULL(notification, "Notification"); - BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, type); - discarded_elems_notif = container_of(notification, - struct bt_notification_discarded_elements, parent); - return discarded_elems_notif->count; -} - -BT_HIDDEN -struct bt_stream *bt_notification_discarded_elements_borrow_stream( - enum bt_notification_type type, - struct bt_notification *notification) -{ - struct bt_notification_discarded_elements *discarded_elems_notif; - - BT_ASSERT_PRE_NON_NULL(notification, "Notification"); - BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, type); - discarded_elems_notif = container_of(notification, - struct bt_notification_discarded_elements, parent); - return discarded_elems_notif->stream; -} diff --git a/lib/graph/notification/event.c b/lib/graph/notification/event.c index ad5d5dd1..a6c7b0ae 100644 --- a/lib/graph/notification/event.c +++ b/lib/graph/notification/event.c @@ -35,8 +35,6 @@ #include #include #include -#include -#include #include #include #include @@ -79,22 +77,19 @@ end: struct bt_notification *bt_notification_event_create( struct bt_graph *graph, struct bt_event_class *event_class, - struct bt_packet *packet, - struct bt_clock_class_priority_map *cc_prio_map) + struct bt_packet *packet) { struct bt_notification_event *notification = NULL; struct bt_event *event; BT_ASSERT_PRE_NON_NULL(event_class, "Event class"); BT_ASSERT_PRE_NON_NULL(packet, "Packet"); - BT_ASSERT_PRE_NON_NULL(cc_prio_map, "Clock class priority map"); BT_LOGD("Creating event notification object: " "event-class-addr=%p, " - "event-class-name=\"%s\", event-class-id=%" PRId64 ", " - "cc-prio-map-addr=%p", + "event-class-name=\"%s\", event-class-id=%" PRId64, event_class, bt_event_class_get_name(event_class), - bt_event_class_get_id(event_class), cc_prio_map); + bt_event_class_get_id(event_class)); BT_ASSERT_PRE(event_class_has_trace(event_class), "Event class is not part of a trace: %!+E", event_class); event = bt_event_create(event_class, packet); @@ -126,21 +121,15 @@ struct bt_notification *bt_notification_event_create( goto error; } - BT_ASSERT(!notification->cc_prio_map); - notification->cc_prio_map = cc_prio_map; - bt_object_get_no_null_check_no_parent_check( - ¬ification->cc_prio_map->base); BT_ASSERT(!notification->event); notification->event = event; - BT_LOGD_STR("Freezing event notification's clock class priority map."); - bt_clock_class_priority_map_freeze(notification->cc_prio_map); BT_LOGD("Created event notification object: " "event-addr=%p, event-class-addr=%p, " "event-class-name=\"%s\", event-class-id=%" PRId64 ", " - "cc-prio-map-addr=%p, notif-addr=%p", + "notif-addr=%p", notification->event, event_class, bt_event_class_get_name(event_class), - bt_event_class_get_id(event_class), cc_prio_map, + bt_event_class_get_id(event_class), notification); goto end; @@ -164,8 +153,6 @@ void bt_notification_event_destroy(struct bt_notification *notif) bt_event_recycle(event_notif->event); } - BT_LOGD_STR("Putting clock class priority map."); - BT_PUT(event_notif->cc_prio_map); g_free(notif); } @@ -188,8 +175,6 @@ void bt_notification_event_recycle(struct bt_notification *notif) BT_LOGD_STR("Recycling event."); bt_event_recycle(event_notif->event); event_notif->event = NULL; - bt_object_put_no_null_check(&event_notif->cc_prio_map->base); - event_notif->cc_prio_map = NULL; graph = notif->graph; notif->graph = NULL; bt_object_pool_recycle_object(&graph->event_notif_pool, notif); @@ -206,16 +191,3 @@ struct bt_event *bt_notification_event_borrow_event( struct bt_notification_event, parent); return event_notification->event; } - -extern struct bt_clock_class_priority_map * -bt_notification_event_borrow_clock_class_priority_map( - struct bt_notification *notification) -{ - struct bt_notification_event *event_notification; - - BT_ASSERT_PRE_NON_NULL(notification, "Notification"); - BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, BT_NOTIFICATION_TYPE_EVENT); - event_notification = container_of(notification, - struct bt_notification_event, parent); - return event_notification->cc_prio_map; -} diff --git a/lib/graph/notification/inactivity.c b/lib/graph/notification/inactivity.c index b6708d3b..fab8f256 100644 --- a/lib/graph/notification/inactivity.c +++ b/lib/graph/notification/inactivity.c @@ -27,8 +27,6 @@ #include #include #include -#include -#include #include #include #include @@ -40,39 +38,18 @@ void bt_notification_inactivity_destroy(struct bt_object *obj) (struct bt_notification_inactivity *) obj; BT_LOGD("Destroying inactivity notification: addr=%p", notification); - BT_LOGD_STR("Putting clock class priority map."); - bt_put(notification->cc_prio_map); - - if (notification->clock_values) { - BT_LOGD_STR("Putting clock values."); - g_hash_table_destroy(notification->clock_values); - } - + bt_clock_value_set_finalize(¬ification->cv_set); g_free(notification); } struct bt_notification *bt_notification_inactivity_create( - struct bt_graph *graph, - struct bt_clock_class_priority_map *cc_prio_map) + struct bt_graph *graph) { struct bt_notification_inactivity *notification; struct bt_notification *ret_notif = NULL; - uint64_t i; + int ret; - if (cc_prio_map) { - /* Function's reference, released at the end */ - bt_get(cc_prio_map); - } else { - cc_prio_map = bt_clock_class_priority_map_create(); - if (!cc_prio_map) { - BT_LOGE_STR("Cannot create empty clock class priority map."); - goto error; - } - } - - BT_LOGD("Creating inactivity notification object: " - "cc-prio-map-addr=%p", - cc_prio_map); + BT_LOGD_STR("Creating inactivity notification object."); notification = g_new0(struct bt_notification_inactivity, 1); if (!notification) { BT_LOGE_STR("Failed to allocate one inactivity notification."); @@ -82,71 +59,50 @@ struct bt_notification *bt_notification_inactivity_create( BT_NOTIFICATION_TYPE_INACTIVITY, bt_notification_inactivity_destroy, NULL); ret_notif = ¬ification->parent; - notification->clock_values = g_hash_table_new_full(g_direct_hash, - g_direct_equal, NULL, (GDestroyNotify) bt_clock_value_recycle); - if (!notification->clock_values) { - BT_LOGE_STR("Failed to allocate a GHashTable."); + ret = bt_clock_value_set_initialize(¬ification->cv_set); + if (ret) { goto error; } - for (i = 0; i < cc_prio_map->entries->len; i++) { - struct bt_clock_value *clock_value; - struct bt_clock_class *clock_class = - cc_prio_map->entries->pdata[i]; - - clock_value = bt_clock_value_create(clock_class); - if (!clock_value) { - BT_LIB_LOGE("Cannot create clock value from clock class: " - "%![cc-]+K", clock_class); - goto error; - } - - g_hash_table_insert(notification->clock_values, - clock_class, clock_value); - } - - notification->cc_prio_map = bt_get(cc_prio_map); - BT_LOGD_STR("Freezing inactivity notification's clock class priority map."); - bt_clock_class_priority_map_freeze(cc_prio_map); - BT_LOGD("Created inactivity notification object: " - "cc-prio-map-addr=%p, notif-addr=%p", - cc_prio_map, ret_notif); + BT_LOGD("Created inactivity notification object: addr=%p", + ret_notif); goto end; error: BT_PUT(ret_notif); end: - bt_put(cc_prio_map); return ret_notif; } -extern struct bt_clock_class_priority_map * -bt_notification_inactivity_borrow_clock_class_priority_map( - struct bt_notification *notification) +int bt_notification_inactivity_set_clock_value(struct bt_notification *notif, + struct bt_clock_class *clock_class, uint64_t raw_value, + bt_bool is_default) { - struct bt_notification_inactivity *inactivity_notification; + struct bt_notification_inactivity *inactivity = (void *) notif; - BT_ASSERT_PRE_NON_NULL(notification, "Notification"); - BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, - BT_NOTIFICATION_TYPE_INACTIVITY); - inactivity_notification = container_of(notification, - struct bt_notification_inactivity, parent); - return inactivity_notification->cc_prio_map; + BT_ASSERT_PRE_NON_NULL(notif, "Notification"); + BT_ASSERT_PRE_NON_NULL(clock_class, "Clock class"); + BT_ASSERT_PRE_HOT(notif, "Notification", ": %!+n", notif); + BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_INACTIVITY); + BT_ASSERT_PRE(is_default, + "You can only set a default clock value as of this version."); + return bt_clock_value_set_set_clock_value(&inactivity->cv_set, + clock_class, raw_value, is_default); } -struct bt_clock_value *bt_notification_inactivity_borrow_clock_value( - struct bt_notification *notification, - struct bt_clock_class *clock_class) +struct bt_clock_value *bt_notification_inactivity_borrow_default_clock_value( + struct bt_notification *notif) { - struct bt_notification_inactivity *inactivity_notification; + struct bt_notification_inactivity *inactivity = (void *) notif; + struct bt_clock_value *clock_value = NULL; + + BT_ASSERT_PRE_NON_NULL(notif, "Notification"); + BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_INACTIVITY); + clock_value = inactivity->cv_set.default_cv; + if (!clock_value) { + BT_LIB_LOGV("No default clock value: %![notif-]+n", notif); + } - BT_ASSERT_PRE_NON_NULL(notification, "Notification"); - BT_ASSERT_PRE_NON_NULL(clock_class, "Clock class"); - BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, - BT_NOTIFICATION_TYPE_INACTIVITY); - inactivity_notification = container_of(notification, - struct bt_notification_inactivity, parent); - return g_hash_table_lookup( - inactivity_notification->clock_values, clock_class); + return clock_value; } diff --git a/lib/graph/notification/stream.c b/lib/graph/notification/stream.c index a1ce7a5a..f8276195 100644 --- a/lib/graph/notification/stream.c +++ b/lib/graph/notification/stream.c @@ -27,12 +27,12 @@ #define BT_LOG_TAG "NOTIF-STREAM" #include +#include #include #include #include #include #include -#include #include static @@ -45,6 +45,7 @@ void bt_notification_stream_end_destroy(struct bt_object *obj) notification); BT_LOGD_STR("Putting stream."); BT_PUT(notification->stream); + bt_clock_value_set_finalize(¬ification->cv_set); g_free(notification); } @@ -53,6 +54,7 @@ struct bt_notification *bt_notification_stream_end_create( { struct bt_notification_stream_end *notification; struct bt_stream_class *stream_class; + int ret; BT_ASSERT_PRE_NON_NULL(stream, "Stream"); stream_class = bt_stream_borrow_class(stream); @@ -75,6 +77,11 @@ struct bt_notification *bt_notification_stream_end_create( BT_NOTIFICATION_TYPE_STREAM_END, bt_notification_stream_end_destroy, NULL); notification->stream = bt_get(stream); + ret = bt_clock_value_set_initialize(¬ification->cv_set); + if (ret) { + goto error; + } + BT_LOGD("Created stream end notification object: " "stream-addr=%p, stream-name=\"%s\", " "stream-class-addr=%p, stream-class-name=\"%s\", " @@ -101,6 +108,38 @@ struct bt_stream *bt_notification_stream_end_borrow_stream( return stream_end->stream; } +int bt_notification_stream_end_set_clock_value(struct bt_notification *notif, + struct bt_clock_class *clock_class, uint64_t raw_value, + bt_bool is_default) +{ + struct bt_notification_stream_end *stream_end = (void *) notif; + + BT_ASSERT_PRE_NON_NULL(notif, "Notification"); + BT_ASSERT_PRE_NON_NULL(clock_class, "Clock class"); + BT_ASSERT_PRE_HOT(notif, "Notification", ": %!+n", notif); + BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_STREAM_END); + BT_ASSERT_PRE(is_default, + "You can only set a default clock value as of this version."); + return bt_clock_value_set_set_clock_value(&stream_end->cv_set, + clock_class, raw_value, is_default); +} + +struct bt_clock_value *bt_notification_stream_end_borrow_default_clock_value( + struct bt_notification *notif) +{ + struct bt_notification_stream_end *stream_end = (void *) notif; + struct bt_clock_value *clock_value = NULL; + + BT_ASSERT_PRE_NON_NULL(notif, "Notification"); + BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_STREAM_END); + clock_value = stream_end->cv_set.default_cv; + if (!clock_value) { + BT_LIB_LOGV("No default clock value: %![notif-]+n", notif); + } + + return clock_value; +} + static void bt_notification_stream_begin_destroy(struct bt_object *obj) { @@ -111,12 +150,14 @@ void bt_notification_stream_begin_destroy(struct bt_object *obj) notification); BT_LOGD_STR("Putting stream."); BT_PUT(notification->stream); + bt_clock_value_set_finalize(¬ification->cv_set); g_free(notification); } struct bt_notification *bt_notification_stream_begin_create( struct bt_graph *graph, struct bt_stream *stream) { + int ret; struct bt_notification_stream_begin *notification; struct bt_stream_class *stream_class; @@ -141,6 +182,11 @@ struct bt_notification *bt_notification_stream_begin_create( BT_NOTIFICATION_TYPE_STREAM_BEGIN, bt_notification_stream_begin_destroy, NULL); notification->stream = bt_get(stream); + ret = bt_clock_value_set_initialize(¬ification->cv_set); + if (ret) { + goto error; + } + BT_LOGD("Created stream beginning notification object: " "stream-addr=%p, stream-name=\"%s\", " "stream-class-addr=%p, stream-class-name=\"%s\", " @@ -166,3 +212,35 @@ struct bt_stream *bt_notification_stream_begin_borrow_stream( struct bt_notification_stream_begin, parent); return stream_begin->stream; } + +int bt_notification_stream_begin_set_clock_value(struct bt_notification *notif, + struct bt_clock_class *clock_class, uint64_t raw_value, + bt_bool is_default) +{ + struct bt_notification_stream_begin *stream_begin = (void *) notif; + + BT_ASSERT_PRE_NON_NULL(notif, "Notification"); + BT_ASSERT_PRE_NON_NULL(clock_class, "Clock class"); + BT_ASSERT_PRE_HOT(notif, "Notification", ": %!+n", notif); + BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_STREAM_BEGIN); + BT_ASSERT_PRE(is_default, + "You can only set a default clock value as of this version."); + return bt_clock_value_set_set_clock_value(&stream_begin->cv_set, + clock_class, raw_value, is_default); +} + +struct bt_clock_value *bt_notification_stream_begin_borrow_default_clock_value( + struct bt_notification *notif) +{ + struct bt_notification_stream_begin *stream_begin = (void *) notif; + struct bt_clock_value *clock_value = NULL; + + BT_ASSERT_PRE_NON_NULL(notif, "Notification"); + BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_STREAM_BEGIN); + clock_value = stream_begin->cv_set.default_cv; + if (!clock_value) { + BT_LIB_LOGV("No default clock value: %![notif-]+n", notif); + } + + return clock_value; +} diff --git a/lib/lib-logging.c b/lib/lib-logging.c index b2d09547..b8ab5745 100644 --- a/lib/lib-logging.c +++ b/lib/lib-logging.c @@ -54,7 +54,6 @@ #include #include #include -#include #include #include #include @@ -63,7 +62,6 @@ #include #include #include -#include #include #include #include @@ -130,12 +128,33 @@ static inline void format_port(char **buf_ch, bool extended, static inline void format_connection(char **buf_ch, bool extended, const char *prefix, struct bt_connection *connection); +static inline void format_clock_value(char **buf_ch, bool extended, + const char *prefix, struct bt_clock_value *clock_value); + static inline void format_object(char **buf_ch, bool extended, const char *prefix, struct bt_object *obj) { BUF_APPEND(", %sref-count=%llu", prefix, obj->ref_count); } +static inline void format_clock_value_set(char **buf_ch, bool extended, + const char *prefix, struct bt_clock_value_set *cv_set) +{ + char tmp_prefix[64]; + + if (!cv_set->clock_values) { + return; + } + + BUF_APPEND(", %ssize=%u", PRFIELD(cv_set->clock_values->len)); + + if (cv_set->default_cv) { + SET_TMP_PREFIX("default-cv-"); + format_clock_value(buf_ch, extended, tmp_prefix, + cv_set->default_cv); + } +} + static inline void format_object_pool(char **buf_ch, bool extended, const char *prefix, struct bt_object_pool *pool) { @@ -878,11 +897,8 @@ static inline void format_event(char **buf_ch, bool extended, return; } - if (event->clock_values) { - BUF_APPEND(", %sclock-value-count=%u", - PRFIELD(g_hash_table_size(event->clock_values))); - } - + SET_TMP_PREFIX("cvs-"); + format_clock_value_set(buf_ch, extended, tmp_prefix, &event->cv_set); packet = bt_event_borrow_packet(event); if (!packet) { return; @@ -947,7 +963,7 @@ static inline void format_clock_value(char **buf_ch, bool extended, const char *prefix, struct bt_clock_value *clock_value) { char tmp_prefix[64]; - BUF_APPEND(", %svalue=%" PRIu64 ", %sns-from-epoch=%" PRId64, + BUF_APPEND(", %sraw-value=%" PRIu64 ", %sns-from-epoch=%" PRId64, PRFIELD(clock_value->value), PRFIELD(clock_value->ns_from_epoch)); @@ -1049,28 +1065,6 @@ static inline void format_notification(char **buf_ch, bool extended, SET_TMP_PREFIX("event-"); format_event(buf_ch, true, tmp_prefix, notif_event->event); - - if (!notif_event->cc_prio_map) { - return; - } - - BUF_APPEND(", %scc-prio-map-addr=%p, %scc-prio-map-cc-count=%u", - PRFIELD(notif_event->cc_prio_map), - PRFIELD(notif_event->cc_prio_map->entries->len)); - break; - } - case BT_NOTIFICATION_TYPE_INACTIVITY: - { - struct bt_notification_inactivity *notif_inactivity = - (void *) notif; - - if (!notif_inactivity->cc_prio_map) { - return; - } - - BUF_APPEND(", %scc-prio-map-addr=%p, %scc-prio-map-cc-count=%u", - PRFIELD(notif_inactivity->cc_prio_map), - PRFIELD(notif_inactivity->cc_prio_map->entries->len)); break; } case BT_NOTIFICATION_TYPE_STREAM_BEGIN: @@ -1109,28 +1103,6 @@ static inline void format_notification(char **buf_ch, bool extended, format_packet(buf_ch, true, tmp_prefix, notif_packet->packet); break; } - case BT_NOTIFICATION_TYPE_DISCARDED_EVENTS: - case BT_NOTIFICATION_TYPE_DISCARDED_PACKETS: - { - struct bt_notification_discarded_elements *notif_discarded = - (void *) notif; - - BUF_APPEND(", %scount=%" PRId64, - PRFIELD(notif_discarded->count)); - - if (notif_discarded->begin_clock_value) { - SET_TMP_PREFIX("begin-clock-value-"); - format_clock_value(buf_ch, true, tmp_prefix, - notif_discarded->begin_clock_value); - } - - if (notif_discarded->end_clock_value) { - SET_TMP_PREFIX("end-clock-value-"); - format_clock_value(buf_ch, true, tmp_prefix, - notif_discarded->end_clock_value); - } - break; - } default: break; } diff --git a/lib/values.c b/lib/values.c index 7514d52a..654d9b7c 100644 --- a/lib/values.c +++ b/lib/values.c @@ -57,7 +57,7 @@ (_value)) #define BT_ASSERT_PRE_VALUE_HOT(_value, _name) \ - BT_ASSERT_PRE_HOT((_value), (_name), ": +%!+v", (_value)) + BT_ASSERT_PRE_HOT((_value), (_name), ": %!+v", (_value)) #define BT_ASSERT_PRE_VALUE_INDEX_IN_BOUNDS(_index, _count) \ BT_ASSERT_PRE((_index) < (_count), \ diff --git a/plugins/ctf/common/metadata/visitor-generate-ir.c b/plugins/ctf/common/metadata/visitor-generate-ir.c index 388c76f9..743b61b1 100644 --- a/plugins/ctf/common/metadata/visitor-generate-ir.c +++ b/plugins/ctf/common/metadata/visitor-generate-ir.c @@ -876,6 +876,8 @@ int get_unary_unsigned(struct bt_list_head *head, uint64_t *value) int ret = 0; struct ctf_node *node; + *value = 0; + if (bt_list_empty(head)) { ret = -1; goto end; diff --git a/plugins/ctf/common/notif-iter/notif-iter.c b/plugins/ctf/common/notif-iter/notif-iter.c index fc9bccc2..8a5089f0 100644 --- a/plugins/ctf/common/notif-iter/notif-iter.c +++ b/plugins/ctf/common/notif-iter/notif-iter.c @@ -130,6 +130,12 @@ struct field_cb_override { void *data; }; +/* Clock value: clock class and raw value */ +struct clock_value { + struct bt_clock_class *clock_class; /* Weak */ + uint64_t raw_value; +}; + /* CTF notification iterator */ struct bt_notif_iter { /* Visit stack */ @@ -151,7 +157,6 @@ struct bt_notif_iter { struct bt_trace *trace; struct bt_stream_class *stream_class; struct bt_event_class *event_class; - struct bt_clock_class_priority_map *cc_prio_map; } meta; /* Current packet header field wrapper (NULL if not created yet) */ @@ -248,6 +253,10 @@ struct bt_notif_iter { /* Current content size (bits) (-1 if unknown) */ int64_t cur_content_size; + /* Current packet default beginning and end clock values */ + struct clock_value cur_packet_begin_cv; + struct clock_value cur_packet_end_cv; + /* * Offset, in the underlying media, of the current packet's start * (-1 if unknown). @@ -561,6 +570,14 @@ enum bt_notif_iter_status buf_ensure_available_bits( return status; } +static inline +void reset_clock_value(struct clock_value *cv) +{ + BT_ASSERT(cv); + cv->clock_class = NULL; + cv->raw_value = UINT64_C(-1); +} + static enum bt_notif_iter_status read_dscope_begin_state( struct bt_notif_iter *notit, @@ -1244,6 +1261,64 @@ enum bt_notif_iter_status read_packet_context_continue_state( STATE_AFTER_STREAM_PACKET_CONTEXT); } +static inline +uint64_t get_field_raw_clock_value(struct bt_field *base_field, + const char *field_name, struct bt_clock_class **user_cc) +{ + struct bt_field *field; + struct bt_field_type *ft; + struct bt_clock_class *clock_class = NULL; + uint64_t val = UINT64_C(-1); + int ret; + + field = bt_field_structure_borrow_field_by_name(base_field, field_name); + if (!field) { + goto end; + } + + ft = bt_field_borrow_type(field); + BT_ASSERT(ft); + + if (!bt_field_type_is_integer(ft)) { + goto end; + } + + clock_class = bt_field_type_integer_borrow_mapped_clock_class(ft); + if (!clock_class) { + goto end; + } + + ret = bt_field_integer_unsigned_get_value(field, &val); + BT_ASSERT(ret == 0); + +end: + *user_cc = clock_class; + return val; +} + +static +void set_current_packet_begin_end(struct bt_notif_iter *notit) +{ + struct bt_clock_class *clock_class; + uint64_t val; + + if (!notit->dscopes.stream_packet_context) { + goto end; + } + + val = get_field_raw_clock_value(notit->dscopes.stream_packet_context, + "timestamp_begin", &clock_class); + notit->cur_packet_begin_cv.clock_class = clock_class; + notit->cur_packet_begin_cv.raw_value = val; + val = get_field_raw_clock_value(notit->dscopes.stream_packet_context, + "timestamp_end", &clock_class); + notit->cur_packet_end_cv.clock_class = clock_class; + notit->cur_packet_end_cv.raw_value = val; + +end: + return; +} + static enum bt_notif_iter_status set_current_packet_content_sizes( struct bt_notif_iter *notit) @@ -1327,14 +1402,19 @@ enum bt_notif_iter_status after_packet_context_state( enum bt_notif_iter_status status; status = set_current_packet_content_sizes(notit); - if (status == BT_NOTIF_ITER_STATUS_OK) { - if (notit->stream_begin_emitted) { - notit->state = STATE_EMIT_NOTIF_NEW_PACKET; - } else { - notit->state = STATE_EMIT_NOTIF_NEW_STREAM; - } + if (status != BT_NOTIF_ITER_STATUS_OK) { + goto end; + } + + set_current_packet_begin_end(notit); + + if (notit->stream_begin_emitted) { + notit->state = STATE_EMIT_NOTIF_NEW_PACKET; + } else { + notit->state = STATE_EMIT_NOTIF_NEW_STREAM; } +end: return status; } @@ -1577,8 +1657,7 @@ enum bt_notif_iter_status set_current_event_notification( notit->packet); BT_ASSERT(notit->graph); notif = bt_notification_event_create(notit->graph, - notit->meta.event_class, notit->packet, - notit->meta.cc_prio_map); + notit->meta.event_class, notit->packet); if (!notif) { BT_LOGE("Cannot create event notification: " "notit-addr=%p, ec-addr=%p, ec-name=\"%s\", " @@ -1970,6 +2049,8 @@ void bt_notif_iter_reset(struct bt_notif_iter *notit) notit->cur_content_size = -1; notit->cur_packet_size = -1; notit->cur_packet_offset = -1; + reset_clock_value(¬it->cur_packet_begin_cv); + reset_clock_value(¬it->cur_packet_end_cv); notit->stream_begin_emitted = false; notit->cur_timestamp_end = NULL; } @@ -2026,6 +2107,8 @@ int bt_notif_iter_switch_packet(struct bt_notif_iter *notit) notit->cur_content_size = -1; notit->cur_packet_size = -1; + reset_clock_value(¬it->cur_packet_begin_cv); + reset_clock_value(¬it->cur_packet_end_cv); notit->cur_sc_field_path_cache = NULL; end: @@ -2717,12 +2800,10 @@ int set_event_clocks(struct bt_notif_iter *notit) while (g_hash_table_iter_next(&iter, (gpointer) &clock_class, (gpointer) &clock_state)) { - struct bt_clock_value *clock_value; - - clock_value = bt_event_borrow_clock_value(notit->event, - clock_class); - if (!clock_value) { - BT_LOGE("Cannot borrow clock value from event with given clock class: " + ret = bt_event_set_clock_value(notit->event, clock_class, + *clock_state, BT_TRUE); + if (ret) { + BT_LOGE("Cannot set event's default clock value: " "notit-addr=%p, clock-class-addr=%p, " "clock-class-name=\"%s\"", notit, clock_class, @@ -2730,12 +2811,10 @@ int set_event_clocks(struct bt_notif_iter *notit) ret = -1; goto end; } - - ret = bt_clock_value_set_value(clock_value, *clock_state); - BT_ASSERT(ret == 0); } ret = 0; + end: return ret; } @@ -2841,6 +2920,30 @@ void notify_new_packet(struct bt_notif_iter *notit, notit->dscopes.stream_packet_context); } + if (notit->cur_packet_begin_cv.clock_class) { + ret = bt_packet_set_beginning_clock_value(notit->packet, + notit->cur_packet_begin_cv.clock_class, + notit->cur_packet_begin_cv.raw_value, BT_TRUE); + if (ret) { + BT_LOGE("Cannot set packet's default beginning clock value: " + "notit-addr=%p, packet-addr=%p", + notit, notit->packet); + goto end; + } + } + + if (notit->cur_packet_end_cv.clock_class) { + ret = bt_packet_set_end_clock_value(notit->packet, + notit->cur_packet_end_cv.clock_class, + notit->cur_packet_end_cv.raw_value, BT_TRUE); + if (ret) { + BT_LOGE("Cannot set packet's default end clock value: " + "notit-addr=%p, packet-addr=%p", + notit, notit->packet); + goto end; + } + } + BT_ASSERT(notit->graph); notif = bt_notification_packet_begin_create(notit->graph, notit->packet); @@ -2848,11 +2951,13 @@ void notify_new_packet(struct bt_notif_iter *notit, BT_LOGE("Cannot create packet beginning notification: " "notit-addr=%p, packet-addr=%p", notit, notit->packet); - return; + goto end; } -end: *notification = notif; + +end: + return; } static @@ -3018,7 +3123,6 @@ void bt_notif_iter_destroy(struct bt_notif_iter *notit) { BT_PUT(notit->packet); BT_PUT(notit->stream); - BT_PUT(notit->meta.cc_prio_map); release_all_dscopes(notit); BT_LOGD("Destroying CTF plugin notification iterator: addr=%p", notit); @@ -3050,7 +3154,6 @@ void bt_notif_iter_destroy(struct bt_notif_iter *notit) enum bt_notif_iter_status bt_notif_iter_get_next_notification( struct bt_notif_iter *notit, - struct bt_clock_class_priority_map *cc_prio_map, struct bt_graph *graph, struct bt_notification **notification) { @@ -3065,15 +3168,9 @@ enum bt_notif_iter_status bt_notif_iter_get_next_notification( goto end; } - if (cc_prio_map != notit->meta.cc_prio_map) { - bt_put(notit->meta.cc_prio_map); - notit->meta.cc_prio_map = bt_get(cc_prio_map); - } - notit->graph = graph; - BT_LOGV("Getting next notification: notit-addr=%p, cc-prio-map-addr=%p", - notit, cc_prio_map); + BT_LOGV("Getting next notification: notit-addr=%p", notit); while (true) { status = handle_state(notit); diff --git a/plugins/ctf/common/notif-iter/notif-iter.h b/plugins/ctf/common/notif-iter/notif-iter.h index ae9b511a..33bd6faf 100644 --- a/plugins/ctf/common/notif-iter/notif-iter.h +++ b/plugins/ctf/common/notif-iter/notif-iter.h @@ -304,8 +304,6 @@ void bt_notif_iter_destroy(struct bt_notif_iter *notif_iter); * call this function again, until another status is returned. * * @param notif_iter CTF notification iterator - * @param cc_prio_map Clock class priority map to use when - * creating an event notification * @param notification Returned notification if the function's * return value is #BT_NOTIF_ITER_STATUS_OK * @returns One of #bt_notif_iter_status values @@ -313,7 +311,6 @@ void bt_notif_iter_destroy(struct bt_notif_iter *notif_iter); BT_HIDDEN enum bt_notif_iter_status bt_notif_iter_get_next_notification( struct bt_notif_iter *notit, - struct bt_clock_class_priority_map *cc_prio_map, struct bt_graph *graph, struct bt_notification **notification); diff --git a/plugins/ctf/fs-src/data-stream-file.c b/plugins/ctf/fs-src/data-stream-file.c index 2fbc3c0c..d51bf109 100644 --- a/plugins/ctf/fs-src/data-stream-file.c +++ b/plugins/ctf/fs-src/data-stream-file.c @@ -826,8 +826,7 @@ enum bt_notification_iterator_status ctf_fs_ds_file_next( enum bt_notification_iterator_status status; notif_iter_status = bt_notif_iter_get_next_notification( - ds_file->notif_iter, ds_file->cc_prio_map, ds_file->graph, - notif); + ds_file->notif_iter, ds_file->graph, notif); switch (notif_iter_status) { case BT_NOTIF_ITER_STATUS_EOF: diff --git a/plugins/ctf/fs-src/fs.c b/plugins/ctf/fs-src/fs.c index eac20e42..4cd70a21 100644 --- a/plugins/ctf/fs-src/fs.c +++ b/plugins/ctf/fs-src/fs.c @@ -964,42 +964,6 @@ end: return ret; } -static -int create_cc_prio_map(struct ctf_fs_trace *ctf_fs_trace) -{ - int ret = 0; - size_t i; - int count; - - BT_ASSERT(ctf_fs_trace); - ctf_fs_trace->cc_prio_map = bt_clock_class_priority_map_create(); - if (!ctf_fs_trace->cc_prio_map) { - ret = -1; - goto end; - } - - count = bt_trace_get_clock_class_count( - ctf_fs_trace->metadata->trace); - BT_ASSERT(count >= 0); - - for (i = 0; i < count; i++) { - struct bt_clock_class *clock_class = - bt_trace_borrow_clock_class_by_index( - ctf_fs_trace->metadata->trace, i); - - BT_ASSERT(clock_class); - ret = bt_clock_class_priority_map_add_clock_class( - ctf_fs_trace->cc_prio_map, clock_class, 0); - - if (ret) { - goto end; - } - } - -end: - return ret; -} - BT_HIDDEN struct ctf_fs_trace *ctf_fs_trace_create(const char *path, const char *name, struct ctf_fs_metadata_config *metadata_config, @@ -1044,11 +1008,6 @@ struct ctf_fs_trace *ctf_fs_trace_create(const char *path, const char *name, goto error; } - ret = create_cc_prio_map(ctf_fs_trace); - if (ret) { - goto error; - } - /* * create_ds_file_groups() created all the streams that this * trace needs. There won't be any more. Therefore it is safe to diff --git a/plugins/text/dmesg/dmesg.c b/plugins/text/dmesg/dmesg.c index 4a3aca80..3bf57ef6 100644 --- a/plugins/text/dmesg/dmesg.c +++ b/plugins/text/dmesg/dmesg.c @@ -259,12 +259,6 @@ int create_meta(struct dmesg_component *dmesg_comp, bool has_ts) goto error; } - dmesg_comp->cc_prio_map = bt_clock_class_priority_map_create(); - if (!dmesg_comp->cc_prio_map) { - BT_LOGE_STR("Cannot create empty clock class priority map."); - goto error; - } - if (has_ts) { dmesg_comp->clock_class = create_clock_class(); if (!dmesg_comp->clock_class) { @@ -279,13 +273,6 @@ int create_meta(struct dmesg_component *dmesg_comp, bool has_ts) goto error; } - ret = bt_clock_class_priority_map_add_clock_class( - dmesg_comp->cc_prio_map, dmesg_comp->clock_class, 0); - if (ret) { - BT_LOGE_STR("Cannot add clock class to clock class priority map."); - goto error; - } - bt_put(ft); ft = create_event_header_ft(dmesg_comp->clock_class); if (!ft) { @@ -677,8 +664,7 @@ skip_ts: } notif = bt_notification_event_create(dmesg_comp->graph, - dmesg_comp->event_class, dmesg_comp->packet, - dmesg_comp->cc_prio_map); + dmesg_comp->event_class, dmesg_comp->packet); if (!notif) { BT_LOGE_STR("Cannot create event notification."); goto error; @@ -688,10 +674,8 @@ skip_ts: BT_ASSERT(event); if (dmesg_comp->clock_class) { - struct bt_clock_value *cv = bt_event_borrow_clock_value(event, - dmesg_comp->clock_class); - - ret = bt_clock_value_set_value(cv, ts); + ret = bt_event_set_clock_value(event, + dmesg_comp->clock_class, ts, BT_TRUE); BT_ASSERT(ret == 0); eh_field = bt_event_borrow_header(event); BT_ASSERT(eh_field); diff --git a/plugins/text/pretty/pretty.c b/plugins/text/pretty/pretty.c index 0caf05bd..1def0826 100644 --- a/plugins/text/pretty/pretty.c +++ b/plugins/text/pretty/pretty.c @@ -140,10 +140,6 @@ enum bt_component_status handle_notification(struct pretty_component *pretty, case BT_NOTIFICATION_TYPE_INACTIVITY: fprintf(stderr, "Inactivity notification\n"); break; - case BT_NOTIFICATION_TYPE_DISCARDED_PACKETS: - case BT_NOTIFICATION_TYPE_DISCARDED_EVENTS: - ret = pretty_print_discarded_elements(pretty, notification); - break; default: break; } diff --git a/plugins/text/pretty/pretty.h b/plugins/text/pretty/pretty.h index 5659035e..76e4217e 100644 --- a/plugins/text/pretty/pretty.h +++ b/plugins/text/pretty/pretty.h @@ -127,9 +127,4 @@ BT_HIDDEN enum bt_component_status pretty_print_event(struct pretty_component *pretty, struct bt_notification *event_notif); -BT_HIDDEN -enum bt_component_status pretty_print_discarded_elements( - struct pretty_component *pretty, - struct bt_notification *notif); - #endif /* BABELTRACE_PLUGIN_TEXT_PRETTY_PRETTY_H */ diff --git a/plugins/text/pretty/print.c b/plugins/text/pretty/print.c index a9e6104d..656d1971 100644 --- a/plugins/text/pretty/print.c +++ b/plugins/text/pretty/print.c @@ -82,14 +82,13 @@ void print_field_name_equal(struct pretty_component *pretty, const char *name) static void print_timestamp_cycles(struct pretty_component *pretty, - struct bt_clock_class *clock_class, struct bt_event *event) { int ret; struct bt_clock_value *clock_value; uint64_t cycles; - clock_value = bt_event_borrow_clock_value(event, clock_class); + clock_value = bt_event_borrow_default_clock_value(event); if (!clock_value) { g_string_append(pretty->string, "????????????????????"); return; @@ -227,16 +226,14 @@ end: static enum bt_component_status print_event_timestamp(struct pretty_component *pretty, - struct bt_event *event, - struct bt_clock_class_priority_map *cc_prio_map, - bool *start_line) + struct bt_event *event, bool *start_line) { bool print_names = pretty->options.print_header_field_names; enum bt_component_status ret = BT_COMPONENT_STATUS_OK; struct bt_stream *stream = NULL; struct bt_stream_class *stream_class = NULL; struct bt_trace *trace = NULL; - struct bt_clock_class *clock_class = NULL; + struct bt_clock_value *clock_value = NULL; stream = bt_event_borrow_stream(event); if (!stream) { @@ -255,16 +252,9 @@ enum bt_component_status print_event_timestamp(struct pretty_component *pretty, goto end; } - if (bt_clock_class_priority_map_get_clock_class_count(cc_prio_map) == 0) { - /* No clock class: skip the timestamp without an error */ - goto end; - } - - clock_class = - bt_clock_class_priority_map_borrow_highest_priority_clock_class( - cc_prio_map); - if (!clock_class) { - ret = BT_COMPONENT_STATUS_ERROR; + clock_value = bt_event_borrow_default_clock_value(event); + if (!clock_value) { + /* No default clock value: skip the timestamp without an error */ goto end; } @@ -277,10 +267,10 @@ enum bt_component_status print_event_timestamp(struct pretty_component *pretty, g_string_append(pretty->string, COLOR_TIMESTAMP); } if (pretty->options.print_timestamp_cycles) { - print_timestamp_cycles(pretty, clock_class, event); + print_timestamp_cycles(pretty, event); } else { struct bt_clock_value *clock_value = - bt_event_borrow_clock_value(event, clock_class); + bt_event_borrow_default_clock_value(event); print_timestamp_wall(pretty, clock_value); } @@ -332,8 +322,7 @@ end: static enum bt_component_status print_event_header(struct pretty_component *pretty, - struct bt_event *event, - struct bt_clock_class_priority_map *cc_prio_map) + struct bt_event *event) { bool print_names = pretty->options.print_header_field_names; enum bt_component_status ret = BT_COMPONENT_STATUS_OK; @@ -357,8 +346,7 @@ enum bt_component_status print_event_header(struct pretty_component *pretty, ret = BT_COMPONENT_STATUS_ERROR; goto end; } - ret = print_event_timestamp(pretty, event, cc_prio_map, - &pretty->start_line); + ret = print_event_timestamp(pretty, event, &pretty->start_line); if (ret != BT_COMPONENT_STATUS_OK) { goto end; } @@ -1485,15 +1473,11 @@ enum bt_component_status pretty_print_event(struct pretty_component *pretty, enum bt_component_status ret; struct bt_event *event = bt_notification_event_borrow_event(event_notif); - struct bt_clock_class_priority_map *cc_prio_map = - bt_notification_event_borrow_clock_class_priority_map( - event_notif); BT_ASSERT(event); - BT_ASSERT(cc_prio_map); pretty->start_line = true; g_string_assign(pretty->string, ""); - ret = print_event_header(pretty, event, cc_prio_map); + ret = print_event_header(pretty, event); if (ret != BT_COMPONENT_STATUS_OK) { goto end; } @@ -1534,121 +1518,3 @@ enum bt_component_status pretty_print_event(struct pretty_component *pretty, end: return ret; } - -BT_HIDDEN -enum bt_component_status pretty_print_discarded_elements( - struct pretty_component *pretty, - struct bt_notification *notif) -{ - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; - struct bt_stream *stream = NULL; - struct bt_stream_class *stream_class = NULL; - struct bt_trace *trace = NULL; - const char *stream_name; - const char *trace_name; - const unsigned char *trace_uuid; - int64_t stream_class_id; - int64_t stream_id; - bool is_discarded_events; - int64_t count; - struct bt_clock_value *clock_value = NULL; - - /* Stream name */ - switch (bt_notification_get_type(notif)) { - case BT_NOTIFICATION_TYPE_DISCARDED_EVENTS: - stream = bt_notification_discarded_events_borrow_stream(notif); - count = bt_notification_discarded_events_get_count(notif); - is_discarded_events = true; - break; - case BT_NOTIFICATION_TYPE_DISCARDED_PACKETS: - stream = bt_notification_discarded_packets_borrow_stream(notif); - count = bt_notification_discarded_packets_get_count(notif); - is_discarded_events = false; - break; - default: - abort(); - } - - BT_ASSERT(stream); - stream_name = bt_stream_get_name(stream); - - /* Stream class ID */ - stream_class = bt_stream_borrow_class(stream); - BT_ASSERT(stream_class); - stream_class_id = bt_stream_class_get_id(stream_class); - - /* Stream ID */ - stream_id = bt_stream_get_id(stream); - - /* Trace path */ - trace = bt_stream_class_borrow_trace(stream_class); - BT_ASSERT(trace); - trace_name = bt_trace_get_name(trace); - if (!trace_name) { - trace_name = "(unknown)"; - } - - /* Trace UUID */ - trace_uuid = bt_trace_get_uuid(trace); - - /* - * Print to standard error stream to remain backward compatible - * with Babeltrace 1. - */ - fprintf(stderr, - "%s%sWARNING%s%s: Tracer discarded %" PRId64 " %s%s between [", - bt_common_color_fg_yellow(), - bt_common_color_bold(), - bt_common_color_reset(), - bt_common_color_fg_yellow(), - count, is_discarded_events ? "event" : "packet", - count == 1 ? "" : "s"); - g_string_assign(pretty->string, ""); - clock_value = is_discarded_events ? - bt_notification_discarded_events_borrow_begin_clock_value(notif) : - bt_notification_discarded_packets_borrow_begin_clock_value(notif); - print_timestamp_wall(pretty, clock_value); - fprintf(stderr, "%s] and [", pretty->string->str); - g_string_assign(pretty->string, ""); - clock_value = is_discarded_events ? - bt_notification_discarded_events_borrow_end_clock_value(notif) : - bt_notification_discarded_packets_borrow_end_clock_value(notif); - print_timestamp_wall(pretty, clock_value); - fprintf(stderr, "%s] in trace \"%s\" ", - pretty->string->str, trace_name); - - if (trace_uuid) { - fprintf(stderr, - "(UUID: %02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x) ", - trace_uuid[0], - trace_uuid[1], - trace_uuid[2], - trace_uuid[3], - trace_uuid[4], - trace_uuid[5], - trace_uuid[6], - trace_uuid[7], - trace_uuid[8], - trace_uuid[9], - trace_uuid[10], - trace_uuid[11], - trace_uuid[12], - trace_uuid[13], - trace_uuid[14], - trace_uuid[15]); - } else { - fprintf(stderr, "(no UUID) "); - } - - fprintf(stderr, "within stream \"%s\" (stream class ID: %" PRId64 ", ", - stream_name, stream_class_id); - - if (stream_id >= 0) { - fprintf(stderr, "stream ID: %" PRId64, stream_id); - } else { - fprintf(stderr, "no stream ID"); - } - - fprintf(stderr, ").%s\n", bt_common_color_reset()); - return ret; -} diff --git a/plugins/utils/counter/counter.c b/plugins/utils/counter/counter.c index bb53a41f..e782a7b7 100644 --- a/plugins/utils/counter/counter.c +++ b/plugins/utils/counter/counter.c @@ -48,8 +48,6 @@ uint64_t get_total_count(struct counter *counter) counter->count.packet_begin + counter->count.packet_end + counter->count.inactivity + - counter->count.discarded_events + - counter->count.discarded_packets + counter->count.other; } @@ -64,14 +62,6 @@ void print_count(struct counter *counter) PRINTF_COUNT("packet beginning", "packet beginnings", packet_begin); PRINTF_COUNT("packet end", "packet ends", packet_end); PRINTF_COUNT("inactivity", "inactivities", inactivity); - PRINTF_COUNT("discarded events notification", - "discarded events notifications", discarded_events_notifs); - PRINTF_COUNT(" known discarded event", " known discarded events", - discarded_events); - PRINTF_COUNT("discarded packets notification", - "discarded packets notifications", discarded_packets_notifs); - PRINTF_COUNT(" known discarded packet", " known discarded packets", - discarded_packets); if (counter->count.other > 0) { PRINTF_COUNT(" other (unknown) notification", @@ -217,7 +207,6 @@ enum bt_component_status counter_consume(struct bt_private_component *component) enum bt_component_status ret = BT_COMPONENT_STATUS_OK; struct counter *counter; enum bt_notification_iterator_status it_ret; - int64_t count; uint64_t notif_count; bt_notification_array notifs; @@ -273,22 +262,6 @@ enum bt_component_status counter_consume(struct bt_private_component *component) case BT_NOTIFICATION_TYPE_PACKET_END: counter->count.packet_end++; break; - case BT_NOTIFICATION_TYPE_DISCARDED_EVENTS: - counter->count.discarded_events_notifs++; - count = bt_notification_discarded_events_get_count( - notif); - if (count >= 0) { - counter->count.discarded_events += count; - } - break; - case BT_NOTIFICATION_TYPE_DISCARDED_PACKETS: - counter->count.discarded_packets_notifs++; - count = bt_notification_discarded_packets_get_count( - notif); - if (count >= 0) { - counter->count.discarded_packets += count; - } - break; default: counter->count.other++; } diff --git a/plugins/utils/counter/counter.h b/plugins/utils/counter/counter.h index aa6e7c8d..8554df58 100644 --- a/plugins/utils/counter/counter.h +++ b/plugins/utils/counter/counter.h @@ -37,10 +37,6 @@ struct counter { uint64_t packet_begin; uint64_t packet_end; uint64_t inactivity; - uint64_t discarded_events_notifs; - uint64_t discarded_events; - uint64_t discarded_packets_notifs; - uint64_t discarded_packets; uint64_t other; } count; uint64_t last_printed_total; diff --git a/plugins/utils/muxer/muxer.c b/plugins/utils/muxer/muxer.c index 2e52f3d7..f3740a35 100644 --- a/plugins/utils/muxer/muxer.c +++ b/plugins/utils/muxer/muxer.c @@ -601,7 +601,6 @@ int get_notif_ts_ns(struct muxer_comp *muxer_comp, struct bt_notification *notif, int64_t last_returned_ts_ns, int64_t *ts_ns) { - struct bt_clock_class_priority_map *cc_prio_map = NULL; struct bt_clock_class *clock_class = NULL; struct bt_clock_value *clock_value = NULL; struct bt_event *event = NULL; @@ -619,14 +618,14 @@ int get_notif_ts_ns(struct muxer_comp *muxer_comp, switch (bt_notification_get_type(notif)) { case BT_NOTIFICATION_TYPE_EVENT: - cc_prio_map = - bt_notification_event_borrow_clock_class_priority_map( - notif); + event = bt_notification_event_borrow_event(notif); + BT_ASSERT(event); + clock_value = bt_event_borrow_default_clock_value(event); break; case BT_NOTIFICATION_TYPE_INACTIVITY: - cc_prio_map = - bt_notification_inactivity_borrow_clock_class_priority_map( + clock_value = + bt_notification_inactivity_borrow_default_clock_value( notif); break; default: @@ -636,33 +635,20 @@ int get_notif_ts_ns(struct muxer_comp *muxer_comp, goto end; } - if (!cc_prio_map) { - BT_LOGE("Cannot get notification's clock class priority map: " - "notif-addr=%p", notif); - goto error; - } - /* - * If the clock class priority map is empty, then we consider - * that this notification has no time. In this case it's always - * the youngest. + * If the clock value is missing, then we consider that this + * notification has no time. In this case it's always the + * youngest. */ - if (bt_clock_class_priority_map_get_clock_class_count(cc_prio_map) == 0) { - BT_LOGV_STR("Notification's clock class priority map contains 0 clock classes: " + if (!clock_value) { + BT_LOGV_STR("Notification's default clock value is missing: " "using the last returned timestamp."); *ts_ns = last_returned_ts_ns; goto end; } - clock_class = - bt_clock_class_priority_map_borrow_highest_priority_clock_class( - cc_prio_map); - if (!clock_class) { - BT_LOGE("Cannot get the clock class with the highest priority from clock class priority map: " - "cc-prio-map-addr=%p", cc_prio_map); - goto error; - } - + clock_class = bt_clock_value_borrow_class(clock_value); + BT_ASSERT(clock_class); cc_uuid = bt_clock_class_get_uuid(clock_class); cc_name = bt_clock_class_get_name(clock_class); @@ -814,30 +800,6 @@ int get_notif_ts_ns(struct muxer_comp *muxer_comp, } } - switch (bt_notification_get_type(notif)) { - case BT_NOTIFICATION_TYPE_EVENT: - event = bt_notification_event_borrow_event(notif); - BT_ASSERT(event); - clock_value = bt_event_borrow_clock_value(event, - clock_class); - break; - case BT_NOTIFICATION_TYPE_INACTIVITY: - clock_value = bt_notification_inactivity_borrow_clock_value( - notif, clock_class); - break; - default: - BT_LOGF("Unexpected notification type at this point: " - "type=%d", bt_notification_get_type(notif)); - abort(); - } - - if (!clock_value) { - BT_LOGE("Cannot get notification's clock value for clock class: " - "clock-class-addr=%p, clock-class-name=\"%s\"", - clock_class, cc_name); - goto error; - } - ret = bt_clock_value_get_value_ns_from_epoch(clock_value, ts_ns); if (ret) { BT_LOGE("Cannot get nanoseconds from Epoch of clock value: " diff --git a/tests/lib/Makefile.am b/tests/lib/Makefile.am index 1ee9fffb..298f24bd 100644 --- a/tests/lib/Makefile.am +++ b/tests/lib/Makefile.am @@ -27,13 +27,11 @@ test_ir_visit_LDADD = $(COMMON_TEST_LDADD) test_graph_topo_LDADD = $(COMMON_TEST_LDADD) -test_cc_prio_map_LDADD = $(COMMON_TEST_LDADD) - test_bt_notification_iterator_LDADD = $(COMMON_TEST_LDADD) noinst_PROGRAMS = test_bitfield test_ctf_writer test_bt_values \ test_ctf_ir_ref test_bt_ctf_field_type_validation test_ir_visit \ - test_graph_topo test_cc_prio_map test_bt_notification_iterator + test_graph_topo test_bt_notification_iterator test_bitfield_SOURCES = test_bitfield.c test_ctf_writer_SOURCES = test_ctf_writer.c @@ -42,7 +40,6 @@ test_ctf_ir_ref_SOURCES = test_ctf_ir_ref.c test_bt_ctf_field_type_validation_SOURCES = test_bt_ctf_field_type_validation.c test_ir_visit_SOURCES = test_ir_visit.c test_graph_topo_SOURCES = test_graph_topo.c -test_cc_prio_map_SOURCES = test_cc_prio_map.c test_bt_notification_iterator_SOURCES = test_bt_notification_iterator.c check_SCRIPTS = test_ctf_writer_complete diff --git a/tests/lib/test_bt_notification_iterator.c b/tests/lib/test_bt_notification_iterator.c index 5ccb91cb..d4511408 100644 --- a/tests/lib/test_bt_notification_iterator.c +++ b/tests/lib/test_bt_notification_iterator.c @@ -30,7 +30,6 @@ #include #include #include -#include #include #include #include @@ -89,7 +88,6 @@ static bool debug = false; static enum test current_test; static GArray *test_events; static struct bt_graph *graph; -static struct bt_clock_class_priority_map *src_empty_cc_prio_map; static struct bt_stream_class *src_stream_class; static struct bt_event_class *src_event_class; static struct bt_stream *src_stream1; @@ -295,8 +293,6 @@ void init_static_data(void) BT_ASSERT(trace); ret = bt_trace_set_packet_header_field_type(trace, empty_struct_ft); BT_ASSERT(ret == 0); - src_empty_cc_prio_map = bt_clock_class_priority_map_create(); - BT_ASSERT(src_empty_cc_prio_map); src_stream_class = bt_stream_class_create("my-stream-class"); BT_ASSERT(src_stream_class); ret = bt_stream_class_set_packet_context_field_type(src_stream_class, @@ -353,7 +349,6 @@ void fini_static_data(void) g_array_free(test_events, TRUE); /* Metadata */ - bt_put(src_empty_cc_prio_map); bt_put(src_stream_class); bt_put(src_event_class); bt_put(src_stream1); @@ -411,8 +406,7 @@ void src_iter_next_seq_one(struct src_iter_user_data *user_data, switch (user_data->seq[user_data->at]) { case SEQ_INACTIVITY: - *notif = bt_notification_inactivity_create(graph, - src_empty_cc_prio_map); + *notif = bt_notification_inactivity_create(graph); break; case SEQ_STREAM1_BEGIN: *notif = bt_notification_stream_begin_create(graph, @@ -478,7 +472,7 @@ void src_iter_next_seq_one(struct src_iter_user_data *user_data, if (event_packet) { *notif = bt_notification_event_create(graph, src_event_class, - event_packet, src_empty_cc_prio_map); + event_packet); } BT_ASSERT(*notif); diff --git a/tests/lib/test_cc_prio_map.c b/tests/lib/test_cc_prio_map.c deleted file mode 100644 index 9982b797..00000000 --- a/tests/lib/test_cc_prio_map.c +++ /dev/null @@ -1,121 +0,0 @@ -/* - * test_cc_prio_map.c - * - * Copyright 2017 - Philippe Proulx - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; under version 2 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#include -#include -#include -#include - -#include "tap/tap.h" - -#define NR_TESTS 17 - -static void test_clock_class_priority_map(void) -{ - struct bt_clock_class_priority_map *cc_prio_map; - struct bt_clock_class_priority_map *cc_prio_map_copy; - struct bt_clock_class *cc1; - struct bt_clock_class *cc2; - struct bt_clock_class *cc3; - struct bt_clock_class *cc; - uint64_t prio; - int ret; - - cc_prio_map = bt_clock_class_priority_map_create(); - ok(cc_prio_map, "bt_clock_class_priority_map_create() succeeds"); - cc1 = bt_clock_class_create("cc1", 1); - BT_ASSERT(cc1); - cc2 = bt_clock_class_create("cc2", 2); - BT_ASSERT(cc2); - cc3 = bt_clock_class_create("cc3", 3); - BT_ASSERT(cc3); - ok(!bt_clock_class_priority_map_get_highest_priority_clock_class(cc_prio_map), - "bt_clock_class_priority_map_get_highest_priority_clock_class() returns NULL when there's no clock classes"); - ret = bt_clock_class_priority_map_add_clock_class(cc_prio_map, cc2, 75); - BT_ASSERT(ret == 0); - cc = bt_clock_class_priority_map_get_highest_priority_clock_class(cc_prio_map); - ok(cc == cc2, - "bt_clock_class_priority_map_get_highest_priority_clock_class() returns the expected clock class (1)"); - BT_PUT(cc); - ret = bt_clock_class_priority_map_add_clock_class(cc_prio_map, cc1, 1001); - BT_ASSERT(ret == 0); - cc = bt_clock_class_priority_map_get_highest_priority_clock_class(cc_prio_map); - ok(cc == cc2, - "bt_clock_class_priority_map_get_highest_priority_clock_class() returns the expected clock class (2)"); - BT_PUT(cc); - ret = bt_clock_class_priority_map_add_clock_class(cc_prio_map, cc3, 11); - BT_ASSERT(ret == 0); - cc = bt_clock_class_priority_map_get_highest_priority_clock_class(cc_prio_map); - ok(cc == cc3, - "bt_clock_class_priority_map_get_highest_priority_clock_class() returns the expected clock class (3)"); - BT_PUT(cc); - ret = bt_clock_class_priority_map_get_clock_class_priority(cc_prio_map, cc1, &prio); - ok(ret == 0, "bt_clock_class_priority_map_get_clock_class_priority() succeeds"); - ok(prio == 1001, - "bt_clock_class_priority_map_get_clock_class_priority() returns the expected priority (1)"); - ret = bt_clock_class_priority_map_get_clock_class_priority(cc_prio_map, cc2, &prio); - BT_ASSERT(ret == 0); - ok(prio == 75, - "bt_clock_class_priority_map_get_clock_class_priority() returns the expected priority (2)"); - ret = bt_clock_class_priority_map_get_clock_class_priority(cc_prio_map, cc3, &prio); - BT_ASSERT(ret == 0); - ok(prio == 11, - "bt_clock_class_priority_map_get_clock_class_priority() returns the expected priority (3)"); - cc_prio_map_copy = bt_clock_class_priority_map_copy(cc_prio_map); - ok(cc_prio_map_copy, "bt_clock_class_priority_map_copy() succeeds"); - ret = bt_clock_class_priority_map_get_clock_class_priority(cc_prio_map_copy, cc1, &prio); - BT_ASSERT(ret == 0); - ok(prio == 1001, - "bt_clock_class_priority_map_get_clock_class_priority() returns the expected priority (1, copy)"); - ret = bt_clock_class_priority_map_get_clock_class_priority(cc_prio_map_copy, cc2, &prio); - BT_ASSERT(ret == 0); - ok(prio == 75, - "bt_clock_class_priority_map_get_clock_class_priority() returns the expected priority (2, copy)"); - ret = bt_clock_class_priority_map_get_clock_class_priority(cc_prio_map_copy, cc3, &prio); - BT_ASSERT(ret == 0); - ok(prio == 11, - "bt_clock_class_priority_map_get_clock_class_priority() returns the expected priority (3, copy)"); - cc = bt_clock_class_priority_map_get_highest_priority_clock_class(cc_prio_map_copy); - ok(cc == cc3, - "bt_clock_class_priority_map_get_highest_priority_clock_class() returns the expected clock class (copy)"); - BT_PUT(cc); - ret = bt_clock_class_priority_map_add_clock_class(cc_prio_map_copy, cc3, 253); - ok(ret == 0, "bt_clock_class_priority_map_add_clock_class() succeeds for an existing clock class"); - ret = bt_clock_class_priority_map_get_clock_class_priority(cc_prio_map_copy, cc3, &prio); - BT_ASSERT(ret == 0); - ok(prio == 253, - "bt_clock_class_priority_map_get_clock_class_priority() returns the expected priority (updated, copy)"); - cc = bt_clock_class_priority_map_get_highest_priority_clock_class(cc_prio_map_copy); - ok(cc == cc2, - "bt_clock_class_priority_map_get_highest_priority_clock_class() returns the expected clock class (updated, copy)"); - BT_PUT(cc); - - BT_PUT(cc3); - BT_PUT(cc2); - BT_PUT(cc1); - BT_PUT(cc_prio_map); - BT_PUT(cc_prio_map_copy); -} - -int main(int argc, char **argv) -{ - plan_tests(NR_TESTS); - test_clock_class_priority_map(); - return exit_status(); -} diff --git a/tests/plugins/test-utils-muxer.c b/tests/plugins/test-utils-muxer.c index ea5b4644..17052313 100644 --- a/tests/plugins/test-utils-muxer.c +++ b/tests/plugins/test-utils-muxer.c @@ -73,8 +73,6 @@ static bool debug = false; static enum test current_test; static GArray *test_events; static struct bt_graph *graph; -static struct bt_clock_class_priority_map *src_cc_prio_map; -static struct bt_clock_class_priority_map *src_empty_cc_prio_map; static struct bt_clock_class *src_clock_class; static struct bt_stream_class *src_stream_class; static struct bt_event_class *src_event_class; @@ -326,13 +324,6 @@ void init_static_data(void) BT_ASSERT(ret == 0); ret = bt_trace_add_clock_class(trace, src_clock_class); BT_ASSERT(ret == 0); - src_empty_cc_prio_map = bt_clock_class_priority_map_create(); - BT_ASSERT(src_empty_cc_prio_map); - src_cc_prio_map = bt_clock_class_priority_map_create(); - BT_ASSERT(src_cc_prio_map); - ret = bt_clock_class_priority_map_add_clock_class(src_cc_prio_map, - src_clock_class, 0); - BT_ASSERT(ret == 0); src_stream_class = bt_stream_class_create("my-stream-class"); BT_ASSERT(src_stream_class); ret = bt_stream_class_set_packet_context_field_type(src_stream_class, @@ -399,8 +390,6 @@ void fini_static_data(void) g_array_free(test_events, TRUE); /* Metadata */ - bt_put(src_empty_cc_prio_map); - bt_put(src_cc_prio_map); bt_put(src_clock_class); bt_put(src_stream_class); bt_put(src_event_class); @@ -507,16 +496,14 @@ enum bt_notification_iterator_status src_iter_init( static struct bt_notification *src_create_event_notif(struct bt_packet *packet, - struct bt_clock_class_priority_map *cc_prio_map, int64_t ts_ns) + int64_t ts_ns) { int ret; struct bt_event *event; struct bt_notification *notif; - struct bt_clock_value *clock_value; struct bt_field *field; - notif = bt_notification_event_create(graph, src_event_class, - packet, cc_prio_map); + notif = bt_notification_event_create(graph, src_event_class, packet); BT_ASSERT(notif); event = bt_notification_event_borrow_event(notif); BT_ASSERT(event); @@ -526,10 +513,13 @@ struct bt_notification *src_create_event_notif(struct bt_packet *packet, BT_ASSERT(field); ret = bt_field_integer_unsigned_set_value(field, (uint64_t) ts_ns); BT_ASSERT(ret == 0); - clock_value = bt_event_borrow_clock_value(event, src_clock_class); - BT_ASSERT(clock_value); - ret = bt_clock_value_set_value(clock_value, (uint64_t) ts_ns); - BT_ASSERT(ret == 0); + + if (ts_ns != UINT64_C(-1)) { + ret = bt_event_set_clock_value(event, src_clock_class, (uint64_t) ts_ns, + BT_TRUE); + BT_ASSERT(ret == 0); + } + return notif; } @@ -578,7 +568,7 @@ enum bt_notification_iterator_status src_iter_next_seq( default: { notifs[0] = src_create_event_notif(user_data->packet, - src_cc_prio_map, cur_ts_ns); + cur_ts_ns); BT_ASSERT(notifs[0]); break; } @@ -634,8 +624,7 @@ enum bt_notification_iterator_status src_iter_next( } else if (user_data->at < 7) { notifs[0] = src_create_event_notif( - user_data->packet, - src_empty_cc_prio_map, 0); + user_data->packet, UINT64_C(-1)); BT_ASSERT(notifs[0]); } else if (user_data->at == 7) { notifs[0] = @@ -760,33 +749,21 @@ void append_test_event_from_notification(struct bt_notification *notification) { int ret; struct test_event test_event; + struct bt_clock_value *cv; switch (bt_notification_get_type(notification)) { case BT_NOTIFICATION_TYPE_EVENT: { struct bt_event *event; - struct bt_clock_class_priority_map *cc_prio_map; test_event.type = TEST_EV_TYPE_NOTIF_EVENT; - cc_prio_map = - bt_notification_event_borrow_clock_class_priority_map( - notification); - BT_ASSERT(cc_prio_map); event = bt_notification_event_borrow_event(notification); BT_ASSERT(event); + cv = bt_event_borrow_default_clock_value(event); - if (bt_clock_class_priority_map_get_clock_class_count(cc_prio_map) > 0) { - struct bt_clock_value *clock_value; - struct bt_clock_class *clock_class = - bt_clock_class_priority_map_borrow_highest_priority_clock_class( - cc_prio_map); - - BT_ASSERT(clock_class); - clock_value = bt_event_borrow_clock_value(event, - clock_class); - BT_ASSERT(clock_value); + if (cv) { ret = bt_clock_value_get_value_ns_from_epoch( - clock_value, &test_event.ts_ns); + cv, &test_event.ts_ns); BT_ASSERT(ret == 0); } else { test_event.ts_ns = -1; @@ -796,26 +773,13 @@ void append_test_event_from_notification(struct bt_notification *notification) } case BT_NOTIFICATION_TYPE_INACTIVITY: { - struct bt_clock_class_priority_map *cc_prio_map; - test_event.type = TEST_EV_TYPE_NOTIF_INACTIVITY; - cc_prio_map = bt_notification_inactivity_borrow_clock_class_priority_map( + cv = bt_notification_inactivity_borrow_default_clock_value( notification); - BT_ASSERT(cc_prio_map); - - if (bt_clock_class_priority_map_get_clock_class_count(cc_prio_map) > 0) { - struct bt_clock_value *clock_value; - struct bt_clock_class *clock_class = - bt_clock_class_priority_map_borrow_highest_priority_clock_class( - cc_prio_map); - - BT_ASSERT(clock_class); - clock_value = - bt_notification_inactivity_borrow_clock_value( - notification, clock_class); - BT_ASSERT(clock_value); + + if (cv) { ret = bt_clock_value_get_value_ns_from_epoch( - clock_value, &test_event.ts_ns); + cv, &test_event.ts_ns); BT_ASSERT(ret == 0); } else { test_event.ts_ns = -1;