2 * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca>
4 * SPDX-License-Identifier: GPL-2.0-only
8 #ifndef _LTT_TRACE_KERNEL_H
9 #define _LTT_TRACE_KERNEL_H
11 #include <urcu/list.h>
13 #include <lttng/lttng.h>
14 #include <common/lttng-kernel.h>
15 #include <common/lttng-kernel-old.h>
16 #include <common/defaults.h>
21 /* Kernel event list */
22 struct ltt_kernel_event_list
{
23 struct cds_list_head head
;
26 /* Channel stream list */
27 struct ltt_kernel_stream_list
{
28 struct cds_list_head head
;
32 struct ltt_kernel_channel_list
{
33 struct cds_list_head head
;
36 struct ltt_kernel_context
{
37 struct lttng_kernel_context ctx
;
38 struct cds_list_head list
;
39 /* Indicates whether or not the context is in a list. */
44 struct ltt_kernel_event
{
47 enum lttng_event_type type
;
48 struct lttng_kernel_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
;
56 struct ltt_kernel_event_notifier_rule
{
59 enum lttng_event_type type
;
60 struct lttng_trigger
*trigger
;
62 const struct lttng_bytecode
*filter
;
63 struct lttng_userspace_probe_location
*userspace_probe_location
;
64 struct cds_lfht_node ht_node
;
65 /* call_rcu delayed reclaim. */
66 struct rcu_head rcu_node
;
70 struct ltt_kernel_channel
{
72 uint64_t key
; /* Key to reference this channel with the consumer. */
74 unsigned int stream_count
;
75 unsigned int event_count
;
76 bool published_to_notification_thread
;
77 struct cds_list_head ctx_list
;
78 struct lttng_channel
*channel
;
79 struct ltt_kernel_event_list events_list
;
80 struct ltt_kernel_stream_list stream_list
;
81 struct cds_list_head list
;
82 /* Session pointer which has a reference to this object. */
83 struct ltt_kernel_session
*session
;
84 bool sent_to_consumer
;
88 struct ltt_kernel_metadata
{
90 uint64_t key
; /* Key to reference this channel with the consumer. */
91 struct lttng_channel
*conf
;
95 struct ltt_kernel_stream
{
99 bool sent_to_consumer
;
100 /* Format is %s_%d respectively channel name and CPU number. */
101 char name
[DEFAULT_STREAM_NAME_LEN
];
102 uint64_t tracefile_size
;
103 uint64_t tracefile_count
;
104 struct cds_list_head list
;
108 struct ltt_kernel_session
{
110 int metadata_stream_fd
;
111 int consumer_fds_sent
;
112 unsigned int channel_count
;
113 unsigned int stream_count_global
;
114 struct ltt_kernel_metadata
*metadata
;
115 struct ltt_kernel_channel_list channel_list
;
116 /* UID/GID of the user owning the session */
119 struct consumer_output
*consumer
;
120 /* Tracing session id */
122 /* Session is active or not meaning it has been started or stopped. */
123 unsigned int active
:1;
124 /* Tell or not if the session has to output the traces. */
125 unsigned int output_traces
;
126 unsigned int snapshot_mode
;
127 unsigned int has_non_default_channel
;
128 bool is_live_session
;
129 /* Current trace chunk of the ltt_session. */
130 struct lttng_trace_chunk
*current_trace_chunk
;
132 struct process_attr_tracker
*tracker_pid
;
133 struct process_attr_tracker
*tracker_vpid
;
134 struct process_attr_tracker
*tracker_uid
;
135 struct process_attr_tracker
*tracker_vuid
;
136 struct process_attr_tracker
*tracker_gid
;
137 struct process_attr_tracker
*tracker_vgid
;
141 * Lookup functions. NULL is returned if not found.
143 struct ltt_kernel_event
*trace_kernel_get_event_by_name(
144 char *name
, struct ltt_kernel_channel
*channel
,
145 enum lttng_event_type type
);
146 struct ltt_kernel_event
*trace_kernel_find_event(
147 char *name
, struct ltt_kernel_channel
*channel
,
148 enum lttng_event_type type
,
149 struct lttng_bytecode
*filter
);
150 struct ltt_kernel_channel
*trace_kernel_get_channel_by_name(
151 const char *name
, struct ltt_kernel_session
*session
);
154 * Create functions malloc() the data structure.
156 struct ltt_kernel_session
*trace_kernel_create_session(void);
157 struct ltt_kernel_channel
*trace_kernel_create_channel(
158 struct lttng_channel
*chan
);
159 enum lttng_error_code
trace_kernel_create_event(struct lttng_event
*ev
,
160 char *filter_expression
, struct lttng_bytecode
*filter
,
161 struct ltt_kernel_event
**kernel_event
);
162 struct ltt_kernel_metadata
*trace_kernel_create_metadata(void);
163 struct ltt_kernel_stream
*trace_kernel_create_stream(const char *name
,
165 struct ltt_kernel_context
*trace_kernel_create_context(
166 struct lttng_kernel_context
*ctx
);
167 enum lttng_error_code
trace_kernel_create_event_notifier_rule(
168 struct lttng_trigger
*trigger
,
170 struct ltt_kernel_event_notifier_rule
**event_notifier_rule
);
171 struct ltt_kernel_context
*trace_kernel_copy_context(
172 struct ltt_kernel_context
*ctx
);
173 enum lttng_error_code
trace_kernel_init_event_notifier_from_event_rule(
174 const struct lttng_event_rule
*rule
,
175 struct lttng_kernel_event_notifier
*kernel_event_notifier
);
178 * Destroy functions free() the data structure and remove from linked list if
181 void trace_kernel_destroy_session(struct ltt_kernel_session
*session
);
182 void trace_kernel_destroy_metadata(struct ltt_kernel_metadata
*metadata
);
183 void trace_kernel_destroy_channel(struct ltt_kernel_channel
*channel
);
184 void trace_kernel_destroy_event(struct ltt_kernel_event
*event
);
185 void trace_kernel_destroy_stream(struct ltt_kernel_stream
*stream
);
186 void trace_kernel_destroy_context(struct ltt_kernel_context
*ctx
);
187 void trace_kernel_destroy_event_notifier_rule(struct ltt_kernel_event_notifier_rule
*rule
);
188 void trace_kernel_free_session(struct ltt_kernel_session
*session
);
190 #endif /* _LTT_TRACE_KERNEL_H */