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(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(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 cds_list_for_each_entry_safe(enabler
, tmpenabler
,
234 &session
->enablers_head
, node
)
235 lttng_enabler_destroy(enabler
);
236 cds_list_for_each_entry_safe(event
, tmpevent
,
237 &session
->events_head
, node
)
238 _lttng_event_destroy(event
);
239 cds_list_for_each_entry_safe(_enum
, tmp_enum
,
240 &session
->enums_head
, node
)
241 _lttng_enum_destroy(_enum
);
242 cds_list_for_each_entry_safe(chan
, tmpchan
, &session
->chan_head
, node
)
243 _lttng_channel_unmap(chan
);
244 cds_list_del(&session
->node
);
245 lttng_destroy_context(session
->ctx
);
250 int lttng_enum_create(const struct lttng_enum_desc
*desc
,
251 struct lttng_session
*session
)
253 const char *enum_name
= desc
->name
;
254 struct lttng_enum
*_enum
;
255 struct cds_hlist_head
*head
;
256 struct cds_hlist_node
*node
;
258 size_t name_len
= strlen(enum_name
);
262 hash
= jhash(enum_name
, name_len
, 0);
263 head
= &session
->enums_ht
.table
[hash
& (LTTNG_UST_ENUM_HT_SIZE
- 1)];
264 cds_hlist_for_each_entry(_enum
, node
, head
, hlist
) {
266 if (!strncmp(_enum
->desc
->name
, desc
->name
,
267 LTTNG_UST_SYM_NAME_LEN
- 1)) {
273 notify_socket
= lttng_get_notify_socket(session
->owner
);
274 if (notify_socket
< 0) {
279 _enum
= zmalloc(sizeof(*_enum
));
284 _enum
->session
= session
;
287 ret
= ustcomm_register_enum(notify_socket
,
294 DBG("Error (%d) registering enumeration to sessiond", ret
);
295 goto sessiond_register_error
;
297 cds_list_add(&_enum
->node
, &session
->enums_head
);
298 cds_hlist_add_head(&_enum
->hlist
, head
);
301 sessiond_register_error
:
310 int lttng_create_enum_check(const struct lttng_type
*type
,
311 struct lttng_session
*session
)
313 switch (type
->atype
) {
316 const struct lttng_enum_desc
*enum_desc
;
319 enum_desc
= type
->u
.basic
.enumeration
.desc
;
320 ret
= lttng_enum_create(enum_desc
, session
);
321 if (ret
&& ret
!= -EEXIST
) {
322 DBG("Unable to create enum error: (%d)", ret
);
329 const struct lttng_event_field
*tag_field_generic
;
330 const struct lttng_enum_desc
*enum_desc
;
333 tag_field_generic
= lttng_ust_dynamic_type_tag_field();
334 enum_desc
= tag_field_generic
->type
.u
.basic
.enumeration
.desc
;
335 ret
= lttng_enum_create(enum_desc
, session
);
336 if (ret
&& ret
!= -EEXIST
) {
337 DBG("Unable to create enum error: (%d)", ret
);
343 /* TODO: nested types when they become supported. */
350 int lttng_create_all_event_enums(size_t nr_fields
,
351 const struct lttng_event_field
*event_fields
,
352 struct lttng_session
*session
)
357 /* For each field, ensure enum is part of the session. */
358 for (i
= 0; i
< nr_fields
; i
++) {
359 const struct lttng_type
*type
= &event_fields
[i
].type
;
361 ret
= lttng_create_enum_check(type
, session
);
369 int lttng_create_all_ctx_enums(size_t nr_fields
,
370 const struct lttng_ctx_field
*ctx_fields
,
371 struct lttng_session
*session
)
376 /* For each field, ensure enum is part of the session. */
377 for (i
= 0; i
< nr_fields
; i
++) {
378 const struct lttng_type
*type
= &ctx_fields
[i
].event_field
.type
;
380 ret
= lttng_create_enum_check(type
, session
);
388 int lttng_session_enable(struct lttng_session
*session
)
391 struct lttng_channel
*chan
;
394 if (session
->active
) {
399 notify_socket
= lttng_get_notify_socket(session
->owner
);
400 if (notify_socket
< 0)
401 return notify_socket
;
403 /* Set transient enabler state to "enabled" */
407 * Snapshot the number of events per channel to know the type of header
410 cds_list_for_each_entry(chan
, &session
->chan_head
, node
) {
411 const struct lttng_ctx
*ctx
;
412 const struct lttng_ctx_field
*fields
= NULL
;
413 size_t nr_fields
= 0;
416 /* don't change it if session stop/restart */
417 if (chan
->header_type
)
421 nr_fields
= ctx
->nr_fields
;
422 fields
= ctx
->fields
;
423 ret
= lttng_create_all_ctx_enums(nr_fields
, fields
,
426 DBG("Error (%d) adding enum to session", ret
);
430 ret
= ustcomm_register_channel(notify_socket
,
439 DBG("Error (%d) registering channel to sessiond", ret
);
442 if (chan_id
!= chan
->id
) {
443 DBG("Error: channel registration id (%u) does not match id assigned at creation (%u)",
449 /* We need to sync enablers with session before activation. */
450 lttng_session_sync_enablers(session
);
452 /* Set atomically the state to "active" */
453 CMM_ACCESS_ONCE(session
->active
) = 1;
454 CMM_ACCESS_ONCE(session
->been_active
) = 1;
456 session
->statedump_pending
= 1;
457 lttng_ust_sockinfo_session_enabled(session
->owner
);
462 int lttng_session_disable(struct lttng_session
*session
)
466 if (!session
->active
) {
470 /* Set atomically the state to "inactive" */
471 CMM_ACCESS_ONCE(session
->active
) = 0;
473 /* Set transient enabler state to "disabled" */
475 lttng_session_sync_enablers(session
);
480 int lttng_channel_enable(struct lttng_channel
*channel
)
484 if (channel
->enabled
) {
488 /* Set transient enabler state to "enabled" */
490 lttng_session_sync_enablers(channel
->session
);
491 /* Set atomically the state to "enabled" */
492 CMM_ACCESS_ONCE(channel
->enabled
) = 1;
497 int lttng_channel_disable(struct lttng_channel
*channel
)
501 if (!channel
->enabled
) {
505 /* Set atomically the state to "disabled" */
506 CMM_ACCESS_ONCE(channel
->enabled
) = 0;
507 /* Set transient enabler state to "enabled" */
509 lttng_session_sync_enablers(channel
->session
);
515 * Supports event creation while tracing session is active.
518 int lttng_event_create(const struct lttng_event_desc
*desc
,
519 struct lttng_channel
*chan
)
521 const char *event_name
= desc
->name
;
522 struct lttng_event
*event
;
523 struct lttng_session
*session
= chan
->session
;
524 struct cds_hlist_head
*head
;
525 struct cds_hlist_node
*node
;
527 size_t name_len
= strlen(event_name
);
529 int notify_socket
, loglevel
;
532 hash
= jhash(event_name
, name_len
, 0);
533 head
= &chan
->session
->events_ht
.table
[hash
& (LTTNG_UST_EVENT_HT_SIZE
- 1)];
534 cds_hlist_for_each_entry(event
, node
, head
, hlist
) {
536 if (!strncmp(event
->desc
->name
, desc
->name
,
537 LTTNG_UST_SYM_NAME_LEN
- 1)
538 && chan
== event
->chan
) {
544 notify_socket
= lttng_get_notify_socket(session
->owner
);
545 if (notify_socket
< 0) {
550 ret
= lttng_create_all_event_enums(desc
->nr_fields
, desc
->fields
,
553 DBG("Error (%d) adding enum to session", ret
);
554 goto create_enum_error
;
558 * Check if loglevel match. Refuse to connect event if not.
560 event
= zmalloc(sizeof(struct lttng_event
));
567 /* Event will be enabled by enabler sync. */
569 event
->registered
= 0;
570 CDS_INIT_LIST_HEAD(&event
->bytecode_runtime_head
);
571 CDS_INIT_LIST_HEAD(&event
->enablers_ref_head
);
575 loglevel
= *(*event
->desc
->loglevel
);
577 loglevel
= TRACE_DEFAULT
;
578 if (desc
->u
.ext
.model_emf_uri
)
579 uri
= *(desc
->u
.ext
.model_emf_uri
);
583 /* Fetch event ID from sessiond */
584 ret
= ustcomm_register_event(notify_socket
,
596 DBG("Error (%d) registering event to sessiond", ret
);
597 goto sessiond_register_error
;
600 /* Populate lttng_event structure before tracepoint registration. */
602 cds_list_add(&event
->node
, &chan
->session
->events_head
);
603 cds_hlist_add_head(&event
->hlist
, head
);
606 sessiond_register_error
:
616 int lttng_desc_match_wildcard_enabler(const struct lttng_event_desc
*desc
,
617 struct lttng_enabler
*enabler
)
620 unsigned int has_loglevel
= 0;
622 assert(enabler
->type
== LTTNG_ENABLER_WILDCARD
);
623 /* Compare excluding final '*' */
624 if (strncmp(desc
->name
, enabler
->event_param
.name
,
625 strlen(enabler
->event_param
.name
) - 1))
627 if (desc
->loglevel
) {
628 loglevel
= *(*desc
->loglevel
);
631 if (!lttng_loglevel_match(loglevel
,
633 enabler
->event_param
.loglevel_type
,
634 enabler
->event_param
.loglevel
))
640 int lttng_desc_match_event_enabler(const struct lttng_event_desc
*desc
,
641 struct lttng_enabler
*enabler
)
644 unsigned int has_loglevel
= 0;
646 assert(enabler
->type
== LTTNG_ENABLER_EVENT
);
647 if (strcmp(desc
->name
, enabler
->event_param
.name
))
649 if (desc
->loglevel
) {
650 loglevel
= *(*desc
->loglevel
);
653 if (!lttng_loglevel_match(loglevel
,
655 enabler
->event_param
.loglevel_type
,
656 enabler
->event_param
.loglevel
))
662 int lttng_desc_match_enabler(const struct lttng_event_desc
*desc
,
663 struct lttng_enabler
*enabler
)
665 struct lttng_ust_excluder_node
*excluder
;
667 /* If event matches with an excluder, return 'does not match' */
668 cds_list_for_each_entry(excluder
, &enabler
->excluder_head
, node
) {
671 for (count
= 0; count
< excluder
->excluder
.count
; count
++) {
675 excluder_name
= (char *) (excluder
->excluder
.names
)
676 + count
* LTTNG_UST_SYM_NAME_LEN
;
677 len
= strnlen(excluder_name
, LTTNG_UST_SYM_NAME_LEN
);
678 if (len
> 0 && excluder_name
[len
- 1] == '*') {
679 found
= !strncmp(desc
->name
, excluder_name
,
682 found
= !strncmp(desc
->name
, excluder_name
,
683 LTTNG_UST_SYM_NAME_LEN
- 1);
690 switch (enabler
->type
) {
691 case LTTNG_ENABLER_WILDCARD
:
692 return lttng_desc_match_wildcard_enabler(desc
, enabler
);
693 case LTTNG_ENABLER_EVENT
:
694 return lttng_desc_match_event_enabler(desc
, enabler
);
701 int lttng_event_match_enabler(struct lttng_event
*event
,
702 struct lttng_enabler
*enabler
)
704 if (lttng_desc_match_enabler(event
->desc
, enabler
)
705 && event
->chan
== enabler
->chan
)
712 struct lttng_enabler_ref
* lttng_event_enabler_ref(struct lttng_event
*event
,
713 struct lttng_enabler
*enabler
)
715 struct lttng_enabler_ref
*enabler_ref
;
717 cds_list_for_each_entry(enabler_ref
,
718 &event
->enablers_ref_head
, node
) {
719 if (enabler_ref
->ref
== enabler
)
726 * Create struct lttng_event if it is missing and present in the list of
730 void lttng_create_event_if_missing(struct lttng_enabler
*enabler
)
732 struct lttng_session
*session
= enabler
->chan
->session
;
733 struct lttng_probe_desc
*probe_desc
;
734 const struct lttng_event_desc
*desc
;
735 struct lttng_event
*event
;
737 struct cds_list_head
*probe_list
;
739 probe_list
= lttng_get_probe_list_head();
741 * For each probe event, if we find that a probe event matches
742 * our enabler, create an associated lttng_event if not
745 cds_list_for_each_entry(probe_desc
, probe_list
, head
) {
746 for (i
= 0; i
< probe_desc
->nr_events
; i
++) {
748 struct cds_hlist_head
*head
;
749 struct cds_hlist_node
*node
;
750 const char *event_name
;
754 desc
= probe_desc
->event_desc
[i
];
755 if (!lttng_desc_match_enabler(desc
, enabler
))
757 event_name
= desc
->name
;
758 name_len
= strlen(event_name
);
761 * Check if already created.
763 hash
= jhash(event_name
, name_len
, 0);
764 head
= &session
->events_ht
.table
[hash
& (LTTNG_UST_EVENT_HT_SIZE
- 1)];
765 cds_hlist_for_each_entry(event
, node
, head
, hlist
) {
766 if (event
->desc
== desc
767 && event
->chan
== enabler
->chan
)
774 * We need to create an event for this
777 ret
= lttng_event_create(probe_desc
->event_desc
[i
],
780 DBG("Unable to create event %s, error %d\n",
781 probe_desc
->event_desc
[i
]->name
, ret
);
788 * Create events associated with an enabler (if not already present),
789 * and add backward reference from the event to the enabler.
792 int lttng_enabler_ref_events(struct lttng_enabler
*enabler
)
794 struct lttng_session
*session
= enabler
->chan
->session
;
795 struct lttng_event
*event
;
797 /* First ensure that probe events are created for this enabler. */
798 lttng_create_event_if_missing(enabler
);
800 /* For each event matching enabler in session event list. */
801 cds_list_for_each_entry(event
, &session
->events_head
, node
) {
802 struct lttng_enabler_ref
*enabler_ref
;
804 if (!lttng_event_match_enabler(event
, enabler
))
807 enabler_ref
= lttng_event_enabler_ref(event
, enabler
);
810 * If no backward ref, create it.
811 * Add backward ref from event to enabler.
813 enabler_ref
= zmalloc(sizeof(*enabler_ref
));
816 enabler_ref
->ref
= enabler
;
817 cds_list_add(&enabler_ref
->node
,
818 &event
->enablers_ref_head
);
822 * Link filter bytecodes if not linked yet.
824 lttng_enabler_event_link_bytecode(event
, enabler
);
826 /* TODO: merge event context. */
832 * Called at library load: connect the probe on all enablers matching
834 * Called with session mutex held.
836 int lttng_fix_pending_events(void)
838 struct lttng_session
*session
;
840 cds_list_for_each_entry(session
, &sessions
, node
) {
841 lttng_session_lazy_sync_enablers(session
);
847 * For each session of the owner thread, execute pending statedump.
848 * Only dump state for the sessions owned by the caller thread, because
849 * we don't keep ust_lock across the entire iteration.
851 void lttng_handle_pending_statedump(void *owner
)
853 struct lttng_session
*session
;
855 /* Execute state dump */
856 do_lttng_ust_statedump(owner
);
858 /* Clear pending state dump */
862 cds_list_for_each_entry(session
, &sessions
, node
) {
863 if (session
->owner
!= owner
)
865 if (!session
->statedump_pending
)
867 session
->statedump_pending
= 0;
875 * Only used internally at session destruction.
878 void _lttng_event_destroy(struct lttng_event
*event
)
880 struct lttng_enabler_ref
*enabler_ref
, *tmp_enabler_ref
;
882 cds_list_del(&event
->node
);
883 lttng_destroy_context(event
->ctx
);
884 lttng_free_event_filter_runtime(event
);
885 /* Free event enabler refs */
886 cds_list_for_each_entry_safe(enabler_ref
, tmp_enabler_ref
,
887 &event
->enablers_ref_head
, node
)
893 void _lttng_enum_destroy(struct lttng_enum
*_enum
)
895 cds_list_del(&_enum
->node
);
899 void lttng_ust_events_exit(void)
901 struct lttng_session
*session
, *tmpsession
;
903 cds_list_for_each_entry_safe(session
, tmpsession
, &sessions
, node
)
904 lttng_session_destroy(session
);
908 * Enabler management.
910 struct lttng_enabler
*lttng_enabler_create(enum lttng_enabler_type type
,
911 struct lttng_ust_event
*event_param
,
912 struct lttng_channel
*chan
)
914 struct lttng_enabler
*enabler
;
916 enabler
= zmalloc(sizeof(*enabler
));
919 enabler
->type
= type
;
920 CDS_INIT_LIST_HEAD(&enabler
->filter_bytecode_head
);
921 CDS_INIT_LIST_HEAD(&enabler
->excluder_head
);
922 memcpy(&enabler
->event_param
, event_param
,
923 sizeof(enabler
->event_param
));
924 enabler
->chan
= chan
;
926 enabler
->enabled
= 0;
927 cds_list_add(&enabler
->node
, &enabler
->chan
->session
->enablers_head
);
928 lttng_session_lazy_sync_enablers(enabler
->chan
->session
);
932 int lttng_enabler_enable(struct lttng_enabler
*enabler
)
934 enabler
->enabled
= 1;
935 lttng_session_lazy_sync_enablers(enabler
->chan
->session
);
939 int lttng_enabler_disable(struct lttng_enabler
*enabler
)
941 enabler
->enabled
= 0;
942 lttng_session_lazy_sync_enablers(enabler
->chan
->session
);
946 int lttng_enabler_attach_bytecode(struct lttng_enabler
*enabler
,
947 struct lttng_ust_filter_bytecode_node
*bytecode
)
949 bytecode
->enabler
= enabler
;
950 cds_list_add_tail(&bytecode
->node
, &enabler
->filter_bytecode_head
);
951 lttng_session_lazy_sync_enablers(enabler
->chan
->session
);
955 int lttng_enabler_attach_exclusion(struct lttng_enabler
*enabler
,
956 struct lttng_ust_excluder_node
*excluder
)
958 excluder
->enabler
= enabler
;
959 cds_list_add_tail(&excluder
->node
, &enabler
->excluder_head
);
960 lttng_session_lazy_sync_enablers(enabler
->chan
->session
);
964 int lttng_attach_context(struct lttng_ust_context
*context_param
,
965 union ust_args
*uargs
,
966 struct lttng_ctx
**ctx
, struct lttng_session
*session
)
969 * We cannot attach a context after trace has been started for a
970 * session because the metadata does not allow expressing this
971 * information outside of the original channel scope.
973 if (session
->been_active
)
976 switch (context_param
->ctx
) {
977 case LTTNG_UST_CONTEXT_PTHREAD_ID
:
978 return lttng_add_pthread_id_to_ctx(ctx
);
979 case LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER
:
981 struct lttng_ust_perf_counter_ctx
*perf_ctx_param
;
983 perf_ctx_param
= &context_param
->u
.perf_counter
;
984 return lttng_add_perf_counter_to_ctx(
985 perf_ctx_param
->type
,
986 perf_ctx_param
->config
,
987 perf_ctx_param
->name
,
990 case LTTNG_UST_CONTEXT_VTID
:
991 return lttng_add_vtid_to_ctx(ctx
);
992 case LTTNG_UST_CONTEXT_VPID
:
993 return lttng_add_vpid_to_ctx(ctx
);
994 case LTTNG_UST_CONTEXT_PROCNAME
:
995 return lttng_add_procname_to_ctx(ctx
);
996 case LTTNG_UST_CONTEXT_IP
:
997 return lttng_add_ip_to_ctx(ctx
);
998 case LTTNG_UST_CONTEXT_CPU_ID
:
999 return lttng_add_cpu_id_to_ctx(ctx
);
1000 case LTTNG_UST_CONTEXT_APP_CONTEXT
:
1001 return lttng_ust_add_app_context_to_ctx_rcu(uargs
->app_context
.ctxname
,
1008 int lttng_enabler_attach_context(struct lttng_enabler
*enabler
,
1009 struct lttng_ust_context
*context_param
)
1011 #if 0 // disabled for now.
1012 struct lttng_session
*session
= enabler
->chan
->session
;
1015 ret
= lttng_attach_context(context_param
, &enabler
->ctx
,
1019 lttng_session_lazy_sync_enablers(enabler
->chan
->session
);
1025 void lttng_enabler_destroy(struct lttng_enabler
*enabler
)
1027 struct lttng_ust_filter_bytecode_node
*filter_node
, *tmp_filter_node
;
1028 struct lttng_ust_excluder_node
*excluder_node
, *tmp_excluder_node
;
1030 /* Destroy filter bytecode */
1031 cds_list_for_each_entry_safe(filter_node
, tmp_filter_node
,
1032 &enabler
->filter_bytecode_head
, node
) {
1036 /* Destroy excluders */
1037 cds_list_for_each_entry_safe(excluder_node
, tmp_excluder_node
,
1038 &enabler
->excluder_head
, node
) {
1039 free(excluder_node
);
1042 /* Destroy contexts */
1043 lttng_destroy_context(enabler
->ctx
);
1045 cds_list_del(&enabler
->node
);
1050 * lttng_session_sync_enablers should be called just before starting a
1054 void lttng_session_sync_enablers(struct lttng_session
*session
)
1056 struct lttng_enabler
*enabler
;
1057 struct lttng_event
*event
;
1059 cds_list_for_each_entry(enabler
, &session
->enablers_head
, node
)
1060 lttng_enabler_ref_events(enabler
);
1062 * For each event, if at least one of its enablers is enabled,
1063 * and its channel and session transient states are enabled, we
1064 * enable the event, else we disable it.
1066 cds_list_for_each_entry(event
, &session
->events_head
, node
) {
1067 struct lttng_enabler_ref
*enabler_ref
;
1068 struct lttng_bytecode_runtime
*runtime
;
1069 int enabled
= 0, has_enablers_without_bytecode
= 0;
1072 cds_list_for_each_entry(enabler_ref
,
1073 &event
->enablers_ref_head
, node
) {
1074 if (enabler_ref
->ref
->enabled
) {
1080 * Enabled state is based on union of enablers, with
1081 * intesection of session and channel transient enable
1084 enabled
= enabled
&& session
->tstate
&& event
->chan
->tstate
;
1086 CMM_STORE_SHARED(event
->enabled
, enabled
);
1088 * Sync tracepoint registration with event enabled
1092 if (!event
->registered
)
1093 register_event(event
);
1095 if (event
->registered
)
1096 unregister_event(event
);
1099 /* Check if has enablers without bytecode enabled */
1100 cds_list_for_each_entry(enabler_ref
,
1101 &event
->enablers_ref_head
, node
) {
1102 if (enabler_ref
->ref
->enabled
1103 && cds_list_empty(&enabler_ref
->ref
->filter_bytecode_head
)) {
1104 has_enablers_without_bytecode
= 1;
1108 event
->has_enablers_without_bytecode
=
1109 has_enablers_without_bytecode
;
1111 /* Enable filters */
1112 cds_list_for_each_entry(runtime
,
1113 &event
->bytecode_runtime_head
, node
) {
1114 lttng_filter_sync_state(runtime
);
1120 * Apply enablers to session events, adding events to session if need
1121 * be. It is required after each modification applied to an active
1122 * session, and right before session "start".
1123 * "lazy" sync means we only sync if required.
1126 void lttng_session_lazy_sync_enablers(struct lttng_session
*session
)
1128 /* We can skip if session is not active */
1129 if (!session
->active
)
1131 lttng_session_sync_enablers(session
);
1135 * Update all sessions with the given app context.
1136 * Called with ust lock held.
1137 * This is invoked when an application context gets loaded/unloaded. It
1138 * ensures the context callbacks are in sync with the application
1139 * context (either app context callbacks, or dummy callbacks).
1141 void lttng_ust_context_set_session_provider(const char *name
,
1142 size_t (*get_size
)(struct lttng_ctx_field
*field
, size_t offset
),
1143 void (*record
)(struct lttng_ctx_field
*field
,
1144 struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
1145 struct lttng_channel
*chan
),
1146 void (*get_value
)(struct lttng_ctx_field
*field
,
1147 struct lttng_ctx_value
*value
))
1149 struct lttng_session
*session
;
1151 cds_list_for_each_entry(session
, &sessions
, node
) {
1152 struct lttng_channel
*chan
;
1153 struct lttng_event
*event
;
1156 ret
= lttng_ust_context_set_provider_rcu(&session
->ctx
,
1157 name
, get_size
, record
, get_value
);
1160 cds_list_for_each_entry(chan
, &session
->chan_head
, node
) {
1161 ret
= lttng_ust_context_set_provider_rcu(&chan
->ctx
,
1162 name
, get_size
, record
, get_value
);
1166 cds_list_for_each_entry(event
, &session
->events_head
, node
) {
1167 ret
= lttng_ust_context_set_provider_rcu(&event
->ctx
,
1168 name
, get_size
, record
, get_value
);