Fix: lttng: enable-channel: leak of popt arguments
[lttng-tools.git] / src / bin / lttng-sessiond / trace-kernel.hpp
1 /*
2 * Copyright (C) 2011 EfficiOS Inc.
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 */
7
8 #ifndef _LTT_TRACE_KERNEL_H
9 #define _LTT_TRACE_KERNEL_H
10
11 #include <urcu/list.h>
12
13 #include <lttng/lttng.h>
14 #include <common/lttng-kernel.hpp>
15 #include <common/lttng-kernel-old.hpp>
16 #include <common/defaults.hpp>
17
18 #include "consumer.hpp"
19 #include "tracker.hpp"
20
21 /* Kernel event list */
22 struct ltt_kernel_event_list {
23 struct cds_list_head head;
24 };
25
26 /* Channel stream list */
27 struct ltt_kernel_stream_list {
28 struct cds_list_head head;
29 };
30
31 /* Channel list */
32 struct ltt_kernel_channel_list {
33 struct cds_list_head head;
34 };
35
36 struct ltt_kernel_context {
37 struct lttng_kernel_abi_context ctx;
38 struct cds_list_head list;
39 /* Indicates whether or not the context is in a list. */
40 bool in_list;
41 };
42
43 /* Kernel event */
44 struct ltt_kernel_event {
45 int fd;
46 int enabled;
47 enum lttng_event_type type;
48 struct lttng_kernel_abi_event *event;
49 struct cds_list_head list;
50 char *filter_expression;
51 struct lttng_bytecode *filter;
52 struct lttng_userspace_probe_location *userspace_probe_location;
53 };
54
55 /* Kernel event */
56 struct ltt_kernel_event_notifier_rule {
57 int fd;
58 uint64_t error_counter_index;
59 int enabled;
60 enum lttng_event_type type;
61 struct lttng_trigger *trigger;
62 uint64_t token;
63 const struct lttng_bytecode *filter;
64 struct lttng_userspace_probe_location *userspace_probe_location;
65 struct cds_lfht_node ht_node;
66 /* call_rcu delayed reclaim. */
67 struct rcu_head rcu_node;
68 };
69
70 /* Kernel channel */
71 struct ltt_kernel_channel {
72 int fd;
73 uint64_t key; /* Key to reference this channel with the consumer. */
74 int enabled;
75 unsigned int stream_count;
76 unsigned int event_count;
77 bool published_to_notification_thread;
78 struct cds_list_head ctx_list;
79 struct lttng_channel *channel;
80 struct ltt_kernel_event_list events_list;
81 struct ltt_kernel_stream_list stream_list;
82 struct cds_list_head list;
83 /* Session pointer which has a reference to this object. */
84 struct ltt_kernel_session *session;
85 bool sent_to_consumer;
86 };
87
88 /* Metadata */
89 struct ltt_kernel_metadata {
90 int fd;
91 uint64_t key; /* Key to reference this channel with the consumer. */
92 struct lttng_channel *conf;
93 };
94
95 /* Channel stream */
96 struct ltt_kernel_stream {
97 int fd;
98 int state;
99 int cpu;
100 bool sent_to_consumer;
101 /* Format is %s_%d respectively channel name and CPU number. */
102 char name[DEFAULT_STREAM_NAME_LEN];
103 uint64_t tracefile_size;
104 uint64_t tracefile_count;
105 struct cds_list_head list;
106 };
107
108 /* Kernel session */
109 struct ltt_kernel_session {
110 int fd;
111 int metadata_stream_fd;
112 int consumer_fds_sent;
113 unsigned int channel_count;
114 unsigned int stream_count_global;
115 struct ltt_kernel_metadata *metadata;
116 struct ltt_kernel_channel_list channel_list;
117 /* UID/GID of the user owning the session */
118 uid_t uid;
119 gid_t gid;
120 struct consumer_output *consumer;
121 /* Tracing session id */
122 uint64_t id;
123 /* Session is active or not meaning it has been started or stopped. */
124 unsigned int active:1;
125 /* Tell or not if the session has to output the traces. */
126 unsigned int output_traces;
127 unsigned int snapshot_mode;
128 unsigned int has_non_default_channel;
129 bool is_live_session;
130 /* Current trace chunk of the ltt_session. */
131 struct lttng_trace_chunk *current_trace_chunk;
132 /* Tracker lists */
133 struct process_attr_tracker *tracker_pid;
134 struct process_attr_tracker *tracker_vpid;
135 struct process_attr_tracker *tracker_uid;
136 struct process_attr_tracker *tracker_vuid;
137 struct process_attr_tracker *tracker_gid;
138 struct process_attr_tracker *tracker_vgid;
139 };
140
141 /*
142 * Lookup functions. NULL is returned if not found.
143 */
144 struct ltt_kernel_event *trace_kernel_get_event_by_name(
145 char *name, struct ltt_kernel_channel *channel,
146 enum lttng_event_type type);
147 struct ltt_kernel_event *trace_kernel_find_event(
148 char *name, struct ltt_kernel_channel *channel,
149 enum lttng_event_type type,
150 struct lttng_bytecode *filter);
151 struct ltt_kernel_channel *trace_kernel_get_channel_by_name(
152 const char *name, struct ltt_kernel_session *session);
153
154 /*
155 * Create functions malloc() the data structure.
156 */
157 struct ltt_kernel_session *trace_kernel_create_session(void);
158 struct ltt_kernel_channel *trace_kernel_create_channel(
159 struct lttng_channel *chan);
160 enum lttng_error_code trace_kernel_create_event(struct lttng_event *ev,
161 char *filter_expression, struct lttng_bytecode *filter,
162 struct ltt_kernel_event **kernel_event);
163 struct ltt_kernel_metadata *trace_kernel_create_metadata(void);
164 struct ltt_kernel_stream *trace_kernel_create_stream(const char *name,
165 unsigned int count);
166 struct ltt_kernel_context *trace_kernel_create_context(
167 struct lttng_kernel_abi_context *ctx);
168 /* Trigger is only non-const to acquire a reference. */
169 enum lttng_error_code trace_kernel_create_event_notifier_rule(
170 struct lttng_trigger *trigger,
171 uint64_t token,
172 uint64_t error_counter_index,
173 struct ltt_kernel_event_notifier_rule **event_notifier_rule);
174 struct ltt_kernel_context *trace_kernel_copy_context(
175 struct ltt_kernel_context *ctx);
176 enum lttng_error_code trace_kernel_init_event_notifier_from_event_rule(
177 const struct lttng_event_rule *rule,
178 struct lttng_kernel_abi_event_notifier *kernel_event_notifier);
179
180 /*
181 * Destroy functions free() the data structure and remove from linked list if
182 * it's applies.
183 */
184 void trace_kernel_destroy_session(struct ltt_kernel_session *session);
185 void trace_kernel_destroy_metadata(struct ltt_kernel_metadata *metadata);
186 void trace_kernel_destroy_channel(struct ltt_kernel_channel *channel);
187 void trace_kernel_destroy_event(struct ltt_kernel_event *event);
188 void trace_kernel_destroy_stream(struct ltt_kernel_stream *stream);
189 void trace_kernel_destroy_context(struct ltt_kernel_context *ctx);
190 void trace_kernel_destroy_event_notifier_rule(struct ltt_kernel_event_notifier_rule *rule);
191 void trace_kernel_free_session(struct ltt_kernel_session *session);
192
193 #endif /* _LTT_TRACE_KERNEL_H */
This page took 0.042839 seconds and 4 git commands to generate.