SoW-2020-0002: Trace Hit Counters: trigger error reporting integration
[lttng-tools.git] / include / lttng / trigger / trigger-internal.h
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
8#ifndef LTTNG_TRIGGER_INTERNAL_H
9#define LTTNG_TRIGGER_INTERNAL_H
10
11#include <lttng/trigger/trigger.h>
3da864a9 12#include <common/credentials.h>
2463b787 13#include <common/dynamic-array.h>
a58c490f 14#include <common/macros.h>
3da864a9 15#include <common/optional.h>
a58c490f
JG
16#include <stdint.h>
17#include <stdbool.h>
72756a3f 18#include <sys/types.h>
f01d28b4 19#include <urcu/ref.h>
a58c490f 20
c0a66c84
JG
21struct lttng_payload;
22struct lttng_payload_view;
23
a58c490f 24struct lttng_trigger {
f01d28b4
JR
25 /* Reference counting is only exposed to internal users. */
26 struct urcu_ref ref;
27
a58c490f
JG
28 struct lttng_condition *condition;
29 struct lttng_action *action;
2463b787
JR
30 char *name;
31 /* For now only the uid portion of the credentials is used. */
32 struct lttng_credentials creds;
33 LTTNG_OPTIONAL(uint64_t) error_count;
34 struct {
35 enum lttng_trigger_firing_policy_type type;
36 uint64_t threshold;
37 uint64_t current_count;
38 } firing_policy;
39 /*
40 * Internal use only.
41 * The unique token passed to the tracer to identify a event-rule
42 * notification.
43 */
44 LTTNG_OPTIONAL(uint64_t) tracer_token;
45 /*
46 * Internal use only.
47 * Error accounting counter index.
48 */
49 LTTNG_OPTIONAL(uint64_t) error_counter_index;
50
51 /*
52 * This ordered set is used to hold the capture bytecodoes and their
53 * expression. lttng_action_capture_bytecode_element.
54 * We could only have bytecodes here... the expression are a left over
55 * from the generation process of the set. They are used for comparison
56 * during the gathering process. They are refcounted (TODO) and are the same
57 * object that are present un the underlying action object/s
58 */
59 struct lttng_dynamic_pointer_array capture_bytecode_set;
60};
61
62struct lttng_triggers {
63 struct lttng_dynamic_pointer_array array;
a58c490f
JG
64};
65
66struct lttng_trigger_comm {
67 /* length excludes its own length. */
2463b787 68 uint32_t name_length /* Includes '\0' */;
a58c490f 69 uint32_t length;
2463b787
JR
70 /* Credentials, only the uid portion is used for now */
71 int64_t uid;
72 /* Policy */
73 /* Maps to enum lttng_trigger_firing_policy_type. */
74 uint8_t policy_type;
75 uint64_t policy_threshold;
76 uint64_t error_count;
77 /* A name, condition and action object follow. */
a58c490f
JG
78 char payload[];
79} LTTNG_PACKED;
80
2463b787
JR
81struct lttng_triggers_comm {
82 uint32_t count;
83 uint32_t length;
84 /* Count * lttng_trigger_comm structure */
85 char payload[];
86};
87
a58c490f 88LTTNG_HIDDEN
c0a66c84 89ssize_t lttng_trigger_create_from_payload(struct lttng_payload_view *view,
a58c490f
JG
90 struct lttng_trigger **trigger);
91
92LTTNG_HIDDEN
2463b787 93int lttng_trigger_serialize(const struct lttng_trigger *trigger,
c0a66c84 94 struct lttng_payload *payload);
a58c490f 95
9b63a4aa 96LTTNG_HIDDEN
2463b787
JR
97bool lttng_trigger_validate(const struct lttng_trigger *trigger);
98
99LTTNG_HIDDEN
100int lttng_trigger_assign_name(
101 struct lttng_trigger *dst, const struct lttng_trigger *src);
102
103LTTNG_HIDDEN
104void lttng_trigger_set_tracer_token(
105 struct lttng_trigger *trigger, uint64_t token);
106
107LTTNG_HIDDEN
108uint64_t lttng_trigger_get_tracer_token(const struct lttng_trigger *trigger);
109
110LTTNG_HIDDEN
111void lttng_trigger_set_error_counter_index(
112 struct lttng_trigger *trigger, uint64_t error_counter_index);
9b63a4aa
JG
113
114LTTNG_HIDDEN
2463b787 115uint64_t lttng_trigger_get_error_counter_index(
9b63a4aa
JG
116 const struct lttng_trigger *trigger);
117
a58c490f 118LTTNG_HIDDEN
2463b787
JR
119int lttng_trigger_generate_name(struct lttng_trigger *trigger, uint64_t offset);
120
121LTTNG_HIDDEN
122bool lttng_trigger_is_equal(
123 const struct lttng_trigger *a, const struct lttng_trigger *b);
a58c490f 124
f01d28b4
JR
125LTTNG_HIDDEN
126void lttng_trigger_get(struct lttng_trigger *trigger);
127
128LTTNG_HIDDEN
129void lttng_trigger_put(struct lttng_trigger *trigger);
130
2463b787
JR
131/*
132 * Allocate a new set of lttng_trigger.
133 * The returned object must be freed via lttng_triggers_destroy.
134 */
135LTTNG_HIDDEN
136struct lttng_triggers *lttng_triggers_create(void);
137
138/*
139 * Return the non-const pointer of an element at index "index" of a
140 * lttng_triggers.
141 *
142 * The ownership of the lttng_triggers element is NOT transfered.
143 * The returned object can NOT be freed via lttng_trigger_destroy.
144 */
145LTTNG_HIDDEN
146struct lttng_trigger *lttng_triggers_get_pointer_of_index(
147 const struct lttng_triggers *triggers, unsigned int index);
148
149/*
150 * Add a trigger to the triggers object.
151 */
152LTTNG_HIDDEN
153int lttng_triggers_add(
154 struct lttng_triggers *triggers, struct lttng_trigger *trigger);
155
156/*
157 * Serialize a trigger set to a lttng_payload object.
158 * Return LTTNG_OK on success, negative lttng error code on error.
159 */
160LTTNG_HIDDEN
161int lttng_triggers_serialize(const struct lttng_triggers *triggers,
162 struct lttng_payload *payload);
163
164LTTNG_HIDDEN
165ssize_t lttng_triggers_create_from_payload(struct lttng_payload_view *view,
166 struct lttng_triggers **triggers);
167
3da864a9
JR
168LTTNG_HIDDEN
169const struct lttng_credentials *lttng_trigger_get_credentials(
170 const struct lttng_trigger *trigger);
171
172LTTNG_HIDDEN
2463b787 173void lttng_trigger_set_credentials(struct lttng_trigger *trigger,
3da864a9
JR
174 const struct lttng_credentials *creds);
175
2463b787
JR
176
177/*
178 * Fire the trigger.
179 * Increment the firing count.
180 */
181LTTNG_HIDDEN
182void lttng_trigger_fire(struct lttng_trigger *trigger);
183
184/*
185 * Check if the trigger would fire.
186 */
187LTTNG_HIDDEN
188bool lttng_trigger_should_fire(const struct lttng_trigger *trigger);
189
190LTTNG_HIDDEN
191bool lttng_trigger_is_ready_to_fire(
192 struct lttng_trigger *trigger);
193
194LTTNG_HIDDEN
195uint64_t lttng_trigger_get_error_count(
196 const struct lttng_trigger *trigger);
197
198LTTNG_HIDDEN
199void lttng_trigger_set_error_count(struct lttng_trigger *trigger,
200 uint64_t error_count);
201
202/*
203 * Return the type of any uderlying domain requirement. If no particular
204 * requirement is needed return LTTNG_DOMAIN_NONE.
205 */
206LTTNG_HIDDEN
207enum lttng_domain_type lttng_trigger_get_underlying_domain_type_restriction(
208 const struct lttng_trigger *trigger);
209
210LTTNG_HIDDEN
211struct lttng_trigger *lttng_trigger_copy(const struct lttng_trigger *trigger);
212
213LTTNG_HIDDEN
214unsigned int lttng_trigger_get_capture_bytecode_count(
215 const struct lttng_trigger *trigger);
216
217LTTNG_HIDDEN
218const struct lttng_bytecode *
219lttng_trigger_get_capture_bytecode_at_index(
220 const struct lttng_trigger *trigger, unsigned int index);
221
a58c490f 222#endif /* LTTNG_TRIGGER_INTERNAL_H */
This page took 0.047713 seconds and 5 git commands to generate.