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 * Ensure that a state-dump will be performed for this session at the end
390 * of the current handle_message().
392 int lttng_session_statedump(struct lttng_session
*session
)
394 session
->statedump_pending
= 1;
395 lttng_ust_sockinfo_session_enabled(session
->owner
);
399 int lttng_session_enable(struct lttng_session
*session
)
402 struct lttng_channel
*chan
;
405 if (session
->active
) {
410 notify_socket
= lttng_get_notify_socket(session
->owner
);
411 if (notify_socket
< 0)
412 return notify_socket
;
414 /* Set transient enabler state to "enabled" */
418 * Snapshot the number of events per channel to know the type of header
421 cds_list_for_each_entry(chan
, &session
->chan_head
, node
) {
422 const struct lttng_ctx
*ctx
;
423 const struct lttng_ctx_field
*fields
= NULL
;
424 size_t nr_fields
= 0;
427 /* don't change it if session stop/restart */
428 if (chan
->header_type
)
432 nr_fields
= ctx
->nr_fields
;
433 fields
= ctx
->fields
;
434 ret
= lttng_create_all_ctx_enums(nr_fields
, fields
,
437 DBG("Error (%d) adding enum to session", ret
);
441 ret
= ustcomm_register_channel(notify_socket
,
450 DBG("Error (%d) registering channel to sessiond", ret
);
453 if (chan_id
!= chan
->id
) {
454 DBG("Error: channel registration id (%u) does not match id assigned at creation (%u)",
460 /* We need to sync enablers with session before activation. */
461 lttng_session_sync_enablers(session
);
463 /* Set atomically the state to "active" */
464 CMM_ACCESS_ONCE(session
->active
) = 1;
465 CMM_ACCESS_ONCE(session
->been_active
) = 1;
467 ret
= lttng_session_statedump(session
);
474 int lttng_session_disable(struct lttng_session
*session
)
478 if (!session
->active
) {
482 /* Set atomically the state to "inactive" */
483 CMM_ACCESS_ONCE(session
->active
) = 0;
485 /* Set transient enabler state to "disabled" */
487 lttng_session_sync_enablers(session
);
492 int lttng_channel_enable(struct lttng_channel
*channel
)
496 if (channel
->enabled
) {
500 /* Set transient enabler state to "enabled" */
502 lttng_session_sync_enablers(channel
->session
);
503 /* Set atomically the state to "enabled" */
504 CMM_ACCESS_ONCE(channel
->enabled
) = 1;
509 int lttng_channel_disable(struct lttng_channel
*channel
)
513 if (!channel
->enabled
) {
517 /* Set atomically the state to "disabled" */
518 CMM_ACCESS_ONCE(channel
->enabled
) = 0;
519 /* Set transient enabler state to "enabled" */
521 lttng_session_sync_enablers(channel
->session
);
527 * Supports event creation while tracing session is active.
530 int lttng_event_create(const struct lttng_event_desc
*desc
,
531 struct lttng_channel
*chan
)
533 const char *event_name
= desc
->name
;
534 struct lttng_event
*event
;
535 struct lttng_session
*session
= chan
->session
;
536 struct cds_hlist_head
*head
;
537 struct cds_hlist_node
*node
;
539 size_t name_len
= strlen(event_name
);
541 int notify_socket
, loglevel
;
544 hash
= jhash(event_name
, name_len
, 0);
545 head
= &chan
->session
->events_ht
.table
[hash
& (LTTNG_UST_EVENT_HT_SIZE
- 1)];
546 cds_hlist_for_each_entry(event
, node
, head
, hlist
) {
548 if (!strncmp(event
->desc
->name
, desc
->name
,
549 LTTNG_UST_SYM_NAME_LEN
- 1)
550 && chan
== event
->chan
) {
556 notify_socket
= lttng_get_notify_socket(session
->owner
);
557 if (notify_socket
< 0) {
562 ret
= lttng_create_all_event_enums(desc
->nr_fields
, desc
->fields
,
565 DBG("Error (%d) adding enum to session", ret
);
566 goto create_enum_error
;
570 * Check if loglevel match. Refuse to connect event if not.
572 event
= zmalloc(sizeof(struct lttng_event
));
579 /* Event will be enabled by enabler sync. */
581 event
->registered
= 0;
582 CDS_INIT_LIST_HEAD(&event
->bytecode_runtime_head
);
583 CDS_INIT_LIST_HEAD(&event
->enablers_ref_head
);
587 loglevel
= *(*event
->desc
->loglevel
);
589 loglevel
= TRACE_DEFAULT
;
590 if (desc
->u
.ext
.model_emf_uri
)
591 uri
= *(desc
->u
.ext
.model_emf_uri
);
595 /* Fetch event ID from sessiond */
596 ret
= ustcomm_register_event(notify_socket
,
608 DBG("Error (%d) registering event to sessiond", ret
);
609 goto sessiond_register_error
;
612 /* Populate lttng_event structure before tracepoint registration. */
614 cds_list_add(&event
->node
, &chan
->session
->events_head
);
615 cds_hlist_add_head(&event
->hlist
, head
);
618 sessiond_register_error
:
628 int lttng_desc_match_wildcard_enabler(const struct lttng_event_desc
*desc
,
629 struct lttng_enabler
*enabler
)
632 unsigned int has_loglevel
= 0;
634 assert(enabler
->type
== LTTNG_ENABLER_WILDCARD
);
635 /* Compare excluding final '*' */
636 if (strncmp(desc
->name
, enabler
->event_param
.name
,
637 strlen(enabler
->event_param
.name
) - 1))
639 if (desc
->loglevel
) {
640 loglevel
= *(*desc
->loglevel
);
643 if (!lttng_loglevel_match(loglevel
,
645 enabler
->event_param
.loglevel_type
,
646 enabler
->event_param
.loglevel
))
652 int lttng_desc_match_event_enabler(const struct lttng_event_desc
*desc
,
653 struct lttng_enabler
*enabler
)
656 unsigned int has_loglevel
= 0;
658 assert(enabler
->type
== LTTNG_ENABLER_EVENT
);
659 if (strcmp(desc
->name
, enabler
->event_param
.name
))
661 if (desc
->loglevel
) {
662 loglevel
= *(*desc
->loglevel
);
665 if (!lttng_loglevel_match(loglevel
,
667 enabler
->event_param
.loglevel_type
,
668 enabler
->event_param
.loglevel
))
674 int lttng_desc_match_enabler(const struct lttng_event_desc
*desc
,
675 struct lttng_enabler
*enabler
)
677 struct lttng_ust_excluder_node
*excluder
;
679 /* If event matches with an excluder, return 'does not match' */
680 cds_list_for_each_entry(excluder
, &enabler
->excluder_head
, node
) {
683 for (count
= 0; count
< excluder
->excluder
.count
; count
++) {
687 excluder_name
= (char *) (excluder
->excluder
.names
)
688 + count
* LTTNG_UST_SYM_NAME_LEN
;
689 len
= strnlen(excluder_name
, LTTNG_UST_SYM_NAME_LEN
);
690 if (len
> 0 && excluder_name
[len
- 1] == '*') {
691 found
= !strncmp(desc
->name
, excluder_name
,
694 found
= !strncmp(desc
->name
, excluder_name
,
695 LTTNG_UST_SYM_NAME_LEN
- 1);
702 switch (enabler
->type
) {
703 case LTTNG_ENABLER_WILDCARD
:
704 return lttng_desc_match_wildcard_enabler(desc
, enabler
);
705 case LTTNG_ENABLER_EVENT
:
706 return lttng_desc_match_event_enabler(desc
, enabler
);
713 int lttng_event_match_enabler(struct lttng_event
*event
,
714 struct lttng_enabler
*enabler
)
716 if (lttng_desc_match_enabler(event
->desc
, enabler
)
717 && event
->chan
== enabler
->chan
)
724 struct lttng_enabler_ref
* lttng_event_enabler_ref(struct lttng_event
*event
,
725 struct lttng_enabler
*enabler
)
727 struct lttng_enabler_ref
*enabler_ref
;
729 cds_list_for_each_entry(enabler_ref
,
730 &event
->enablers_ref_head
, node
) {
731 if (enabler_ref
->ref
== enabler
)
738 * Create struct lttng_event if it is missing and present in the list of
742 void lttng_create_event_if_missing(struct lttng_enabler
*enabler
)
744 struct lttng_session
*session
= enabler
->chan
->session
;
745 struct lttng_probe_desc
*probe_desc
;
746 const struct lttng_event_desc
*desc
;
747 struct lttng_event
*event
;
749 struct cds_list_head
*probe_list
;
751 probe_list
= lttng_get_probe_list_head();
753 * For each probe event, if we find that a probe event matches
754 * our enabler, create an associated lttng_event if not
757 cds_list_for_each_entry(probe_desc
, probe_list
, head
) {
758 for (i
= 0; i
< probe_desc
->nr_events
; i
++) {
760 struct cds_hlist_head
*head
;
761 struct cds_hlist_node
*node
;
762 const char *event_name
;
766 desc
= probe_desc
->event_desc
[i
];
767 if (!lttng_desc_match_enabler(desc
, enabler
))
769 event_name
= desc
->name
;
770 name_len
= strlen(event_name
);
773 * Check if already created.
775 hash
= jhash(event_name
, name_len
, 0);
776 head
= &session
->events_ht
.table
[hash
& (LTTNG_UST_EVENT_HT_SIZE
- 1)];
777 cds_hlist_for_each_entry(event
, node
, head
, hlist
) {
778 if (event
->desc
== desc
779 && event
->chan
== enabler
->chan
)
786 * We need to create an event for this
789 ret
= lttng_event_create(probe_desc
->event_desc
[i
],
792 DBG("Unable to create event %s, error %d\n",
793 probe_desc
->event_desc
[i
]->name
, ret
);
800 * Create events associated with an enabler (if not already present),
801 * and add backward reference from the event to the enabler.
804 int lttng_enabler_ref_events(struct lttng_enabler
*enabler
)
806 struct lttng_session
*session
= enabler
->chan
->session
;
807 struct lttng_event
*event
;
809 /* First ensure that probe events are created for this enabler. */
810 lttng_create_event_if_missing(enabler
);
812 /* For each event matching enabler in session event list. */
813 cds_list_for_each_entry(event
, &session
->events_head
, node
) {
814 struct lttng_enabler_ref
*enabler_ref
;
816 if (!lttng_event_match_enabler(event
, enabler
))
819 enabler_ref
= lttng_event_enabler_ref(event
, enabler
);
822 * If no backward ref, create it.
823 * Add backward ref from event to enabler.
825 enabler_ref
= zmalloc(sizeof(*enabler_ref
));
828 enabler_ref
->ref
= enabler
;
829 cds_list_add(&enabler_ref
->node
,
830 &event
->enablers_ref_head
);
834 * Link filter bytecodes if not linked yet.
836 lttng_enabler_event_link_bytecode(event
, enabler
);
838 /* TODO: merge event context. */
844 * Called at library load: connect the probe on all enablers matching
846 * Called with session mutex held.
848 int lttng_fix_pending_events(void)
850 struct lttng_session
*session
;
852 cds_list_for_each_entry(session
, &sessions
, node
) {
853 lttng_session_lazy_sync_enablers(session
);
859 * For each session of the owner thread, execute pending statedump.
860 * Only dump state for the sessions owned by the caller thread, because
861 * we don't keep ust_lock across the entire iteration.
863 void lttng_handle_pending_statedump(void *owner
)
865 struct lttng_session
*session
;
867 /* Execute state dump */
868 do_lttng_ust_statedump(owner
);
870 /* Clear pending state dump */
874 cds_list_for_each_entry(session
, &sessions
, node
) {
875 if (session
->owner
!= owner
)
877 if (!session
->statedump_pending
)
879 session
->statedump_pending
= 0;
887 * Only used internally at session destruction.
890 void _lttng_event_destroy(struct lttng_event
*event
)
892 struct lttng_enabler_ref
*enabler_ref
, *tmp_enabler_ref
;
894 cds_list_del(&event
->node
);
895 lttng_destroy_context(event
->ctx
);
896 lttng_free_event_filter_runtime(event
);
897 /* Free event enabler refs */
898 cds_list_for_each_entry_safe(enabler_ref
, tmp_enabler_ref
,
899 &event
->enablers_ref_head
, node
)
905 void _lttng_enum_destroy(struct lttng_enum
*_enum
)
907 cds_list_del(&_enum
->node
);
911 void lttng_ust_events_exit(void)
913 struct lttng_session
*session
, *tmpsession
;
915 cds_list_for_each_entry_safe(session
, tmpsession
, &sessions
, node
)
916 lttng_session_destroy(session
);
920 * Enabler management.
922 struct lttng_enabler
*lttng_enabler_create(enum lttng_enabler_type type
,
923 struct lttng_ust_event
*event_param
,
924 struct lttng_channel
*chan
)
926 struct lttng_enabler
*enabler
;
928 enabler
= zmalloc(sizeof(*enabler
));
931 enabler
->type
= type
;
932 CDS_INIT_LIST_HEAD(&enabler
->filter_bytecode_head
);
933 CDS_INIT_LIST_HEAD(&enabler
->excluder_head
);
934 memcpy(&enabler
->event_param
, event_param
,
935 sizeof(enabler
->event_param
));
936 enabler
->chan
= chan
;
938 enabler
->enabled
= 0;
939 cds_list_add(&enabler
->node
, &enabler
->chan
->session
->enablers_head
);
940 lttng_session_lazy_sync_enablers(enabler
->chan
->session
);
944 int lttng_enabler_enable(struct lttng_enabler
*enabler
)
946 enabler
->enabled
= 1;
947 lttng_session_lazy_sync_enablers(enabler
->chan
->session
);
951 int lttng_enabler_disable(struct lttng_enabler
*enabler
)
953 enabler
->enabled
= 0;
954 lttng_session_lazy_sync_enablers(enabler
->chan
->session
);
958 int lttng_enabler_attach_bytecode(struct lttng_enabler
*enabler
,
959 struct lttng_ust_filter_bytecode_node
*bytecode
)
961 bytecode
->enabler
= enabler
;
962 cds_list_add_tail(&bytecode
->node
, &enabler
->filter_bytecode_head
);
963 lttng_session_lazy_sync_enablers(enabler
->chan
->session
);
967 int lttng_enabler_attach_exclusion(struct lttng_enabler
*enabler
,
968 struct lttng_ust_excluder_node
*excluder
)
970 excluder
->enabler
= enabler
;
971 cds_list_add_tail(&excluder
->node
, &enabler
->excluder_head
);
972 lttng_session_lazy_sync_enablers(enabler
->chan
->session
);
976 int lttng_attach_context(struct lttng_ust_context
*context_param
,
977 union ust_args
*uargs
,
978 struct lttng_ctx
**ctx
, struct lttng_session
*session
)
981 * We cannot attach a context after trace has been started for a
982 * session because the metadata does not allow expressing this
983 * information outside of the original channel scope.
985 if (session
->been_active
)
988 switch (context_param
->ctx
) {
989 case LTTNG_UST_CONTEXT_PTHREAD_ID
:
990 return lttng_add_pthread_id_to_ctx(ctx
);
991 case LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER
:
993 struct lttng_ust_perf_counter_ctx
*perf_ctx_param
;
995 perf_ctx_param
= &context_param
->u
.perf_counter
;
996 return lttng_add_perf_counter_to_ctx(
997 perf_ctx_param
->type
,
998 perf_ctx_param
->config
,
999 perf_ctx_param
->name
,
1002 case LTTNG_UST_CONTEXT_VTID
:
1003 return lttng_add_vtid_to_ctx(ctx
);
1004 case LTTNG_UST_CONTEXT_VPID
:
1005 return lttng_add_vpid_to_ctx(ctx
);
1006 case LTTNG_UST_CONTEXT_PROCNAME
:
1007 return lttng_add_procname_to_ctx(ctx
);
1008 case LTTNG_UST_CONTEXT_IP
:
1009 return lttng_add_ip_to_ctx(ctx
);
1010 case LTTNG_UST_CONTEXT_CPU_ID
:
1011 return lttng_add_cpu_id_to_ctx(ctx
);
1012 case LTTNG_UST_CONTEXT_APP_CONTEXT
:
1013 return lttng_ust_add_app_context_to_ctx_rcu(uargs
->app_context
.ctxname
,
1020 int lttng_enabler_attach_context(struct lttng_enabler
*enabler
,
1021 struct lttng_ust_context
*context_param
)
1023 #if 0 // disabled for now.
1024 struct lttng_session
*session
= enabler
->chan
->session
;
1027 ret
= lttng_attach_context(context_param
, &enabler
->ctx
,
1031 lttng_session_lazy_sync_enablers(enabler
->chan
->session
);
1037 void lttng_enabler_destroy(struct lttng_enabler
*enabler
)
1039 struct lttng_ust_filter_bytecode_node
*filter_node
, *tmp_filter_node
;
1040 struct lttng_ust_excluder_node
*excluder_node
, *tmp_excluder_node
;
1042 /* Destroy filter bytecode */
1043 cds_list_for_each_entry_safe(filter_node
, tmp_filter_node
,
1044 &enabler
->filter_bytecode_head
, node
) {
1048 /* Destroy excluders */
1049 cds_list_for_each_entry_safe(excluder_node
, tmp_excluder_node
,
1050 &enabler
->excluder_head
, node
) {
1051 free(excluder_node
);
1054 /* Destroy contexts */
1055 lttng_destroy_context(enabler
->ctx
);
1057 cds_list_del(&enabler
->node
);
1062 * lttng_session_sync_enablers should be called just before starting a
1066 void lttng_session_sync_enablers(struct lttng_session
*session
)
1068 struct lttng_enabler
*enabler
;
1069 struct lttng_event
*event
;
1071 cds_list_for_each_entry(enabler
, &session
->enablers_head
, node
)
1072 lttng_enabler_ref_events(enabler
);
1074 * For each event, if at least one of its enablers is enabled,
1075 * and its channel and session transient states are enabled, we
1076 * enable the event, else we disable it.
1078 cds_list_for_each_entry(event
, &session
->events_head
, node
) {
1079 struct lttng_enabler_ref
*enabler_ref
;
1080 struct lttng_bytecode_runtime
*runtime
;
1081 int enabled
= 0, has_enablers_without_bytecode
= 0;
1084 cds_list_for_each_entry(enabler_ref
,
1085 &event
->enablers_ref_head
, node
) {
1086 if (enabler_ref
->ref
->enabled
) {
1092 * Enabled state is based on union of enablers, with
1093 * intesection of session and channel transient enable
1096 enabled
= enabled
&& session
->tstate
&& event
->chan
->tstate
;
1098 CMM_STORE_SHARED(event
->enabled
, enabled
);
1100 * Sync tracepoint registration with event enabled
1104 if (!event
->registered
)
1105 register_event(event
);
1107 if (event
->registered
)
1108 unregister_event(event
);
1111 /* Check if has enablers without bytecode enabled */
1112 cds_list_for_each_entry(enabler_ref
,
1113 &event
->enablers_ref_head
, node
) {
1114 if (enabler_ref
->ref
->enabled
1115 && cds_list_empty(&enabler_ref
->ref
->filter_bytecode_head
)) {
1116 has_enablers_without_bytecode
= 1;
1120 event
->has_enablers_without_bytecode
=
1121 has_enablers_without_bytecode
;
1123 /* Enable filters */
1124 cds_list_for_each_entry(runtime
,
1125 &event
->bytecode_runtime_head
, node
) {
1126 lttng_filter_sync_state(runtime
);
1129 __tracepoint_probe_prune_release_queue();
1133 * Apply enablers to session events, adding events to session if need
1134 * be. It is required after each modification applied to an active
1135 * session, and right before session "start".
1136 * "lazy" sync means we only sync if required.
1139 void lttng_session_lazy_sync_enablers(struct lttng_session
*session
)
1141 /* We can skip if session is not active */
1142 if (!session
->active
)
1144 lttng_session_sync_enablers(session
);
1148 * Update all sessions with the given app context.
1149 * Called with ust lock held.
1150 * This is invoked when an application context gets loaded/unloaded. It
1151 * ensures the context callbacks are in sync with the application
1152 * context (either app context callbacks, or dummy callbacks).
1154 void lttng_ust_context_set_session_provider(const char *name
,
1155 size_t (*get_size
)(struct lttng_ctx_field
*field
, size_t offset
),
1156 void (*record
)(struct lttng_ctx_field
*field
,
1157 struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
1158 struct lttng_channel
*chan
),
1159 void (*get_value
)(struct lttng_ctx_field
*field
,
1160 struct lttng_ctx_value
*value
))
1162 struct lttng_session
*session
;
1164 cds_list_for_each_entry(session
, &sessions
, node
) {
1165 struct lttng_channel
*chan
;
1166 struct lttng_event
*event
;
1169 ret
= lttng_ust_context_set_provider_rcu(&session
->ctx
,
1170 name
, get_size
, record
, get_value
);
1173 cds_list_for_each_entry(chan
, &session
->chan_head
, node
) {
1174 ret
= lttng_ust_context_set_provider_rcu(&chan
->ctx
,
1175 name
, get_size
, record
, get_value
);
1179 cds_list_for_each_entry(event
, &session
->events_head
, node
) {
1180 ret
= lttng_ust_context_set_provider_rcu(&event
->ctx
,
1181 name
, get_size
, record
, get_value
);