*
*/
-#include <lttng/condition/condition-internal.h>
-#include <lttng/condition/buffer-usage-internal.h>
-#include <common/macros.h>
-#include <common/error.h>
#include <assert.h>
-#include <math.h>
+#include <common/error.h>
+#include <common/macros.h>
+#include <common/mi-lttng.h>
#include <float.h>
+#include <lttng/condition/buffer-usage-internal.h>
+#include <lttng/condition/condition-internal.h>
+#include <math.h>
#include <time.h>
#define IS_USAGE_CONDITION(condition) ( \
lttng_condition_get_type(condition) == LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH \
)
-static
-double fixed_to_double(uint32_t val)
-{
- return (double) val / (double) UINT32_MAX;
-}
-
-static
-uint64_t double_to_fixed(double val)
-{
- return (val * (double) UINT32_MAX);
-}
-
static
bool is_usage_evaluation(const struct lttng_evaluation *evaluation)
{
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) {
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;
usage_comm.domain_type = (int8_t) usage->domain.type;
if (usage->threshold_bytes.set) {
- usage_comm.threshold = usage->threshold_bytes.value;
+ usage_comm.threshold_bytes = usage->threshold_bytes.value;
} else {
- uint64_t val = double_to_fixed(
- usage->threshold_ratio.value);
-
- if (val > UINT32_MAX) {
- /* overflow. */
- ret = -1;
- goto end;
- }
- usage_comm.threshold = val;
+ usage_comm.threshold_ratio = usage->threshold_ratio.value;
}
ret = lttng_dynamic_buffer_append(&payload->buffer, &usage_comm,
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;
+
+ assert(condition);
+ assert(IS_USAGE_CONDITION(condition));
+
+ status = lttng_condition_buffer_usage_get_session_name(
+ condition, &session_name);
+ assert(status == LTTNG_CONDITION_STATUS_OK);
+ assert(session_name);
+
+ status = lttng_condition_buffer_usage_get_channel_name(
+ condition, &channel_name);
+ assert(status == LTTNG_CONDITION_STATUS_OK);
+ assert(session_name);
+
+ status = lttng_condition_buffer_usage_get_domain_type(
+ condition, &domain_type);
+ 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);
+ 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)
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;
}
if (condition_comm->threshold_set_in_bytes) {
status = lttng_condition_buffer_usage_set_threshold(condition,
- condition_comm->threshold);
+ condition_comm->threshold_bytes);
} else {
status = lttng_condition_buffer_usage_set_threshold_ratio(
- condition,
- fixed_to_double(condition_comm->threshold));
+ condition, condition_comm->threshold_ratio);
}
if (status != LTTNG_CONDITION_STATUS_OK) {