X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Fplugins%2Futils%2Fcounter%2Fcounter.c;h=0bbecd0e5800ecb4362cd65162d6302145c05894;hb=9c08c816a55bbc538957648b49d41354e43c7cdf;hp=42ac5ad6585b310efdad5c1fae0730ad4ace0341;hpb=350ad6c1c5f45a4e90c33e3c1354125c209bbf02;p=babeltrace.git diff --git a/src/plugins/utils/counter/counter.c b/src/plugins/utils/counter/counter.c index 42ac5ad6..0bbecd0e 100644 --- a/src/plugins/utils/counter/counter.c +++ b/src/plugins/utils/counter/counter.c @@ -20,8 +20,10 @@ * SOFTWARE. */ +#define BT_COMP_LOG_SELF_COMP (counter->self_comp) +#define BT_LOG_OUTPUT_LEVEL (counter->log_level) #define BT_LOG_TAG "PLUGIN/FLT.UTILS.COUNTER" -#include "logging.h" +#include "plugins/comp-logging.h" #include #include "common/macros.h" @@ -51,8 +53,6 @@ uint64_t get_total_count(struct counter *counter) return counter->count.event + counter->count.stream_begin + counter->count.stream_end + - counter->count.stream_activity_begin + - counter->count.stream_activity_end + counter->count.packet_begin + counter->count.packet_end + counter->count.disc_events + @@ -69,8 +69,6 @@ void print_count(struct counter *counter) PRINTF_COUNT("Event", event); PRINTF_COUNT("Stream beginning", stream_begin); PRINTF_COUNT("Stream end", stream_end); - PRINTF_COUNT("Stream activity beginning", stream_activity_begin); - PRINTF_COUNT("Stream activity end", stream_activity_end); PRINTF_COUNT("Packet beginning", packet_begin); PRINTF_COUNT("Packet end", packet_end); PRINTF_COUNT("Discarded event", disc_events); @@ -135,25 +133,38 @@ void counter_finalize(bt_self_component_sink *comp) } BT_HIDDEN -bt_self_component_status counter_init( +bt_component_class_init_method_status counter_init( bt_self_component_sink *component, const bt_value *params, __attribute__((unused)) void *init_method_data) { - bt_self_component_status ret; + bt_component_class_init_method_status status = + BT_COMPONENT_CLASS_INIT_METHOD_STATUS_OK; + bt_self_component_add_port_status add_port_status; struct counter *counter = g_new0(struct counter, 1); const bt_value *step = NULL; const bt_value *hide_zero = NULL; if (!counter) { - ret = BT_SELF_COMPONENT_STATUS_NOMEM; + status = BT_COMPONENT_CLASS_INIT_METHOD_STATUS_MEMORY_ERROR; goto error; } - ret = bt_self_component_sink_add_input_port(component, + counter->self_comp = + bt_self_component_sink_as_self_component(component); + counter->log_level = bt_component_get_logging_level( + bt_self_component_as_component(counter->self_comp)); + add_port_status = bt_self_component_sink_add_input_port(component, "in", NULL, NULL); - if (ret != BT_SELF_COMPONENT_STATUS_OK) { + switch (add_port_status) { + case BT_SELF_COMPONENT_ADD_PORT_STATUS_ERROR: + status = BT_COMPONENT_CLASS_INIT_METHOD_STATUS_ERROR; goto error; + case BT_SELF_COMPONENT_ADD_PORT_STATUS_MEMORY_ERROR: + status = BT_COMPONENT_CLASS_INIT_METHOD_STATUS_MEMORY_ERROR; + goto error; + default: + break; } counter->last_printed_total = -1ULL; @@ -161,19 +172,19 @@ bt_self_component_status counter_init( step = bt_value_map_borrow_entry_value_const(params, "step"); if (step) { if (!bt_value_is_unsigned_integer(step)) { - BT_LOGE("`step` parameter: expecting an unsigned integer value: " + BT_COMP_LOGE("`step` parameter: expecting an unsigned integer value: " "type=%s", bt_common_value_type_string( bt_value_get_type(step))); goto error; } - counter->step = bt_value_unsigned_integer_get(step); + counter->step = bt_value_integer_unsigned_get(step); } hide_zero = bt_value_map_borrow_entry_value_const(params, "hide-zero"); if (hide_zero) { if (!bt_value_is_bool(hide_zero)) { - BT_LOGE("`hide-zero` parameter: expecting a boolean value: " + BT_COMP_LOGE("`hide-zero` parameter: expecting a boolean value: " "type=%s", bt_common_value_type_string( bt_value_get_type(hide_zero))); goto error; @@ -189,17 +200,22 @@ bt_self_component_status counter_init( error: destroy_private_counter_data(counter); - ret = BT_SELF_COMPONENT_STATUS_ERROR; + + if (status == BT_COMPONENT_CLASS_INIT_METHOD_STATUS_OK) { + status = BT_COMPONENT_CLASS_INIT_METHOD_STATUS_ERROR; + } end: - return ret; + return status; } BT_HIDDEN -bt_self_component_status counter_graph_is_configured( +bt_component_class_sink_graph_is_configured_method_status +counter_graph_is_configured( bt_self_component_sink *comp) { - bt_self_component_status status = BT_SELF_COMPONENT_STATUS_OK; + bt_component_class_sink_graph_is_configured_method_status status = + BT_COMPONENT_CLASS_SINK_GRAPH_IS_CONFIGURED_METHOD_STATUS_OK; struct counter *counter; bt_self_component_port_input_message_iterator *iterator; @@ -210,7 +226,7 @@ bt_self_component_status counter_graph_is_configured( bt_self_component_sink_borrow_input_port_by_name(comp, in_port_name)); if (!iterator) { - status = BT_SELF_COMPONENT_STATUS_NOMEM; + status = BT_COMPONENT_CLASS_SINK_GRAPH_IS_CONFIGURED_METHOD_STATUS_MEMORY_ERROR; goto end; } @@ -222,12 +238,13 @@ end: } BT_HIDDEN -bt_self_component_status counter_consume( +bt_component_class_sink_consume_method_status counter_consume( bt_self_component_sink *comp) { - bt_self_component_status ret = BT_SELF_COMPONENT_STATUS_OK; + bt_component_class_sink_consume_method_status status = + BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_OK; struct counter *counter; - bt_message_iterator_status it_ret; + bt_message_iterator_next_status next_status; uint64_t msg_count; bt_message_array_const msgs; @@ -237,20 +254,20 @@ bt_self_component_status counter_consume( if (G_UNLIKELY(!counter->msg_iter)) { try_print_last(counter); - ret = BT_SELF_COMPONENT_STATUS_END; + status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_END; goto end; } /* Consume messages */ - it_ret = bt_self_component_port_input_message_iterator_next( + next_status = bt_self_component_port_input_message_iterator_next( counter->msg_iter, &msgs, &msg_count); - if (it_ret < 0) { - ret = BT_SELF_COMPONENT_STATUS_ERROR; + if (next_status < 0) { + status = (int) next_status; goto end; } - switch (it_ret) { - case BT_MESSAGE_ITERATOR_STATUS_OK: + switch (next_status) { + case BT_MESSAGE_ITERATOR_NEXT_STATUS_OK: { uint64_t i; @@ -277,12 +294,6 @@ bt_self_component_status counter_consume( case BT_MESSAGE_TYPE_STREAM_END: counter->count.stream_end++; break; - case BT_MESSAGE_TYPE_STREAM_ACTIVITY_BEGINNING: - counter->count.stream_activity_begin++; - break; - case BT_MESSAGE_TYPE_STREAM_ACTIVITY_END: - counter->count.stream_activity_end++; - break; case BT_MESSAGE_TYPE_DISCARDED_EVENTS: counter->count.disc_events++; break; @@ -296,18 +307,18 @@ bt_self_component_status counter_consume( bt_message_put_ref(msg); } - ret = BT_SELF_COMPONENT_STATUS_OK; + status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_OK; break; } - case BT_MESSAGE_ITERATOR_STATUS_AGAIN: - ret = BT_SELF_COMPONENT_STATUS_AGAIN; + case BT_MESSAGE_ITERATOR_NEXT_STATUS_AGAIN: + status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_AGAIN; goto end; - case BT_MESSAGE_ITERATOR_STATUS_END: + case BT_MESSAGE_ITERATOR_NEXT_STATUS_END: try_print_last(counter); - ret = BT_SELF_COMPONENT_STATUS_END; + status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_END; goto end; - case BT_MESSAGE_ITERATOR_STATUS_NOMEM: - ret = BT_SELF_COMPONENT_STATUS_NOMEM; + case BT_MESSAGE_ITERATOR_NEXT_STATUS_MEMORY_ERROR: + status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_MEMORY_ERROR; goto end; default: break; @@ -316,5 +327,5 @@ bt_self_component_status counter_consume( try_print_count(counter, msg_count); end: - return ret; + return status; }