2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, version 2 only,
6 * as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include <sys/types.h>
27 #include <urcu/compiler.h>
29 #include <common/common.h>
32 #include "ust-consumer.h"
37 * Delete ust context safely. RCU read lock must be held before calling
41 void delete_ust_app_ctx(int sock
, struct ust_app_ctx
*ua_ctx
)
44 ustctl_release_object(sock
, ua_ctx
->obj
);
51 * Delete ust app event safely. RCU read lock must be held before calling
55 void delete_ust_app_event(int sock
, struct ust_app_event
*ua_event
)
58 struct lttng_ht_iter iter
;
59 struct ust_app_ctx
*ua_ctx
;
61 /* Destroy each context of event */
62 cds_lfht_for_each_entry(ua_event
->ctx
->ht
, &iter
.iter
, ua_ctx
,
64 ret
= lttng_ht_del(ua_event
->ctx
, &iter
);
66 delete_ust_app_ctx(sock
, ua_ctx
);
68 lttng_ht_destroy(ua_event
->ctx
);
70 if (ua_event
->obj
!= NULL
) {
71 ustctl_release_object(sock
, ua_event
->obj
);
78 * Delete ust app stream safely. RCU read lock must be held before calling
82 void delete_ust_app_stream(int sock
, struct ltt_ust_stream
*stream
)
85 ustctl_release_object(sock
, stream
->obj
);
86 lttng_fd_put(LTTNG_FD_APPS
, 2);
93 * Delete ust app channel safely. RCU read lock must be held before calling
97 void delete_ust_app_channel(int sock
, struct ust_app_channel
*ua_chan
)
100 struct lttng_ht_iter iter
;
101 struct ust_app_event
*ua_event
;
102 struct ust_app_ctx
*ua_ctx
;
103 struct ltt_ust_stream
*stream
, *stmp
;
106 cds_list_for_each_entry_safe(stream
, stmp
, &ua_chan
->streams
.head
, list
) {
107 cds_list_del(&stream
->list
);
108 delete_ust_app_stream(sock
, stream
);
112 cds_lfht_for_each_entry(ua_chan
->ctx
->ht
, &iter
.iter
, ua_ctx
, node
.node
) {
113 ret
= lttng_ht_del(ua_chan
->ctx
, &iter
);
115 delete_ust_app_ctx(sock
, ua_ctx
);
117 lttng_ht_destroy(ua_chan
->ctx
);
120 cds_lfht_for_each_entry(ua_chan
->events
->ht
, &iter
.iter
, ua_event
,
122 ret
= lttng_ht_del(ua_chan
->events
, &iter
);
124 delete_ust_app_event(sock
, ua_event
);
126 lttng_ht_destroy(ua_chan
->events
);
128 if (ua_chan
->obj
!= NULL
) {
129 ustctl_release_object(sock
, ua_chan
->obj
);
130 lttng_fd_put(LTTNG_FD_APPS
, 2);
137 * Delete ust app session safely. RCU read lock must be held before calling
141 void delete_ust_app_session(int sock
, struct ust_app_session
*ua_sess
)
144 struct lttng_ht_iter iter
;
145 struct ust_app_channel
*ua_chan
;
147 if (ua_sess
->metadata
) {
148 if (ua_sess
->metadata
->stream_obj
) {
149 ustctl_release_object(sock
, ua_sess
->metadata
->stream_obj
);
150 lttng_fd_put(LTTNG_FD_APPS
, 2);
151 free(ua_sess
->metadata
->stream_obj
);
153 if (ua_sess
->metadata
->obj
) {
154 ustctl_release_object(sock
, ua_sess
->metadata
->obj
);
155 lttng_fd_put(LTTNG_FD_APPS
, 2);
156 free(ua_sess
->metadata
->obj
);
158 trace_ust_destroy_metadata(ua_sess
->metadata
);
161 cds_lfht_for_each_entry(ua_sess
->channels
->ht
, &iter
.iter
, ua_chan
,
163 ret
= lttng_ht_del(ua_sess
->channels
, &iter
);
165 delete_ust_app_channel(sock
, ua_chan
);
167 lttng_ht_destroy(ua_sess
->channels
);
169 if (ua_sess
->handle
!= -1) {
170 ustctl_release_handle(sock
, ua_sess
->handle
);
176 * Delete a traceable application structure from the global list. Never call
177 * this function outside of a call_rcu call.
180 void delete_ust_app(struct ust_app
*app
)
183 struct lttng_ht_iter iter
;
184 struct ust_app_session
*ua_sess
;
188 /* Delete ust app sessions info */
193 cds_lfht_for_each_entry(app
->sessions
->ht
, &iter
.iter
, ua_sess
,
195 ret
= lttng_ht_del(app
->sessions
, &iter
);
197 delete_ust_app_session(app
->sock
, ua_sess
);
199 lttng_ht_destroy(app
->sessions
);
202 * Wait until we have deleted the application from the sock hash table
203 * before closing this socket, otherwise an application could re-use the
204 * socket ID and race with the teardown, using the same hash table entry.
206 * It's OK to leave the close in call_rcu. We want it to stay unique for
207 * all RCU readers that could run concurrently with unregister app,
208 * therefore we _need_ to only close that socket after a grace period. So
209 * it should stay in this RCU callback.
211 * This close() is a very important step of the synchronization model so
212 * every modification to this function must be carefully reviewed.
218 lttng_fd_put(LTTNG_FD_APPS
, 1);
220 DBG2("UST app pid %d deleted", app
->pid
);
227 * URCU intermediate call to delete an UST app.
230 void delete_ust_app_rcu(struct rcu_head
*head
)
232 struct lttng_ht_node_ulong
*node
=
233 caa_container_of(head
, struct lttng_ht_node_ulong
, head
);
234 struct ust_app
*app
=
235 caa_container_of(node
, struct ust_app
, pid_n
);
237 DBG3("Call RCU deleting app PID %d", app
->pid
);
242 * Alloc new UST app session.
245 struct ust_app_session
*alloc_ust_app_session(void)
247 struct ust_app_session
*ua_sess
;
249 /* Init most of the default value by allocating and zeroing */
250 ua_sess
= zmalloc(sizeof(struct ust_app_session
));
251 if (ua_sess
== NULL
) {
256 ua_sess
->handle
= -1;
257 ua_sess
->channels
= lttng_ht_new(0, LTTNG_HT_TYPE_STRING
);
266 * Alloc new UST app channel.
269 struct ust_app_channel
*alloc_ust_app_channel(char *name
,
270 struct lttng_ust_channel
*attr
)
272 struct ust_app_channel
*ua_chan
;
274 /* Init most of the default value by allocating and zeroing */
275 ua_chan
= zmalloc(sizeof(struct ust_app_channel
));
276 if (ua_chan
== NULL
) {
281 /* Setup channel name */
282 strncpy(ua_chan
->name
, name
, sizeof(ua_chan
->name
));
283 ua_chan
->name
[sizeof(ua_chan
->name
) - 1] = '\0';
285 ua_chan
->enabled
= 1;
286 ua_chan
->handle
= -1;
287 ua_chan
->ctx
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
288 ua_chan
->events
= lttng_ht_new(0, LTTNG_HT_TYPE_STRING
);
289 lttng_ht_node_init_str(&ua_chan
->node
, ua_chan
->name
);
291 CDS_INIT_LIST_HEAD(&ua_chan
->streams
.head
);
293 /* Copy attributes */
295 memcpy(&ua_chan
->attr
, attr
, sizeof(ua_chan
->attr
));
298 DBG3("UST app channel %s allocated", ua_chan
->name
);
307 * Alloc new UST app event.
310 struct ust_app_event
*alloc_ust_app_event(char *name
,
311 struct lttng_ust_event
*attr
)
313 struct ust_app_event
*ua_event
;
315 /* Init most of the default value by allocating and zeroing */
316 ua_event
= zmalloc(sizeof(struct ust_app_event
));
317 if (ua_event
== NULL
) {
322 ua_event
->enabled
= 1;
323 strncpy(ua_event
->name
, name
, sizeof(ua_event
->name
));
324 ua_event
->name
[sizeof(ua_event
->name
) - 1] = '\0';
325 ua_event
->ctx
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
326 lttng_ht_node_init_str(&ua_event
->node
, ua_event
->name
);
328 /* Copy attributes */
330 memcpy(&ua_event
->attr
, attr
, sizeof(ua_event
->attr
));
333 DBG3("UST app event %s allocated", ua_event
->name
);
342 * Alloc new UST app context.
345 struct ust_app_ctx
*alloc_ust_app_ctx(struct lttng_ust_context
*uctx
)
347 struct ust_app_ctx
*ua_ctx
;
349 ua_ctx
= zmalloc(sizeof(struct ust_app_ctx
));
350 if (ua_ctx
== NULL
) {
355 memcpy(&ua_ctx
->ctx
, uctx
, sizeof(ua_ctx
->ctx
));
358 DBG3("UST app context %d allocated", ua_ctx
->ctx
.ctx
);
365 * Find an ust_app using the sock and return it. RCU read side lock must be
366 * held before calling this helper function.
369 struct ust_app
*find_app_by_sock(int sock
)
371 struct lttng_ht_node_ulong
*node
;
372 struct lttng_ht_iter iter
;
374 lttng_ht_lookup(ust_app_ht_by_sock
, (void *)((unsigned long) sock
), &iter
);
375 node
= lttng_ht_iter_get_node_ulong(&iter
);
377 DBG2("UST app find by sock %d not found", sock
);
381 return caa_container_of(node
, struct ust_app
, sock_n
);
388 * Create the channel context on the tracer.
391 int create_ust_channel_context(struct ust_app_channel
*ua_chan
,
392 struct ust_app_ctx
*ua_ctx
, struct ust_app
*app
)
396 ret
= ustctl_add_context(app
->sock
, &ua_ctx
->ctx
,
397 ua_chan
->obj
, &ua_ctx
->obj
);
402 ua_ctx
->handle
= ua_ctx
->obj
->handle
;
404 DBG2("UST app context created successfully for channel %s", ua_chan
->name
);
411 * Create the event context on the tracer.
414 int create_ust_event_context(struct ust_app_event
*ua_event
,
415 struct ust_app_ctx
*ua_ctx
, struct ust_app
*app
)
419 ret
= ustctl_add_context(app
->sock
, &ua_ctx
->ctx
,
420 ua_event
->obj
, &ua_ctx
->obj
);
425 ua_ctx
->handle
= ua_ctx
->obj
->handle
;
427 DBG2("UST app context created successfully for event %s", ua_event
->name
);
434 * Disable the specified event on to UST tracer for the UST session.
436 static int disable_ust_event(struct ust_app
*app
,
437 struct ust_app_session
*ua_sess
, struct ust_app_event
*ua_event
)
441 ret
= ustctl_disable(app
->sock
, ua_event
->obj
);
443 ERR("UST app event %s disable failed for app (pid: %d) "
444 "and session handle %d with ret %d",
445 ua_event
->attr
.name
, app
->pid
, ua_sess
->handle
, ret
);
449 DBG2("UST app event %s disabled successfully for app (pid: %d)",
450 ua_event
->attr
.name
, app
->pid
);
457 * Disable the specified channel on to UST tracer for the UST session.
459 static int disable_ust_channel(struct ust_app
*app
,
460 struct ust_app_session
*ua_sess
, struct ust_app_channel
*ua_chan
)
464 ret
= ustctl_disable(app
->sock
, ua_chan
->obj
);
466 ERR("UST app channel %s disable failed for app (pid: %d) "
467 "and session handle %d with ret %d",
468 ua_chan
->name
, app
->pid
, ua_sess
->handle
, ret
);
472 DBG2("UST app channel %s disabled successfully for app (pid: %d)",
473 ua_chan
->name
, app
->pid
);
480 * Enable the specified channel on to UST tracer for the UST session.
482 static int enable_ust_channel(struct ust_app
*app
,
483 struct ust_app_session
*ua_sess
, struct ust_app_channel
*ua_chan
)
487 ret
= ustctl_enable(app
->sock
, ua_chan
->obj
);
489 ERR("UST app channel %s enable failed for app (pid: %d) "
490 "and session handle %d with ret %d",
491 ua_chan
->name
, app
->pid
, ua_sess
->handle
, ret
);
495 ua_chan
->enabled
= 1;
497 DBG2("UST app channel %s enabled successfully for app (pid: %d)",
498 ua_chan
->name
, app
->pid
);
505 * Enable the specified event on to UST tracer for the UST session.
507 static int enable_ust_event(struct ust_app
*app
,
508 struct ust_app_session
*ua_sess
, struct ust_app_event
*ua_event
)
512 ret
= ustctl_enable(app
->sock
, ua_event
->obj
);
514 ERR("UST app event %s enable failed for app (pid: %d) "
515 "and session handle %d with ret %d",
516 ua_event
->attr
.name
, app
->pid
, ua_sess
->handle
, ret
);
520 DBG2("UST app event %s enabled successfully for app (pid: %d)",
521 ua_event
->attr
.name
, app
->pid
);
528 * Open metadata onto the UST tracer for a UST session.
530 static int open_ust_metadata(struct ust_app
*app
,
531 struct ust_app_session
*ua_sess
)
534 struct lttng_ust_channel_attr uattr
;
536 uattr
.overwrite
= ua_sess
->metadata
->attr
.overwrite
;
537 uattr
.subbuf_size
= ua_sess
->metadata
->attr
.subbuf_size
;
538 uattr
.num_subbuf
= ua_sess
->metadata
->attr
.num_subbuf
;
539 uattr
.switch_timer_interval
=
540 ua_sess
->metadata
->attr
.switch_timer_interval
;
541 uattr
.read_timer_interval
=
542 ua_sess
->metadata
->attr
.read_timer_interval
;
543 uattr
.output
= ua_sess
->metadata
->attr
.output
;
545 /* We are going to receive 2 fds, we need to reserve them. */
546 ret
= lttng_fd_get(LTTNG_FD_APPS
, 2);
548 ERR("Exhausted number of available FD upon metadata open");
551 /* UST tracer metadata creation */
552 ret
= ustctl_open_metadata(app
->sock
, ua_sess
->handle
, &uattr
,
553 &ua_sess
->metadata
->obj
);
555 ERR("UST app open metadata failed for app pid:%d with ret %d",
560 ua_sess
->metadata
->handle
= ua_sess
->metadata
->obj
->handle
;
567 * Create stream onto the UST tracer for a UST session.
569 static int create_ust_stream(struct ust_app
*app
,
570 struct ust_app_session
*ua_sess
)
574 /* We are going to receive 2 fds, we need to reserve them. */
575 ret
= lttng_fd_get(LTTNG_FD_APPS
, 2);
577 ERR("Exhausted number of available FD upon metadata stream create");
580 ret
= ustctl_create_stream(app
->sock
, ua_sess
->metadata
->obj
,
581 &ua_sess
->metadata
->stream_obj
);
583 ERR("UST create metadata stream failed");
592 * Create the specified channel onto the UST tracer for a UST session.
594 static int create_ust_channel(struct ust_app
*app
,
595 struct ust_app_session
*ua_sess
, struct ust_app_channel
*ua_chan
)
599 /* TODO: remove cast and use lttng-ust-abi.h */
601 /* We are going to receive 2 fds, we need to reserve them. */
602 ret
= lttng_fd_get(LTTNG_FD_APPS
, 2);
604 ERR("Exhausted number of available FD upon create channel");
607 ret
= ustctl_create_channel(app
->sock
, ua_sess
->handle
,
608 (struct lttng_ust_channel_attr
*)&ua_chan
->attr
, &ua_chan
->obj
);
610 ERR("Creating channel %s for app (pid: %d, sock: %d) "
611 "and session handle %d with ret %d",
612 ua_chan
->name
, app
->pid
, app
->sock
,
613 ua_sess
->handle
, ret
);
614 lttng_fd_put(LTTNG_FD_APPS
, 2);
618 ua_chan
->handle
= ua_chan
->obj
->handle
;
620 DBG2("UST app channel %s created successfully for pid:%d and sock:%d",
621 ua_chan
->name
, app
->pid
, app
->sock
);
623 /* If channel is not enabled, disable it on the tracer */
624 if (!ua_chan
->enabled
) {
625 ret
= disable_ust_channel(app
, ua_sess
, ua_chan
);
636 * Create the specified event onto the UST tracer for a UST session.
639 int create_ust_event(struct ust_app
*app
, struct ust_app_session
*ua_sess
,
640 struct ust_app_channel
*ua_chan
, struct ust_app_event
*ua_event
)
644 /* Create UST event on tracer */
645 ret
= ustctl_create_event(app
->sock
, &ua_event
->attr
, ua_chan
->obj
,
648 if (ret
== -EEXIST
|| ret
== -EPERM
) {
652 ERR("Error ustctl create event %s for app pid: %d with ret %d",
653 ua_event
->attr
.name
, app
->pid
, ret
);
657 ua_event
->handle
= ua_event
->obj
->handle
;
659 DBG2("UST app event %s created successfully for pid:%d",
660 ua_event
->attr
.name
, app
->pid
);
662 /* If event not enabled, disable it on the tracer */
663 if (ua_event
->enabled
== 0) {
664 ret
= disable_ust_event(app
, ua_sess
, ua_event
);
667 * If we hit an EPERM, something is wrong with our disable call. If
668 * we get an EEXIST, there is a problem on the tracer side since we
673 /* Code flow problem */
676 /* It's OK for our use case. */
691 * Copy data between an UST app event and a LTT event.
693 static void shadow_copy_event(struct ust_app_event
*ua_event
,
694 struct ltt_ust_event
*uevent
)
696 struct lttng_ht_iter iter
;
697 struct ltt_ust_context
*uctx
;
698 struct ust_app_ctx
*ua_ctx
;
700 strncpy(ua_event
->name
, uevent
->attr
.name
, sizeof(ua_event
->name
));
701 ua_event
->name
[sizeof(ua_event
->name
) - 1] = '\0';
703 ua_event
->enabled
= uevent
->enabled
;
705 /* Copy event attributes */
706 memcpy(&ua_event
->attr
, &uevent
->attr
, sizeof(ua_event
->attr
));
708 cds_lfht_for_each_entry(uevent
->ctx
->ht
, &iter
.iter
, uctx
, node
.node
) {
709 ua_ctx
= alloc_ust_app_ctx(&uctx
->ctx
);
710 if (ua_ctx
== NULL
) {
711 /* malloc() failed. We should simply stop */
715 lttng_ht_node_init_ulong(&ua_ctx
->node
,
716 (unsigned long) ua_ctx
->ctx
.ctx
);
717 lttng_ht_add_unique_ulong(ua_event
->ctx
, &ua_ctx
->node
);
722 * Copy data between an UST app channel and a LTT channel.
724 static void shadow_copy_channel(struct ust_app_channel
*ua_chan
,
725 struct ltt_ust_channel
*uchan
)
727 struct lttng_ht_iter iter
;
728 struct lttng_ht_node_str
*ua_event_node
;
729 struct ltt_ust_event
*uevent
;
730 struct ltt_ust_context
*uctx
;
731 struct ust_app_event
*ua_event
;
732 struct ust_app_ctx
*ua_ctx
;
734 DBG2("UST app shadow copy of channel %s started", ua_chan
->name
);
736 strncpy(ua_chan
->name
, uchan
->name
, sizeof(ua_chan
->name
));
737 ua_chan
->name
[sizeof(ua_chan
->name
) - 1] = '\0';
738 /* Copy event attributes */
739 memcpy(&ua_chan
->attr
, &uchan
->attr
, sizeof(ua_chan
->attr
));
741 ua_chan
->enabled
= uchan
->enabled
;
743 cds_lfht_for_each_entry(uchan
->ctx
->ht
, &iter
.iter
, uctx
, node
.node
) {
744 ua_ctx
= alloc_ust_app_ctx(&uctx
->ctx
);
745 if (ua_ctx
== NULL
) {
748 lttng_ht_node_init_ulong(&ua_ctx
->node
,
749 (unsigned long) ua_ctx
->ctx
.ctx
);
750 lttng_ht_add_unique_ulong(ua_chan
->ctx
, &ua_ctx
->node
);
753 /* Copy all events from ltt ust channel to ust app channel */
754 cds_lfht_for_each_entry(uchan
->events
->ht
, &iter
.iter
, uevent
, node
.node
) {
755 struct lttng_ht_iter uiter
;
757 lttng_ht_lookup(ua_chan
->events
, (void *) uevent
->attr
.name
, &uiter
);
758 ua_event_node
= lttng_ht_iter_get_node_str(&uiter
);
759 if (ua_event_node
== NULL
) {
760 DBG2("UST event %s not found on shadow copy channel",
762 ua_event
= alloc_ust_app_event(uevent
->attr
.name
, &uevent
->attr
);
763 if (ua_event
== NULL
) {
766 shadow_copy_event(ua_event
, uevent
);
767 lttng_ht_add_unique_str(ua_chan
->events
, &ua_event
->node
);
771 DBG3("UST app shadow copy of channel %s done", ua_chan
->name
);
775 * Copy data between a UST app session and a regular LTT session.
777 static void shadow_copy_session(struct ust_app_session
*ua_sess
,
778 struct ltt_ust_session
*usess
, struct ust_app
*app
)
780 struct lttng_ht_node_str
*ua_chan_node
;
781 struct lttng_ht_iter iter
;
782 struct ltt_ust_channel
*uchan
;
783 struct ust_app_channel
*ua_chan
;
789 /* Get date and time for unique app path */
791 timeinfo
= localtime(&rawtime
);
792 strftime(datetime
, sizeof(datetime
), "%Y%m%d-%H%M%S", timeinfo
);
794 DBG2("Shadow copy of session handle %d", ua_sess
->handle
);
796 ua_sess
->id
= usess
->id
;
797 ua_sess
->uid
= usess
->uid
;
798 ua_sess
->gid
= usess
->gid
;
800 ret
= snprintf(ua_sess
->path
, PATH_MAX
, "%s-%d-%s/", app
->name
, app
->pid
,
803 PERROR("asprintf UST shadow copy session");
804 /* TODO: We cannot return an error from here.. */
808 /* TODO: support all UST domain */
810 /* Iterate over all channels in global domain. */
811 cds_lfht_for_each_entry(usess
->domain_global
.channels
->ht
, &iter
.iter
,
813 struct lttng_ht_iter uiter
;
815 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
816 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
817 if (ua_chan_node
!= NULL
) {
818 /* Session exist. Contiuing. */
822 DBG2("Channel %s not found on shadow session copy, creating it",
824 ua_chan
= alloc_ust_app_channel(uchan
->name
, &uchan
->attr
);
825 if (ua_chan
== NULL
) {
826 /* malloc failed FIXME: Might want to do handle ENOMEM .. */
830 shadow_copy_channel(ua_chan
, uchan
);
831 lttng_ht_add_unique_str(ua_sess
->channels
, &ua_chan
->node
);
836 * Lookup sesison wrapper.
839 void __lookup_session_by_app(struct ltt_ust_session
*usess
,
840 struct ust_app
*app
, struct lttng_ht_iter
*iter
)
842 /* Get right UST app session from app */
843 lttng_ht_lookup(app
->sessions
, (void *)((unsigned long) usess
->id
), iter
);
847 * Return ust app session from the app session hashtable using the UST session
850 static struct ust_app_session
*lookup_session_by_app(
851 struct ltt_ust_session
*usess
, struct ust_app
*app
)
853 struct lttng_ht_iter iter
;
854 struct lttng_ht_node_ulong
*node
;
856 __lookup_session_by_app(usess
, app
, &iter
);
857 node
= lttng_ht_iter_get_node_ulong(&iter
);
862 return caa_container_of(node
, struct ust_app_session
, node
);
869 * Create a UST session onto the tracer of app and add it the session
872 * Return ust app session or NULL on error.
874 static struct ust_app_session
*create_ust_app_session(
875 struct ltt_ust_session
*usess
, struct ust_app
*app
)
878 struct ust_app_session
*ua_sess
;
880 ua_sess
= lookup_session_by_app(usess
, app
);
881 if (ua_sess
== NULL
) {
882 DBG2("UST app pid: %d session id %d not found, creating it",
883 app
->pid
, usess
->id
);
884 ua_sess
= alloc_ust_app_session();
885 if (ua_sess
== NULL
) {
886 /* Only malloc can failed so something is really wrong */
889 shadow_copy_session(ua_sess
, usess
, app
);
892 if (ua_sess
->handle
== -1) {
893 ret
= ustctl_create_session(app
->sock
);
895 ERR("Creating session for app pid %d", app
->pid
);
896 /* This means that the tracer is gone... */
897 ua_sess
= (void*) -1UL;
901 ua_sess
->handle
= ret
;
903 /* Add ust app session to app's HT */
904 lttng_ht_node_init_ulong(&ua_sess
->node
, (unsigned long) ua_sess
->id
);
905 lttng_ht_add_unique_ulong(app
->sessions
, &ua_sess
->node
);
907 DBG2("UST app session created successfully with handle %d", ret
);
914 delete_ust_app_session(-1, ua_sess
);
919 * Create a context for the channel on the tracer.
922 int create_ust_app_channel_context(struct ust_app_session
*ua_sess
,
923 struct ust_app_channel
*ua_chan
, struct lttng_ust_context
*uctx
,
927 struct lttng_ht_iter iter
;
928 struct lttng_ht_node_ulong
*node
;
929 struct ust_app_ctx
*ua_ctx
;
931 DBG2("UST app adding context to channel %s", ua_chan
->name
);
933 lttng_ht_lookup(ua_chan
->ctx
, (void *)((unsigned long)uctx
->ctx
), &iter
);
934 node
= lttng_ht_iter_get_node_ulong(&iter
);
940 ua_ctx
= alloc_ust_app_ctx(uctx
);
941 if (ua_ctx
== NULL
) {
947 lttng_ht_node_init_ulong(&ua_ctx
->node
, (unsigned long) ua_ctx
->ctx
.ctx
);
948 lttng_ht_add_unique_ulong(ua_chan
->ctx
, &ua_ctx
->node
);
950 ret
= create_ust_channel_context(ua_chan
, ua_ctx
, app
);
960 * Create an UST context and enable it for the event on the tracer.
963 int create_ust_app_event_context(struct ust_app_session
*ua_sess
,
964 struct ust_app_event
*ua_event
, struct lttng_ust_context
*uctx
,
968 struct lttng_ht_iter iter
;
969 struct lttng_ht_node_ulong
*node
;
970 struct ust_app_ctx
*ua_ctx
;
972 DBG2("UST app adding context to event %s", ua_event
->name
);
974 lttng_ht_lookup(ua_event
->ctx
, (void *)((unsigned long)uctx
->ctx
), &iter
);
975 node
= lttng_ht_iter_get_node_ulong(&iter
);
981 ua_ctx
= alloc_ust_app_ctx(uctx
);
982 if (ua_ctx
== NULL
) {
988 lttng_ht_node_init_ulong(&ua_ctx
->node
, (unsigned long) ua_ctx
->ctx
.ctx
);
989 lttng_ht_add_unique_ulong(ua_event
->ctx
, &ua_ctx
->node
);
991 ret
= create_ust_event_context(ua_event
, ua_ctx
, app
);
1001 * Enable on the tracer side a ust app event for the session and channel.
1004 int enable_ust_app_event(struct ust_app_session
*ua_sess
,
1005 struct ust_app_event
*ua_event
, struct ust_app
*app
)
1009 ret
= enable_ust_event(app
, ua_sess
, ua_event
);
1014 ua_event
->enabled
= 1;
1021 * Disable on the tracer side a ust app event for the session and channel.
1023 static int disable_ust_app_event(struct ust_app_session
*ua_sess
,
1024 struct ust_app_event
*ua_event
, struct ust_app
*app
)
1028 ret
= disable_ust_event(app
, ua_sess
, ua_event
);
1033 ua_event
->enabled
= 0;
1040 * Lookup ust app channel for session and disable it on the tracer side.
1043 int disable_ust_app_channel(struct ust_app_session
*ua_sess
,
1044 struct ust_app_channel
*ua_chan
, struct ust_app
*app
)
1048 ret
= disable_ust_channel(app
, ua_sess
, ua_chan
);
1053 ua_chan
->enabled
= 0;
1060 * Lookup ust app channel for session and enable it on the tracer side.
1062 static int enable_ust_app_channel(struct ust_app_session
*ua_sess
,
1063 struct ltt_ust_channel
*uchan
, struct ust_app
*app
)
1066 struct lttng_ht_iter iter
;
1067 struct lttng_ht_node_str
*ua_chan_node
;
1068 struct ust_app_channel
*ua_chan
;
1070 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &iter
);
1071 ua_chan_node
= lttng_ht_iter_get_node_str(&iter
);
1072 if (ua_chan_node
== NULL
) {
1073 DBG2("Unable to find channel %s in ust session id %u",
1074 uchan
->name
, ua_sess
->id
);
1078 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
1080 ret
= enable_ust_channel(app
, ua_sess
, ua_chan
);
1090 * Create UST app channel and create it on the tracer.
1092 static struct ust_app_channel
*create_ust_app_channel(
1093 struct ust_app_session
*ua_sess
, struct ltt_ust_channel
*uchan
,
1094 struct ust_app
*app
)
1097 struct lttng_ht_iter iter
;
1098 struct lttng_ht_node_str
*ua_chan_node
;
1099 struct ust_app_channel
*ua_chan
;
1101 /* Lookup channel in the ust app session */
1102 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &iter
);
1103 ua_chan_node
= lttng_ht_iter_get_node_str(&iter
);
1104 if (ua_chan_node
!= NULL
) {
1105 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
1109 ua_chan
= alloc_ust_app_channel(uchan
->name
, &uchan
->attr
);
1110 if (ua_chan
== NULL
) {
1111 /* Only malloc can fail here */
1114 shadow_copy_channel(ua_chan
, uchan
);
1116 ret
= create_ust_channel(app
, ua_sess
, ua_chan
);
1118 /* Not found previously means that it does not exist on the tracer */
1119 assert(ret
!= -EEXIST
);
1123 lttng_ht_add_unique_str(ua_sess
->channels
, &ua_chan
->node
);
1125 DBG2("UST app create channel %s for PID %d completed", ua_chan
->name
,
1132 delete_ust_app_channel(-1, ua_chan
);
1137 * Create UST app event and create it on the tracer side.
1140 int create_ust_app_event(struct ust_app_session
*ua_sess
,
1141 struct ust_app_channel
*ua_chan
, struct ltt_ust_event
*uevent
,
1142 struct ust_app
*app
)
1145 struct lttng_ht_iter iter
;
1146 struct lttng_ht_node_str
*ua_event_node
;
1147 struct ust_app_event
*ua_event
;
1149 /* Get event node */
1150 lttng_ht_lookup(ua_chan
->events
, (void *)uevent
->attr
.name
, &iter
);
1151 ua_event_node
= lttng_ht_iter_get_node_str(&iter
);
1152 if (ua_event_node
!= NULL
) {
1157 /* Does not exist so create one */
1158 ua_event
= alloc_ust_app_event(uevent
->attr
.name
, &uevent
->attr
);
1159 if (ua_event
== NULL
) {
1160 /* Only malloc can failed so something is really wrong */
1164 shadow_copy_event(ua_event
, uevent
);
1166 /* Create it on the tracer side */
1167 ret
= create_ust_event(app
, ua_sess
, ua_chan
, ua_event
);
1169 /* Not found previously means that it does not exist on the tracer */
1170 assert(ret
!= -EEXIST
);
1174 lttng_ht_add_unique_str(ua_chan
->events
, &ua_event
->node
);
1176 DBG2("UST app create event %s for PID %d completed", ua_event
->name
,
1183 /* Valid. Calling here is already in a read side lock */
1184 delete_ust_app_event(-1, ua_event
);
1189 * Create UST metadata and open it on the tracer side.
1191 static int create_ust_app_metadata(struct ust_app_session
*ua_sess
,
1192 char *pathname
, struct ust_app
*app
)
1196 if (ua_sess
->metadata
== NULL
) {
1197 /* Allocate UST metadata */
1198 ua_sess
->metadata
= trace_ust_create_metadata(pathname
);
1199 if (ua_sess
->metadata
== NULL
) {
1200 /* malloc() failed */
1204 ret
= open_ust_metadata(app
, ua_sess
);
1206 DBG3("Opening metadata failed. Cleaning up memory");
1208 /* Cleanup failed metadata struct */
1209 free(ua_sess
->metadata
);
1211 * This is very important because delete_ust_app_session check if
1212 * the pointer is null or not in order to delete the metadata.
1214 ua_sess
->metadata
= NULL
;
1218 DBG2("UST metadata opened for app pid %d", app
->pid
);
1221 /* Open UST metadata stream */
1222 if (ua_sess
->metadata
->stream_obj
== NULL
) {
1223 ret
= create_ust_stream(app
, ua_sess
);
1228 ret
= snprintf(ua_sess
->metadata
->pathname
, PATH_MAX
,
1229 "%s/metadata", ua_sess
->path
);
1231 PERROR("asprintf UST create stream");
1235 DBG2("UST metadata stream object created for app pid %d",
1238 ERR("Attempting to create stream without metadata opened");
1249 * Return pointer to traceable apps list.
1251 struct lttng_ht
*ust_app_get_ht(void)
1257 * Return ust app pointer or NULL if not found.
1259 struct ust_app
*ust_app_find_by_pid(pid_t pid
)
1261 struct lttng_ht_node_ulong
*node
;
1262 struct lttng_ht_iter iter
;
1265 lttng_ht_lookup(ust_app_ht
, (void *)((unsigned long) pid
), &iter
);
1266 node
= lttng_ht_iter_get_node_ulong(&iter
);
1268 DBG2("UST app no found with pid %d", pid
);
1273 DBG2("Found UST app by pid %d", pid
);
1275 return caa_container_of(node
, struct ust_app
, pid_n
);
1283 * Using pid and uid (of the app), allocate a new ust_app struct and
1284 * add it to the global traceable app list.
1286 * On success, return 0, else return malloc -ENOMEM, or -EINVAL if app
1287 * bitness is not supported.
1289 int ust_app_register(struct ust_register_msg
*msg
, int sock
)
1291 struct ust_app
*lta
;
1294 if ((msg
->bits_per_long
== 64 && ust_consumerd64_fd
== -EINVAL
)
1295 || (msg
->bits_per_long
== 32 && ust_consumerd32_fd
== -EINVAL
)) {
1296 ERR("Registration failed: application \"%s\" (pid: %d) has "
1297 "%d-bit long, but no consumerd for this long size is available.\n",
1298 msg
->name
, msg
->pid
, msg
->bits_per_long
);
1303 lttng_fd_put(LTTNG_FD_APPS
, 1);
1306 if (msg
->major
!= LTTNG_UST_COMM_MAJOR
) {
1307 ERR("Registration failed: application \"%s\" (pid: %d) has "
1308 "communication protocol version %u.%u, but sessiond supports 2.x.\n",
1309 msg
->name
, msg
->pid
, msg
->major
, msg
->minor
);
1314 lttng_fd_put(LTTNG_FD_APPS
, 1);
1317 lta
= zmalloc(sizeof(struct ust_app
));
1323 lta
->ppid
= msg
->ppid
;
1324 lta
->uid
= msg
->uid
;
1325 lta
->gid
= msg
->gid
;
1326 lta
->compatible
= 0; /* Not compatible until proven */
1327 lta
->bits_per_long
= msg
->bits_per_long
;
1328 lta
->v_major
= msg
->major
;
1329 lta
->v_minor
= msg
->minor
;
1330 strncpy(lta
->name
, msg
->name
, sizeof(lta
->name
));
1331 lta
->name
[16] = '\0';
1332 lta
->sessions
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
1334 lta
->pid
= msg
->pid
;
1335 lttng_ht_node_init_ulong(<a
->pid_n
, (unsigned long)lta
->pid
);
1337 lttng_ht_node_init_ulong(<a
->sock_n
, (unsigned long)lta
->sock
);
1342 * On a re-registration, we want to kick out the previous registration of
1345 lttng_ht_add_replace_ulong(ust_app_ht
, <a
->pid_n
);
1348 * The socket _should_ be unique until _we_ call close. So, a add_unique
1349 * for the ust_app_ht_by_sock is used which asserts fail if the entry was
1350 * already in the table.
1352 lttng_ht_add_unique_ulong(ust_app_ht_by_sock
, <a
->sock_n
);
1356 DBG("App registered with pid:%d ppid:%d uid:%d gid:%d sock:%d name:%s"
1357 " (version %d.%d)", lta
->pid
, lta
->ppid
, lta
->uid
, lta
->gid
,
1358 lta
->sock
, lta
->name
, lta
->v_major
, lta
->v_minor
);
1364 * Unregister app by removing it from the global traceable app list and freeing
1367 * The socket is already closed at this point so no close to sock.
1369 void ust_app_unregister(int sock
)
1371 struct ust_app
*lta
;
1372 struct lttng_ht_node_ulong
*node
;
1373 struct lttng_ht_iter iter
;
1378 /* Get the node reference for a call_rcu */
1379 lttng_ht_lookup(ust_app_ht_by_sock
, (void *)((unsigned long) sock
), &iter
);
1380 node
= lttng_ht_iter_get_node_ulong(&iter
);
1382 ERR("Unable to find app by sock %d", sock
);
1386 lta
= caa_container_of(node
, struct ust_app
, sock_n
);
1388 DBG("PID %d unregistering with sock %d", lta
->pid
, sock
);
1390 /* Remove application from PID hash table */
1391 ret
= lttng_ht_del(ust_app_ht_by_sock
, &iter
);
1394 /* Assign second node for deletion */
1395 iter
.iter
.node
= <a
->pid_n
.node
;
1397 ret
= lttng_ht_del(ust_app_ht
, &iter
);
1401 call_rcu(<a
->pid_n
.head
, delete_ust_app_rcu
);
1409 * Return traceable_app_count
1411 unsigned long ust_app_list_count(void)
1413 unsigned long count
;
1416 count
= lttng_ht_get_count(ust_app_ht
);
1423 * Fill events array with all events name of all registered apps.
1425 int ust_app_list_events(struct lttng_event
**events
)
1428 size_t nbmem
, count
= 0;
1429 struct lttng_ht_iter iter
;
1430 struct ust_app
*app
;
1431 struct lttng_event
*tmp
;
1433 nbmem
= UST_APP_EVENT_LIST_SIZE
;
1434 tmp
= zmalloc(nbmem
* sizeof(struct lttng_event
));
1436 PERROR("zmalloc ust app events");
1443 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1444 struct lttng_ust_tracepoint_iter uiter
;
1446 if (!app
->compatible
) {
1448 * TODO: In time, we should notice the caller of this error by
1449 * telling him that this is a version error.
1453 handle
= ustctl_tracepoint_list(app
->sock
);
1455 ERR("UST app list events getting handle failed for app pid %d",
1460 while ((ret
= ustctl_tracepoint_list_get(app
->sock
, handle
,
1461 &uiter
)) != -ENOENT
) {
1462 if (count
>= nbmem
) {
1463 DBG2("Reallocating event list from %zu to %zu entries", nbmem
,
1466 tmp
= realloc(tmp
, nbmem
* sizeof(struct lttng_event
));
1468 PERROR("realloc ust app events");
1473 memcpy(tmp
[count
].name
, uiter
.name
, LTTNG_UST_SYM_NAME_LEN
);
1474 tmp
[count
].loglevel
= uiter
.loglevel
;
1475 tmp
[count
].type
= (enum lttng_event_type
) LTTNG_UST_TRACEPOINT
;
1476 tmp
[count
].pid
= app
->pid
;
1477 tmp
[count
].enabled
= -1;
1485 DBG2("UST app list events done (%zu events)", count
);
1494 * Fill events array with all events name of all registered apps.
1496 int ust_app_list_event_fields(struct lttng_event_field
**fields
)
1499 size_t nbmem
, count
= 0;
1500 struct lttng_ht_iter iter
;
1501 struct ust_app
*app
;
1502 struct lttng_event_field
*tmp
;
1504 nbmem
= UST_APP_EVENT_LIST_SIZE
;
1505 tmp
= zmalloc(nbmem
* sizeof(struct lttng_event_field
));
1507 PERROR("zmalloc ust app event fields");
1514 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1515 struct lttng_ust_field_iter uiter
;
1517 if (!app
->compatible
) {
1519 * TODO: In time, we should notice the caller of this error by
1520 * telling him that this is a version error.
1524 handle
= ustctl_tracepoint_field_list(app
->sock
);
1526 ERR("UST app list event fields getting handle failed for app pid %d",
1531 while ((ret
= ustctl_tracepoint_field_list_get(app
->sock
, handle
,
1532 &uiter
)) != -ENOENT
) {
1533 if (count
>= nbmem
) {
1534 DBG2("Reallocating event field list from %zu to %zu entries", nbmem
,
1537 tmp
= realloc(tmp
, nbmem
* sizeof(struct lttng_event_field
));
1539 PERROR("realloc ust app event fields");
1545 memcpy(tmp
[count
].field_name
, uiter
.field_name
, LTTNG_UST_SYM_NAME_LEN
);
1546 tmp
[count
].type
= uiter
.type
;
1548 memcpy(tmp
[count
].event
.name
, uiter
.event_name
, LTTNG_UST_SYM_NAME_LEN
);
1549 tmp
[count
].event
.loglevel
= uiter
.loglevel
;
1550 tmp
[count
].event
.type
= LTTNG_UST_TRACEPOINT
;
1551 tmp
[count
].event
.pid
= app
->pid
;
1552 tmp
[count
].event
.enabled
= -1;
1560 DBG2("UST app list event fields done (%zu events)", count
);
1569 * Free and clean all traceable apps of the global list.
1571 void ust_app_clean_list(void)
1574 struct lttng_ht_iter iter
;
1575 struct lttng_ht_node_ulong
*node
;
1577 DBG2("UST app cleaning registered apps hash table");
1581 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, node
, node
) {
1582 ret
= lttng_ht_del(ust_app_ht
, &iter
);
1584 call_rcu(&node
->head
, delete_ust_app_rcu
);
1587 /* Cleanup socket hash table */
1588 cds_lfht_for_each_entry(ust_app_ht_by_sock
->ht
, &iter
.iter
, node
, node
) {
1589 ret
= lttng_ht_del(ust_app_ht_by_sock
, &iter
);
1593 /* Destroy is done only when the ht is empty */
1594 lttng_ht_destroy(ust_app_ht
);
1595 lttng_ht_destroy(ust_app_ht_by_sock
);
1601 * Init UST app hash table.
1603 void ust_app_ht_alloc(void)
1605 ust_app_ht
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
1606 ust_app_ht_by_sock
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
1610 * For a specific UST session, disable the channel for all registered apps.
1612 int ust_app_disable_channel_glb(struct ltt_ust_session
*usess
,
1613 struct ltt_ust_channel
*uchan
)
1616 struct lttng_ht_iter iter
;
1617 struct lttng_ht_node_str
*ua_chan_node
;
1618 struct ust_app
*app
;
1619 struct ust_app_session
*ua_sess
;
1620 struct ust_app_channel
*ua_chan
;
1622 if (usess
== NULL
|| uchan
== NULL
) {
1623 ERR("Disabling UST global channel with NULL values");
1628 DBG2("UST app disabling channel %s from global domain for session id %d",
1629 uchan
->name
, usess
->id
);
1633 /* For every registered applications */
1634 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1635 struct lttng_ht_iter uiter
;
1636 if (!app
->compatible
) {
1638 * TODO: In time, we should notice the caller of this error by
1639 * telling him that this is a version error.
1643 ua_sess
= lookup_session_by_app(usess
, app
);
1644 if (ua_sess
== NULL
) {
1649 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
1650 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
1651 /* If the session if found for the app, the channel must be there */
1652 assert(ua_chan_node
);
1654 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
1655 /* The channel must not be already disabled */
1656 assert(ua_chan
->enabled
== 1);
1658 /* Disable channel onto application */
1659 ret
= disable_ust_app_channel(ua_sess
, ua_chan
, app
);
1661 /* XXX: We might want to report this error at some point... */
1673 * For a specific UST session, enable the channel for all registered apps.
1675 int ust_app_enable_channel_glb(struct ltt_ust_session
*usess
,
1676 struct ltt_ust_channel
*uchan
)
1679 struct lttng_ht_iter iter
;
1680 struct ust_app
*app
;
1681 struct ust_app_session
*ua_sess
;
1683 if (usess
== NULL
|| uchan
== NULL
) {
1684 ERR("Adding UST global channel to NULL values");
1689 DBG2("UST app enabling channel %s to global domain for session id %d",
1690 uchan
->name
, usess
->id
);
1694 /* For every registered applications */
1695 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1696 if (!app
->compatible
) {
1698 * TODO: In time, we should notice the caller of this error by
1699 * telling him that this is a version error.
1703 ua_sess
= lookup_session_by_app(usess
, app
);
1704 if (ua_sess
== NULL
) {
1708 /* Enable channel onto application */
1709 ret
= enable_ust_app_channel(ua_sess
, uchan
, app
);
1711 /* XXX: We might want to report this error at some point... */
1723 * Disable an event in a channel and for a specific session.
1725 int ust_app_disable_event_glb(struct ltt_ust_session
*usess
,
1726 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
)
1729 struct lttng_ht_iter iter
, uiter
;
1730 struct lttng_ht_node_str
*ua_chan_node
, *ua_event_node
;
1731 struct ust_app
*app
;
1732 struct ust_app_session
*ua_sess
;
1733 struct ust_app_channel
*ua_chan
;
1734 struct ust_app_event
*ua_event
;
1736 DBG("UST app disabling event %s for all apps in channel "
1737 "%s for session id %d", uevent
->attr
.name
, uchan
->name
, usess
->id
);
1741 /* For all registered applications */
1742 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1743 if (!app
->compatible
) {
1745 * TODO: In time, we should notice the caller of this error by
1746 * telling him that this is a version error.
1750 ua_sess
= lookup_session_by_app(usess
, app
);
1751 if (ua_sess
== NULL
) {
1756 /* Lookup channel in the ust app session */
1757 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
1758 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
1759 if (ua_chan_node
== NULL
) {
1760 DBG2("Channel %s not found in session id %d for app pid %d."
1761 "Skipping", uchan
->name
, usess
->id
, app
->pid
);
1764 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
1766 lttng_ht_lookup(ua_chan
->events
, (void *)uevent
->attr
.name
, &uiter
);
1767 ua_event_node
= lttng_ht_iter_get_node_str(&uiter
);
1768 if (ua_event_node
== NULL
) {
1769 DBG2("Event %s not found in channel %s for app pid %d."
1770 "Skipping", uevent
->attr
.name
, uchan
->name
, app
->pid
);
1773 ua_event
= caa_container_of(ua_event_node
, struct ust_app_event
, node
);
1775 ret
= disable_ust_app_event(ua_sess
, ua_event
, app
);
1777 /* XXX: Report error someday... */
1788 * For a specific UST session and UST channel, the event for all
1791 int ust_app_disable_all_event_glb(struct ltt_ust_session
*usess
,
1792 struct ltt_ust_channel
*uchan
)
1795 struct lttng_ht_iter iter
, uiter
;
1796 struct lttng_ht_node_str
*ua_chan_node
;
1797 struct ust_app
*app
;
1798 struct ust_app_session
*ua_sess
;
1799 struct ust_app_channel
*ua_chan
;
1800 struct ust_app_event
*ua_event
;
1802 DBG("UST app disabling all event for all apps in channel "
1803 "%s for session id %d", uchan
->name
, usess
->id
);
1807 /* For all registered applications */
1808 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1809 if (!app
->compatible
) {
1811 * TODO: In time, we should notice the caller of this error by
1812 * telling him that this is a version error.
1816 ua_sess
= lookup_session_by_app(usess
, app
);
1817 /* If ua_sess is NULL, there is a code flow error */
1820 /* Lookup channel in the ust app session */
1821 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
1822 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
1823 /* If the channel is not found, there is a code flow error */
1824 assert(ua_chan_node
);
1826 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
1828 /* Disable each events of channel */
1829 cds_lfht_for_each_entry(ua_chan
->events
->ht
, &uiter
.iter
, ua_event
,
1831 ret
= disable_ust_app_event(ua_sess
, ua_event
, app
);
1833 /* XXX: Report error someday... */
1845 * For a specific UST session, create the channel for all registered apps.
1847 int ust_app_create_channel_glb(struct ltt_ust_session
*usess
,
1848 struct ltt_ust_channel
*uchan
)
1850 struct lttng_ht_iter iter
;
1851 struct ust_app
*app
;
1852 struct ust_app_session
*ua_sess
;
1853 struct ust_app_channel
*ua_chan
;
1855 /* Very wrong code flow */
1859 DBG2("UST app adding channel %s to global domain for session id %d",
1860 uchan
->name
, usess
->id
);
1864 /* For every registered applications */
1865 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1866 if (!app
->compatible
) {
1868 * TODO: In time, we should notice the caller of this error by
1869 * telling him that this is a version error.
1874 * Create session on the tracer side and add it to app session HT. Note
1875 * that if session exist, it will simply return a pointer to the ust
1878 ua_sess
= create_ust_app_session(usess
, app
);
1879 if (ua_sess
== NULL
) {
1880 /* The malloc() failed. */
1882 } else if (ua_sess
== (void *) -1UL) {
1883 /* The application's socket is not valid. Contiuing */
1887 /* Create channel onto application */
1888 ua_chan
= create_ust_app_channel(ua_sess
, uchan
, app
);
1889 if (ua_chan
== NULL
) {
1890 /* Major problem here and it's maybe the tracer or malloc() */
1904 * Enable event for a specific session and channel on the tracer.
1906 int ust_app_enable_event_glb(struct ltt_ust_session
*usess
,
1907 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
)
1910 struct lttng_ht_iter iter
, uiter
;
1911 struct lttng_ht_node_str
*ua_chan_node
, *ua_event_node
;
1912 struct ust_app
*app
;
1913 struct ust_app_session
*ua_sess
;
1914 struct ust_app_channel
*ua_chan
;
1915 struct ust_app_event
*ua_event
;
1917 DBG("UST app enabling event %s for all apps for session id %d",
1918 uevent
->attr
.name
, usess
->id
);
1921 * NOTE: At this point, this function is called only if the session and
1922 * channel passed are already created for all apps. and enabled on the
1928 /* For all registered applications */
1929 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1930 if (!app
->compatible
) {
1932 * TODO: In time, we should notice the caller of this error by
1933 * telling him that this is a version error.
1937 ua_sess
= lookup_session_by_app(usess
, app
);
1938 /* If ua_sess is NULL, there is a code flow error */
1941 /* Lookup channel in the ust app session */
1942 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
1943 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
1944 /* If the channel is not found, there is a code flow error */
1945 assert(ua_chan_node
);
1947 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
1949 lttng_ht_lookup(ua_chan
->events
, (void*)uevent
->attr
.name
, &uiter
);
1950 ua_event_node
= lttng_ht_iter_get_node_str(&uiter
);
1951 if (ua_event_node
== NULL
) {
1952 DBG3("UST app enable event %s not found for app PID %d."
1953 "Skipping app", uevent
->attr
.name
, app
->pid
);
1956 ua_event
= caa_container_of(ua_event_node
, struct ust_app_event
, node
);
1958 ret
= enable_ust_app_event(ua_sess
, ua_event
, app
);
1970 * For a specific existing UST session and UST channel, creates the event for
1971 * all registered apps.
1973 int ust_app_create_event_glb(struct ltt_ust_session
*usess
,
1974 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
)
1977 struct lttng_ht_iter iter
, uiter
;
1978 struct lttng_ht_node_str
*ua_chan_node
;
1979 struct ust_app
*app
;
1980 struct ust_app_session
*ua_sess
;
1981 struct ust_app_channel
*ua_chan
;
1983 DBG("UST app creating event %s for all apps for session id %d",
1984 uevent
->attr
.name
, usess
->id
);
1988 /* For all registered applications */
1989 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
1990 if (!app
->compatible
) {
1992 * TODO: In time, we should notice the caller of this error by
1993 * telling him that this is a version error.
1997 ua_sess
= lookup_session_by_app(usess
, app
);
1998 /* If ua_sess is NULL, there is a code flow error */
2001 /* Lookup channel in the ust app session */
2002 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
2003 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
2004 /* If the channel is not found, there is a code flow error */
2005 assert(ua_chan_node
);
2007 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
2009 ret
= create_ust_app_event(ua_sess
, ua_chan
, uevent
, app
);
2011 if (ret
!= -EEXIST
) {
2012 /* Possible value at this point: -ENOMEM. If so, we stop! */
2015 DBG2("UST app event %s already exist on app PID %d",
2016 uevent
->attr
.name
, app
->pid
);
2027 * Start tracing for a specific UST session and app.
2029 int ust_app_start_trace(struct ltt_ust_session
*usess
, struct ust_app
*app
)
2032 struct lttng_ht_iter iter
;
2033 struct ust_app_session
*ua_sess
;
2034 struct ust_app_channel
*ua_chan
;
2035 struct ltt_ust_stream
*ustream
;
2038 DBG("Starting tracing for ust app pid %d", app
->pid
);
2042 if (!app
->compatible
) {
2046 ua_sess
= lookup_session_by_app(usess
, app
);
2047 if (ua_sess
== NULL
) {
2048 goto error_rcu_unlock
;
2051 /* Upon restart, we skip the setup, already done */
2052 if (ua_sess
->started
) {
2056 /* Indicate that the session has been started once */
2057 ua_sess
->started
= 1;
2059 ret
= create_ust_app_metadata(ua_sess
, usess
->pathname
, app
);
2061 goto error_rcu_unlock
;
2064 /* For each channel */
2065 cds_lfht_for_each_entry(ua_sess
->channels
->ht
, &iter
.iter
, ua_chan
,
2067 /* Create all streams */
2069 /* Create UST stream */
2070 ustream
= zmalloc(sizeof(*ustream
));
2071 if (ustream
== NULL
) {
2072 PERROR("zmalloc ust stream");
2073 goto error_rcu_unlock
;
2076 /* We are going to receive 2 fds, we need to reserve them. */
2077 ret
= lttng_fd_get(LTTNG_FD_APPS
, 2);
2079 ERR("Exhausted number of available FD upon stream create");
2081 goto error_rcu_unlock
;
2083 ret
= ustctl_create_stream(app
->sock
, ua_chan
->obj
,
2086 /* Got all streams */
2087 lttng_fd_put(LTTNG_FD_APPS
, 2);
2091 ustream
->handle
= ustream
->obj
->handle
;
2093 /* Order is important */
2094 cds_list_add_tail(&ustream
->list
, &ua_chan
->streams
.head
);
2095 ret
= snprintf(ustream
->name
, sizeof(ustream
->name
), "%s_%u",
2096 ua_chan
->name
, ua_chan
->streams
.count
++);
2098 PERROR("asprintf UST create stream");
2100 * XXX what should we do here with the
2105 DBG2("UST stream %d ready (handle: %d)", ua_chan
->streams
.count
,
2110 switch (app
->bits_per_long
) {
2112 consumerd_fd
= ust_consumerd64_fd
;
2115 consumerd_fd
= ust_consumerd32_fd
;
2119 goto error_rcu_unlock
;
2122 /* Setup UST consumer socket and send fds to it */
2123 ret
= ust_consumer_send_session(consumerd_fd
, ua_sess
, usess
->consumer
);
2125 goto error_rcu_unlock
;
2129 /* This start the UST tracing */
2130 ret
= ustctl_start_session(app
->sock
, ua_sess
->handle
);
2132 ERR("Error starting tracing for app pid: %d", app
->pid
);
2133 goto error_rcu_unlock
;
2136 /* Quiescent wait after starting trace */
2137 ustctl_wait_quiescent(app
->sock
);
2149 * Stop tracing for a specific UST session and app.
2151 int ust_app_stop_trace(struct ltt_ust_session
*usess
, struct ust_app
*app
)
2154 struct lttng_ht_iter iter
;
2155 struct ust_app_session
*ua_sess
;
2156 struct ust_app_channel
*ua_chan
;
2158 DBG("Stopping tracing for ust app pid %d", app
->pid
);
2162 if (!app
->compatible
) {
2166 ua_sess
= lookup_session_by_app(usess
, app
);
2167 if (ua_sess
== NULL
) {
2168 /* Only malloc can failed so something is really wrong */
2169 goto error_rcu_unlock
;
2173 * If started = 0, it means that stop trace has been called for a session
2174 * that was never started. This is a code flow error and should never
2177 assert(ua_sess
->started
== 1);
2179 /* This inhibits UST tracing */
2180 ret
= ustctl_stop_session(app
->sock
, ua_sess
->handle
);
2182 ERR("Error stopping tracing for app pid: %d", app
->pid
);
2183 goto error_rcu_unlock
;
2186 /* Quiescent wait after stopping trace */
2187 ustctl_wait_quiescent(app
->sock
);
2189 /* Flushing buffers */
2190 cds_lfht_for_each_entry(ua_sess
->channels
->ht
, &iter
.iter
, ua_chan
,
2192 ret
= ustctl_sock_flush_buffer(app
->sock
, ua_chan
->obj
);
2194 ERR("UST app PID %d channel %s flush failed with ret %d",
2195 app
->pid
, ua_chan
->name
, ret
);
2196 /* Continuing flushing all buffers */
2201 /* Flush all buffers before stopping */
2202 ret
= ustctl_sock_flush_buffer(app
->sock
, ua_sess
->metadata
->obj
);
2204 ERR("UST app PID %d metadata flush failed with ret %d", app
->pid
,
2218 * Destroy a specific UST session in apps.
2220 int ust_app_destroy_trace(struct ltt_ust_session
*usess
, struct ust_app
*app
)
2222 struct ust_app_session
*ua_sess
;
2223 struct lttng_ust_object_data obj
;
2224 struct lttng_ht_iter iter
;
2225 struct lttng_ht_node_ulong
*node
;
2228 DBG("Destroy tracing for ust app pid %d", app
->pid
);
2232 if (!app
->compatible
) {
2236 __lookup_session_by_app(usess
, app
, &iter
);
2237 node
= lttng_ht_iter_get_node_ulong(&iter
);
2239 /* Only malloc can failed so something is really wrong */
2240 goto error_rcu_unlock
;
2242 ua_sess
= caa_container_of(node
, struct ust_app_session
, node
);
2243 ret
= lttng_ht_del(app
->sessions
, &iter
);
2245 obj
.handle
= ua_sess
->handle
;
2248 obj
.memory_map_size
= 0;
2249 ustctl_release_object(app
->sock
, &obj
);
2251 delete_ust_app_session(app
->sock
, ua_sess
);
2253 /* Quiescent wait after stopping trace */
2254 ustctl_wait_quiescent(app
->sock
);
2266 * Start tracing for the UST session.
2268 int ust_app_start_trace_all(struct ltt_ust_session
*usess
)
2271 struct lttng_ht_iter iter
;
2272 struct ust_app
*app
;
2274 DBG("Starting all UST traces");
2278 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2279 ret
= ust_app_start_trace(usess
, app
);
2281 /* Continue to next apps even on error */
2292 * Start tracing for the UST session.
2294 int ust_app_stop_trace_all(struct ltt_ust_session
*usess
)
2297 struct lttng_ht_iter iter
;
2298 struct ust_app
*app
;
2300 DBG("Stopping all UST traces");
2304 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2305 ret
= ust_app_stop_trace(usess
, app
);
2307 /* Continue to next apps even on error */
2318 * Destroy app UST session.
2320 int ust_app_destroy_trace_all(struct ltt_ust_session
*usess
)
2323 struct lttng_ht_iter iter
;
2324 struct ust_app
*app
;
2326 DBG("Destroy all UST traces");
2330 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2331 ret
= ust_app_destroy_trace(usess
, app
);
2333 /* Continue to next apps even on error */
2344 * Add channels/events from UST global domain to registered apps at sock.
2346 void ust_app_global_update(struct ltt_ust_session
*usess
, int sock
)
2349 struct lttng_ht_iter iter
, uiter
, iter_ctx
;
2350 struct ust_app
*app
;
2351 struct ust_app_session
*ua_sess
;
2352 struct ust_app_channel
*ua_chan
;
2353 struct ust_app_event
*ua_event
;
2354 struct ust_app_ctx
*ua_ctx
;
2356 if (usess
== NULL
) {
2357 ERR("No UST session on global update. Returning");
2361 DBG2("UST app global update for app sock %d for session id %d", sock
,
2366 app
= find_app_by_sock(sock
);
2368 ERR("Failed to update app sock %d", sock
);
2372 if (!app
->compatible
) {
2376 ua_sess
= create_ust_app_session(usess
, app
);
2377 if (ua_sess
== NULL
) {
2382 * We can iterate safely here over all UST app session sicne the create ust
2383 * app session above made a shadow copy of the UST global domain from the
2386 cds_lfht_for_each_entry(ua_sess
->channels
->ht
, &iter
.iter
, ua_chan
,
2388 ret
= create_ust_channel(app
, ua_sess
, ua_chan
);
2390 /* FIXME: Should we quit here or continue... */
2394 cds_lfht_for_each_entry(ua_chan
->ctx
->ht
, &iter_ctx
.iter
, ua_ctx
,
2396 ret
= create_ust_channel_context(ua_chan
, ua_ctx
, app
);
2398 /* FIXME: Should we quit here or continue... */
2404 /* For each events */
2405 cds_lfht_for_each_entry(ua_chan
->events
->ht
, &uiter
.iter
, ua_event
,
2407 ret
= create_ust_event(app
, ua_sess
, ua_chan
, ua_event
);
2409 /* FIXME: Should we quit here or continue... */
2413 /* Add context on events. */
2414 cds_lfht_for_each_entry(ua_event
->ctx
->ht
, &iter_ctx
.iter
,
2415 ua_ctx
, node
.node
) {
2416 ret
= create_ust_event_context(ua_event
, ua_ctx
, app
);
2418 /* FIXME: Should we quit here or continue... */
2425 if (usess
->start_trace
) {
2426 ret
= ust_app_start_trace(usess
, app
);
2431 DBG2("UST trace started for app pid %d", app
->pid
);
2440 * Add context to a specific channel for global UST domain.
2442 int ust_app_add_ctx_channel_glb(struct ltt_ust_session
*usess
,
2443 struct ltt_ust_channel
*uchan
, struct ltt_ust_context
*uctx
)
2446 struct lttng_ht_node_str
*ua_chan_node
;
2447 struct lttng_ht_iter iter
, uiter
;
2448 struct ust_app_channel
*ua_chan
= NULL
;
2449 struct ust_app_session
*ua_sess
;
2450 struct ust_app
*app
;
2454 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2455 if (!app
->compatible
) {
2457 * TODO: In time, we should notice the caller of this error by
2458 * telling him that this is a version error.
2462 ua_sess
= lookup_session_by_app(usess
, app
);
2463 if (ua_sess
== NULL
) {
2467 /* Lookup channel in the ust app session */
2468 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
2469 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
2470 if (ua_chan_node
== NULL
) {
2473 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
,
2476 ret
= create_ust_app_channel_context(ua_sess
, ua_chan
, &uctx
->ctx
, app
);
2487 * Add context to a specific event in a channel for global UST domain.
2489 int ust_app_add_ctx_event_glb(struct ltt_ust_session
*usess
,
2490 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
,
2491 struct ltt_ust_context
*uctx
)
2494 struct lttng_ht_node_str
*ua_chan_node
, *ua_event_node
;
2495 struct lttng_ht_iter iter
, uiter
;
2496 struct ust_app_session
*ua_sess
;
2497 struct ust_app_event
*ua_event
;
2498 struct ust_app_channel
*ua_chan
= NULL
;
2499 struct ust_app
*app
;
2503 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2504 if (!app
->compatible
) {
2506 * TODO: In time, we should notice the caller of this error by
2507 * telling him that this is a version error.
2511 ua_sess
= lookup_session_by_app(usess
, app
);
2512 if (ua_sess
== NULL
) {
2516 /* Lookup channel in the ust app session */
2517 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &uiter
);
2518 ua_chan_node
= lttng_ht_iter_get_node_str(&uiter
);
2519 if (ua_chan_node
== NULL
) {
2522 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
,
2525 lttng_ht_lookup(ua_chan
->events
, (void *)uevent
->attr
.name
, &uiter
);
2526 ua_event_node
= lttng_ht_iter_get_node_str(&uiter
);
2527 if (ua_event_node
== NULL
) {
2530 ua_event
= caa_container_of(ua_event_node
, struct ust_app_event
,
2533 ret
= create_ust_app_event_context(ua_sess
, ua_event
, &uctx
->ctx
, app
);
2544 * Enable event for a channel from a UST session for a specific PID.
2546 int ust_app_enable_event_pid(struct ltt_ust_session
*usess
,
2547 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
, pid_t pid
)
2550 struct lttng_ht_iter iter
;
2551 struct lttng_ht_node_str
*ua_chan_node
, *ua_event_node
;
2552 struct ust_app
*app
;
2553 struct ust_app_session
*ua_sess
;
2554 struct ust_app_channel
*ua_chan
;
2555 struct ust_app_event
*ua_event
;
2557 DBG("UST app enabling event %s for PID %d", uevent
->attr
.name
, pid
);
2561 app
= ust_app_find_by_pid(pid
);
2563 ERR("UST app enable event per PID %d not found", pid
);
2568 if (!app
->compatible
) {
2573 ua_sess
= lookup_session_by_app(usess
, app
);
2574 /* If ua_sess is NULL, there is a code flow error */
2577 /* Lookup channel in the ust app session */
2578 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &iter
);
2579 ua_chan_node
= lttng_ht_iter_get_node_str(&iter
);
2580 /* If the channel is not found, there is a code flow error */
2581 assert(ua_chan_node
);
2583 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
2585 lttng_ht_lookup(ua_chan
->events
, (void *)uevent
->attr
.name
, &iter
);
2586 ua_event_node
= lttng_ht_iter_get_node_str(&iter
);
2587 if (ua_event_node
== NULL
) {
2588 ret
= create_ust_app_event(ua_sess
, ua_chan
, uevent
, app
);
2593 ua_event
= caa_container_of(ua_event_node
, struct ust_app_event
, node
);
2595 ret
= enable_ust_app_event(ua_sess
, ua_event
, app
);
2607 * Disable event for a channel from a UST session for a specific PID.
2609 int ust_app_disable_event_pid(struct ltt_ust_session
*usess
,
2610 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
, pid_t pid
)
2613 struct lttng_ht_iter iter
;
2614 struct lttng_ht_node_str
*ua_chan_node
, *ua_event_node
;
2615 struct ust_app
*app
;
2616 struct ust_app_session
*ua_sess
;
2617 struct ust_app_channel
*ua_chan
;
2618 struct ust_app_event
*ua_event
;
2620 DBG("UST app disabling event %s for PID %d", uevent
->attr
.name
, pid
);
2624 app
= ust_app_find_by_pid(pid
);
2626 ERR("UST app disable event per PID %d not found", pid
);
2631 if (!app
->compatible
) {
2636 ua_sess
= lookup_session_by_app(usess
, app
);
2637 /* If ua_sess is NULL, there is a code flow error */
2640 /* Lookup channel in the ust app session */
2641 lttng_ht_lookup(ua_sess
->channels
, (void *)uchan
->name
, &iter
);
2642 ua_chan_node
= lttng_ht_iter_get_node_str(&iter
);
2643 if (ua_chan_node
== NULL
) {
2644 /* Channel does not exist, skip disabling */
2647 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
2649 lttng_ht_lookup(ua_chan
->events
, (void *)uevent
->attr
.name
, &iter
);
2650 ua_event_node
= lttng_ht_iter_get_node_str(&iter
);
2651 if (ua_event_node
== NULL
) {
2652 /* Event does not exist, skip disabling */
2655 ua_event
= caa_container_of(ua_event_node
, struct ust_app_event
, node
);
2657 ret
= disable_ust_app_event(ua_sess
, ua_event
, app
);
2668 * Validate version of UST apps and set the compatible bit.
2670 int ust_app_validate_version(int sock
)
2673 struct ust_app
*app
;
2677 app
= find_app_by_sock(sock
);
2680 ret
= ustctl_tracer_version(sock
, &app
->version
);
2685 /* Validate version */
2686 if (app
->version
.major
> UST_APP_MAJOR_VERSION
) {
2690 DBG2("UST app PID %d is compatible with major version %d "
2691 "(supporting <= %d)", app
->pid
, app
->version
.major
,
2692 UST_APP_MAJOR_VERSION
);
2693 app
->compatible
= 1;
2698 DBG2("UST app PID %d is not compatible with major version %d "
2699 "(supporting <= %d)", app
->pid
, app
->version
.major
,
2700 UST_APP_MAJOR_VERSION
);
2701 app
->compatible
= 0;
2707 * Calibrate registered applications.
2709 int ust_app_calibrate_glb(struct lttng_ust_calibrate
*calibrate
)
2712 struct lttng_ht_iter iter
;
2713 struct ust_app
*app
;
2717 cds_lfht_for_each_entry(ust_app_ht
->ht
, &iter
.iter
, app
, pid_n
.node
) {
2718 if (!app
->compatible
) {
2720 * TODO: In time, we should notice the caller of this error by
2721 * telling him that this is a version error.
2726 ret
= ustctl_calibrate(app
->sock
, calibrate
);
2730 /* Means that it's not implemented on the tracer side. */
2734 /* TODO: Report error to user */
2735 DBG2("Calibrate app PID %d returned with error %d",
2742 DBG("UST app global domain calibration finished");