2 * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca>
3 * Copyright (C) 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 * SPDX-License-Identifier: GPL-2.0-only
10 #define _LTT_UST_APP_H
14 #include <common/index-allocator.h>
15 #include <common/uuid.h>
16 #include <lttng/map/map.h>
18 #include "trace-ust.h"
19 #include "ust-registry.h"
22 #define UST_APP_EVENT_LIST_SIZE 32
24 /* Process name (short). */
25 #define UST_APP_PROCNAME_LEN 16
27 struct lttng_bytecode
;
28 struct lttng_ust_filter_bytecode
;
30 extern int ust_consumerd64_fd
, ust_consumerd32_fd
;
33 * Object used to close the notify socket in a call_rcu(). Since the
34 * application might not be found, we need an independant object containing the
37 struct ust_app_notify_sock_obj
{
42 struct ust_app_ht_key
{
44 const struct lttng_bytecode
*filter
;
45 enum lttng_ust_loglevel_type loglevel_type
;
46 const struct lttng_event_exclusion
*exclusion
;
47 uint64_t tracer_token
;
51 * Application registration data structure.
53 struct ust_register_msg
{
54 enum ustctl_socket_type type
;
63 uint32_t bits_per_long
;
64 uint32_t uint8_t_alignment
;
65 uint32_t uint16_t_alignment
;
66 uint32_t uint32_t_alignment
;
67 uint32_t uint64_t_alignment
;
68 uint32_t long_alignment
;
69 int byte_order
; /* BIG_ENDIAN or LITTLE_ENDIAN */
70 char name
[LTTNG_UST_ABI_PROCNAME_LEN
];
74 * Global applications HT used by the session daemon. This table is indexed by
75 * PID using the pid_n node and pid value of an ust_app.
77 extern struct lttng_ht
*ust_app_ht
;
80 * Global applications HT used by the session daemon. This table is indexed by
81 * socket using the sock_n node and sock value of an ust_app.
83 * The 'sock' in question here is the 'command' socket.
85 extern struct lttng_ht
*ust_app_ht_by_sock
;
88 * Global applications HT used by the session daemon. This table is indexed by
89 * socket using the notify_sock_n node and notify_sock value of an ust_app.
91 extern struct lttng_ht
*ust_app_ht_by_notify_sock
;
93 /* Stream list containing ust_app_stream. */
94 struct ust_app_stream_list
{
96 struct cds_list_head head
;
99 /* counter list containing ust_app_counter. */
100 struct ust_app_counter_list
{
102 struct cds_list_head head
;
107 struct lttng_ust_context_attr ctx
;
108 struct lttng_ust_object_data
*obj
;
109 struct lttng_ht_node_ulong node
;
110 struct cds_list_head list
;
113 struct ust_app_event
{
116 struct lttng_ust_object_data
*obj
;
117 struct lttng_ust_event attr
;
118 char name
[LTTNG_UST_SYM_NAME_LEN
];
119 struct lttng_ht_node_str node
;
120 struct lttng_bytecode
*filter
;
121 struct lttng_event_exclusion
*exclusion
;
124 struct ust_app_event_notifier_rule
{
126 uint64_t error_counter_index
;
128 struct lttng_ust_object_data
*obj
;
129 /* Holds a strong reference. */
130 struct lttng_trigger
*trigger
;
131 /* Unique ID returned by the tracer to identify this event notifier. */
133 struct lttng_ht_node_u64 node
;
134 /* The trigger object owns the filter. */
135 const struct lttng_bytecode
*filter
;
137 struct lttng_event_exclusion
*exclusion
;
138 /* For delayed reclaim. */
139 struct rcu_head rcu_head
;
142 struct ust_app_stream
{
144 char pathname
[PATH_MAX
];
145 /* Format is %s_%d respectively channel name and CPU number. */
146 char name
[DEFAULT_STREAM_NAME_LEN
];
147 struct lttng_ust_object_data
*obj
;
148 /* Using a list of streams to keep order. */
149 struct cds_list_head list
;
152 struct ust_app_map_counter
{
154 struct lttng_ust_object_data
*obj
;
155 /* Using a list of counters to keep order. */
156 struct cds_list_head list
;
159 struct ust_app_channel
{
162 /* Channel and streams were sent to the UST tracer. */
165 * Unique key used to identify the channel on the consumer side.
166 * 0 is a reserved 'invalid' value used to indicate that the consumer
167 * does not know about this channel (i.e. an error occurred).
170 /* Id of the tracing channel set on creation. */
171 uint64_t tracing_channel_id
;
172 /* Number of stream that this channel is expected to receive. */
173 unsigned int expected_stream_count
;
174 char name
[LTTNG_UST_SYM_NAME_LEN
];
175 struct lttng_ust_object_data
*obj
;
176 struct ustctl_consumer_channel_attr attr
;
177 struct ust_app_stream_list streams
;
178 /* Session pointer that owns this object. */
179 struct ust_app_session
*session
;
181 * Contexts are kept in a hash table for fast lookup and in an ordered list
182 * so we are able to enable them on the tracer side in the same order the
185 struct lttng_ht
*ctx
;
186 struct cds_list_head ctx_list
;
188 struct lttng_ht
*events
;
189 uint64_t tracefile_size
;
190 uint64_t tracefile_count
;
191 uint64_t monitor_timer_interval
;
193 * Node indexed by channel name in the channels' hash table of a session.
195 struct lttng_ht_node_str node
;
197 * Node indexed by UST channel object descriptor (handle). Stored in the
198 * ust_objd hash table in the ust_app object.
200 struct lttng_ht_node_ulong ust_objd_node
;
201 /* For delayed reclaim */
202 struct rcu_head rcu_head
;
208 /* Counters were sent to the UST tracer. */
211 * FIXME frdeso: what is difference between key and tracing_map_id
212 * Unique key used to identify the map.
215 /* Id of the tracing map set on creation. */
216 uint64_t tracing_map_id
;
218 enum lttng_map_bitness bitness
;
219 char name
[LTTNG_UST_SYM_NAME_LEN
];
220 struct lttng_ust_object_data
*obj
;
221 struct ust_app_counter_list counters
;
222 /* Session pointer that owns this object. */
223 struct ust_app_session
*session
;
224 struct lttng_ht
*events
;
225 struct ltt_ust_map_dead_pid_kv_values
*dead_app_kv_values
;
228 struct ustctl_daemon_counter
*map_handle
;
230 * Node indexed by channel name in the channels' hash table of a session.
232 struct lttng_ht_node_str node
;
234 * Node indexed by UST channel object descriptor (handle). Stored in the
235 * ust_objd hash table in the ust_app object.
237 struct lttng_ht_node_ulong ust_objd_node
;
238 /* For delayed reclaim */
239 struct rcu_head rcu_head
;
242 struct ust_app_session
{
244 * Lock protecting this session's ust app interaction. Held
245 * across command send/recv to/from app. Never nests within the
246 * session registry lock.
248 pthread_mutex_t lock
;
251 /* started: has the session been in started state at any time ? */
252 int started
; /* allows detection of start vs restart. */
253 int handle
; /* used has unique identifier for app session */
255 bool deleted
; /* Session deleted flag. Check with lock held. */
258 * Tracing session ID. Multiple ust app session can have the same tracing
259 * session id making this value NOT unique to the object.
262 uint64_t id
; /* Unique session identifier */
263 struct lttng_ht
*channels
; /* Registered channels */
264 struct lttng_ht
*maps
; /* Registered maps */
265 struct lttng_ht_node_u64 node
;
267 * Node indexed by UST session object descriptor (handle). Stored in the
268 * ust_sessions_objd hash table in the ust_app object.
270 struct lttng_ht_node_ulong ust_objd_node
;
271 /* Starts with 'ust'; no leading slash. */
273 /* UID/GID of the application owning the session */
274 struct lttng_credentials real_credentials
;
275 /* Effective UID and GID. Same as the tracing session. */
276 struct lttng_credentials effective_credentials
;
277 struct cds_list_head teardown_node
;
279 * Once at least *one* session is created onto the application, the
280 * corresponding consumer is set so we can use it on unregistration.
282 struct consumer_output
*consumer
;
283 enum lttng_buffer_type buffer_type
;
284 /* ABI of the session. Same value as the application. */
285 uint32_t bits_per_long
;
286 /* For delayed reclaim */
287 struct rcu_head rcu_head
;
288 /* If the channel's streams have to be outputed or not. */
289 unsigned int output_traces
;
290 unsigned int live_timer_interval
; /* usec */
292 /* Metadata channel attributes. */
293 struct ustctl_consumer_channel_attr metadata_attr
;
295 char root_shm_path
[PATH_MAX
];
296 char shm_path
[PATH_MAX
];
300 * Registered traceable applications. Libust registers to the session daemon
301 * and a linked list is kept of all running traceable app.
305 pthread_mutex_t sock_lock
; /* Protects sock protocol. */
310 uid_t uid
; /* User ID that owns the apps */
311 gid_t gid
; /* Group ID that owns the apps */
314 uint32_t bits_per_long
;
315 uint32_t uint8_t_alignment
;
316 uint32_t uint16_t_alignment
;
317 uint32_t uint32_t_alignment
;
318 uint32_t uint64_t_alignment
;
319 uint32_t long_alignment
;
320 int byte_order
; /* BIG_ENDIAN or LITTLE_ENDIAN */
322 int compatible
; /* If the lttng-ust tracer version does not match the
323 supported version of the session daemon, this flag is
324 set to 0 (NOT compatible) else 1. */
325 struct lttng_ust_tracer_version version
;
326 uint32_t v_major
; /* Version major number */
327 uint32_t v_minor
; /* Version minor number */
328 /* Extra for the NULL byte. */
329 char name
[UST_APP_PROCNAME_LEN
+ 1];
330 /* Type of buffer this application uses. */
331 enum lttng_buffer_type buffer_type
;
332 struct lttng_ht
*sessions
;
333 struct lttng_ht_node_ulong pid_n
;
334 struct lttng_ht_node_ulong sock_n
;
335 struct lttng_ht_node_ulong notify_sock_n
;
337 * This is a list of ust app session that, once the app is going into
338 * teardown mode, in the RCU call, each node in this list is removed and
341 * Element of the list are added when an application unregisters after each
342 * ht_del of ust_app_session associated to this app. This list is NOT used
343 * when a session is destroyed.
345 struct cds_list_head teardown_head
;
347 * Hash table containing ust_app_channel indexed by channel objd.
349 struct lttng_ht
*ust_chan_objd
;
351 * Hash table containing ust_app_map indexed by map objd.
353 struct lttng_ht
*ust_map_objd
;
355 * Hash table containing ust_app_session indexed by objd.
357 struct lttng_ht
*ust_sessions_objd
;
360 * If this application is of the agent domain and this is non negative then
361 * a lookup MUST be done to acquire a read side reference to the
362 * corresponding agent app object. If the lookup fails, this should be set
363 * to a negative value indicating that the agent application is gone.
367 * Time at which the app is registred.
368 * Used for path creation
370 time_t registration_time
;
376 * Handle to the lttng_ust object representing the event
379 struct lttng_ust_object_data
*object
;
380 struct lttng_pipe
*event_pipe
;
381 struct lttng_ust_object_data
*counter
;
382 struct lttng_ust_object_data
**counter_cpu
;
384 } event_notifier_group
;
386 * Hashtable indexing the application's event notifier rule's
387 * (ust_app_event_notifier_rule) by their token's value.
389 struct lttng_ht
*token_to_event_notifier_rule_ht
;
392 #ifdef HAVE_LIBLTTNG_UST_CTL
394 int ust_app_register(struct ust_register_msg
*msg
, int sock
);
395 int ust_app_register_done(struct ust_app
*app
);
396 int ust_app_version(struct ust_app
*app
);
397 void ust_app_unregister(int sock
);
398 int ust_app_start_trace_all(struct ltt_ust_session
*usess
);
399 int ust_app_stop_trace_all(struct ltt_ust_session
*usess
);
400 int ust_app_destroy_trace_all(struct ltt_ust_session
*usess
);
401 int ust_app_list_events(struct lttng_event
**events
);
402 int ust_app_list_event_fields(struct lttng_event_field
**fields
);
403 int ust_app_create_channel_event_glb(struct ltt_ust_session
*usess
,
404 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
);
405 int ust_app_disable_channel_glb(struct ltt_ust_session
*usess
,
406 struct ltt_ust_channel
*uchan
);
407 int ust_app_enable_channel_glb(struct ltt_ust_session
*usess
,
408 struct ltt_ust_channel
*uchan
);
409 int ust_app_enable_channel_event_glb(struct ltt_ust_session
*usess
,
410 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
);
411 int ust_app_disable_channel_event_glb(struct ltt_ust_session
*usess
,
412 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
);
413 int ust_app_map_list_values(const struct ltt_ust_session
*usess
,
414 struct ltt_ust_map
*umap
,
415 const struct lttng_map_query
*query
,
416 struct lttng_map_content
**map_content
);
417 int ust_app_enable_map_glb(struct ltt_ust_session
*usess
,
418 struct ltt_ust_map
*umap
);
419 int ust_app_disable_map_glb(struct ltt_ust_session
*usess
,
420 struct ltt_ust_map
*umap
);
421 int ust_app_create_map_event_glb(struct ltt_ust_session
*usess
,
422 struct ltt_ust_map
*umap
, struct ltt_ust_event
*uevent
);
423 int ust_app_enable_map_event_glb(struct ltt_ust_session
*usess
,
424 struct ltt_ust_map
*umap
, struct ltt_ust_event
*uevent
);
425 int ust_app_disable_map_event_glb(struct ltt_ust_session
*usess
,
426 struct ltt_ust_map
*umap
, struct ltt_ust_event
*uevent
);
428 int ust_app_add_ctx_channel_glb(struct ltt_ust_session
*usess
,
429 struct ltt_ust_channel
*uchan
, struct ltt_ust_context
*uctx
);
430 void ust_app_global_update(struct ltt_ust_session
*usess
, struct ust_app
*app
);
431 void ust_app_global_update_all(struct ltt_ust_session
*usess
);
432 void ust_app_global_update_event_notifier_rules(struct ust_app
*app
);
433 void ust_app_global_update_all_event_notifier_rules(void);
435 void ust_app_update_event_notifier_error_count(struct lttng_trigger
*trigger
);
437 void ust_app_clean_list(void);
438 int ust_app_ht_alloc(void);
439 struct ust_app
*ust_app_find_by_pid(pid_t pid
);
440 struct ust_app_stream
*ust_app_alloc_stream(void);
441 struct ust_app_map_counter
*ust_app_alloc_map_counter(void);
442 int ust_app_recv_registration(int sock
, struct ust_register_msg
*msg
);
443 int ust_app_recv_notify(int sock
);
444 void ust_app_add(struct ust_app
*app
);
445 struct ust_app
*ust_app_create(struct ust_register_msg
*msg
, int sock
);
446 void ust_app_notify_sock_unregister(int sock
);
447 ssize_t
ust_app_push_metadata(struct ust_registry_session
*registry
,
448 struct consumer_socket
*socket
, int send_zero_data
);
449 void ust_app_destroy(struct ust_app
*app
);
450 enum lttng_error_code
ust_app_snapshot_record(
451 const struct ltt_ust_session
*usess
,
452 const struct consumer_output
*output
, int wait
,
453 uint64_t nb_packets_per_stream
);
454 uint64_t ust_app_get_size_one_more_packet_per_stream(
455 const struct ltt_ust_session
*usess
, uint64_t cur_nr_packets
);
456 struct ust_app
*ust_app_find_by_sock(int sock
);
457 int ust_app_uid_get_channel_runtime_stats(uint64_t ust_session_id
,
458 struct cds_list_head
*buffer_reg_uid_list
,
459 struct consumer_output
*consumer
, uint64_t uchan_id
,
460 int overwrite
, uint64_t *discarded
, uint64_t *lost
);
461 int ust_app_pid_get_channel_runtime_stats(struct ltt_ust_session
*usess
,
462 struct ltt_ust_channel
*uchan
,
463 struct consumer_output
*consumer
,
464 int overwrite
, uint64_t *discarded
, uint64_t *lost
);
465 int ust_app_regenerate_statedump_all(struct ltt_ust_session
*usess
);
466 enum lttng_error_code
ust_app_rotate_session(struct ltt_session
*session
);
467 enum lttng_error_code
ust_app_create_channel_subdirectories(
468 const struct ltt_ust_session
*session
);
469 int ust_app_release_object(struct ust_app
*app
,
470 struct lttng_ust_object_data
*data
);
471 enum lttng_error_code
ust_app_clear_session(struct ltt_session
*session
);
472 enum lttng_error_code
ust_app_open_packets(struct ltt_session
*session
);
474 int ust_app_setup_event_notifier_group(struct ust_app
*app
);
477 int ust_app_supported(void)
482 #else /* HAVE_LIBLTTNG_UST_CTL */
485 int ust_app_destroy_trace_all(struct ltt_ust_session
*usess
)
490 int ust_app_start_trace(struct ltt_ust_session
*usess
, struct ust_app
*app
)
495 int ust_app_start_trace_all(struct ltt_ust_session
*usess
)
500 int ust_app_stop_trace_all(struct ltt_ust_session
*usess
)
505 int ust_app_list_events(struct lttng_event
**events
)
510 int ust_app_list_event_fields(struct lttng_event_field
**fields
)
515 int ust_app_register(struct ust_register_msg
*msg
, int sock
)
520 int ust_app_register_done(struct ust_app
*app
)
525 int ust_app_version(struct ust_app
*app
)
530 void ust_app_unregister(int sock
)
534 void ust_app_lock_list(void)
538 void ust_app_unlock_list(void)
542 void ust_app_clean_list(void)
546 struct ust_app_list
*ust_app_get_list(void)
551 struct ust_app
*ust_app_get_by_pid(pid_t pid
)
556 int ust_app_ht_alloc(void)
561 void ust_app_global_update(struct ltt_ust_session
*usess
, struct ust_app
*app
)
564 void ust_app_global_update_event_notifier_rules(struct ust_app
*app
)
567 void ust_app_global_update_all_event_notifier_rules(void)
570 int ust_app_setup_event_notifier_group(struct ust_app
*app
)
575 int ust_app_disable_channel_glb(struct ltt_ust_session
*usess
,
576 struct ltt_ust_channel
*uchan
)
581 int ust_app_enable_channel_glb(struct ltt_ust_session
*usess
,
582 struct ltt_ust_channel
*uchan
)
587 int ust_app_create_channel_event_glb(struct ltt_ust_session
*usess
,
588 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
)
593 int ust_app_disable_channel_event_glb(struct ltt_ust_session
*usess
,
594 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
)
599 int ust_app_enable_channel_event_glb(struct ltt_ust_session
*usess
,
600 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
)
605 int ust_app_disable_map_glb(struct ltt_ust_session
*usess
,
606 struct ltt_ust_map
*umap
)
611 int ust_app_map_list_values(const struct ltt_ust_session
*usess
,
612 struct ltt_ust_map
*umap
,
613 const struct lttng_map_query
*query
,
614 struct lttng_map_content
**map_content
)
619 int ust_app_enable_map_glb(struct ltt_ust_session
*usess
,
620 struct ltt_ust_map
*umap
)
625 int ust_app_create_map_event_glb(struct ltt_ust_session
*usess
,
626 struct ltt_ust_map
*umap
, struct ltt_ust_event
*uevent
)
631 int ust_app_disable_map_event_glb(struct ltt_ust_session
*usess
,
632 struct ltt_ust_map
*umap
, struct ltt_ust_event
*uevent
)
637 int ust_app_enable_map_event_glb(struct ltt_ust_session
*usess
,
638 struct ltt_ust_map
*umap
, struct ltt_ust_event
*uevent
)
643 int ust_app_add_ctx_channel_glb(struct ltt_ust_session
*usess
,
644 struct ltt_ust_channel
*uchan
, struct ltt_ust_context
*uctx
)
649 int ust_app_enable_event_pid(struct ltt_ust_session
*usess
,
650 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
,
656 int ust_app_recv_registration(int sock
, struct ust_register_msg
*msg
)
661 int ust_app_recv_notify(int sock
)
666 struct ust_app
*ust_app_create(struct ust_register_msg
*msg
, int sock
)
671 void ust_app_add(struct ust_app
*app
)
675 void ust_app_notify_sock_unregister(int sock
)
679 ssize_t
ust_app_push_metadata(struct ust_registry_session
*registry
,
680 struct consumer_socket
*socket
, int send_zero_data
)
685 void ust_app_destroy(struct ust_app
*app
)
690 enum lttng_error_code
ust_app_snapshot_record(struct ltt_ust_session
*usess
,
691 const struct consumer_output
*output
, int wait
, uint64_t max_stream_size
)
696 unsigned int ust_app_get_nb_stream(struct ltt_ust_session
*usess
)
701 void ust_app_update_event_notifier_error_count(
702 struct lttng_trigger
*lttng_trigger
)
707 int ust_app_supported(void)
712 struct ust_app
*ust_app_find_by_sock(int sock
)
717 struct ust_app
*ust_app_find_by_pid(pid_t pid
)
722 uint64_t ust_app_get_size_one_more_packet_per_stream(
723 const struct ltt_ust_session
*usess
, uint64_t cur_nr_packets
) {
727 int ust_app_uid_get_channel_runtime_stats(uint64_t ust_session_id
,
728 struct cds_list_head
*buffer_reg_uid_list
,
729 struct consumer_output
*consumer
, int overwrite
,
730 uint64_t uchan_id
, uint64_t *discarded
, uint64_t *lost
)
736 int ust_app_pid_get_channel_runtime_stats(struct ltt_ust_session
*usess
,
737 struct ltt_ust_channel
*uchan
,
738 struct consumer_output
*consumer
,
739 int overwrite
, uint64_t *discarded
, uint64_t *lost
)
745 int ust_app_regenerate_statedump_all(struct ltt_ust_session
*usess
)
751 enum lttng_error_code
ust_app_rotate_session(struct ltt_session
*session
)
757 enum lttng_error_code
ust_app_create_channel_subdirectories(
758 const struct ltt_ust_session
*session
)
764 int ust_app_release_object(struct ust_app
*app
, struct lttng_ust_object_data
*data
)
770 enum lttng_error_code
ust_app_clear_session(struct ltt_session
*session
)
776 enum lttng_error_code
ust_app_open_packets(struct ltt_session
*session
)
781 #endif /* HAVE_LIBLTTNG_UST_CTL */
783 #endif /* _LTT_UST_APP_H */