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