lttng-ctl: Implement the buffer usage condition evaluation interface
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 27 Feb 2017 23:48:07 +0000 (18:48 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 1 Mar 2017 04:02:50 +0000 (23:02 -0500)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
include/lttng/condition/buffer-usage-internal.h
src/lib/lttng-ctl/buffer-usage.c

index dfe9608df882ed0807837eb00887632dc40e02d0..c3f473cc2d1ccda8b4b915788d3ce2ff75554f6d 100644 (file)
@@ -20,6 +20,7 @@
 
 #include <lttng/condition/buffer-usage.h>
 #include <lttng/condition/condition-internal.h>
+#include <lttng/condition/evaluation-internal.h>
 #include <lttng/domain.h>
 
 struct lttng_condition_buffer_usage {
@@ -41,4 +42,14 @@ struct lttng_condition_buffer_usage {
        } domain;
 };
 
+struct lttng_evaluation_buffer_usage {
+       struct lttng_evaluation parent;
+       uint64_t buffer_use;
+       uint64_t buffer_capacity;
+};
+
+LTTNG_HIDDEN
+struct lttng_evaluation *lttng_evaluation_buffer_usage_create(uint64_t use,
+               uint64_t capacity);
+
 #endif /* LTTNG_CONDITION_BUFFER_USAGE_INTERNAL_H */
index aaa5f2a9de09c698b1c2e1e99400530b0073840c..b6e4c8cd86ebfba1fd095d570aeee8988cc65c52 100644 (file)
@@ -30,10 +30,12 @@ bool is_usage_condition(struct lttng_condition *condition)
 }
 
 static
-bool is_usage_condition(struct lttng_condition *condition)
+bool is_usage_evaluation(struct lttng_evaluation *evaluation)
 {
-       return is_low_usage_condition(condition) ||
-                       is_high_usage_condition(condition);
+       enum lttng_condition_type type = lttng_evaluation_get_type(evaluation);
+
+       return type == LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW ||
+                       type == LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH;
 }
 
 static
@@ -334,3 +336,75 @@ lttng_condition_buffer_usage_set_domain_type(
 end:
        return status;
 }
+
+static
+void lttng_evaluation_buffer_usage_destroy(
+               struct lttng_evaluation *evaluation)
+{
+       struct lttng_evaluation_buffer_usage *usage;
+
+       usage = container_of(evaluation, struct lttng_evaluation_buffer_usage,
+                       parent);
+       free(usage);
+}
+
+LTTNG_HIDDEN
+struct lttng_evaluation *lttng_evaluation_buffer_usage_create(uint64_t use,
+               uint64_t capacity)
+{
+       struct lttng_evaluation_buffer_usage *usage;
+
+       usage = zmalloc(sizeof(struct lttng_evaluation_buffer_usage));
+       if (!usage) {
+               goto end;
+       }
+
+       usage->buffer_use = use;
+       usage->buffer_capacity = capacity;
+       usage->parent.destroy = lttng_evaluation_buffer_usage_destroy;
+end:
+       return &usage->parent;
+}
+
+/*
+ * Get the sampled buffer usage which caused the associated condition to
+ * evaluate to "true".
+ */
+enum lttng_evaluation_status
+lttng_evaluation_buffer_usage_get_usage_percentage(
+               struct lttng_evaluation *evaluation, double *usage_percent)
+{
+       struct lttng_evaluation_buffer_usage *usage;
+       enum lttng_evaluation_status status = LTTNG_EVALUATION_STATUS_OK;
+
+       if (!evaluation || !is_usage_evaluation(evaluation) || !usage_percent) {
+               status = LTTNG_EVALUATION_STATUS_INVALID;
+               goto end;
+       }
+
+       usage = container_of(evaluation, struct lttng_evaluation_buffer_usage,
+                       parent);
+       *usage_percent = (double) usage->buffer_use /
+                       (double) usage->buffer_capacity;
+end:
+       return status;
+}
+
+enum lttng_evaluation_status
+lttng_evaluation_buffer_usage_get_usage(struct lttng_evaluation *evaluation,
+               uint64_t *usage_bytes)
+{
+       struct lttng_evaluation_buffer_usage *usage;
+       enum lttng_evaluation_status status = LTTNG_EVALUATION_STATUS_OK;
+
+       if (!evaluation || !is_usage_evaluation(evaluation) || !usage_bytes) {
+               status = LTTNG_EVALUATION_STATUS_INVALID;
+               goto end;
+       }
+
+       usage = container_of(evaluation, struct lttng_evaluation_buffer_usage,
+                       parent);
+       *usage_bytes = usage->buffer_use;
+end:
+       return status;
+}
This page took 0.028647 seconds and 5 git commands to generate.