X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fcommon%2Fconditions%2Fbuffer-usage.c;h=22da01c7a057f62fd88176f30ff80bb8bd6c34b9;hb=a0377dfefe40662ba7d68617bce6ff467114136c;hp=54affe765d682378649d68fb3e20c2721bd5c4aa;hpb=f66473ac08601dfdbed5a33a8d41957293372b45;p=lttng-tools.git diff --git a/src/common/conditions/buffer-usage.c b/src/common/conditions/buffer-usage.c index 54affe765..22da01c7a 100644 --- a/src/common/conditions/buffer-usage.c +++ b/src/common/conditions/buffer-usage.c @@ -5,13 +5,13 @@ * */ -#include -#include -#include #include -#include -#include +#include +#include #include +#include +#include +#include #include #define IS_USAGE_CONDITION(condition) ( \ @@ -62,8 +62,8 @@ bool lttng_condition_buffer_usage_validate( ERR("Invalid buffer condition: a target channel name must be set."); goto end; } - if (!usage->threshold_ratio.set && !usage->threshold_bytes.set) { - ERR("Invalid buffer condition: a threshold must be set."); + if (usage->threshold_ratio.set == usage->threshold_bytes.set) { + ERR("Invalid buffer condition: a threshold must be set or both type cannot be used simultaneously."); goto end; } if (!usage->domain.set) { @@ -84,7 +84,7 @@ int lttng_condition_buffer_usage_serialize( int ret; struct lttng_condition_buffer_usage *usage; size_t session_name_len, channel_name_len; - struct lttng_condition_buffer_usage_comm usage_comm; + struct lttng_condition_buffer_usage_comm usage_comm = {}; if (!condition || !IS_USAGE_CONDITION(condition)) { ret = -1; @@ -171,20 +171,20 @@ bool lttng_condition_buffer_usage_is_equal(const struct lttng_condition *_a, } /* Condition is not valid if this is not true. */ - assert(a->session_name); - assert(b->session_name); + LTTNG_ASSERT(a->session_name); + LTTNG_ASSERT(b->session_name); if (strcmp(a->session_name, b->session_name)) { goto end; } - assert(a->channel_name); - assert(b->channel_name); + LTTNG_ASSERT(a->channel_name); + LTTNG_ASSERT(b->channel_name); if (strcmp(a->channel_name, b->channel_name)) { goto end; } - assert(a->domain.set); - assert(b->domain.set); + LTTNG_ASSERT(a->domain.set); + LTTNG_ASSERT(b->domain.set); if (a->domain.type != b->domain.type) { goto end; } @@ -193,6 +193,128 @@ end: return is_equal; } +static enum lttng_error_code lttng_condition_buffer_usage_mi_serialize( + const struct lttng_condition *condition, + struct mi_writer *writer) +{ + int ret; + enum lttng_error_code ret_code; + enum lttng_condition_status status; + const char *session_name = NULL, *channel_name = NULL; + enum lttng_domain_type domain_type; + bool is_threshold_bytes = false; + double threshold_ratio; + uint64_t threshold_bytes; + const char *condition_type_str = NULL; + + LTTNG_ASSERT(condition); + LTTNG_ASSERT(IS_USAGE_CONDITION(condition)); + + status = lttng_condition_buffer_usage_get_session_name( + condition, &session_name); + LTTNG_ASSERT(status == LTTNG_CONDITION_STATUS_OK); + LTTNG_ASSERT(session_name); + + status = lttng_condition_buffer_usage_get_channel_name( + condition, &channel_name); + LTTNG_ASSERT(status == LTTNG_CONDITION_STATUS_OK); + LTTNG_ASSERT(session_name); + + status = lttng_condition_buffer_usage_get_domain_type( + condition, &domain_type); + LTTNG_ASSERT(status == LTTNG_CONDITION_STATUS_OK); + + status = lttng_condition_buffer_usage_get_threshold( + condition, &threshold_bytes); + if (status == LTTNG_CONDITION_STATUS_OK) { + is_threshold_bytes = true; + } else if (status != LTTNG_CONDITION_STATUS_UNSET) { + /* Unexpected at this stage. */ + ret_code = LTTNG_ERR_INVALID; + goto end; + } + + if (!is_threshold_bytes) { + status = lttng_condition_buffer_usage_get_threshold_ratio( + condition, &threshold_ratio); + LTTNG_ASSERT(status == LTTNG_CONDITION_STATUS_OK); + } + + switch (lttng_condition_get_type(condition)) { + case LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH: + condition_type_str = + mi_lttng_element_condition_buffer_usage_high; + break; + case LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW: + condition_type_str = + mi_lttng_element_condition_buffer_usage_low; + break; + default: + abort(); + break; + } + + /* Open the sub type condition element. */ + ret = mi_lttng_writer_open_element(writer, condition_type_str); + if (ret) { + goto mi_error; + } + + /* Session name. */ + ret = mi_lttng_writer_write_element_string( + writer, mi_lttng_element_session_name, session_name); + if (ret) { + goto mi_error; + } + + /* Channel name. */ + ret = mi_lttng_writer_write_element_string(writer, + mi_lttng_element_condition_channel_name, channel_name); + if (ret) { + goto mi_error; + } + + /* Domain. */ + ret = mi_lttng_writer_write_element_string(writer, + config_element_domain, + mi_lttng_domaintype_string(domain_type)); + if (ret) { + goto mi_error; + } + + if (is_threshold_bytes) { + /* Usage in bytes. */ + ret = mi_lttng_writer_write_element_unsigned_int(writer, + mi_lttng_element_condition_threshold_bytes, + threshold_bytes); + if (ret) { + goto mi_error; + } + } else { + /* Ratio. */ + ret = mi_lttng_writer_write_element_double(writer, + mi_lttng_element_condition_threshold_ratio, + threshold_ratio); + if (ret) { + goto mi_error; + } + } + + /* Closing sub type condition element. */ + ret = mi_lttng_writer_close_element(writer); + if (ret) { + goto mi_error; + } + + ret_code = LTTNG_OK; + goto end; + +mi_error: + ret_code = LTTNG_ERR_MI_IO_FAIL; +end: + return ret_code; +} + static struct lttng_condition *lttng_condition_buffer_usage_create( enum lttng_condition_type type) @@ -209,6 +331,7 @@ struct lttng_condition *lttng_condition_buffer_usage_create( condition->parent.serialize = lttng_condition_buffer_usage_serialize; condition->parent.equal = lttng_condition_buffer_usage_is_equal; condition->parent.destroy = lttng_condition_buffer_usage_destroy; + condition->parent.mi_serialize = lttng_condition_buffer_usage_mi_serialize; return &condition->parent; }