4 * Holds LTTng per-session event registry.
6 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; only
11 * version 2.1 of the License.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26 #include <urcu/list.h>
27 #include <urcu/hlist.h>
36 #include <lttng/ust-endian.h>
40 #include <urcu/compiler.h>
41 #include <urcu/uatomic.h>
42 #include <urcu/arch.h>
44 #include <lttng/tracepoint.h>
45 #include <lttng/ust-events.h>
47 #include <usterr-signal-safe.h>
49 #include <lttng/ust-ctl.h>
51 #include <lttng/ust-dynamic-type.h>
52 #include <lttng/ust-context-provider.h>
55 #include "lttng-ust-uuid.h"
57 #include "tracepoint-internal.h"
58 #include "lttng-tracer.h"
59 #include "lttng-tracer-core.h"
60 #include "lttng-ust-statedump.h"
62 #include "../libringbuffer/shm.h"
66 * All operations within this file are called by the communication
67 * thread, under ust_lock protection.
70 static CDS_LIST_HEAD(sessions
);
72 struct cds_list_head
*_lttng_get_sessions(void)
77 static void _lttng_event_destroy(struct lttng_event
*event
);
78 static void _lttng_enum_destroy(struct lttng_enum
*_enum
);
81 void lttng_session_lazy_sync_enablers(struct lttng_session
*session
);
83 void lttng_session_sync_enablers(struct lttng_session
*session
);
85 void lttng_enabler_destroy(struct lttng_enabler
*enabler
);
88 * Called with ust lock held.
90 int lttng_session_active(void)
92 struct lttng_session
*iter
;
94 cds_list_for_each_entry(iter
, &sessions
, node
) {
102 int lttng_loglevel_match(int loglevel
,
103 unsigned int has_loglevel
,
104 enum lttng_ust_loglevel_type req_type
,
108 loglevel
= TRACE_DEFAULT
;
110 case LTTNG_UST_LOGLEVEL_RANGE
:
111 if (loglevel
<= req_loglevel
112 || (req_loglevel
== -1 && loglevel
<= TRACE_DEBUG
))
116 case LTTNG_UST_LOGLEVEL_SINGLE
:
117 if (loglevel
== req_loglevel
118 || (req_loglevel
== -1 && loglevel
<= TRACE_DEBUG
))
122 case LTTNG_UST_LOGLEVEL_ALL
:
124 if (loglevel
<= TRACE_DEBUG
)
131 void synchronize_trace(void)
136 struct lttng_session
*lttng_session_create(void)
138 struct lttng_session
*session
;
141 session
= zmalloc(sizeof(struct lttng_session
));
144 if (lttng_session_context_init(&session
->ctx
)) {
148 CDS_INIT_LIST_HEAD(&session
->chan_head
);
149 CDS_INIT_LIST_HEAD(&session
->events_head
);
150 CDS_INIT_LIST_HEAD(&session
->enums_head
);
151 CDS_INIT_LIST_HEAD(&session
->enablers_head
);
152 for (i
= 0; i
< LTTNG_UST_EVENT_HT_SIZE
; i
++)
153 CDS_INIT_HLIST_HEAD(&session
->events_ht
.table
[i
]);
154 for (i
= 0; i
< LTTNG_UST_ENUM_HT_SIZE
; i
++)
155 CDS_INIT_HLIST_HEAD(&session
->enums_ht
.table
[i
]);
156 cds_list_add(&session
->node
, &sessions
);
161 * Only used internally at session destruction.
164 void _lttng_channel_unmap(struct lttng_channel
*lttng_chan
)
166 struct channel
*chan
;
167 struct lttng_ust_shm_handle
*handle
;
169 cds_list_del(<tng_chan
->node
);
170 lttng_destroy_context(lttng_chan
->ctx
);
171 chan
= lttng_chan
->chan
;
172 handle
= lttng_chan
->handle
;
174 * note: lttng_chan is private data contained within handle. It
175 * will be freed along with the handle.
177 channel_destroy(chan
, handle
, 0);
181 void register_event(struct lttng_event
*event
)
184 const struct lttng_event_desc
*desc
;
186 assert(event
->registered
== 0);
188 ret
= __tracepoint_probe_register_queue_release(desc
->name
,
189 desc
->probe_callback
,
190 event
, desc
->signature
);
193 event
->registered
= 1;
197 void unregister_event(struct lttng_event
*event
)
200 const struct lttng_event_desc
*desc
;
202 assert(event
->registered
== 1);
204 ret
= __tracepoint_probe_unregister_queue_release(desc
->name
,
205 desc
->probe_callback
,
209 event
->registered
= 0;
213 * Only used internally at session destruction.
216 void _lttng_event_unregister(struct lttng_event
*event
)
218 if (event
->registered
)
219 unregister_event(event
);
222 void lttng_session_destroy(struct lttng_session
*session
)
224 struct lttng_channel
*chan
, *tmpchan
;
225 struct lttng_event
*event
, *tmpevent
;
226 struct lttng_enum
*_enum
, *tmp_enum
;
227 struct lttng_enabler
*enabler
, *tmpenabler
;
229 CMM_ACCESS_ONCE(session
->active
) = 0;
230 cds_list_for_each_entry(event
, &session
->events_head
, node
) {
231 _lttng_event_unregister(event
);
233 synchronize_trace(); /* Wait for in-flight events to complete */
234 __tracepoint_probe_prune_release_queue();
235 cds_list_for_each_entry_safe(enabler
, tmpenabler
,
236 &session
->enablers_head
, node
)
237 lttng_enabler_destroy(enabler
);
238 cds_list_for_each_entry_safe(event
, tmpevent
,
239 &session
->events_head
, node
)
240 _lttng_event_destroy(event
);
241 cds_list_for_each_entry_safe(_enum
, tmp_enum
,
242 &session
->enums_head
, node
)
243 _lttng_enum_destroy(_enum
);
244 cds_list_for_each_entry_safe(chan
, tmpchan
, &session
->chan_head
, node
)
245 _lttng_channel_unmap(chan
);
246 cds_list_del(&session
->node
);
247 lttng_destroy_context(session
->ctx
);
252 int lttng_enum_create(const struct lttng_enum_desc
*desc
,
253 struct lttng_session
*session
)
255 const char *enum_name
= desc
->name
;
256 struct lttng_enum
*_enum
;
257 struct cds_hlist_head
*head
;
258 struct cds_hlist_node
*node
;
260 size_t name_len
= strlen(enum_name
);
264 hash
= jhash(enum_name
, name_len
, 0);
265 head
= &session
->enums_ht
.table
[hash
& (LTTNG_UST_ENUM_HT_SIZE
- 1)];
266 cds_hlist_for_each_entry(_enum
, node
, head
, hlist
) {
268 if (!strncmp(_enum
->desc
->name
, desc
->name
,
269 LTTNG_UST_SYM_NAME_LEN
- 1)) {
275 notify_socket
= lttng_get_notify_socket(session
->owner
);
276 if (notify_socket
< 0) {
281 _enum
= zmalloc(sizeof(*_enum
));
286 _enum
->session
= session
;
289 ret
= ustcomm_register_enum(notify_socket
,
296 DBG("Error (%d) registering enumeration to sessiond", ret
);
297 goto sessiond_register_error
;
299 cds_list_add(&_enum
->node
, &session
->enums_head
);
300 cds_hlist_add_head(&_enum
->hlist
, head
);
303 sessiond_register_error
:
312 int lttng_create_enum_check(const struct lttng_type
*type
,
313 struct lttng_session
*session
)
315 switch (type
->atype
) {
318 const struct lttng_enum_desc
*enum_desc
;
321 enum_desc
= type
->u
.basic
.enumeration
.desc
;
322 ret
= lttng_enum_create(enum_desc
, session
);
323 if (ret
&& ret
!= -EEXIST
) {
324 DBG("Unable to create enum error: (%d)", ret
);
331 const struct lttng_event_field
*tag_field_generic
;
332 const struct lttng_enum_desc
*enum_desc
;
335 tag_field_generic
= lttng_ust_dynamic_type_tag_field();
336 enum_desc
= tag_field_generic
->type
.u
.basic
.enumeration
.desc
;
337 ret
= lttng_enum_create(enum_desc
, session
);
338 if (ret
&& ret
!= -EEXIST
) {
339 DBG("Unable to create enum error: (%d)", ret
);
345 /* TODO: nested types when they become supported. */
352 int lttng_create_all_event_enums(size_t nr_fields
,
353 const struct lttng_event_field
*event_fields
,
354 struct lttng_session
*session
)
359 /* For each field, ensure enum is part of the session. */
360 for (i
= 0; i
< nr_fields
; i
++) {
361 const struct lttng_type
*type
= &event_fields
[i
].type
;
363 ret
= lttng_create_enum_check(type
, session
);
371 int lttng_create_all_ctx_enums(size_t nr_fields
,
372 const struct lttng_ctx_field
*ctx_fields
,
373 struct lttng_session
*session
)
378 /* For each field, ensure enum is part of the session. */
379 for (i
= 0; i
< nr_fields
; i
++) {
380 const struct lttng_type
*type
= &ctx_fields
[i
].event_field
.type
;
382 ret
= lttng_create_enum_check(type
, session
);
390 * Ensure that a state-dump will be performed for this session at the end
391 * of the current handle_message().
393 int lttng_session_statedump(struct lttng_session
*session
)
395 session
->statedump_pending
= 1;
396 lttng_ust_sockinfo_session_enabled(session
->owner
);
400 int lttng_session_enable(struct lttng_session
*session
)
403 struct lttng_channel
*chan
;
406 if (session
->active
) {
411 notify_socket
= lttng_get_notify_socket(session
->owner
);
412 if (notify_socket
< 0)
413 return notify_socket
;
415 /* Set transient enabler state to "enabled" */
419 * Snapshot the number of events per channel to know the type of header
422 cds_list_for_each_entry(chan
, &session
->chan_head
, node
) {
423 const struct lttng_ctx
*ctx
;
424 const struct lttng_ctx_field
*fields
= NULL
;
425 size_t nr_fields
= 0;
428 /* don't change it if session stop/restart */
429 if (chan
->header_type
)
433 nr_fields
= ctx
->nr_fields
;
434 fields
= ctx
->fields
;
435 ret
= lttng_create_all_ctx_enums(nr_fields
, fields
,
438 DBG("Error (%d) adding enum to session", ret
);
442 ret
= ustcomm_register_channel(notify_socket
,
451 DBG("Error (%d) registering channel to sessiond", ret
);
454 if (chan_id
!= chan
->id
) {
455 DBG("Error: channel registration id (%u) does not match id assigned at creation (%u)",
461 /* We need to sync enablers with session before activation. */
462 lttng_session_sync_enablers(session
);
464 /* Set atomically the state to "active" */
465 CMM_ACCESS_ONCE(session
->active
) = 1;
466 CMM_ACCESS_ONCE(session
->been_active
) = 1;
468 ret
= lttng_session_statedump(session
);
475 int lttng_session_disable(struct lttng_session
*session
)
479 if (!session
->active
) {
483 /* Set atomically the state to "inactive" */
484 CMM_ACCESS_ONCE(session
->active
) = 0;
486 /* Set transient enabler state to "disabled" */
488 lttng_session_sync_enablers(session
);
493 int lttng_channel_enable(struct lttng_channel
*channel
)
497 if (channel
->enabled
) {
501 /* Set transient enabler state to "enabled" */
503 lttng_session_sync_enablers(channel
->session
);
504 /* Set atomically the state to "enabled" */
505 CMM_ACCESS_ONCE(channel
->enabled
) = 1;
510 int lttng_channel_disable(struct lttng_channel
*channel
)
514 if (!channel
->enabled
) {
518 /* Set atomically the state to "disabled" */
519 CMM_ACCESS_ONCE(channel
->enabled
) = 0;
520 /* Set transient enabler state to "enabled" */
522 lttng_session_sync_enablers(channel
->session
);
528 * Supports event creation while tracing session is active.
531 int lttng_event_create(const struct lttng_event_desc
*desc
,
532 struct lttng_channel
*chan
)
534 const char *event_name
= desc
->name
;
535 struct lttng_event
*event
;
536 struct lttng_session
*session
= chan
->session
;
537 struct cds_hlist_head
*head
;
538 struct cds_hlist_node
*node
;
540 size_t name_len
= strlen(event_name
);
542 int notify_socket
, loglevel
;
545 hash
= jhash(event_name
, name_len
, 0);
546 head
= &chan
->session
->events_ht
.table
[hash
& (LTTNG_UST_EVENT_HT_SIZE
- 1)];
547 cds_hlist_for_each_entry(event
, node
, head
, hlist
) {
549 if (!strncmp(event
->desc
->name
, desc
->name
,
550 LTTNG_UST_SYM_NAME_LEN
- 1)
551 && chan
== event
->chan
) {
557 notify_socket
= lttng_get_notify_socket(session
->owner
);
558 if (notify_socket
< 0) {
563 ret
= lttng_create_all_event_enums(desc
->nr_fields
, desc
->fields
,
566 DBG("Error (%d) adding enum to session", ret
);
567 goto create_enum_error
;
571 * Check if loglevel match. Refuse to connect event if not.
573 event
= zmalloc(sizeof(struct lttng_event
));
580 /* Event will be enabled by enabler sync. */
582 event
->registered
= 0;
583 CDS_INIT_LIST_HEAD(&event
->bytecode_runtime_head
);
584 CDS_INIT_LIST_HEAD(&event
->enablers_ref_head
);
588 loglevel
= *(*event
->desc
->loglevel
);
590 loglevel
= TRACE_DEFAULT
;
591 if (desc
->u
.ext
.model_emf_uri
)
592 uri
= *(desc
->u
.ext
.model_emf_uri
);
596 /* Fetch event ID from sessiond */
597 ret
= ustcomm_register_event(notify_socket
,
609 DBG("Error (%d) registering event to sessiond", ret
);
610 goto sessiond_register_error
;
613 /* Populate lttng_event structure before tracepoint registration. */
615 cds_list_add(&event
->node
, &chan
->session
->events_head
);
616 cds_hlist_add_head(&event
->hlist
, head
);
619 sessiond_register_error
:
629 int lttng_desc_match_wildcard_enabler(const struct lttng_event_desc
*desc
,
630 struct lttng_enabler
*enabler
)
633 unsigned int has_loglevel
= 0;
635 assert(enabler
->type
== LTTNG_ENABLER_WILDCARD
);
636 /* Compare excluding final '*' */
637 if (strncmp(desc
->name
, enabler
->event_param
.name
,
638 strlen(enabler
->event_param
.name
) - 1))
640 if (desc
->loglevel
) {
641 loglevel
= *(*desc
->loglevel
);
644 if (!lttng_loglevel_match(loglevel
,
646 enabler
->event_param
.loglevel_type
,
647 enabler
->event_param
.loglevel
))
653 int lttng_desc_match_event_enabler(const struct lttng_event_desc
*desc
,
654 struct lttng_enabler
*enabler
)
657 unsigned int has_loglevel
= 0;
659 assert(enabler
->type
== LTTNG_ENABLER_EVENT
);
660 if (strcmp(desc
->name
, enabler
->event_param
.name
))
662 if (desc
->loglevel
) {
663 loglevel
= *(*desc
->loglevel
);
666 if (!lttng_loglevel_match(loglevel
,
668 enabler
->event_param
.loglevel_type
,
669 enabler
->event_param
.loglevel
))
675 int lttng_desc_match_enabler(const struct lttng_event_desc
*desc
,
676 struct lttng_enabler
*enabler
)
678 struct lttng_ust_excluder_node
*excluder
;
680 /* If event matches with an excluder, return 'does not match' */
681 cds_list_for_each_entry(excluder
, &enabler
->excluder_head
, node
) {
684 for (count
= 0; count
< excluder
->excluder
.count
; count
++) {
688 excluder_name
= (char *) (excluder
->excluder
.names
)
689 + count
* LTTNG_UST_SYM_NAME_LEN
;
690 len
= strnlen(excluder_name
, LTTNG_UST_SYM_NAME_LEN
);
691 if (len
> 0 && excluder_name
[len
- 1] == '*') {
692 found
= !strncmp(desc
->name
, excluder_name
,
695 found
= !strncmp(desc
->name
, excluder_name
,
696 LTTNG_UST_SYM_NAME_LEN
- 1);
703 switch (enabler
->type
) {
704 case LTTNG_ENABLER_WILDCARD
:
705 return lttng_desc_match_wildcard_enabler(desc
, enabler
);
706 case LTTNG_ENABLER_EVENT
:
707 return lttng_desc_match_event_enabler(desc
, enabler
);
714 int lttng_event_match_enabler(struct lttng_event
*event
,
715 struct lttng_enabler
*enabler
)
717 if (lttng_desc_match_enabler(event
->desc
, enabler
)
718 && event
->chan
== enabler
->chan
)
725 struct lttng_enabler_ref
* lttng_event_enabler_ref(struct lttng_event
*event
,
726 struct lttng_enabler
*enabler
)
728 struct lttng_enabler_ref
*enabler_ref
;
730 cds_list_for_each_entry(enabler_ref
,
731 &event
->enablers_ref_head
, node
) {
732 if (enabler_ref
->ref
== enabler
)
739 * Create struct lttng_event if it is missing and present in the list of
743 void lttng_create_event_if_missing(struct lttng_enabler
*enabler
)
745 struct lttng_session
*session
= enabler
->chan
->session
;
746 struct lttng_probe_desc
*probe_desc
;
747 const struct lttng_event_desc
*desc
;
748 struct lttng_event
*event
;
750 struct cds_list_head
*probe_list
;
752 probe_list
= lttng_get_probe_list_head();
754 * For each probe event, if we find that a probe event matches
755 * our enabler, create an associated lttng_event if not
758 cds_list_for_each_entry(probe_desc
, probe_list
, head
) {
759 for (i
= 0; i
< probe_desc
->nr_events
; i
++) {
761 struct cds_hlist_head
*head
;
762 struct cds_hlist_node
*node
;
763 const char *event_name
;
767 desc
= probe_desc
->event_desc
[i
];
768 if (!lttng_desc_match_enabler(desc
, enabler
))
770 event_name
= desc
->name
;
771 name_len
= strlen(event_name
);
774 * Check if already created.
776 hash
= jhash(event_name
, name_len
, 0);
777 head
= &session
->events_ht
.table
[hash
& (LTTNG_UST_EVENT_HT_SIZE
- 1)];
778 cds_hlist_for_each_entry(event
, node
, head
, hlist
) {
779 if (event
->desc
== desc
780 && event
->chan
== enabler
->chan
)
787 * We need to create an event for this
790 ret
= lttng_event_create(probe_desc
->event_desc
[i
],
793 DBG("Unable to create event %s, error %d\n",
794 probe_desc
->event_desc
[i
]->name
, ret
);
801 * Create events associated with an enabler (if not already present),
802 * and add backward reference from the event to the enabler.
805 int lttng_enabler_ref_events(struct lttng_enabler
*enabler
)
807 struct lttng_session
*session
= enabler
->chan
->session
;
808 struct lttng_event
*event
;
810 /* First ensure that probe events are created for this enabler. */
811 lttng_create_event_if_missing(enabler
);
813 /* For each event matching enabler in session event list. */
814 cds_list_for_each_entry(event
, &session
->events_head
, node
) {
815 struct lttng_enabler_ref
*enabler_ref
;
817 if (!lttng_event_match_enabler(event
, enabler
))
820 enabler_ref
= lttng_event_enabler_ref(event
, enabler
);
823 * If no backward ref, create it.
824 * Add backward ref from event to enabler.
826 enabler_ref
= zmalloc(sizeof(*enabler_ref
));
829 enabler_ref
->ref
= enabler
;
830 cds_list_add(&enabler_ref
->node
,
831 &event
->enablers_ref_head
);
835 * Link filter bytecodes if not linked yet.
837 lttng_enabler_event_link_bytecode(event
, enabler
);
839 /* TODO: merge event context. */
845 * Called at library load: connect the probe on all enablers matching
847 * Called with session mutex held.
849 int lttng_fix_pending_events(void)
851 struct lttng_session
*session
;
853 cds_list_for_each_entry(session
, &sessions
, node
) {
854 lttng_session_lazy_sync_enablers(session
);
860 * For each session of the owner thread, execute pending statedump.
861 * Only dump state for the sessions owned by the caller thread, because
862 * we don't keep ust_lock across the entire iteration.
864 void lttng_handle_pending_statedump(void *owner
)
866 struct lttng_session
*session
;
868 /* Execute state dump */
869 do_lttng_ust_statedump(owner
);
871 /* Clear pending state dump */
875 cds_list_for_each_entry(session
, &sessions
, node
) {
876 if (session
->owner
!= owner
)
878 if (!session
->statedump_pending
)
880 session
->statedump_pending
= 0;
888 * Only used internally at session destruction.
891 void _lttng_event_destroy(struct lttng_event
*event
)
893 struct lttng_enabler_ref
*enabler_ref
, *tmp_enabler_ref
;
895 cds_list_del(&event
->node
);
896 lttng_destroy_context(event
->ctx
);
897 lttng_free_event_filter_runtime(event
);
898 /* Free event enabler refs */
899 cds_list_for_each_entry_safe(enabler_ref
, tmp_enabler_ref
,
900 &event
->enablers_ref_head
, node
)
906 void _lttng_enum_destroy(struct lttng_enum
*_enum
)
908 cds_list_del(&_enum
->node
);
912 void lttng_ust_events_exit(void)
914 struct lttng_session
*session
, *tmpsession
;
916 cds_list_for_each_entry_safe(session
, tmpsession
, &sessions
, node
)
917 lttng_session_destroy(session
);
921 * Enabler management.
923 struct lttng_enabler
*lttng_enabler_create(enum lttng_enabler_type type
,
924 struct lttng_ust_event
*event_param
,
925 struct lttng_channel
*chan
)
927 struct lttng_enabler
*enabler
;
929 enabler
= zmalloc(sizeof(*enabler
));
932 enabler
->type
= type
;
933 CDS_INIT_LIST_HEAD(&enabler
->filter_bytecode_head
);
934 CDS_INIT_LIST_HEAD(&enabler
->excluder_head
);
935 memcpy(&enabler
->event_param
, event_param
,
936 sizeof(enabler
->event_param
));
937 enabler
->chan
= chan
;
939 enabler
->enabled
= 0;
940 cds_list_add(&enabler
->node
, &enabler
->chan
->session
->enablers_head
);
941 lttng_session_lazy_sync_enablers(enabler
->chan
->session
);
945 int lttng_enabler_enable(struct lttng_enabler
*enabler
)
947 enabler
->enabled
= 1;
948 lttng_session_lazy_sync_enablers(enabler
->chan
->session
);
952 int lttng_enabler_disable(struct lttng_enabler
*enabler
)
954 enabler
->enabled
= 0;
955 lttng_session_lazy_sync_enablers(enabler
->chan
->session
);
959 int lttng_enabler_attach_bytecode(struct lttng_enabler
*enabler
,
960 struct lttng_ust_filter_bytecode_node
*bytecode
)
962 bytecode
->enabler
= enabler
;
963 cds_list_add_tail(&bytecode
->node
, &enabler
->filter_bytecode_head
);
964 lttng_session_lazy_sync_enablers(enabler
->chan
->session
);
968 int lttng_enabler_attach_exclusion(struct lttng_enabler
*enabler
,
969 struct lttng_ust_excluder_node
*excluder
)
971 excluder
->enabler
= enabler
;
972 cds_list_add_tail(&excluder
->node
, &enabler
->excluder_head
);
973 lttng_session_lazy_sync_enablers(enabler
->chan
->session
);
977 int lttng_attach_context(struct lttng_ust_context
*context_param
,
978 union ust_args
*uargs
,
979 struct lttng_ctx
**ctx
, struct lttng_session
*session
)
982 * We cannot attach a context after trace has been started for a
983 * session because the metadata does not allow expressing this
984 * information outside of the original channel scope.
986 if (session
->been_active
)
989 switch (context_param
->ctx
) {
990 case LTTNG_UST_CONTEXT_PTHREAD_ID
:
991 return lttng_add_pthread_id_to_ctx(ctx
);
992 case LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER
:
994 struct lttng_ust_perf_counter_ctx
*perf_ctx_param
;
996 perf_ctx_param
= &context_param
->u
.perf_counter
;
997 return lttng_add_perf_counter_to_ctx(
998 perf_ctx_param
->type
,
999 perf_ctx_param
->config
,
1000 perf_ctx_param
->name
,
1003 case LTTNG_UST_CONTEXT_VTID
:
1004 return lttng_add_vtid_to_ctx(ctx
);
1005 case LTTNG_UST_CONTEXT_VPID
:
1006 return lttng_add_vpid_to_ctx(ctx
);
1007 case LTTNG_UST_CONTEXT_PROCNAME
:
1008 return lttng_add_procname_to_ctx(ctx
);
1009 case LTTNG_UST_CONTEXT_IP
:
1010 return lttng_add_ip_to_ctx(ctx
);
1011 case LTTNG_UST_CONTEXT_CPU_ID
:
1012 return lttng_add_cpu_id_to_ctx(ctx
);
1013 case LTTNG_UST_CONTEXT_APP_CONTEXT
:
1014 return lttng_ust_add_app_context_to_ctx_rcu(uargs
->app_context
.ctxname
,
1021 int lttng_enabler_attach_context(struct lttng_enabler
*enabler
,
1022 struct lttng_ust_context
*context_param
)
1024 #if 0 // disabled for now.
1025 struct lttng_session
*session
= enabler
->chan
->session
;
1028 ret
= lttng_attach_context(context_param
, &enabler
->ctx
,
1032 lttng_session_lazy_sync_enablers(enabler
->chan
->session
);
1038 void lttng_enabler_destroy(struct lttng_enabler
*enabler
)
1040 struct lttng_ust_filter_bytecode_node
*filter_node
, *tmp_filter_node
;
1041 struct lttng_ust_excluder_node
*excluder_node
, *tmp_excluder_node
;
1043 /* Destroy filter bytecode */
1044 cds_list_for_each_entry_safe(filter_node
, tmp_filter_node
,
1045 &enabler
->filter_bytecode_head
, node
) {
1049 /* Destroy excluders */
1050 cds_list_for_each_entry_safe(excluder_node
, tmp_excluder_node
,
1051 &enabler
->excluder_head
, node
) {
1052 free(excluder_node
);
1055 /* Destroy contexts */
1056 lttng_destroy_context(enabler
->ctx
);
1058 cds_list_del(&enabler
->node
);
1063 * lttng_session_sync_enablers should be called just before starting a
1067 void lttng_session_sync_enablers(struct lttng_session
*session
)
1069 struct lttng_enabler
*enabler
;
1070 struct lttng_event
*event
;
1072 cds_list_for_each_entry(enabler
, &session
->enablers_head
, node
)
1073 lttng_enabler_ref_events(enabler
);
1075 * For each event, if at least one of its enablers is enabled,
1076 * and its channel and session transient states are enabled, we
1077 * enable the event, else we disable it.
1079 cds_list_for_each_entry(event
, &session
->events_head
, node
) {
1080 struct lttng_enabler_ref
*enabler_ref
;
1081 struct lttng_bytecode_runtime
*runtime
;
1082 int enabled
= 0, has_enablers_without_bytecode
= 0;
1085 cds_list_for_each_entry(enabler_ref
,
1086 &event
->enablers_ref_head
, node
) {
1087 if (enabler_ref
->ref
->enabled
) {
1093 * Enabled state is based on union of enablers, with
1094 * intesection of session and channel transient enable
1097 enabled
= enabled
&& session
->tstate
&& event
->chan
->tstate
;
1099 CMM_STORE_SHARED(event
->enabled
, enabled
);
1101 * Sync tracepoint registration with event enabled
1105 if (!event
->registered
)
1106 register_event(event
);
1108 if (event
->registered
)
1109 unregister_event(event
);
1112 /* Check if has enablers without bytecode enabled */
1113 cds_list_for_each_entry(enabler_ref
,
1114 &event
->enablers_ref_head
, node
) {
1115 if (enabler_ref
->ref
->enabled
1116 && cds_list_empty(&enabler_ref
->ref
->filter_bytecode_head
)) {
1117 has_enablers_without_bytecode
= 1;
1121 event
->has_enablers_without_bytecode
=
1122 has_enablers_without_bytecode
;
1124 /* Enable filters */
1125 cds_list_for_each_entry(runtime
,
1126 &event
->bytecode_runtime_head
, node
) {
1127 lttng_filter_sync_state(runtime
);
1130 __tracepoint_probe_prune_release_queue();
1134 * Apply enablers to session events, adding events to session if need
1135 * be. It is required after each modification applied to an active
1136 * session, and right before session "start".
1137 * "lazy" sync means we only sync if required.
1140 void lttng_session_lazy_sync_enablers(struct lttng_session
*session
)
1142 /* We can skip if session is not active */
1143 if (!session
->active
)
1145 lttng_session_sync_enablers(session
);
1149 * Update all sessions with the given app context.
1150 * Called with ust lock held.
1151 * This is invoked when an application context gets loaded/unloaded. It
1152 * ensures the context callbacks are in sync with the application
1153 * context (either app context callbacks, or dummy callbacks).
1155 void lttng_ust_context_set_session_provider(const char *name
,
1156 size_t (*get_size
)(struct lttng_ctx_field
*field
, size_t offset
),
1157 void (*record
)(struct lttng_ctx_field
*field
,
1158 struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
1159 struct lttng_channel
*chan
),
1160 void (*get_value
)(struct lttng_ctx_field
*field
,
1161 struct lttng_ctx_value
*value
))
1163 struct lttng_session
*session
;
1165 cds_list_for_each_entry(session
, &sessions
, node
) {
1166 struct lttng_channel
*chan
;
1167 struct lttng_event
*event
;
1170 ret
= lttng_ust_context_set_provider_rcu(&session
->ctx
,
1171 name
, get_size
, record
, get_value
);
1174 cds_list_for_each_entry(chan
, &session
->chan_head
, node
) {
1175 ret
= lttng_ust_context_set_provider_rcu(&chan
->ctx
,
1176 name
, get_size
, record
, get_value
);
1180 cds_list_for_each_entry(event
, &session
->events_head
, node
) {
1181 ret
= lttng_ust_context_set_provider_rcu(&event
->ctx
,
1182 name
, get_size
, record
, get_value
);