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
25 #include <urcu/list.h>
26 #include <urcu/hlist.h>
35 #include <lttng/ust-endian.h>
39 #include <urcu/compiler.h>
40 #include <urcu/uatomic.h>
41 #include <urcu/arch.h>
43 #include <lttng/tracepoint.h>
44 #include <lttng/ust-events.h>
46 #include <usterr-signal-safe.h>
48 #include <lttng/ust-ctl.h>
50 #include <lttng/ust-dynamic-type.h>
51 #include <lttng/ust-context-provider.h>
54 #include "lttng-ust-uuid.h"
56 #include "tracepoint-internal.h"
57 #include "lttng-tracer.h"
58 #include "lttng-tracer-core.h"
59 #include "lttng-ust-statedump.h"
61 #include "../libringbuffer/shm.h"
65 * All operations within this file are called by the communication
66 * thread, under ust_lock protection.
69 static CDS_LIST_HEAD(sessions
);
71 struct cds_list_head
*_lttng_get_sessions(void)
76 static void _lttng_event_destroy(struct lttng_event
*event
);
77 static void _lttng_enum_destroy(struct lttng_enum
*_enum
);
80 void lttng_session_lazy_sync_enablers(struct lttng_session
*session
);
82 void lttng_session_sync_enablers(struct lttng_session
*session
);
84 void lttng_enabler_destroy(struct lttng_enabler
*enabler
);
87 * Called with ust lock held.
89 int lttng_session_active(void)
91 struct lttng_session
*iter
;
93 cds_list_for_each_entry(iter
, &sessions
, node
) {
101 int lttng_loglevel_match(int loglevel
,
102 unsigned int has_loglevel
,
103 enum lttng_ust_loglevel_type req_type
,
107 loglevel
= TRACE_DEFAULT
;
109 case LTTNG_UST_LOGLEVEL_RANGE
:
110 if (loglevel
<= req_loglevel
111 || (req_loglevel
== -1 && loglevel
<= TRACE_DEBUG
))
115 case LTTNG_UST_LOGLEVEL_SINGLE
:
116 if (loglevel
== req_loglevel
117 || (req_loglevel
== -1 && loglevel
<= TRACE_DEBUG
))
121 case LTTNG_UST_LOGLEVEL_ALL
:
123 if (loglevel
<= TRACE_DEBUG
)
130 void synchronize_trace(void)
135 struct lttng_session
*lttng_session_create(void)
137 struct lttng_session
*session
;
140 session
= zmalloc(sizeof(struct lttng_session
));
143 if (lttng_session_context_init(&session
->ctx
)) {
147 CDS_INIT_LIST_HEAD(&session
->chan_head
);
148 CDS_INIT_LIST_HEAD(&session
->events_head
);
149 CDS_INIT_LIST_HEAD(&session
->enums_head
);
150 CDS_INIT_LIST_HEAD(&session
->enablers_head
);
151 for (i
= 0; i
< LTTNG_UST_EVENT_HT_SIZE
; i
++)
152 CDS_INIT_HLIST_HEAD(&session
->events_ht
.table
[i
]);
153 for (i
= 0; i
< LTTNG_UST_ENUM_HT_SIZE
; i
++)
154 CDS_INIT_HLIST_HEAD(&session
->enums_ht
.table
[i
]);
155 cds_list_add(&session
->node
, &sessions
);
160 * Only used internally at session destruction.
163 void _lttng_channel_unmap(struct lttng_channel
*lttng_chan
)
165 struct channel
*chan
;
166 struct lttng_ust_shm_handle
*handle
;
168 cds_list_del(<tng_chan
->node
);
169 lttng_destroy_context(lttng_chan
->ctx
);
170 chan
= lttng_chan
->chan
;
171 handle
= lttng_chan
->handle
;
173 * note: lttng_chan is private data contained within handle. It
174 * will be freed along with the handle.
176 channel_destroy(chan
, handle
, 0);
180 void register_event(struct lttng_event
*event
)
183 const struct lttng_event_desc
*desc
;
185 assert(event
->registered
== 0);
187 ret
= __tracepoint_probe_register_queue_release(desc
->name
,
188 desc
->probe_callback
,
189 event
, desc
->signature
);
192 event
->registered
= 1;
196 void unregister_event(struct lttng_event
*event
)
199 const struct lttng_event_desc
*desc
;
201 assert(event
->registered
== 1);
203 ret
= __tracepoint_probe_unregister_queue_release(desc
->name
,
204 desc
->probe_callback
,
208 event
->registered
= 0;
212 * Only used internally at session destruction.
215 void _lttng_event_unregister(struct lttng_event
*event
)
217 if (event
->registered
)
218 unregister_event(event
);
221 void lttng_session_destroy(struct lttng_session
*session
)
223 struct lttng_channel
*chan
, *tmpchan
;
224 struct lttng_event
*event
, *tmpevent
;
225 struct lttng_enum
*_enum
, *tmp_enum
;
226 struct lttng_enabler
*enabler
, *tmpenabler
;
228 CMM_ACCESS_ONCE(session
->active
) = 0;
229 cds_list_for_each_entry(event
, &session
->events_head
, node
) {
230 _lttng_event_unregister(event
);
232 synchronize_trace(); /* Wait for in-flight events to complete */
233 __tracepoint_probe_prune_release_queue();
234 cds_list_for_each_entry_safe(enabler
, tmpenabler
,
235 &session
->enablers_head
, node
)
236 lttng_enabler_destroy(enabler
);
237 cds_list_for_each_entry_safe(event
, tmpevent
,
238 &session
->events_head
, node
)
239 _lttng_event_destroy(event
);
240 cds_list_for_each_entry_safe(_enum
, tmp_enum
,
241 &session
->enums_head
, node
)
242 _lttng_enum_destroy(_enum
);
243 cds_list_for_each_entry_safe(chan
, tmpchan
, &session
->chan_head
, node
)
244 _lttng_channel_unmap(chan
);
245 cds_list_del(&session
->node
);
246 lttng_destroy_context(session
->ctx
);
251 int lttng_enum_create(const struct lttng_enum_desc
*desc
,
252 struct lttng_session
*session
)
254 const char *enum_name
= desc
->name
;
255 struct lttng_enum
*_enum
;
256 struct cds_hlist_head
*head
;
257 struct cds_hlist_node
*node
;
259 size_t name_len
= strlen(enum_name
);
263 hash
= jhash(enum_name
, name_len
, 0);
264 head
= &session
->enums_ht
.table
[hash
& (LTTNG_UST_ENUM_HT_SIZE
- 1)];
265 cds_hlist_for_each_entry(_enum
, node
, head
, hlist
) {
267 if (!strncmp(_enum
->desc
->name
, desc
->name
,
268 LTTNG_UST_SYM_NAME_LEN
- 1)) {
274 notify_socket
= lttng_get_notify_socket(session
->owner
);
275 if (notify_socket
< 0) {
280 _enum
= zmalloc(sizeof(*_enum
));
285 _enum
->session
= session
;
288 ret
= ustcomm_register_enum(notify_socket
,
295 DBG("Error (%d) registering enumeration to sessiond", ret
);
296 goto sessiond_register_error
;
298 cds_list_add(&_enum
->node
, &session
->enums_head
);
299 cds_hlist_add_head(&_enum
->hlist
, head
);
302 sessiond_register_error
:
311 int lttng_create_enum_check(const struct lttng_type
*type
,
312 struct lttng_session
*session
)
314 switch (type
->atype
) {
317 const struct lttng_enum_desc
*enum_desc
;
320 enum_desc
= type
->u
.basic
.enumeration
.desc
;
321 ret
= lttng_enum_create(enum_desc
, session
);
322 if (ret
&& ret
!= -EEXIST
) {
323 DBG("Unable to create enum error: (%d)", ret
);
330 const struct lttng_event_field
*tag_field_generic
;
331 const struct lttng_enum_desc
*enum_desc
;
334 tag_field_generic
= lttng_ust_dynamic_type_tag_field();
335 enum_desc
= tag_field_generic
->type
.u
.basic
.enumeration
.desc
;
336 ret
= lttng_enum_create(enum_desc
, session
);
337 if (ret
&& ret
!= -EEXIST
) {
338 DBG("Unable to create enum error: (%d)", ret
);
344 /* TODO: nested types when they become supported. */
351 int lttng_create_all_event_enums(size_t nr_fields
,
352 const struct lttng_event_field
*event_fields
,
353 struct lttng_session
*session
)
358 /* For each field, ensure enum is part of the session. */
359 for (i
= 0; i
< nr_fields
; i
++) {
360 const struct lttng_type
*type
= &event_fields
[i
].type
;
362 ret
= lttng_create_enum_check(type
, session
);
370 int lttng_create_all_ctx_enums(size_t nr_fields
,
371 const struct lttng_ctx_field
*ctx_fields
,
372 struct lttng_session
*session
)
377 /* For each field, ensure enum is part of the session. */
378 for (i
= 0; i
< nr_fields
; i
++) {
379 const struct lttng_type
*type
= &ctx_fields
[i
].event_field
.type
;
381 ret
= lttng_create_enum_check(type
, session
);
389 int lttng_session_enable(struct lttng_session
*session
)
392 struct lttng_channel
*chan
;
395 if (session
->active
) {
400 notify_socket
= lttng_get_notify_socket(session
->owner
);
401 if (notify_socket
< 0)
402 return notify_socket
;
404 /* Set transient enabler state to "enabled" */
408 * Snapshot the number of events per channel to know the type of header
411 cds_list_for_each_entry(chan
, &session
->chan_head
, node
) {
412 const struct lttng_ctx
*ctx
;
413 const struct lttng_ctx_field
*fields
= NULL
;
414 size_t nr_fields
= 0;
417 /* don't change it if session stop/restart */
418 if (chan
->header_type
)
422 nr_fields
= ctx
->nr_fields
;
423 fields
= ctx
->fields
;
424 ret
= lttng_create_all_ctx_enums(nr_fields
, fields
,
427 DBG("Error (%d) adding enum to session", ret
);
431 ret
= ustcomm_register_channel(notify_socket
,
440 DBG("Error (%d) registering channel to sessiond", ret
);
443 if (chan_id
!= chan
->id
) {
444 DBG("Error: channel registration id (%u) does not match id assigned at creation (%u)",
450 /* We need to sync enablers with session before activation. */
451 lttng_session_sync_enablers(session
);
453 /* Set atomically the state to "active" */
454 CMM_ACCESS_ONCE(session
->active
) = 1;
455 CMM_ACCESS_ONCE(session
->been_active
) = 1;
457 session
->statedump_pending
= 1;
458 lttng_ust_sockinfo_session_enabled(session
->owner
);
463 int lttng_session_disable(struct lttng_session
*session
)
467 if (!session
->active
) {
471 /* Set atomically the state to "inactive" */
472 CMM_ACCESS_ONCE(session
->active
) = 0;
474 /* Set transient enabler state to "disabled" */
476 lttng_session_sync_enablers(session
);
481 int lttng_channel_enable(struct lttng_channel
*channel
)
485 if (channel
->enabled
) {
489 /* Set transient enabler state to "enabled" */
491 lttng_session_sync_enablers(channel
->session
);
492 /* Set atomically the state to "enabled" */
493 CMM_ACCESS_ONCE(channel
->enabled
) = 1;
498 int lttng_channel_disable(struct lttng_channel
*channel
)
502 if (!channel
->enabled
) {
506 /* Set atomically the state to "disabled" */
507 CMM_ACCESS_ONCE(channel
->enabled
) = 0;
508 /* Set transient enabler state to "enabled" */
510 lttng_session_sync_enablers(channel
->session
);
516 * Supports event creation while tracing session is active.
519 int lttng_event_create(const struct lttng_event_desc
*desc
,
520 struct lttng_channel
*chan
)
522 const char *event_name
= desc
->name
;
523 struct lttng_event
*event
;
524 struct lttng_session
*session
= chan
->session
;
525 struct cds_hlist_head
*head
;
526 struct cds_hlist_node
*node
;
528 size_t name_len
= strlen(event_name
);
530 int notify_socket
, loglevel
;
533 hash
= jhash(event_name
, name_len
, 0);
534 head
= &chan
->session
->events_ht
.table
[hash
& (LTTNG_UST_EVENT_HT_SIZE
- 1)];
535 cds_hlist_for_each_entry(event
, node
, head
, hlist
) {
537 if (!strncmp(event
->desc
->name
, desc
->name
,
538 LTTNG_UST_SYM_NAME_LEN
- 1)
539 && chan
== event
->chan
) {
545 notify_socket
= lttng_get_notify_socket(session
->owner
);
546 if (notify_socket
< 0) {
551 ret
= lttng_create_all_event_enums(desc
->nr_fields
, desc
->fields
,
554 DBG("Error (%d) adding enum to session", ret
);
555 goto create_enum_error
;
559 * Check if loglevel match. Refuse to connect event if not.
561 event
= zmalloc(sizeof(struct lttng_event
));
568 /* Event will be enabled by enabler sync. */
570 event
->registered
= 0;
571 CDS_INIT_LIST_HEAD(&event
->bytecode_runtime_head
);
572 CDS_INIT_LIST_HEAD(&event
->enablers_ref_head
);
576 loglevel
= *(*event
->desc
->loglevel
);
578 loglevel
= TRACE_DEFAULT
;
579 if (desc
->u
.ext
.model_emf_uri
)
580 uri
= *(desc
->u
.ext
.model_emf_uri
);
584 /* Fetch event ID from sessiond */
585 ret
= ustcomm_register_event(notify_socket
,
597 DBG("Error (%d) registering event to sessiond", ret
);
598 goto sessiond_register_error
;
601 /* Populate lttng_event structure before tracepoint registration. */
603 cds_list_add(&event
->node
, &chan
->session
->events_head
);
604 cds_hlist_add_head(&event
->hlist
, head
);
607 sessiond_register_error
:
617 int lttng_desc_match_wildcard_enabler(const struct lttng_event_desc
*desc
,
618 struct lttng_enabler
*enabler
)
621 unsigned int has_loglevel
= 0;
623 assert(enabler
->type
== LTTNG_ENABLER_WILDCARD
);
624 /* Compare excluding final '*' */
625 if (strncmp(desc
->name
, enabler
->event_param
.name
,
626 strlen(enabler
->event_param
.name
) - 1))
628 if (desc
->loglevel
) {
629 loglevel
= *(*desc
->loglevel
);
632 if (!lttng_loglevel_match(loglevel
,
634 enabler
->event_param
.loglevel_type
,
635 enabler
->event_param
.loglevel
))
641 int lttng_desc_match_event_enabler(const struct lttng_event_desc
*desc
,
642 struct lttng_enabler
*enabler
)
645 unsigned int has_loglevel
= 0;
647 assert(enabler
->type
== LTTNG_ENABLER_EVENT
);
648 if (strcmp(desc
->name
, enabler
->event_param
.name
))
650 if (desc
->loglevel
) {
651 loglevel
= *(*desc
->loglevel
);
654 if (!lttng_loglevel_match(loglevel
,
656 enabler
->event_param
.loglevel_type
,
657 enabler
->event_param
.loglevel
))
663 int lttng_desc_match_enabler(const struct lttng_event_desc
*desc
,
664 struct lttng_enabler
*enabler
)
666 struct lttng_ust_excluder_node
*excluder
;
668 /* If event matches with an excluder, return 'does not match' */
669 cds_list_for_each_entry(excluder
, &enabler
->excluder_head
, node
) {
672 for (count
= 0; count
< excluder
->excluder
.count
; count
++) {
676 excluder_name
= (char *) (excluder
->excluder
.names
)
677 + count
* LTTNG_UST_SYM_NAME_LEN
;
678 len
= strnlen(excluder_name
, LTTNG_UST_SYM_NAME_LEN
);
679 if (len
> 0 && excluder_name
[len
- 1] == '*') {
680 found
= !strncmp(desc
->name
, excluder_name
,
683 found
= !strncmp(desc
->name
, excluder_name
,
684 LTTNG_UST_SYM_NAME_LEN
- 1);
691 switch (enabler
->type
) {
692 case LTTNG_ENABLER_WILDCARD
:
693 return lttng_desc_match_wildcard_enabler(desc
, enabler
);
694 case LTTNG_ENABLER_EVENT
:
695 return lttng_desc_match_event_enabler(desc
, enabler
);
702 int lttng_event_match_enabler(struct lttng_event
*event
,
703 struct lttng_enabler
*enabler
)
705 if (lttng_desc_match_enabler(event
->desc
, enabler
)
706 && event
->chan
== enabler
->chan
)
713 struct lttng_enabler_ref
* lttng_event_enabler_ref(struct lttng_event
*event
,
714 struct lttng_enabler
*enabler
)
716 struct lttng_enabler_ref
*enabler_ref
;
718 cds_list_for_each_entry(enabler_ref
,
719 &event
->enablers_ref_head
, node
) {
720 if (enabler_ref
->ref
== enabler
)
727 * Create struct lttng_event if it is missing and present in the list of
731 void lttng_create_event_if_missing(struct lttng_enabler
*enabler
)
733 struct lttng_session
*session
= enabler
->chan
->session
;
734 struct lttng_probe_desc
*probe_desc
;
735 const struct lttng_event_desc
*desc
;
736 struct lttng_event
*event
;
738 struct cds_list_head
*probe_list
;
740 probe_list
= lttng_get_probe_list_head();
742 * For each probe event, if we find that a probe event matches
743 * our enabler, create an associated lttng_event if not
746 cds_list_for_each_entry(probe_desc
, probe_list
, head
) {
747 for (i
= 0; i
< probe_desc
->nr_events
; i
++) {
749 struct cds_hlist_head
*head
;
750 struct cds_hlist_node
*node
;
751 const char *event_name
;
755 desc
= probe_desc
->event_desc
[i
];
756 if (!lttng_desc_match_enabler(desc
, enabler
))
758 event_name
= desc
->name
;
759 name_len
= strlen(event_name
);
762 * Check if already created.
764 hash
= jhash(event_name
, name_len
, 0);
765 head
= &session
->events_ht
.table
[hash
& (LTTNG_UST_EVENT_HT_SIZE
- 1)];
766 cds_hlist_for_each_entry(event
, node
, head
, hlist
) {
767 if (event
->desc
== desc
768 && event
->chan
== enabler
->chan
)
775 * We need to create an event for this
778 ret
= lttng_event_create(probe_desc
->event_desc
[i
],
781 DBG("Unable to create event %s, error %d\n",
782 probe_desc
->event_desc
[i
]->name
, ret
);
789 * Create events associated with an enabler (if not already present),
790 * and add backward reference from the event to the enabler.
793 int lttng_enabler_ref_events(struct lttng_enabler
*enabler
)
795 struct lttng_session
*session
= enabler
->chan
->session
;
796 struct lttng_event
*event
;
798 /* First ensure that probe events are created for this enabler. */
799 lttng_create_event_if_missing(enabler
);
801 /* For each event matching enabler in session event list. */
802 cds_list_for_each_entry(event
, &session
->events_head
, node
) {
803 struct lttng_enabler_ref
*enabler_ref
;
805 if (!lttng_event_match_enabler(event
, enabler
))
808 enabler_ref
= lttng_event_enabler_ref(event
, enabler
);
811 * If no backward ref, create it.
812 * Add backward ref from event to enabler.
814 enabler_ref
= zmalloc(sizeof(*enabler_ref
));
817 enabler_ref
->ref
= enabler
;
818 cds_list_add(&enabler_ref
->node
,
819 &event
->enablers_ref_head
);
823 * Link filter bytecodes if not linked yet.
825 lttng_enabler_event_link_bytecode(event
, enabler
);
827 /* TODO: merge event context. */
833 * Called at library load: connect the probe on all enablers matching
835 * Called with session mutex held.
837 int lttng_fix_pending_events(void)
839 struct lttng_session
*session
;
841 cds_list_for_each_entry(session
, &sessions
, node
) {
842 lttng_session_lazy_sync_enablers(session
);
848 * For each session of the owner thread, execute pending statedump.
849 * Only dump state for the sessions owned by the caller thread, because
850 * we don't keep ust_lock across the entire iteration.
852 void lttng_handle_pending_statedump(void *owner
)
854 struct lttng_session
*session
;
856 /* Execute state dump */
857 do_lttng_ust_statedump(owner
);
859 /* Clear pending state dump */
863 cds_list_for_each_entry(session
, &sessions
, node
) {
864 if (session
->owner
!= owner
)
866 if (!session
->statedump_pending
)
868 session
->statedump_pending
= 0;
876 * Only used internally at session destruction.
879 void _lttng_event_destroy(struct lttng_event
*event
)
881 struct lttng_enabler_ref
*enabler_ref
, *tmp_enabler_ref
;
883 cds_list_del(&event
->node
);
884 lttng_destroy_context(event
->ctx
);
885 lttng_free_event_filter_runtime(event
);
886 /* Free event enabler refs */
887 cds_list_for_each_entry_safe(enabler_ref
, tmp_enabler_ref
,
888 &event
->enablers_ref_head
, node
)
894 void _lttng_enum_destroy(struct lttng_enum
*_enum
)
896 cds_list_del(&_enum
->node
);
900 void lttng_ust_events_exit(void)
902 struct lttng_session
*session
, *tmpsession
;
904 cds_list_for_each_entry_safe(session
, tmpsession
, &sessions
, node
)
905 lttng_session_destroy(session
);
909 * Enabler management.
911 struct lttng_enabler
*lttng_enabler_create(enum lttng_enabler_type type
,
912 struct lttng_ust_event
*event_param
,
913 struct lttng_channel
*chan
)
915 struct lttng_enabler
*enabler
;
917 enabler
= zmalloc(sizeof(*enabler
));
920 enabler
->type
= type
;
921 CDS_INIT_LIST_HEAD(&enabler
->filter_bytecode_head
);
922 CDS_INIT_LIST_HEAD(&enabler
->excluder_head
);
923 memcpy(&enabler
->event_param
, event_param
,
924 sizeof(enabler
->event_param
));
925 enabler
->chan
= chan
;
927 enabler
->enabled
= 0;
928 cds_list_add(&enabler
->node
, &enabler
->chan
->session
->enablers_head
);
929 lttng_session_lazy_sync_enablers(enabler
->chan
->session
);
933 int lttng_enabler_enable(struct lttng_enabler
*enabler
)
935 enabler
->enabled
= 1;
936 lttng_session_lazy_sync_enablers(enabler
->chan
->session
);
940 int lttng_enabler_disable(struct lttng_enabler
*enabler
)
942 enabler
->enabled
= 0;
943 lttng_session_lazy_sync_enablers(enabler
->chan
->session
);
947 int lttng_enabler_attach_bytecode(struct lttng_enabler
*enabler
,
948 struct lttng_ust_filter_bytecode_node
*bytecode
)
950 bytecode
->enabler
= enabler
;
951 cds_list_add_tail(&bytecode
->node
, &enabler
->filter_bytecode_head
);
952 lttng_session_lazy_sync_enablers(enabler
->chan
->session
);
956 int lttng_enabler_attach_exclusion(struct lttng_enabler
*enabler
,
957 struct lttng_ust_excluder_node
*excluder
)
959 excluder
->enabler
= enabler
;
960 cds_list_add_tail(&excluder
->node
, &enabler
->excluder_head
);
961 lttng_session_lazy_sync_enablers(enabler
->chan
->session
);
965 int lttng_attach_context(struct lttng_ust_context
*context_param
,
966 union ust_args
*uargs
,
967 struct lttng_ctx
**ctx
, struct lttng_session
*session
)
970 * We cannot attach a context after trace has been started for a
971 * session because the metadata does not allow expressing this
972 * information outside of the original channel scope.
974 if (session
->been_active
)
977 switch (context_param
->ctx
) {
978 case LTTNG_UST_CONTEXT_PTHREAD_ID
:
979 return lttng_add_pthread_id_to_ctx(ctx
);
980 case LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER
:
982 struct lttng_ust_perf_counter_ctx
*perf_ctx_param
;
984 perf_ctx_param
= &context_param
->u
.perf_counter
;
985 return lttng_add_perf_counter_to_ctx(
986 perf_ctx_param
->type
,
987 perf_ctx_param
->config
,
988 perf_ctx_param
->name
,
991 case LTTNG_UST_CONTEXT_VTID
:
992 return lttng_add_vtid_to_ctx(ctx
);
993 case LTTNG_UST_CONTEXT_VPID
:
994 return lttng_add_vpid_to_ctx(ctx
);
995 case LTTNG_UST_CONTEXT_PROCNAME
:
996 return lttng_add_procname_to_ctx(ctx
);
997 case LTTNG_UST_CONTEXT_IP
:
998 return lttng_add_ip_to_ctx(ctx
);
999 case LTTNG_UST_CONTEXT_CPU_ID
:
1000 return lttng_add_cpu_id_to_ctx(ctx
);
1001 case LTTNG_UST_CONTEXT_APP_CONTEXT
:
1002 return lttng_ust_add_app_context_to_ctx_rcu(uargs
->app_context
.ctxname
,
1009 int lttng_enabler_attach_context(struct lttng_enabler
*enabler
,
1010 struct lttng_ust_context
*context_param
)
1012 #if 0 // disabled for now.
1013 struct lttng_session
*session
= enabler
->chan
->session
;
1016 ret
= lttng_attach_context(context_param
, &enabler
->ctx
,
1020 lttng_session_lazy_sync_enablers(enabler
->chan
->session
);
1026 void lttng_enabler_destroy(struct lttng_enabler
*enabler
)
1028 struct lttng_ust_filter_bytecode_node
*filter_node
, *tmp_filter_node
;
1029 struct lttng_ust_excluder_node
*excluder_node
, *tmp_excluder_node
;
1031 /* Destroy filter bytecode */
1032 cds_list_for_each_entry_safe(filter_node
, tmp_filter_node
,
1033 &enabler
->filter_bytecode_head
, node
) {
1037 /* Destroy excluders */
1038 cds_list_for_each_entry_safe(excluder_node
, tmp_excluder_node
,
1039 &enabler
->excluder_head
, node
) {
1040 free(excluder_node
);
1043 /* Destroy contexts */
1044 lttng_destroy_context(enabler
->ctx
);
1046 cds_list_del(&enabler
->node
);
1051 * lttng_session_sync_enablers should be called just before starting a
1055 void lttng_session_sync_enablers(struct lttng_session
*session
)
1057 struct lttng_enabler
*enabler
;
1058 struct lttng_event
*event
;
1060 cds_list_for_each_entry(enabler
, &session
->enablers_head
, node
)
1061 lttng_enabler_ref_events(enabler
);
1063 * For each event, if at least one of its enablers is enabled,
1064 * and its channel and session transient states are enabled, we
1065 * enable the event, else we disable it.
1067 cds_list_for_each_entry(event
, &session
->events_head
, node
) {
1068 struct lttng_enabler_ref
*enabler_ref
;
1069 struct lttng_bytecode_runtime
*runtime
;
1070 int enabled
= 0, has_enablers_without_bytecode
= 0;
1073 cds_list_for_each_entry(enabler_ref
,
1074 &event
->enablers_ref_head
, node
) {
1075 if (enabler_ref
->ref
->enabled
) {
1081 * Enabled state is based on union of enablers, with
1082 * intesection of session and channel transient enable
1085 enabled
= enabled
&& session
->tstate
&& event
->chan
->tstate
;
1087 CMM_STORE_SHARED(event
->enabled
, enabled
);
1089 * Sync tracepoint registration with event enabled
1093 if (!event
->registered
)
1094 register_event(event
);
1096 if (event
->registered
)
1097 unregister_event(event
);
1100 /* Check if has enablers without bytecode enabled */
1101 cds_list_for_each_entry(enabler_ref
,
1102 &event
->enablers_ref_head
, node
) {
1103 if (enabler_ref
->ref
->enabled
1104 && cds_list_empty(&enabler_ref
->ref
->filter_bytecode_head
)) {
1105 has_enablers_without_bytecode
= 1;
1109 event
->has_enablers_without_bytecode
=
1110 has_enablers_without_bytecode
;
1112 /* Enable filters */
1113 cds_list_for_each_entry(runtime
,
1114 &event
->bytecode_runtime_head
, node
) {
1115 lttng_filter_sync_state(runtime
);
1118 __tracepoint_probe_prune_release_queue();
1122 * Apply enablers to session events, adding events to session if need
1123 * be. It is required after each modification applied to an active
1124 * session, and right before session "start".
1125 * "lazy" sync means we only sync if required.
1128 void lttng_session_lazy_sync_enablers(struct lttng_session
*session
)
1130 /* We can skip if session is not active */
1131 if (!session
->active
)
1133 lttng_session_sync_enablers(session
);
1137 * Update all sessions with the given app context.
1138 * Called with ust lock held.
1139 * This is invoked when an application context gets loaded/unloaded. It
1140 * ensures the context callbacks are in sync with the application
1141 * context (either app context callbacks, or dummy callbacks).
1143 void lttng_ust_context_set_session_provider(const char *name
,
1144 size_t (*get_size
)(struct lttng_ctx_field
*field
, size_t offset
),
1145 void (*record
)(struct lttng_ctx_field
*field
,
1146 struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
1147 struct lttng_channel
*chan
),
1148 void (*get_value
)(struct lttng_ctx_field
*field
,
1149 struct lttng_ctx_value
*value
))
1151 struct lttng_session
*session
;
1153 cds_list_for_each_entry(session
, &sessions
, node
) {
1154 struct lttng_channel
*chan
;
1155 struct lttng_event
*event
;
1158 ret
= lttng_ust_context_set_provider_rcu(&session
->ctx
,
1159 name
, get_size
, record
, get_value
);
1162 cds_list_for_each_entry(chan
, &session
->chan_head
, node
) {
1163 ret
= lttng_ust_context_set_provider_rcu(&chan
->ctx
,
1164 name
, get_size
, record
, get_value
);
1168 cds_list_for_each_entry(event
, &session
->events_head
, node
) {
1169 ret
= lttng_ust_context_set_provider_rcu(&event
->ctx
,
1170 name
, get_size
, record
, get_value
);