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 * Ensure that a state-dump will be performed for this session at the end
389 * of the current handle_message().
391 int lttng_session_statedump(struct lttng_session
*session
)
393 session
->statedump_pending
= 1;
394 lttng_ust_sockinfo_session_enabled(session
->owner
);
398 int lttng_session_enable(struct lttng_session
*session
)
401 struct lttng_channel
*chan
;
404 if (session
->active
) {
409 notify_socket
= lttng_get_notify_socket(session
->owner
);
410 if (notify_socket
< 0)
411 return notify_socket
;
413 /* Set transient enabler state to "enabled" */
417 * Snapshot the number of events per channel to know the type of header
420 cds_list_for_each_entry(chan
, &session
->chan_head
, node
) {
421 const struct lttng_ctx
*ctx
;
422 const struct lttng_ctx_field
*fields
= NULL
;
423 size_t nr_fields
= 0;
426 /* don't change it if session stop/restart */
427 if (chan
->header_type
)
431 nr_fields
= ctx
->nr_fields
;
432 fields
= ctx
->fields
;
433 ret
= lttng_create_all_ctx_enums(nr_fields
, fields
,
436 DBG("Error (%d) adding enum to session", ret
);
440 ret
= ustcomm_register_channel(notify_socket
,
449 DBG("Error (%d) registering channel to sessiond", ret
);
452 if (chan_id
!= chan
->id
) {
453 DBG("Error: channel registration id (%u) does not match id assigned at creation (%u)",
459 /* We need to sync enablers with session before activation. */
460 lttng_session_sync_enablers(session
);
462 /* Set atomically the state to "active" */
463 CMM_ACCESS_ONCE(session
->active
) = 1;
464 CMM_ACCESS_ONCE(session
->been_active
) = 1;
466 ret
= lttng_session_statedump(session
);
473 int lttng_session_disable(struct lttng_session
*session
)
477 if (!session
->active
) {
481 /* Set atomically the state to "inactive" */
482 CMM_ACCESS_ONCE(session
->active
) = 0;
484 /* Set transient enabler state to "disabled" */
486 lttng_session_sync_enablers(session
);
491 int lttng_channel_enable(struct lttng_channel
*channel
)
495 if (channel
->enabled
) {
499 /* Set transient enabler state to "enabled" */
501 lttng_session_sync_enablers(channel
->session
);
502 /* Set atomically the state to "enabled" */
503 CMM_ACCESS_ONCE(channel
->enabled
) = 1;
508 int lttng_channel_disable(struct lttng_channel
*channel
)
512 if (!channel
->enabled
) {
516 /* Set atomically the state to "disabled" */
517 CMM_ACCESS_ONCE(channel
->enabled
) = 0;
518 /* Set transient enabler state to "enabled" */
520 lttng_session_sync_enablers(channel
->session
);
526 * Supports event creation while tracing session is active.
529 int lttng_event_create(const struct lttng_event_desc
*desc
,
530 struct lttng_channel
*chan
)
532 const char *event_name
= desc
->name
;
533 struct lttng_event
*event
;
534 struct lttng_session
*session
= chan
->session
;
535 struct cds_hlist_head
*head
;
536 struct cds_hlist_node
*node
;
538 size_t name_len
= strlen(event_name
);
540 int notify_socket
, loglevel
;
543 hash
= jhash(event_name
, name_len
, 0);
544 head
= &chan
->session
->events_ht
.table
[hash
& (LTTNG_UST_EVENT_HT_SIZE
- 1)];
545 cds_hlist_for_each_entry(event
, node
, head
, hlist
) {
547 if (!strncmp(event
->desc
->name
, desc
->name
,
548 LTTNG_UST_SYM_NAME_LEN
- 1)
549 && chan
== event
->chan
) {
555 notify_socket
= lttng_get_notify_socket(session
->owner
);
556 if (notify_socket
< 0) {
561 ret
= lttng_create_all_event_enums(desc
->nr_fields
, desc
->fields
,
564 DBG("Error (%d) adding enum to session", ret
);
565 goto create_enum_error
;
569 * Check if loglevel match. Refuse to connect event if not.
571 event
= zmalloc(sizeof(struct lttng_event
));
578 /* Event will be enabled by enabler sync. */
580 event
->registered
= 0;
581 CDS_INIT_LIST_HEAD(&event
->bytecode_runtime_head
);
582 CDS_INIT_LIST_HEAD(&event
->enablers_ref_head
);
586 loglevel
= *(*event
->desc
->loglevel
);
588 loglevel
= TRACE_DEFAULT
;
589 if (desc
->u
.ext
.model_emf_uri
)
590 uri
= *(desc
->u
.ext
.model_emf_uri
);
594 /* Fetch event ID from sessiond */
595 ret
= ustcomm_register_event(notify_socket
,
607 DBG("Error (%d) registering event to sessiond", ret
);
608 goto sessiond_register_error
;
611 /* Populate lttng_event structure before tracepoint registration. */
613 cds_list_add(&event
->node
, &chan
->session
->events_head
);
614 cds_hlist_add_head(&event
->hlist
, head
);
617 sessiond_register_error
:
627 int lttng_desc_match_wildcard_enabler(const struct lttng_event_desc
*desc
,
628 struct lttng_enabler
*enabler
)
631 unsigned int has_loglevel
= 0;
633 assert(enabler
->type
== LTTNG_ENABLER_WILDCARD
);
634 /* Compare excluding final '*' */
635 if (strncmp(desc
->name
, enabler
->event_param
.name
,
636 strlen(enabler
->event_param
.name
) - 1))
638 if (desc
->loglevel
) {
639 loglevel
= *(*desc
->loglevel
);
642 if (!lttng_loglevel_match(loglevel
,
644 enabler
->event_param
.loglevel_type
,
645 enabler
->event_param
.loglevel
))
651 int lttng_desc_match_event_enabler(const struct lttng_event_desc
*desc
,
652 struct lttng_enabler
*enabler
)
655 unsigned int has_loglevel
= 0;
657 assert(enabler
->type
== LTTNG_ENABLER_EVENT
);
658 if (strcmp(desc
->name
, enabler
->event_param
.name
))
660 if (desc
->loglevel
) {
661 loglevel
= *(*desc
->loglevel
);
664 if (!lttng_loglevel_match(loglevel
,
666 enabler
->event_param
.loglevel_type
,
667 enabler
->event_param
.loglevel
))
673 int lttng_desc_match_enabler(const struct lttng_event_desc
*desc
,
674 struct lttng_enabler
*enabler
)
676 struct lttng_ust_excluder_node
*excluder
;
678 /* If event matches with an excluder, return 'does not match' */
679 cds_list_for_each_entry(excluder
, &enabler
->excluder_head
, node
) {
682 for (count
= 0; count
< excluder
->excluder
.count
; count
++) {
686 excluder_name
= (char *) (excluder
->excluder
.names
)
687 + count
* LTTNG_UST_SYM_NAME_LEN
;
688 len
= strnlen(excluder_name
, LTTNG_UST_SYM_NAME_LEN
);
689 if (len
> 0 && excluder_name
[len
- 1] == '*') {
690 found
= !strncmp(desc
->name
, excluder_name
,
693 found
= !strncmp(desc
->name
, excluder_name
,
694 LTTNG_UST_SYM_NAME_LEN
- 1);
701 switch (enabler
->type
) {
702 case LTTNG_ENABLER_WILDCARD
:
703 return lttng_desc_match_wildcard_enabler(desc
, enabler
);
704 case LTTNG_ENABLER_EVENT
:
705 return lttng_desc_match_event_enabler(desc
, enabler
);
712 int lttng_event_match_enabler(struct lttng_event
*event
,
713 struct lttng_enabler
*enabler
)
715 if (lttng_desc_match_enabler(event
->desc
, enabler
)
716 && event
->chan
== enabler
->chan
)
723 struct lttng_enabler_ref
* lttng_event_enabler_ref(struct lttng_event
*event
,
724 struct lttng_enabler
*enabler
)
726 struct lttng_enabler_ref
*enabler_ref
;
728 cds_list_for_each_entry(enabler_ref
,
729 &event
->enablers_ref_head
, node
) {
730 if (enabler_ref
->ref
== enabler
)
737 * Create struct lttng_event if it is missing and present in the list of
741 void lttng_create_event_if_missing(struct lttng_enabler
*enabler
)
743 struct lttng_session
*session
= enabler
->chan
->session
;
744 struct lttng_probe_desc
*probe_desc
;
745 const struct lttng_event_desc
*desc
;
746 struct lttng_event
*event
;
748 struct cds_list_head
*probe_list
;
750 probe_list
= lttng_get_probe_list_head();
752 * For each probe event, if we find that a probe event matches
753 * our enabler, create an associated lttng_event if not
756 cds_list_for_each_entry(probe_desc
, probe_list
, head
) {
757 for (i
= 0; i
< probe_desc
->nr_events
; i
++) {
759 struct cds_hlist_head
*head
;
760 struct cds_hlist_node
*node
;
761 const char *event_name
;
765 desc
= probe_desc
->event_desc
[i
];
766 if (!lttng_desc_match_enabler(desc
, enabler
))
768 event_name
= desc
->name
;
769 name_len
= strlen(event_name
);
772 * Check if already created.
774 hash
= jhash(event_name
, name_len
, 0);
775 head
= &session
->events_ht
.table
[hash
& (LTTNG_UST_EVENT_HT_SIZE
- 1)];
776 cds_hlist_for_each_entry(event
, node
, head
, hlist
) {
777 if (event
->desc
== desc
778 && event
->chan
== enabler
->chan
)
785 * We need to create an event for this
788 ret
= lttng_event_create(probe_desc
->event_desc
[i
],
791 DBG("Unable to create event %s, error %d\n",
792 probe_desc
->event_desc
[i
]->name
, ret
);
799 * Create events associated with an enabler (if not already present),
800 * and add backward reference from the event to the enabler.
803 int lttng_enabler_ref_events(struct lttng_enabler
*enabler
)
805 struct lttng_session
*session
= enabler
->chan
->session
;
806 struct lttng_event
*event
;
808 /* First ensure that probe events are created for this enabler. */
809 lttng_create_event_if_missing(enabler
);
811 /* For each event matching enabler in session event list. */
812 cds_list_for_each_entry(event
, &session
->events_head
, node
) {
813 struct lttng_enabler_ref
*enabler_ref
;
815 if (!lttng_event_match_enabler(event
, enabler
))
818 enabler_ref
= lttng_event_enabler_ref(event
, enabler
);
821 * If no backward ref, create it.
822 * Add backward ref from event to enabler.
824 enabler_ref
= zmalloc(sizeof(*enabler_ref
));
827 enabler_ref
->ref
= enabler
;
828 cds_list_add(&enabler_ref
->node
,
829 &event
->enablers_ref_head
);
833 * Link filter bytecodes if not linked yet.
835 lttng_enabler_event_link_bytecode(event
, enabler
);
837 /* TODO: merge event context. */
843 * Called at library load: connect the probe on all enablers matching
845 * Called with session mutex held.
847 int lttng_fix_pending_events(void)
849 struct lttng_session
*session
;
851 cds_list_for_each_entry(session
, &sessions
, node
) {
852 lttng_session_lazy_sync_enablers(session
);
858 * For each session of the owner thread, execute pending statedump.
859 * Only dump state for the sessions owned by the caller thread, because
860 * we don't keep ust_lock across the entire iteration.
862 void lttng_handle_pending_statedump(void *owner
)
864 struct lttng_session
*session
;
866 /* Execute state dump */
867 do_lttng_ust_statedump(owner
);
869 /* Clear pending state dump */
873 cds_list_for_each_entry(session
, &sessions
, node
) {
874 if (session
->owner
!= owner
)
876 if (!session
->statedump_pending
)
878 session
->statedump_pending
= 0;
886 * Only used internally at session destruction.
889 void _lttng_event_destroy(struct lttng_event
*event
)
891 struct lttng_enabler_ref
*enabler_ref
, *tmp_enabler_ref
;
893 cds_list_del(&event
->node
);
894 lttng_destroy_context(event
->ctx
);
895 lttng_free_event_filter_runtime(event
);
896 /* Free event enabler refs */
897 cds_list_for_each_entry_safe(enabler_ref
, tmp_enabler_ref
,
898 &event
->enablers_ref_head
, node
)
904 void _lttng_enum_destroy(struct lttng_enum
*_enum
)
906 cds_list_del(&_enum
->node
);
910 void lttng_ust_events_exit(void)
912 struct lttng_session
*session
, *tmpsession
;
914 cds_list_for_each_entry_safe(session
, tmpsession
, &sessions
, node
)
915 lttng_session_destroy(session
);
919 * Enabler management.
921 struct lttng_enabler
*lttng_enabler_create(enum lttng_enabler_type type
,
922 struct lttng_ust_event
*event_param
,
923 struct lttng_channel
*chan
)
925 struct lttng_enabler
*enabler
;
927 enabler
= zmalloc(sizeof(*enabler
));
930 enabler
->type
= type
;
931 CDS_INIT_LIST_HEAD(&enabler
->filter_bytecode_head
);
932 CDS_INIT_LIST_HEAD(&enabler
->excluder_head
);
933 memcpy(&enabler
->event_param
, event_param
,
934 sizeof(enabler
->event_param
));
935 enabler
->chan
= chan
;
937 enabler
->enabled
= 0;
938 cds_list_add(&enabler
->node
, &enabler
->chan
->session
->enablers_head
);
939 lttng_session_lazy_sync_enablers(enabler
->chan
->session
);
943 int lttng_enabler_enable(struct lttng_enabler
*enabler
)
945 enabler
->enabled
= 1;
946 lttng_session_lazy_sync_enablers(enabler
->chan
->session
);
950 int lttng_enabler_disable(struct lttng_enabler
*enabler
)
952 enabler
->enabled
= 0;
953 lttng_session_lazy_sync_enablers(enabler
->chan
->session
);
957 int lttng_enabler_attach_bytecode(struct lttng_enabler
*enabler
,
958 struct lttng_ust_filter_bytecode_node
*bytecode
)
960 bytecode
->enabler
= enabler
;
961 cds_list_add_tail(&bytecode
->node
, &enabler
->filter_bytecode_head
);
962 lttng_session_lazy_sync_enablers(enabler
->chan
->session
);
966 int lttng_enabler_attach_exclusion(struct lttng_enabler
*enabler
,
967 struct lttng_ust_excluder_node
*excluder
)
969 excluder
->enabler
= enabler
;
970 cds_list_add_tail(&excluder
->node
, &enabler
->excluder_head
);
971 lttng_session_lazy_sync_enablers(enabler
->chan
->session
);
975 int lttng_attach_context(struct lttng_ust_context
*context_param
,
976 union ust_args
*uargs
,
977 struct lttng_ctx
**ctx
, struct lttng_session
*session
)
980 * We cannot attach a context after trace has been started for a
981 * session because the metadata does not allow expressing this
982 * information outside of the original channel scope.
984 if (session
->been_active
)
987 switch (context_param
->ctx
) {
988 case LTTNG_UST_CONTEXT_PTHREAD_ID
:
989 return lttng_add_pthread_id_to_ctx(ctx
);
990 case LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER
:
992 struct lttng_ust_perf_counter_ctx
*perf_ctx_param
;
994 perf_ctx_param
= &context_param
->u
.perf_counter
;
995 return lttng_add_perf_counter_to_ctx(
996 perf_ctx_param
->type
,
997 perf_ctx_param
->config
,
998 perf_ctx_param
->name
,
1001 case LTTNG_UST_CONTEXT_VTID
:
1002 return lttng_add_vtid_to_ctx(ctx
);
1003 case LTTNG_UST_CONTEXT_VPID
:
1004 return lttng_add_vpid_to_ctx(ctx
);
1005 case LTTNG_UST_CONTEXT_PROCNAME
:
1006 return lttng_add_procname_to_ctx(ctx
);
1007 case LTTNG_UST_CONTEXT_IP
:
1008 return lttng_add_ip_to_ctx(ctx
);
1009 case LTTNG_UST_CONTEXT_CPU_ID
:
1010 return lttng_add_cpu_id_to_ctx(ctx
);
1011 case LTTNG_UST_CONTEXT_APP_CONTEXT
:
1012 return lttng_ust_add_app_context_to_ctx_rcu(uargs
->app_context
.ctxname
,
1019 int lttng_enabler_attach_context(struct lttng_enabler
*enabler
,
1020 struct lttng_ust_context
*context_param
)
1022 #if 0 // disabled for now.
1023 struct lttng_session
*session
= enabler
->chan
->session
;
1026 ret
= lttng_attach_context(context_param
, &enabler
->ctx
,
1030 lttng_session_lazy_sync_enablers(enabler
->chan
->session
);
1036 void lttng_enabler_destroy(struct lttng_enabler
*enabler
)
1038 struct lttng_ust_filter_bytecode_node
*filter_node
, *tmp_filter_node
;
1039 struct lttng_ust_excluder_node
*excluder_node
, *tmp_excluder_node
;
1041 /* Destroy filter bytecode */
1042 cds_list_for_each_entry_safe(filter_node
, tmp_filter_node
,
1043 &enabler
->filter_bytecode_head
, node
) {
1047 /* Destroy excluders */
1048 cds_list_for_each_entry_safe(excluder_node
, tmp_excluder_node
,
1049 &enabler
->excluder_head
, node
) {
1050 free(excluder_node
);
1053 /* Destroy contexts */
1054 lttng_destroy_context(enabler
->ctx
);
1056 cds_list_del(&enabler
->node
);
1061 * lttng_session_sync_enablers should be called just before starting a
1065 void lttng_session_sync_enablers(struct lttng_session
*session
)
1067 struct lttng_enabler
*enabler
;
1068 struct lttng_event
*event
;
1070 cds_list_for_each_entry(enabler
, &session
->enablers_head
, node
)
1071 lttng_enabler_ref_events(enabler
);
1073 * For each event, if at least one of its enablers is enabled,
1074 * and its channel and session transient states are enabled, we
1075 * enable the event, else we disable it.
1077 cds_list_for_each_entry(event
, &session
->events_head
, node
) {
1078 struct lttng_enabler_ref
*enabler_ref
;
1079 struct lttng_bytecode_runtime
*runtime
;
1080 int enabled
= 0, has_enablers_without_bytecode
= 0;
1083 cds_list_for_each_entry(enabler_ref
,
1084 &event
->enablers_ref_head
, node
) {
1085 if (enabler_ref
->ref
->enabled
) {
1091 * Enabled state is based on union of enablers, with
1092 * intesection of session and channel transient enable
1095 enabled
= enabled
&& session
->tstate
&& event
->chan
->tstate
;
1097 CMM_STORE_SHARED(event
->enabled
, enabled
);
1099 * Sync tracepoint registration with event enabled
1103 if (!event
->registered
)
1104 register_event(event
);
1106 if (event
->registered
)
1107 unregister_event(event
);
1110 /* Check if has enablers without bytecode enabled */
1111 cds_list_for_each_entry(enabler_ref
,
1112 &event
->enablers_ref_head
, node
) {
1113 if (enabler_ref
->ref
->enabled
1114 && cds_list_empty(&enabler_ref
->ref
->filter_bytecode_head
)) {
1115 has_enablers_without_bytecode
= 1;
1119 event
->has_enablers_without_bytecode
=
1120 has_enablers_without_bytecode
;
1122 /* Enable filters */
1123 cds_list_for_each_entry(runtime
,
1124 &event
->bytecode_runtime_head
, node
) {
1125 lttng_filter_sync_state(runtime
);
1131 * Apply enablers to session events, adding events to session if need
1132 * be. It is required after each modification applied to an active
1133 * session, and right before session "start".
1134 * "lazy" sync means we only sync if required.
1137 void lttng_session_lazy_sync_enablers(struct lttng_session
*session
)
1139 /* We can skip if session is not active */
1140 if (!session
->active
)
1142 lttng_session_sync_enablers(session
);
1146 * Update all sessions with the given app context.
1147 * Called with ust lock held.
1148 * This is invoked when an application context gets loaded/unloaded. It
1149 * ensures the context callbacks are in sync with the application
1150 * context (either app context callbacks, or dummy callbacks).
1152 void lttng_ust_context_set_session_provider(const char *name
,
1153 size_t (*get_size
)(struct lttng_ctx_field
*field
, size_t offset
),
1154 void (*record
)(struct lttng_ctx_field
*field
,
1155 struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
1156 struct lttng_channel
*chan
),
1157 void (*get_value
)(struct lttng_ctx_field
*field
,
1158 struct lttng_ctx_value
*value
))
1160 struct lttng_session
*session
;
1162 cds_list_for_each_entry(session
, &sessions
, node
) {
1163 struct lttng_channel
*chan
;
1164 struct lttng_event
*event
;
1167 ret
= lttng_ust_context_set_provider_rcu(&session
->ctx
,
1168 name
, get_size
, record
, get_value
);
1171 cds_list_for_each_entry(chan
, &session
->chan_head
, node
) {
1172 ret
= lttng_ust_context_set_provider_rcu(&chan
->ctx
,
1173 name
, get_size
, record
, get_value
);
1177 cds_list_for_each_entry(event
, &session
->events_head
, node
) {
1178 ret
= lttng_ust_context_set_provider_rcu(&event
->ctx
,
1179 name
, get_size
, record
, get_value
);