SoW-2020-0002: Trace Hit Counters: trigger error reporting integration
[lttng-tools.git] / src / common / evaluation.c
CommitLineData
a58c490f 1/*
ab5be9fa 2 * Copyright (C) 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
a58c490f 3 *
ab5be9fa 4 * SPDX-License-Identifier: LGPL-2.1-only
a58c490f 5 *
a58c490f
JG
6 */
7
2463b787 8#include <lttng/condition/condition-internal.h>
a58c490f
JG
9#include <lttng/condition/evaluation-internal.h>
10#include <lttng/condition/buffer-usage-internal.h>
e8360425 11#include <lttng/condition/session-consumed-size-internal.h>
c19092cd 12#include <lttng/condition/session-rotation-internal.h>
2463b787 13#include <lttng/condition/event-rule-internal.h>
a58c490f
JG
14#include <common/macros.h>
15#include <common/error.h>
16#include <stdbool.h>
17#include <assert.h>
18
c19092cd
JG
19LTTNG_HIDDEN
20void lttng_evaluation_init(struct lttng_evaluation *evaluation,
21 enum lttng_condition_type type)
22{
23 evaluation->type = type;
24}
25
a58c490f 26LTTNG_HIDDEN
9b63a4aa 27int lttng_evaluation_serialize(const struct lttng_evaluation *evaluation,
c0a66c84 28 struct lttng_payload *payload)
a58c490f 29{
3647288f 30 int ret;
db315d75
JG
31 struct lttng_evaluation_comm evaluation_comm = {
32 .type = (int8_t) evaluation->type
33 };
a58c490f 34
c0a66c84 35 ret = lttng_dynamic_buffer_append(&payload->buffer, &evaluation_comm,
3647288f
JG
36 sizeof(evaluation_comm));
37 if (ret) {
38 goto end;
a58c490f 39 }
a58c490f
JG
40
41 if (evaluation->serialize) {
c0a66c84 42 ret = evaluation->serialize(evaluation, payload);
3647288f 43 if (ret) {
a58c490f
JG
44 goto end;
45 }
a58c490f 46 }
a58c490f
JG
47end:
48 return ret;
49}
50
51LTTNG_HIDDEN
c0a66c84 52ssize_t lttng_evaluation_create_from_payload(
2463b787 53 const struct lttng_condition *condition,
c0a66c84 54 struct lttng_payload_view *src_view,
a58c490f
JG
55 struct lttng_evaluation **evaluation)
56{
57 ssize_t ret, evaluation_size = 0;
58 const struct lttng_evaluation_comm *evaluation_comm;
2f571d6f
JG
59 struct lttng_payload_view evaluation_view = src_view ?
60 lttng_payload_view_from_view(src_view,
61 sizeof(*evaluation_comm), -1) :
62 (typeof(evaluation_view)) {};
a58c490f
JG
63
64 if (!src_view || !evaluation) {
65 ret = -1;
66 goto end;
67 }
68
c0a66c84 69 evaluation_comm = (typeof(evaluation_comm)) src_view->buffer.data;
a58c490f
JG
70 evaluation_size += sizeof(*evaluation_comm);
71
72 switch ((enum lttng_condition_type) evaluation_comm->type) {
73 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW:
c0a66c84 74 ret = lttng_evaluation_buffer_usage_low_create_from_payload(
a58c490f
JG
75 &evaluation_view, evaluation);
76 if (ret < 0) {
77 goto end;
78 }
79 evaluation_size += ret;
80 break;
81 case LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH:
c0a66c84 82 ret = lttng_evaluation_buffer_usage_high_create_from_payload(
a58c490f
JG
83 &evaluation_view, evaluation);
84 if (ret < 0) {
85 goto end;
86 }
87 evaluation_size += ret;
88 break;
e8360425 89 case LTTNG_CONDITION_TYPE_SESSION_CONSUMED_SIZE:
c0a66c84 90 ret = lttng_evaluation_session_consumed_size_create_from_payload(
e8360425
JD
91 &evaluation_view, evaluation);
92 if (ret < 0) {
93 goto end;
94 }
95 evaluation_size += ret;
96 break;
c19092cd 97 case LTTNG_CONDITION_TYPE_SESSION_ROTATION_ONGOING:
c0a66c84 98 ret = lttng_evaluation_session_rotation_ongoing_create_from_payload(
c19092cd
JG
99 &evaluation_view, evaluation);
100 if (ret < 0) {
101 goto end;
102 }
103 evaluation_size += ret;
104 break;
105 case LTTNG_CONDITION_TYPE_SESSION_ROTATION_COMPLETED:
c0a66c84 106 ret = lttng_evaluation_session_rotation_completed_create_from_payload(
c19092cd
JG
107 &evaluation_view, evaluation);
108 if (ret < 0) {
109 goto end;
110 }
111 evaluation_size += ret;
112 break;
2463b787
JR
113 case LTTNG_CONDITION_TYPE_EVENT_RULE_HIT:
114 assert(condition);
115 assert(condition->type == LTTNG_CONDITION_TYPE_EVENT_RULE_HIT);
116 ret = lttng_evaluation_event_rule_create_from_payload(
117 container_of(condition,
118 struct lttng_condition_event_rule,
119 parent),
120 &evaluation_view, evaluation);
121 if (ret < 0) {
122 goto end;
123 }
124 evaluation_size += ret;
125 break;
a58c490f
JG
126 default:
127 ERR("Attempted to create evaluation of unknown type (%i)",
128 (int) evaluation_comm->type);
129 ret = -1;
130 goto end;
131 }
c0a66c84 132
a58c490f
JG
133 ret = evaluation_size;
134end:
135 return ret;
136}
137
138enum lttng_condition_type lttng_evaluation_get_type(
139 const struct lttng_evaluation *evaluation)
140{
141 return evaluation ? evaluation->type : LTTNG_CONDITION_TYPE_UNKNOWN;
142}
143
144void lttng_evaluation_destroy(struct lttng_evaluation *evaluation)
145{
146 if (!evaluation) {
147 return;
148 }
149
150 assert(evaluation->destroy);
151 evaluation->destroy(evaluation);
152}
This page took 0.049739 seconds and 5 git commands to generate.