2 * Copyright (C) 2020 Francis Deslauriers <francis.deslauriers@efficios.com>
4 * SPDX-License-Identifier: LGPL-2.1-only
8 #ifndef LTTNG_MAP_INTERNAL_H
9 #define LTTNG_MAP_INTERNAL_H
11 #include <common/macros.h>
12 #include <common/optional.h>
13 #include <common/payload.h>
14 #include <common/payload-view.h>
20 struct lttng_payload_view
;
23 /* Reference counting is only exposed to internal users. */
27 LTTNG_OPTIONAL(bool) is_enabled
;
28 enum lttng_map_bitness bitness
;
29 enum lttng_map_boundary_policy boundary_policy
;
30 enum lttng_domain_type domain
;
31 enum lttng_buffer_type buffer_type
;
33 unsigned int dimension_count
;
34 uint64_t *dimension_sizes
;
37 struct lttng_map_list
{
38 struct lttng_dynamic_pointer_array array
;
41 struct lttng_map_key_value_pair
{
48 struct lttng_map_key_value_pair_list
{
49 enum lttng_map_key_value_pair_list_type type
;
50 uint64_t id
; /* pid_t or uid_t */
53 struct lttng_dynamic_pointer_array array
;
56 struct lttng_map_content
{
57 enum lttng_buffer_type type
;
58 struct lttng_dynamic_pointer_array array
;
61 struct lttng_map_comm
{
62 uint32_t name_length
/* Includes '\0' */;
66 uint8_t boundary_policy
;
69 uint8_t coalesce_hits
;;
70 uint64_t dimension_count
;
72 /* length excludes its own length. */
73 /* A name and dimension sizes follow. */
77 struct lttng_map_list_comm
{
79 /* Count * lttng_map_comm structure */
83 struct lttng_map_key_value_pair_comm
{
84 uint32_t key_length
/* Includes '\0' */;
86 uint8_t has_overflowed
;
87 uint8_t has_underflowed
;
90 struct lttng_map_key_value_pair_list_comm
{
92 uint8_t type
; /* enum lttng_map_key_value_pair_list_type */
93 uint64_t id
; /* pid_t or uid_t */
95 uint8_t summed_all_cpus
;
96 /* Count * lttng_map_key_value_pair_comm structure */
100 struct lttng_map_content_comm
{
102 uint8_t type
; /* enum lttng_buffer_type */
103 /* Count * lttng_map_key_value_pair_list structure */
108 ssize_t
lttng_map_create_from_payload(struct lttng_payload_view
*view
,
109 struct lttng_map
**map
);
112 int lttng_map_serialize(const struct lttng_map
*map
,
113 struct lttng_payload
*payload
);
116 void lttng_map_get(struct lttng_map
*map
);
119 void lttng_map_put(struct lttng_map
*map
);
122 void lttng_map_set_is_enabled(struct lttng_map
*map
, bool enabled
);
125 * Allocate a new list of maps.
126 * The returned object must be freed via lttng_map_list_destroy.
129 struct lttng_map_list
*lttng_map_list_create(void);
132 * Add a map to the maps set.
134 * A reference to the added map is acquired on behalf of the map set
138 enum lttng_map_status
lttng_map_list_add(struct lttng_map_list
*map_list
,
139 struct lttng_map
*map
);
142 ssize_t
lttng_map_list_create_from_payload(struct lttng_payload_view
*view
,
143 struct lttng_map_list
**map_list
);
146 * Serialize a map list to an lttng_payload object.
147 * Return LTTNG_OK on success, negative lttng error code on error.
150 int lttng_map_list_serialize(const struct lttng_map_list
*map_list
,
151 struct lttng_payload
*payload
);
154 struct lttng_map_key_value_pair
*lttng_map_key_value_pair_create(
155 const char *key
, int64_t value
);
158 void lttng_map_key_value_pair_set_has_overflowed(
159 struct lttng_map_key_value_pair
*key_value
);
162 void lttng_map_key_value_pair_set_has_underflowed(
163 struct lttng_map_key_value_pair
*key_value
);
166 ssize_t
lttng_map_key_value_pair_create_from_payload(
167 struct lttng_payload_view
*view
,
168 struct lttng_map_key_value_pair
**key_value
);
171 int lttng_map_key_value_pair_serialize(
172 const struct lttng_map_key_value_pair
*key_value
,
173 struct lttng_payload
*payload
);
176 void lttng_map_key_value_pair_destroy(
177 struct lttng_map_key_value_pair
*key_value
);
180 struct lttng_map_key_value_pair_list
*lttng_map_key_value_pair_list_create(
181 enum lttng_map_key_value_pair_list_type type
,
182 bool summed_all_cpus
);
185 enum lttng_map_status
lttng_map_key_value_pair_list_set_identifier(
186 struct lttng_map_key_value_pair_list
*kv_pair_list
,
187 uint64_t identifier
);
190 enum lttng_map_status
lttng_map_key_value_pair_list_set_cpu(
191 struct lttng_map_key_value_pair_list
*kv_pair_list
,
195 enum lttng_map_status
lttng_map_key_value_pair_list_append_key_value(
196 struct lttng_map_key_value_pair_list
*key_values
,
197 struct lttng_map_key_value_pair
*key_value
);
200 ssize_t
lttng_map_key_value_pair_list_create_from_payload(
201 struct lttng_payload_view
*view
,
202 struct lttng_map_key_value_pair_list
**key_values
);
205 int lttng_map_key_value_pair_list_serialize(
206 const struct lttng_map_key_value_pair_list
*key_values
,
207 struct lttng_payload
*payload
);
210 struct lttng_map_content
*lttng_map_content_create(
211 enum lttng_buffer_type type
);
214 enum lttng_map_status
lttng_map_content_append_key_value_list(
215 struct lttng_map_content
*map_content
,
216 struct lttng_map_key_value_pair_list
*kv_list
);
219 ssize_t
lttng_map_content_create_from_payload(
220 struct lttng_payload_view
*view
,
221 struct lttng_map_content
**map_content
);
224 int lttng_map_content_serialize(
225 const struct lttng_map_content
*map_content
,
226 struct lttng_payload
*payload
);
228 #endif /* LTTNG_MAP_INTERNAL_H */