SoW-2020-0003: Trace Hit Counters
[lttng-tools.git] / src / bin / lttng-sessiond / trace-kernel.h
CommitLineData
fda89c9b 1/*
ab5be9fa 2 * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca>
fda89c9b 3 *
ab5be9fa 4 * SPDX-License-Identifier: GPL-2.0-only
fda89c9b 5 *
fda89c9b
DG
6 */
7
62499ad6
DG
8#ifndef _LTT_TRACE_KERNEL_H
9#define _LTT_TRACE_KERNEL_H
fda89c9b 10
9e78d6ae 11#include <urcu/list.h>
d4a2a84a 12
f3ed775e 13#include <lttng/lttng.h>
ebdb334b 14#include <lttng/map/map.h>
10a8a223 15#include <common/lttng-kernel.h>
4dbc372b 16#include <common/lttng-kernel-old.h>
ce2a9e76 17#include <common/defaults.h>
54012638 18
00e2e675 19#include "consumer.h"
55c9e7ca 20#include "tracker.h"
00e2e675 21
20fe2104
DG
22/* Kernel event list */
23struct ltt_kernel_event_list {
24 struct cds_list_head head;
25};
26
8c0faa1d
DG
27/* Channel stream list */
28struct ltt_kernel_stream_list {
29 struct cds_list_head head;
30};
31
32/* Channel list */
33struct ltt_kernel_channel_list {
34 struct cds_list_head head;
35};
36
ebdb334b
JR
37/* map list */
38struct ltt_kernel_map_list {
39 struct cds_list_head head;
40};
41
645328ae
DG
42struct ltt_kernel_context {
43 struct lttng_kernel_context ctx;
44 struct cds_list_head list;
ba985c3a
JG
45 /* Indicates whether or not the context is in a list. */
46 bool in_list;
645328ae
DG
47};
48
20fe2104
DG
49/* Kernel event */
50struct ltt_kernel_event {
20fe2104 51 int fd;
e953ef25 52 int enabled;
d0ae4ea8 53 enum lttng_event_type type;
f34daff7 54 struct lttng_kernel_event *event;
20fe2104 55 struct cds_list_head list;
00a62084 56 char *filter_expression;
2b00d462 57 struct lttng_bytecode *filter;
3c02e545 58 struct lttng_userspace_probe_location *userspace_probe_location;
20fe2104
DG
59};
60
ebdb334b 61/* Kernel event notifier */
352b58f5
JR
62struct ltt_kernel_event_notifier_rule {
63 int fd;
ebdb334b 64 uint64_t error_counter_index;
352b58f5
JR
65 int enabled;
66 enum lttng_event_type type;
67 struct lttng_trigger *trigger;
68 uint64_t token;
2b00d462 69 const struct lttng_bytecode *filter;
352b58f5
JR
70 struct lttng_userspace_probe_location *userspace_probe_location;
71 struct cds_lfht_node ht_node;
72 /* call_rcu delayed reclaim. */
73 struct rcu_head rcu_node;
74};
75
ebdb334b
JR
76/* Kernel event counter */
77struct ltt_kernel_event_counter {
78 int fd;
79 int enabled;
80 uint64_t action_tracer_token;
81 struct lttng_kernel_event *event;
82 struct lttng_event_rule *event_rule;
83 const struct lttng_bytecode *filter;
84 struct lttng_userspace_probe_location *userspace_probe_location;
85 struct cds_list_head list;
86 struct lttng_ht_node_u64 ht_node;
87
88 /* refcounted */
89 struct lttng_map_key *key;
90 /* call_rcu delayed reclaim. */
91 struct rcu_head rcu_node;
92};
93
20fe2104
DG
94/* Kernel channel */
95struct ltt_kernel_channel {
96 int fd;
e1f3997a 97 uint64_t key; /* Key to reference this channel with the consumer. */
d36b8583 98 int enabled;
8c0faa1d 99 unsigned int stream_count;
cbbbb275 100 unsigned int event_count;
753873bf 101 bool published_to_notification_thread;
645328ae 102 struct cds_list_head ctx_list;
f3ed775e 103 struct lttng_channel *channel;
20fe2104 104 struct ltt_kernel_event_list events_list;
8c0faa1d
DG
105 struct ltt_kernel_stream_list stream_list;
106 struct cds_list_head list;
fb5f35b6
DG
107 /* Session pointer which has a reference to this object. */
108 struct ltt_kernel_session *session;
e99f9447 109 bool sent_to_consumer;
20fe2104
DG
110};
111
ebdb334b
JR
112/* Kernel map */
113struct ltt_kernel_map {
114 int fd;
115 uint64_t key; /* Key to reference this map with the notification thread. */
116 int enabled;
117 unsigned int event_count;
118 struct lttng_map *map;
119 struct lttng_kernel_counter_conf counter_conf;
120 struct lttng_ht *event_counters_ht;
121 struct cds_list_head list;
122 /* Session pointer which has a reference to this object. */
123 struct ltt_kernel_session *session;
124};
125
aaf26714
DG
126/* Metadata */
127struct ltt_kernel_metadata {
128 int fd;
d40f0359 129 uint64_t key; /* Key to reference this channel with the consumer. */
f3ed775e 130 struct lttng_channel *conf;
aaf26714
DG
131};
132
8c0faa1d
DG
133/* Channel stream */
134struct ltt_kernel_stream {
135 int fd;
8c0faa1d 136 int state;
ffe60014 137 int cpu;
6986ab9b 138 bool sent_to_consumer;
00e2e675 139 /* Format is %s_%d respectively channel name and CPU number. */
ce2a9e76 140 char name[DEFAULT_STREAM_NAME_LEN];
1624d5b7
JD
141 uint64_t tracefile_size;
142 uint64_t tracefile_count;
8c0faa1d
DG
143 struct cds_list_head list;
144};
145
20fe2104
DG
146/* Kernel session */
147struct ltt_kernel_session {
148 int fd;
8c0faa1d 149 int metadata_stream_fd;
3bd1e081 150 int consumer_fds_sent;
8c0faa1d 151 unsigned int channel_count;
ebdb334b 152 unsigned int map_count;
8c0faa1d 153 unsigned int stream_count_global;
aaf26714 154 struct ltt_kernel_metadata *metadata;
8c0faa1d 155 struct ltt_kernel_channel_list channel_list;
ebdb334b 156 struct ltt_kernel_map_list map_list;
6df2e2c9
MD
157 /* UID/GID of the user owning the session */
158 uid_t uid;
159 gid_t gid;
00e2e675 160 struct consumer_output *consumer;
53632229 161 /* Tracing session id */
d022620a 162 uint64_t id;
14fb1ebe
DG
163 /* Session is active or not meaning it has been started or stopped. */
164 unsigned int active:1;
2bba9e53
DG
165 /* Tell or not if the session has to output the traces. */
166 unsigned int output_traces;
27babd3a 167 unsigned int snapshot_mode;
85076754 168 unsigned int has_non_default_channel;
a2814ea7 169 bool is_live_session;
82b69413
JG
170 /* Current trace chunk of the ltt_session. */
171 struct lttng_trace_chunk *current_trace_chunk;
55c9e7ca 172 /* Tracker lists */
159b042f
JG
173 struct process_attr_tracker *tracker_pid;
174 struct process_attr_tracker *tracker_vpid;
175 struct process_attr_tracker *tracker_uid;
176 struct process_attr_tracker *tracker_vuid;
177 struct process_attr_tracker *tracker_gid;
178 struct process_attr_tracker *tracker_vgid;
fda89c9b
DG
179};
180
62499ad6
DG
181/*
182 * Lookup functions. NULL is returned if not found.
183 */
184struct ltt_kernel_event *trace_kernel_get_event_by_name(
d0ae4ea8
MD
185 char *name, struct ltt_kernel_channel *channel,
186 enum lttng_event_type type);
00a62084 187struct ltt_kernel_event *trace_kernel_find_event(
ebdb334b
JR
188 struct ltt_kernel_event_list *events_list,
189 uint64_t tracer_token, char *name,
00a62084 190 enum lttng_event_type type,
2b00d462 191 struct lttng_bytecode *filter);
62499ad6 192struct ltt_kernel_channel *trace_kernel_get_channel_by_name(
df4f5a87 193 const char *name, struct ltt_kernel_session *session);
19e70852 194
ebdb334b
JR
195struct ltt_kernel_map *trace_kernel_get_map_by_name(
196 const char *name, struct ltt_kernel_session *session);
197
54012638 198/*
c363b55d 199 * Create functions malloc() the data structure.
54012638 200 */
dec56f6c 201struct ltt_kernel_session *trace_kernel_create_session(void);
fdd9eb17
DG
202struct ltt_kernel_channel *trace_kernel_create_channel(
203 struct lttng_channel *chan);
ebdb334b 204struct ltt_kernel_map *trace_kernel_create_map(const struct lttng_map *map);
71a3bb01 205enum lttng_error_code trace_kernel_create_event(struct lttng_event *ev,
2b00d462 206 char *filter_expression, struct lttng_bytecode *filter,
71a3bb01 207 struct ltt_kernel_event **kernel_event);
a4b92340 208struct ltt_kernel_metadata *trace_kernel_create_metadata(void);
00e2e675
DG
209struct ltt_kernel_stream *trace_kernel_create_stream(const char *name,
210 unsigned int count);
645328ae
DG
211struct ltt_kernel_context *trace_kernel_create_context(
212 struct lttng_kernel_context *ctx);
352b58f5
JR
213enum lttng_error_code trace_kernel_create_event_notifier_rule(
214 struct lttng_trigger *trigger,
215 uint64_t token,
ebdb334b 216 uint64_t error_counter_index,
352b58f5 217 struct ltt_kernel_event_notifier_rule **event_notifier_rule);
df3c77c8
JG
218struct ltt_kernel_context *trace_kernel_copy_context(
219 struct ltt_kernel_context *ctx);
352b58f5
JR
220enum lttng_error_code trace_kernel_init_event_notifier_from_event_rule(
221 const struct lttng_event_rule *rule,
222 struct lttng_kernel_event_notifier *kernel_event_notifier);
ebdb334b
JR
223enum lttng_error_code trace_kernel_init_event_counter_from_event_rule(
224 const struct lttng_event_rule *rule,
225 struct lttng_kernel_counter_event *kernel_counter_event);
54012638 226
c363b55d
DG
227/*
228 * Destroy functions free() the data structure and remove from linked list if
229 * it's applies.
230 */
62499ad6
DG
231void trace_kernel_destroy_session(struct ltt_kernel_session *session);
232void trace_kernel_destroy_metadata(struct ltt_kernel_metadata *metadata);
233void trace_kernel_destroy_channel(struct ltt_kernel_channel *channel);
ebdb334b 234void trace_kernel_destroy_map(struct ltt_kernel_map *map);
62499ad6
DG
235void trace_kernel_destroy_event(struct ltt_kernel_event *event);
236void trace_kernel_destroy_stream(struct ltt_kernel_stream *stream);
645328ae 237void trace_kernel_destroy_context(struct ltt_kernel_context *ctx);
352b58f5 238void trace_kernel_destroy_event_notifier_rule(struct ltt_kernel_event_notifier_rule *rule);
ebdb334b
JR
239void trace_kernel_destroy_event_counter(
240 struct ltt_kernel_event_counter *event_counter);
d070c424 241void trace_kernel_free_session(struct ltt_kernel_session *session);
c363b55d 242
62499ad6 243#endif /* _LTT_TRACE_KERNEL_H */
This page took 0.100095 seconds and 5 git commands to generate.