SoW-2020-0003: Trace Hit Counters
[lttng-tools.git] / src / bin / lttng-sessiond / trace-ust.h
CommitLineData
97ee3a89 1/*
ab5be9fa
MJ
2 * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca>
3 * Copyright (C) 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
97ee3a89 4 *
ab5be9fa 5 * SPDX-License-Identifier: GPL-2.0-only
97ee3a89 6 *
97ee3a89
DG
7 */
8
9#ifndef _LTT_TRACE_UST_H
10#define _LTT_TRACE_UST_H
11
12#include <limits.h>
13#include <urcu/list.h>
bec39940 14
ce2a9e76 15#include <common/defaults.h>
159b042f
JG
16#include <common/hashtable/hashtable.h>
17#include <common/tracker.h>
18#include <lttng/lttng.h>
3bd1e081 19
00e2e675 20#include "consumer.h"
75018ab6 21#include "lttng-ust-ctl.h"
97ee3a89 22
7c1d2758
JG
23struct agent;
24
18eace3b 25struct ltt_ust_ht_key {
ebdb334b 26 uint64_t tracer_token;
18eace3b 27 const char *name;
2b00d462 28 const struct lttng_bytecode *filter;
2106efa0 29 enum lttng_ust_loglevel_type loglevel_type;
b953b8cd 30 int loglevel_value;
7724731b 31 const struct lttng_event_exclusion *exclusion;
ebdb334b 32 struct lttng_map_key *key;
18eace3b
DG
33};
34
f6a9efaa
DG
35/* Context hash table nodes */
36struct ltt_ust_context {
bdf64013 37 struct lttng_ust_context_attr ctx;
bec39940 38 struct lttng_ht_node_ulong node;
31746f93 39 struct cds_list_head list;
97ee3a89
DG
40};
41
42/* UST event */
43struct ltt_ust_event {
37357452 44 unsigned int enabled;
f6a9efaa 45 struct lttng_ust_event attr;
bec39940 46 struct lttng_ht_node_str node;
6b453b5e 47 char *filter_expression;
2b00d462 48 struct lttng_bytecode *filter;
40024f8a 49 struct lttng_event_exclusion *exclusion;
ebdb334b
JR
50
51 /* refcounted */
52 struct lttng_map_key *key;
5b37cc51
JG
53 /*
54 * An internal event is an event which was created by the session daemon
55 * through which, for example, events emitted in Agent domains are
56 * "funelled". This is used to hide internal events from external
57 * clients as they should never be modified by the external world.
58 */
88f06f15 59 bool internal;
2bdd86d4
MD
60};
61
97ee3a89
DG
62/* UST channel */
63struct ltt_ust_channel {
7972aab2 64 uint64_t id; /* unique id per session. */
37357452 65 unsigned int enabled;
51755dc8
JG
66 /*
67 * A UST channel can be part of a userspace sub-domain such as JUL,
68 * Log4j, Python.
69 */
70 enum lttng_domain_type domain;
44d3bd01 71 char name[LTTNG_UST_SYM_NAME_LEN];
ffe60014 72 struct lttng_ust_channel_attr attr;
bec39940 73 struct lttng_ht *ctx;
31746f93 74 struct cds_list_head ctx_list;
bec39940
DG
75 struct lttng_ht *events;
76 struct lttng_ht_node_str node;
1624d5b7
JD
77 uint64_t tracefile_size;
78 uint64_t tracefile_count;
fb83fe64
JD
79 uint64_t per_pid_closed_app_discarded;
80 uint64_t per_pid_closed_app_lost;
e9404c27 81 uint64_t monitor_timer_interval;
97ee3a89
DG
82};
83
ebdb334b
JR
84struct ltt_ust_map_dead_pid_kv_values {
85 pthread_mutex_t lock;
86 struct lttng_ht *dead_app_kv_values_32bits;
87 struct lttng_ht *dead_app_kv_values_64bits;
88};
89
90/* UST map */
91struct ltt_ust_map {
92 uint64_t id; /* unique id per session. */
93 char name[LTTNG_UST_SYM_NAME_LEN];
94 unsigned int enabled;
95 size_t bucket_count;
96 bool coalesce_hits;
97 enum lttng_map_bitness bitness;
98 uint64_t nr_cpu;
99 struct lttng_ht_node_str node;
100 struct lttng_map *map;
101 struct lttng_ht *events;
102 struct ltt_ust_map_dead_pid_kv_values dead_app_kv_values;
103};
104
f6a9efaa
DG
105/* UST domain global (LTTNG_DOMAIN_UST) */
106struct ltt_ust_domain_global {
bec39940 107 struct lttng_ht *channels;
ebdb334b 108 struct lttng_ht *maps;
7972aab2 109 struct cds_list_head registry_buffer_uid_list;
f6a9efaa
DG
110};
111
55c9e7ca 112struct ust_id_tracker_node {
a9ad0c8f
MD
113 struct lttng_ht_node_ulong node;
114};
115
55c9e7ca 116struct ust_id_tracker {
a9ad0c8f
MD
117 struct lttng_ht *ht;
118};
119
97ee3a89
DG
120/* UST session */
121struct ltt_ust_session {
d9bf3ca4 122 uint64_t id; /* Unique identifier of session */
f6a9efaa 123 struct ltt_ust_domain_global domain_global;
fefd409b
DG
124 /* Hash table of agent indexed by agent domain. */
125 struct lttng_ht *agents;
6df2e2c9
MD
126 /* UID/GID of the user owning the session */
127 uid_t uid;
128 gid_t gid;
14fb1ebe
DG
129 /* Is the session active meaning has is been started or stopped. */
130 unsigned int active:1;
00e2e675 131 struct consumer_output *consumer;
f3f0db50
DG
132 /* Sequence number for filters so the tracer knows the ordering. */
133 uint64_t filter_seq_num;
7972aab2
DG
134 /* This indicates which type of buffer this session is set for. */
135 enum lttng_buffer_type buffer_type;
136 /* If set to 1, the buffer_type can not be changed anymore. */
137 int buffer_type_changed;
138 /* For per UID buffer, every buffer reg object is kept of this session */
139 struct cds_list_head buffer_reg_uid_list;
140 /* Next channel ID available for a newly registered channel. */
141 uint64_t next_channel_id;
142 /* Once this value reaches UINT32_MAX, no more id can be allocated. */
143 uint64_t used_channel_id;
2bba9e53
DG
144 /* Tell or not if the session has to output the traces. */
145 unsigned int output_traces;
27babd3a 146 unsigned int snapshot_mode;
85076754 147 unsigned int has_non_default_channel;
ecc48a90 148 unsigned int live_timer_interval; /* usec */
84ad93e8
DG
149
150 /* Metadata channel attributes. */
151 struct lttng_ust_channel_attr metadata_attr;
d7ba1388
MD
152
153 /*
154 * Path where to keep the shared memory files.
155 */
3d071855 156 char root_shm_path[PATH_MAX];
d7ba1388 157 char shm_path[PATH_MAX];
a9ad0c8f 158
82b69413
JG
159 /* Current trace chunk of the ltt_session. */
160 struct lttng_trace_chunk *current_trace_chunk;
55c9e7ca
JR
161
162 /* Trackers used for actual lookup on app registration. */
163 struct ust_id_tracker vpid_tracker;
164 struct ust_id_tracker vuid_tracker;
165 struct ust_id_tracker vgid_tracker;
166
167 /* Tracker list of keys requested by users. */
159b042f
JG
168 struct process_attr_tracker *tracker_vpid;
169 struct process_attr_tracker *tracker_vuid;
170 struct process_attr_tracker *tracker_vgid;
97ee3a89
DG
171};
172
7972aab2
DG
173/*
174 * Validate that the id has reached the maximum allowed or not.
175 *
176 * Return 0 if NOT else 1.
177 */
178static inline int trace_ust_is_max_id(uint64_t id)
179{
180 return (id == UINT64_MAX) ? 1 : 0;
181}
182
183/*
184 * Return next available channel id and increment the used counter. The
185 * trace_ust_is_max_id function MUST be called before in order to validate if
186 * the maximum number of IDs have been reached. If not, it is safe to call this
187 * function.
188 *
189 * Return a unique channel ID. If max is reached, the used_channel_id counter
190 * is returned.
191 */
192static inline uint64_t trace_ust_get_next_chan_id(struct ltt_ust_session *s)
193{
194 if (trace_ust_is_max_id(s->used_channel_id)) {
195 return s->used_channel_id;
196 }
197
198 s->used_channel_id++;
199 return s->next_channel_id++;
200}
201
74d0b642 202#ifdef HAVE_LIBLTTNG_UST_CTL
3bd1e081 203
18eace3b
DG
204int trace_ust_ht_match_event(struct cds_lfht_node *node, const void *_key);
205int trace_ust_ht_match_event_by_name(struct cds_lfht_node *node,
206 const void *_key);
207
97ee3a89
DG
208/*
209 * Lookup functions. NULL is returned if not found.
210 */
18eace3b 211struct ltt_ust_event *trace_ust_find_event(struct lttng_ht *ht,
ebdb334b 212 uint64_t tracer_token, char *name, struct lttng_bytecode *filter,
b953b8cd 213 enum lttng_ust_loglevel_type loglevel_type, int loglevel_value,
ebdb334b
JR
214 struct lttng_event_exclusion *exclusion,
215 struct lttng_map_key *key);
bec39940 216struct ltt_ust_channel *trace_ust_find_channel_by_name(struct lttng_ht *ht,
df4f5a87 217 const char *name);
ebdb334b
JR
218struct ltt_ust_map *trace_ust_find_map_by_name(struct lttng_ht *ht,
219 const char *name);
fefd409b
DG
220struct agent *trace_ust_find_agent(struct ltt_ust_session *session,
221 enum lttng_domain_type domain_type);
97ee3a89
DG
222
223/*
224 * Create functions malloc() the data structure.
225 */
d9bf3ca4 226struct ltt_ust_session *trace_ust_create_session(uint64_t session_id);
51755dc8
JG
227struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *attr,
228 enum lttng_domain_type domain);
ebdb334b
JR
229struct ltt_ust_map *trace_ust_create_map(const struct lttng_map *map);
230enum lttng_error_code trace_ust_create_event(uint64_t tracer_token,
231 const char *ev_name,
232 struct lttng_map_key *key,
233 enum lttng_event_type ev_type,
234 enum lttng_loglevel_type ev_loglevel_type,
235 enum lttng_loglevel ev_loglevel,
6b453b5e 236 char *filter_expression,
2b00d462 237 struct lttng_bytecode *filter,
88f06f15 238 struct lttng_event_exclusion *exclusion,
ebdb334b
JR
239 bool internal_event,
240 struct ltt_ust_event **ust_event);
55cc08a6 241struct ltt_ust_context *trace_ust_create_context(
df4f5a87
JG
242 const struct lttng_event_context *ctx);
243int trace_ust_match_context(const struct ltt_ust_context *uctx,
244 const struct lttng_event_context *ctx);
d5979e4a
DG
245void trace_ust_delete_channel(struct lttng_ht *ht,
246 struct ltt_ust_channel *channel);
ebdb334b
JR
247void trace_ust_delete_map(struct lttng_ht *ht,
248 struct ltt_ust_map *map);
97ee3a89
DG
249
250/*
251 * Destroy functions free() the data structure and remove from linked list if
252 * it's applies.
253 */
254void trace_ust_destroy_session(struct ltt_ust_session *session);
97ee3a89 255void trace_ust_destroy_channel(struct ltt_ust_channel *channel);
ebdb334b 256void trace_ust_destroy_map(struct ltt_ust_map *map);
97ee3a89 257void trace_ust_destroy_event(struct ltt_ust_event *event);
bdf64013 258void trace_ust_destroy_context(struct ltt_ust_context *ctx);
d070c424 259void trace_ust_free_session(struct ltt_ust_session *session);
97ee3a89 260
159b042f 261int trace_ust_id_tracker_lookup(enum lttng_process_attr process_attr,
55c9e7ca 262 struct ltt_ust_session *session,
159b042f
JG
263 int id);
264enum lttng_error_code trace_ust_process_attr_tracker_set_tracking_policy(
55c9e7ca 265 struct ltt_ust_session *session,
159b042f
JG
266 enum lttng_process_attr process_attr,
267 enum lttng_tracking_policy policy);
268enum lttng_error_code trace_ust_process_attr_tracker_inclusion_set_add_value(
55c9e7ca 269 struct ltt_ust_session *session,
159b042f
JG
270 enum lttng_process_attr process_attr,
271 const struct process_attr_value *value);
272enum lttng_error_code trace_ust_process_attr_tracker_inclusion_set_remove_value(
273 struct ltt_ust_session *session,
274 enum lttng_process_attr process_attr,
275 const struct process_attr_value *value);
276const struct process_attr_tracker *trace_ust_get_process_attr_tracker(
55c9e7ca 277 struct ltt_ust_session *session,
159b042f 278 enum lttng_process_attr process_attr);
a5dfbb9d 279
74d0b642 280#else /* HAVE_LIBLTTNG_UST_CTL */
3bd1e081 281
37a86c61
DG
282static inline int trace_ust_ht_match_event(struct cds_lfht_node *node,
283 const void *_key)
284{
285 return 0;
286}
287static inline int trace_ust_ht_match_event_by_name(struct cds_lfht_node *node,
288 const void *_key)
289{
290 return 0;
291}
3bd1e081 292static inline
bec39940 293struct ltt_ust_channel *trace_ust_find_channel_by_name(struct lttng_ht *ht,
df4f5a87 294 const char *name)
3bd1e081
MD
295{
296 return NULL;
297}
ebdb334b
JR
298static inline
299struct ltt_ust_map *trace_ust_find_map_by_name(struct lttng_ht *ht,
300 const char *name)
301{
302 return NULL;
303}
3bd1e081 304static inline
dec56f6c 305struct ltt_ust_session *trace_ust_create_session(unsigned int session_id)
3bd1e081
MD
306{
307 return NULL;
308}
309static inline
51755dc8
JG
310struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *attr,
311 enum lttng_domain_type domain)
3bd1e081
MD
312{
313 return NULL;
314}
315static inline
ebdb334b
JR
316struct ltt_ust_map *trace_ust_create_map(const struct lttng_map *map)
317{
318 return NULL;
319}
320static inline
321enum lttng_error_code trace_ust_create_event(uint64_t tracer_token,
322 const char *ev_name,
323 struct lttng_map_key *key,
324 enum lttng_event_type ev_type,
325 enum lttng_loglevel_type ev_loglevel_type,
326 enum lttng_loglevel ev_loglevel,
327 char *filter_expression,
2b00d462 328 struct lttng_bytecode *filter,
88f06f15 329 struct lttng_event_exclusion *exclusion,
ebdb334b
JR
330 bool internal_event,
331 struct ltt_ust_event **ust_event)
3bd1e081 332{
39687410 333 return LTTNG_ERR_NO_UST;
3bd1e081 334}
3bd1e081
MD
335static inline
336void trace_ust_destroy_session(struct ltt_ust_session *session)
337{
338}
48842b30 339
3bd1e081
MD
340static inline
341void trace_ust_destroy_channel(struct ltt_ust_channel *channel)
342{
343}
48842b30 344
ebdb334b
JR
345static inline
346void trace_ust_destroy_map(struct ltt_ust_map *map)
347{
348}
349
3bd1e081
MD
350static inline
351void trace_ust_destroy_event(struct ltt_ust_event *event)
352{
353}
d070c424
MD
354
355static inline
356void trace_ust_free_session(struct ltt_ust_session *session)
357{
358}
359
34378f76
DG
360static inline
361struct ltt_ust_context *trace_ust_create_context(
df4f5a87 362 const struct lttng_event_context *ctx)
34378f76
DG
363{
364 return NULL;
365}
aa3514e9 366static inline
df4f5a87
JG
367int trace_ust_match_context(const struct ltt_ust_context *uctx,
368 const struct lttng_event_context *ctx)
aa3514e9
MD
369{
370 return 0;
371}
b953b8cd
PP
372static inline
373struct ltt_ust_event *trace_ust_find_event(struct lttng_ht *ht,
ebdb334b 374 uint64_t tracer_token, char *name, struct lttng_bytecode *filter,
b953b8cd 375 enum lttng_ust_loglevel_type loglevel_type, int loglevel_value,
ebdb334b
JR
376 struct lttng_event_exclusion *exclusion,
377 struct lttng_map_key *key)
37a86c61
DG
378{
379 return NULL;
380}
d5979e4a
DG
381static inline
382void trace_ust_delete_channel(struct lttng_ht *ht,
383 struct ltt_ust_channel *channel)
384{
385 return;
386}
fefd409b
DG
387static inline
388struct agent *trace_ust_find_agent(struct ltt_ust_session *session,
389 enum lttng_domain_type domain_type)
390{
391 return NULL;
392}
159b042f
JG
393static inline int trace_ust_id_tracker_lookup(
394 enum lttng_process_attr process_attr,
55c9e7ca 395 struct ltt_ust_session *session,
159b042f 396 int id)
a9ad0c8f
MD
397{
398 return 0;
399}
159b042f
JG
400static inline enum lttng_error_code
401trace_ust_process_attr_tracker_set_tracking_policy(
55c9e7ca 402 struct ltt_ust_session *session,
159b042f
JG
403 enum lttng_process_attr process_attr,
404 enum lttng_tracking_policy policy)
a9ad0c8f 405{
159b042f 406 return LTTNG_OK;
a9ad0c8f 407}
159b042f
JG
408static inline enum lttng_error_code
409trace_ust_process_attr_tracker_inclusion_set_add_value(
55c9e7ca 410 struct ltt_ust_session *session,
159b042f
JG
411 enum lttng_process_attr process_attr,
412 const struct process_attr_value *value)
b4650bd0 413{
159b042f 414 return LTTNG_OK;
b4650bd0 415}
159b042f
JG
416static inline enum lttng_error_code
417trace_ust_process_attr_tracker_inclusion_set_remove_value(
55c9e7ca 418 struct ltt_ust_session *session,
159b042f
JG
419 enum lttng_process_attr process_attr,
420 const struct process_attr_value *value)
a5dfbb9d 421{
159b042f 422 return LTTNG_OK;
a5dfbb9d 423}
159b042f
JG
424static inline const struct process_attr_tracker *
425trace_ust_get_process_attr_tracker(struct ltt_ust_session *session,
426 enum lttng_process_attr process_attr)
427{
428 return NULL;
429}
430
74d0b642 431#endif /* HAVE_LIBLTTNG_UST_CTL */
3bd1e081 432
97ee3a89 433#endif /* _LTT_TRACE_UST_H */
This page took 0.110869 seconds and 5 git commands to generate.