2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; only version 2
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 #include <sys/types.h>
29 #include <urcu/compiler.h>
31 #include <lttng-share.h>
33 #include "hashtable.h"
35 #include "ust-consumer.h"
39 * Delete ust app event safely. RCU read lock must be held before calling
42 static void delete_ust_app_event(int sock
, struct ust_app_event
*ua_event
)
44 /* TODO : remove context */
45 //struct ust_app_ctx *ltctx;
46 //cds_lfht_for_each_entry(lte->ctx, &iter, ltctx, node) {
47 // delete_ust_app_ctx(sock, ltctx);
50 if (ua_event
->obj
!= NULL
) {
51 ustctl_release_object(sock
, ua_event
->obj
);
58 * Delete ust app stream safely. RCU read lock must be held before calling
61 static void delete_ust_app_stream(int sock
, struct ltt_ust_stream
*stream
)
63 ustctl_release_object(sock
, stream
->obj
);
69 * Delete ust app channel safely. RCU read lock must be held before calling
72 static void delete_ust_app_channel(int sock
, struct ust_app_channel
*ua_chan
)
75 struct cds_lfht_iter iter
;
76 struct ust_app_event
*ua_event
;
77 struct ltt_ust_stream
*stream
, *stmp
;
79 cds_list_for_each_entry_safe(stream
, stmp
, &ua_chan
->streams
.head
, list
) {
80 cds_list_del(&stream
->list
);
81 delete_ust_app_stream(sock
, stream
);
84 /* TODO : remove channel context */
85 //cds_lfht_for_each_entry(ltc->ctx, &iter, ltctx, node) {
86 // ret = hashtable_del(ltc->ctx, &iter);
88 // delete_ust_app_ctx(sock, ltctx);
90 //ret = hashtable_destroy(ltc->ctx);
92 cds_lfht_for_each_entry(ua_chan
->events
, &iter
, ua_event
, node
) {
93 ret
= hashtable_del(ua_chan
->events
, &iter
);
95 delete_ust_app_event(sock
, ua_event
);
98 ret
= hashtable_destroy(ua_chan
->events
);
100 ERR("UST app destroy session hashtable failed");
104 if (ua_chan
->obj
!= NULL
) {
105 ustctl_release_object(sock
, ua_chan
->obj
);
115 * Delete ust app session safely. RCU read lock must be held before calling
118 static void delete_ust_app_session(int sock
,
119 struct ust_app_session
*ua_sess
)
122 struct cds_lfht_iter iter
;
123 struct ust_app_channel
*ua_chan
;
125 if (ua_sess
->metadata
) {
126 ustctl_release_object(sock
, ua_sess
->metadata
->stream_obj
);
127 free(ua_sess
->metadata
->stream_obj
);
128 ustctl_release_object(sock
, ua_sess
->metadata
->obj
);
129 free(ua_sess
->metadata
->obj
);
132 cds_lfht_for_each_entry(ua_sess
->channels
, &iter
, ua_chan
, node
) {
133 ret
= hashtable_del(ua_sess
->channels
, &iter
);
135 delete_ust_app_channel(sock
, ua_chan
);
138 ret
= hashtable_destroy(ua_sess
->channels
);
140 ERR("UST app destroy session hashtable failed");
149 * Delete a traceable application structure from the global list. Never call
150 * this function outside of a call_rcu call.
152 static void delete_ust_app(struct ust_app
*app
)
155 struct cds_lfht_node
*node
;
156 struct cds_lfht_iter iter
;
157 struct ust_app_session
*ua_sess
;
162 /* Remove from key hash table */
163 node
= hashtable_lookup(ust_app_sock_key_map
,
164 (void *) ((unsigned long) app
->key
.sock
), sizeof(void *), &iter
);
166 /* Not suppose to happen */
167 ERR("UST app key %d not found in key hash table", app
->key
.sock
);
171 ret
= hashtable_del(ust_app_sock_key_map
, &iter
);
173 ERR("UST app unable to delete app sock %d from key hash table",
176 DBG2("UST app pair sock %d key %d deleted",
177 app
->key
.sock
, app
->key
.pid
);
180 /* Socket is already closed at this point */
182 /* Delete ust app sessions info */
183 sock
= app
->key
.sock
;
186 cds_lfht_for_each_entry(app
->sessions
, &iter
, ua_sess
, node
) {
187 ret
= hashtable_del(app
->sessions
, &iter
);
189 delete_ust_app_session(app
->key
.sock
, ua_sess
);
192 ret
= hashtable_destroy(app
->sessions
);
194 ERR("UST app destroy session hashtable failed");
199 * Wait until we have removed the key from the sock hash table
200 * before closing this socket, otherwise an application could
201 * re-use the socket ID and race with the teardown, using the
202 * same hash table entry.
206 DBG2("UST app pid %d deleted", app
->key
.pid
);
213 * URCU intermediate call to delete an UST app.
215 static void delete_ust_app_rcu(struct rcu_head
*head
)
217 struct cds_lfht_node
*node
=
218 caa_container_of(head
, struct cds_lfht_node
, head
);
219 struct ust_app
*app
=
220 caa_container_of(node
, struct ust_app
, node
);
226 * Find an ust_app using the sock and return it. RCU read side lock must be
227 * held before calling this helper function.
229 static struct ust_app
*find_app_by_sock(int sock
)
231 struct cds_lfht_node
*node
;
232 struct ust_app_key
*key
;
233 struct cds_lfht_iter iter
;
235 node
= hashtable_lookup(ust_app_sock_key_map
,
236 (void *)((unsigned long) sock
), sizeof(void *), &iter
);
238 DBG2("UST app find by sock %d key not found", sock
);
242 key
= caa_container_of(node
, struct ust_app_key
, node
);
244 node
= hashtable_lookup(ust_app_ht
,
245 (void *)((unsigned long) key
->pid
), sizeof(void *), &iter
);
247 DBG2("UST app find by sock %d not found", sock
);
250 return caa_container_of(node
, struct ust_app
, node
);
257 * Disable the specified event on to UST tracer for the UST session.
259 static int disable_ust_event(struct ust_app
*app
,
260 struct ust_app_session
*ua_sess
, struct ust_app_event
*ua_event
)
264 ret
= ustctl_disable(app
->key
.sock
, ua_event
->obj
);
266 ERR("UST app event %s disable failed for app (pid: %d) "
267 "and session handle %d with ret %d",
268 ua_event
->attr
.name
, app
->key
.pid
, ua_sess
->handle
, ret
);
272 DBG2("UST app event %s disabled successfully for app (pid: %d)",
273 ua_event
->attr
.name
, app
->key
.pid
);
280 * Disable the specified channel on to UST tracer for the UST session.
282 static int disable_ust_channel(struct ust_app
*app
,
283 struct ust_app_session
*ua_sess
, struct ust_app_channel
*ua_chan
)
287 ret
= ustctl_disable(app
->key
.sock
, ua_chan
->obj
);
289 ERR("UST app channel %s disable failed for app (pid: %d) "
290 "and session handle %d with ret %d",
291 ua_chan
->name
, app
->key
.pid
, ua_sess
->handle
, ret
);
295 DBG2("UST app channel %s disabled successfully for app (pid: %d)",
296 ua_chan
->name
, app
->key
.pid
);
303 * Enable the specified channel on to UST tracer for the UST session.
305 static int enable_ust_channel(struct ust_app
*app
,
306 struct ust_app_session
*ua_sess
, struct ust_app_channel
*ua_chan
)
310 ret
= ustctl_enable(app
->key
.sock
, ua_chan
->obj
);
312 ERR("UST app channel %s enable failed for app (pid: %d) "
313 "and session handle %d with ret %d",
314 ua_chan
->name
, app
->key
.pid
, ua_sess
->handle
, ret
);
318 ua_chan
->enabled
= 1;
320 DBG2("UST app channel %s enabled successfully for app (pid: %d)",
321 ua_chan
->name
, app
->key
.pid
);
328 * Enable the specified event on to UST tracer for the UST session.
330 static int enable_ust_event(struct ust_app
*app
,
331 struct ust_app_session
*ua_sess
, struct ust_app_event
*ua_event
)
335 ret
= ustctl_enable(app
->key
.sock
, ua_event
->obj
);
337 ERR("UST app event %s enable failed for app (pid: %d) "
338 "and session handle %d with ret %d",
339 ua_event
->attr
.name
, app
->key
.pid
, ua_sess
->handle
, ret
);
343 DBG2("UST app event %s enabled successfully for app (pid: %d)",
344 ua_event
->attr
.name
, app
->key
.pid
);
351 * Open metadata onto the UST tracer for a UST session.
353 static int open_ust_metadata(struct ust_app
*app
,
354 struct ust_app_session
*ua_sess
)
357 struct lttng_ust_channel_attr uattr
;
359 uattr
.overwrite
= ua_sess
->metadata
->attr
.overwrite
;
360 uattr
.subbuf_size
= ua_sess
->metadata
->attr
.subbuf_size
;
361 uattr
.num_subbuf
= ua_sess
->metadata
->attr
.num_subbuf
;
362 uattr
.switch_timer_interval
=
363 ua_sess
->metadata
->attr
.switch_timer_interval
;
364 uattr
.read_timer_interval
=
365 ua_sess
->metadata
->attr
.read_timer_interval
;
366 uattr
.output
= ua_sess
->metadata
->attr
.output
;
368 /* UST tracer metadata creation */
369 ret
= ustctl_open_metadata(app
->key
.sock
, ua_sess
->handle
, &uattr
,
370 &ua_sess
->metadata
->obj
);
372 ERR("UST app open metadata failed for app pid:%d",
382 * Create stream onto the UST tracer for a UST session.
384 static int create_ust_stream(struct ust_app
*app
,
385 struct ust_app_session
*ua_sess
)
389 ret
= ustctl_create_stream(app
->key
.sock
, ua_sess
->metadata
->obj
,
390 &ua_sess
->metadata
->stream_obj
);
392 ERR("UST create metadata stream failed");
401 * Create the specified channel onto the UST tracer for a UST session.
403 static int create_ust_channel(struct ust_app
*app
,
404 struct ust_app_session
*ua_sess
, struct ust_app_channel
*ua_chan
)
408 /* TODO: remove cast and use lttng-ust-abi.h */
409 ret
= ustctl_create_channel(app
->key
.sock
, ua_sess
->handle
,
410 (struct lttng_ust_channel_attr
*)&ua_chan
->attr
, &ua_chan
->obj
);
412 DBG("Error creating channel %s for app (pid: %d, sock: %d) "
413 "and session handle %d with ret %d",
414 ua_chan
->name
, app
->key
.pid
, app
->key
.sock
,
415 ua_sess
->handle
, ret
);
419 ua_chan
->handle
= ua_chan
->obj
->handle
;
420 ua_chan
->attr
.shm_fd
= ua_chan
->obj
->shm_fd
;
421 ua_chan
->attr
.wait_fd
= ua_chan
->obj
->wait_fd
;
422 ua_chan
->attr
.memory_map_size
= ua_chan
->obj
->memory_map_size
;
424 DBG2("UST app channel %s created successfully for pid:%d and sock:%d",
425 ua_chan
->name
, app
->key
.pid
, app
->key
.sock
);
427 /* If channel is not enabled, disable it on the tracer */
428 if (!ua_chan
->enabled
) {
429 ret
= disable_ust_channel(app
, ua_sess
, ua_chan
);
440 * Create the specified event onto the UST tracer for a UST session.
443 int create_ust_event(struct ust_app
*app
, struct ust_app_session
*ua_sess
,
444 struct ust_app_channel
*ua_chan
, struct ust_app_event
*ua_event
)
448 /* Create UST event on tracer */
449 ret
= ustctl_create_event(app
->key
.sock
, &ua_event
->attr
, ua_chan
->obj
,
452 ERR("Error ustctl create event %s for app pid: %d with ret %d",
453 ua_event
->attr
.name
, app
->key
.pid
, ret
);
457 ua_event
->handle
= ua_event
->obj
->handle
;
459 DBG2("UST app event %s created successfully for pid:%d",
460 ua_event
->attr
.name
, app
->key
.pid
);
462 /* If event not enabled, disable it on the tracer */
463 if (!ua_event
->enabled
) {
464 ret
= disable_ust_event(app
, ua_sess
, ua_event
);
475 * Alloc new UST app session.
477 static struct ust_app_session
*alloc_ust_app_session(void)
479 struct ust_app_session
*ua_sess
;
481 /* Init most of the default value by allocating and zeroing */
482 ua_sess
= zmalloc(sizeof(struct ust_app_session
));
483 if (ua_sess
== NULL
) {
488 ua_sess
->handle
= -1;
489 ua_sess
->channels
= hashtable_new_str(0);
498 * Alloc new UST app channel.
500 static struct ust_app_channel
*alloc_ust_app_channel(char *name
,
501 struct lttng_ust_channel
*attr
)
503 struct ust_app_channel
*ua_chan
;
505 /* Init most of the default value by allocating and zeroing */
506 ua_chan
= zmalloc(sizeof(struct ust_app_channel
));
507 if (ua_chan
== NULL
) {
512 /* Setup channel name */
513 strncpy(ua_chan
->name
, name
, sizeof(ua_chan
->name
));
514 ua_chan
->name
[sizeof(ua_chan
->name
) - 1] = '\0';
516 ua_chan
->enabled
= 1;
517 ua_chan
->handle
= -1;
518 ua_chan
->ctx
= hashtable_new(0);
519 ua_chan
->events
= hashtable_new_str(0);
520 hashtable_node_init(&ua_chan
->node
, (void *) ua_chan
->name
,
521 strlen(ua_chan
->name
));
523 CDS_INIT_LIST_HEAD(&ua_chan
->streams
.head
);
525 /* Copy attributes */
527 memcpy(&ua_chan
->attr
, attr
, sizeof(ua_chan
->attr
));
530 DBG3("UST app channel %s allocated", ua_chan
->name
);
539 * Alloc new UST app event.
541 static struct ust_app_event
*alloc_ust_app_event(char *name
,
542 struct lttng_ust_event
*attr
)
544 struct ust_app_event
*ua_event
;
546 /* Init most of the default value by allocating and zeroing */
547 ua_event
= zmalloc(sizeof(struct ust_app_event
));
548 if (ua_event
== NULL
) {
553 ua_event
->enabled
= 1;
554 strncpy(ua_event
->name
, name
, sizeof(ua_event
->name
));
555 ua_event
->name
[sizeof(ua_event
->name
) - 1] = '\0';
556 ua_event
->ctx
= hashtable_new(0);
557 hashtable_node_init(&ua_event
->node
, (void *) ua_event
->name
,
558 strlen(ua_event
->name
));
560 /* Copy attributes */
562 memcpy(&ua_event
->attr
, attr
, sizeof(ua_event
->attr
));
565 DBG3("UST app event %s allocated", ua_event
->name
);
574 * Copy data between an UST app event and a LTT event.
576 static void shadow_copy_event(struct ust_app_event
*ua_event
,
577 struct ltt_ust_event
*uevent
)
579 strncpy(ua_event
->name
, uevent
->attr
.name
, sizeof(ua_event
->name
));
580 ua_event
->name
[sizeof(ua_event
->name
) - 1] = '\0';
582 /* Copy event attributes */
583 memcpy(&ua_event
->attr
, &uevent
->attr
, sizeof(ua_event
->attr
));
585 /* TODO: support copy context */
589 * Copy data between an UST app channel and a LTT channel.
591 static void shadow_copy_channel(struct ust_app_channel
*ua_chan
,
592 struct ltt_ust_channel
*uchan
)
594 struct cds_lfht_iter iter
;
595 struct cds_lfht_node
*ua_event_node
;
596 struct ltt_ust_event
*uevent
;
597 struct ust_app_event
*ua_event
;
599 DBG2("Shadow copy of UST app channel %s", ua_chan
->name
);
601 strncpy(ua_chan
->name
, uchan
->name
, sizeof(ua_chan
->name
));
602 ua_chan
->name
[sizeof(ua_chan
->name
) - 1] = '\0';
603 /* Copy event attributes */
604 memcpy(&ua_chan
->attr
, &uchan
->attr
, sizeof(ua_chan
->attr
));
606 /* TODO: support copy context */
608 /* Copy all events from ltt ust channel to ust app channel */
609 cds_lfht_for_each_entry(uchan
->events
, &iter
, uevent
, node
) {
610 struct cds_lfht_iter uiter
;
612 ua_event_node
= hashtable_lookup(ua_chan
->events
,
613 (void *) uevent
->attr
.name
, strlen(uevent
->attr
.name
),
615 if (ua_event_node
== NULL
) {
616 DBG2("UST event %s not found on shadow copy channel",
618 ua_event
= alloc_ust_app_event(uevent
->attr
.name
, &uevent
->attr
);
619 if (ua_event
== NULL
) {
622 shadow_copy_event(ua_event
, uevent
);
623 hashtable_add_unique(ua_chan
->events
, &ua_event
->node
);
627 DBG3("Shadow copy channel done");
631 * Copy data between a UST app session and a regular LTT session.
633 static void shadow_copy_session(struct ust_app_session
*ua_sess
,
634 struct ltt_ust_session
*usess
,
637 struct cds_lfht_node
*ua_chan_node
;
638 struct cds_lfht_iter iter
;
639 struct ltt_ust_channel
*uchan
;
640 struct ust_app_channel
*ua_chan
;
646 /* Get date and time for unique app path */
648 timeinfo
= localtime(&rawtime
);
649 strftime(datetime
, sizeof(datetime
), "%Y%m%d-%H%M%S", timeinfo
);
651 DBG2("Shadow copy of session handle %d", ua_sess
->handle
);
653 ua_sess
->uid
= usess
->uid
;
655 ret
= snprintf(ua_sess
->path
, PATH_MAX
,
657 usess
->pathname
, app
->name
, app
->key
.pid
,
660 PERROR("asprintf UST shadow copy session");
661 /* TODO: We cannot return an error from here.. */
665 /* TODO: support all UST domain */
667 /* Iterate over all channels in global domain. */
668 cds_lfht_for_each_entry(usess
->domain_global
.channels
, &iter
,
670 struct cds_lfht_iter uiter
;
672 ua_chan_node
= hashtable_lookup(ua_sess
->channels
,
673 (void *)uchan
->name
, strlen(uchan
->name
),
675 if (ua_chan_node
!= NULL
) {
679 DBG2("Channel %s not found on shadow session copy, creating it",
681 ua_chan
= alloc_ust_app_channel(uchan
->name
, &uchan
->attr
);
682 if (ua_chan
== NULL
) {
683 /* malloc failed... continuing */
687 shadow_copy_channel(ua_chan
, uchan
);
688 hashtable_add_unique(ua_sess
->channels
, &ua_chan
->node
);
693 * Lookup sesison wrapper.
696 void __lookup_session_by_app(struct ltt_ust_session
*usess
,
697 struct ust_app
*app
, struct cds_lfht_iter
*iter
)
699 /* Get right UST app session from app */
700 (void) hashtable_lookup(app
->sessions
,
701 (void *) ((unsigned long) usess
->uid
), sizeof(void *),
706 * Return ust app session from the app session hashtable using the UST session
709 static struct ust_app_session
*lookup_session_by_app(
710 struct ltt_ust_session
*usess
, struct ust_app
*app
)
712 struct cds_lfht_iter iter
;
713 struct cds_lfht_node
*node
;
715 __lookup_session_by_app(usess
, app
, &iter
);
716 node
= hashtable_iter_get_node(&iter
);
721 return caa_container_of(node
, struct ust_app_session
, node
);
728 * Create a UST session onto the tracer of app and add it the session
731 * Return ust app session or NULL on error.
733 static struct ust_app_session
*create_ust_app_session(
734 struct ltt_ust_session
*usess
, struct ust_app
*app
)
737 struct ust_app_session
*ua_sess
;
739 ua_sess
= lookup_session_by_app(usess
, app
);
740 if (ua_sess
== NULL
) {
741 DBG2("UST app pid: %d session uid %d not found, creating it",
742 app
->key
.pid
, usess
->uid
);
743 ua_sess
= alloc_ust_app_session();
744 if (ua_sess
== NULL
) {
745 /* Only malloc can failed so something is really wrong */
748 shadow_copy_session(ua_sess
, usess
, app
);
751 if (ua_sess
->handle
== -1) {
752 ret
= ustctl_create_session(app
->key
.sock
);
754 ERR("Error creating session for app pid %d, sock %d",
755 app
->key
.pid
, app
->key
.sock
);
756 /* TODO: free() ua_sess */
760 DBG2("UST app ustctl create session handle %d", ret
);
761 ua_sess
->handle
= ret
;
763 /* Add ust app session to app's HT */
764 hashtable_node_init(&ua_sess
->node
,
765 (void *)((unsigned long) ua_sess
->uid
), sizeof(void *));
766 hashtable_add_unique(app
->sessions
, &ua_sess
->node
);
768 DBG2("UST app session created successfully with handle %d", ret
);
778 * Enable on the tracer side a ust app event for the session and channel.
781 int enable_ust_app_event(struct ust_app_session
*ua_sess
,
782 struct ust_app_event
*ua_event
, struct ust_app
*app
)
786 ret
= enable_ust_event(app
, ua_sess
, ua_event
);
791 ua_event
->enabled
= 1;
798 * Disable on the tracer side a ust app event for the session and channel.
800 static int disable_ust_app_event(struct ust_app_session
*ua_sess
,
801 struct ust_app_channel
*ua_chan
, struct ust_app_event
*ua_event
,
806 ret
= disable_ust_event(app
, ua_sess
, ua_event
);
811 ua_event
->enabled
= 0;
818 * Lookup ust app channel for session and disable it on the tracer side.
821 int disable_ust_app_channel(struct ust_app_session
*ua_sess
,
822 struct ust_app_channel
*ua_chan
, struct ust_app
*app
)
826 ret
= disable_ust_channel(app
, ua_sess
, ua_chan
);
831 ua_chan
->enabled
= 0;
838 * Lookup ust app channel for session and enable it on the tracer side.
840 static int enable_ust_app_channel(struct ust_app_session
*ua_sess
,
841 struct ltt_ust_channel
*uchan
, struct ust_app
*app
)
844 struct cds_lfht_iter iter
;
845 struct cds_lfht_node
*ua_chan_node
;
846 struct ust_app_channel
*ua_chan
;
848 ua_chan_node
= hashtable_lookup(ua_sess
->channels
,
849 (void *)uchan
->name
, strlen(uchan
->name
), &iter
);
850 if (ua_chan_node
== NULL
) {
851 DBG2("Unable to find channel %s in ust session uid %u",
852 uchan
->name
, ua_sess
->uid
);
856 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
858 ret
= enable_ust_channel(app
, ua_sess
, ua_chan
);
868 * Create UST app channel and create it on the tracer.
870 static struct ust_app_channel
*create_ust_app_channel(
871 struct ust_app_session
*ua_sess
, struct ltt_ust_channel
*uchan
,
875 struct cds_lfht_iter iter
;
876 struct cds_lfht_node
*ua_chan_node
;
877 struct ust_app_channel
*ua_chan
;
879 /* Lookup channel in the ust app session */
880 ua_chan_node
= hashtable_lookup(ua_sess
->channels
,
881 (void *)uchan
->name
, strlen(uchan
->name
), &iter
);
882 if (ua_chan_node
== NULL
) {
883 DBG2("Unable to find channel %s in ust session uid %u",
884 uchan
->name
, ua_sess
->uid
);
885 ua_chan
= alloc_ust_app_channel(uchan
->name
, &uchan
->attr
);
886 if (ua_chan
== NULL
) {
889 shadow_copy_channel(ua_chan
, uchan
);
891 hashtable_add_unique(ua_sess
->channels
, &ua_chan
->node
);
893 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
896 ret
= create_ust_channel(app
, ua_sess
, ua_chan
);
908 * Create UST app event and create it on the tracer side.
911 int create_ust_app_event(struct ust_app_session
*ua_sess
,
912 struct ust_app_channel
*ua_chan
, struct ltt_ust_event
*uevent
,
916 struct cds_lfht_iter iter
;
917 struct cds_lfht_node
*ua_event_node
;
918 struct ust_app_event
*ua_event
;
921 ua_event_node
= hashtable_lookup(ua_chan
->events
,
922 (void *)uevent
->attr
.name
, strlen(uevent
->attr
.name
), &iter
);
923 if (ua_event_node
!= NULL
) {
924 ERR("UST app event %s already exist. Stopping creation.",
929 /* Does not exist so create one */
930 ua_event
= alloc_ust_app_event(uevent
->attr
.name
, &uevent
->attr
);
931 if (ua_event
== NULL
) {
932 /* Only malloc can failed so something is really wrong */
936 shadow_copy_event(ua_event
, uevent
);
938 /* Create it on the tracer side */
939 ret
= create_ust_event(app
, ua_sess
, ua_chan
, ua_event
);
941 delete_ust_app_event(app
->key
.sock
, ua_event
);
945 ua_event
->enabled
= 1;
947 hashtable_add_unique(ua_chan
->events
, &ua_event
->node
);
955 * Create UST metadata and open it on the tracer side.
957 static int create_ust_app_metadata(struct ust_app_session
*ua_sess
,
958 char *pathname
, struct ust_app
*app
)
962 if (ua_sess
->metadata
== NULL
) {
963 /* Allocate UST metadata */
964 ua_sess
->metadata
= trace_ust_create_metadata(pathname
);
965 if (ua_sess
->metadata
== NULL
) {
966 ERR("UST app session %d creating metadata failed",
971 ret
= open_ust_metadata(app
, ua_sess
);
976 DBG2("UST metadata opened for app pid %d", app
->key
.pid
);
979 /* Open UST metadata stream */
980 if (ua_sess
->metadata
->stream_obj
== NULL
) {
981 ret
= create_ust_stream(app
, ua_sess
);
986 ret
= mkdir(ua_sess
->path
, S_IRWXU
| S_IRWXG
);
988 PERROR("mkdir UST metadata");
992 ret
= snprintf(ua_sess
->metadata
->pathname
, PATH_MAX
,
993 "%s/metadata", ua_sess
->path
);
995 PERROR("asprintf UST create stream");
999 DBG2("UST metadata stream object created for app pid %d",
1002 ERR("Attempting to create stream without metadata opened");
1013 * Return pointer to traceable apps list.
1015 struct cds_lfht
*ust_app_get_ht(void)
1021 * Return ust app pointer or NULL if not found.
1023 struct ust_app
*ust_app_find_by_pid(pid_t pid
)
1025 struct cds_lfht_node
*node
;
1026 struct cds_lfht_iter iter
;
1029 node
= hashtable_lookup(ust_app_ht
,
1030 (void *)((unsigned long) pid
), sizeof(void *), &iter
);
1032 DBG2("UST app no found with pid %d", pid
);
1037 DBG2("Found UST app by pid %d", pid
);
1039 return caa_container_of(node
, struct ust_app
, node
);
1047 * Using pid and uid (of the app), allocate a new ust_app struct and
1048 * add it to the global traceable app list.
1050 * On success, return 0, else return malloc -ENOMEM, or -EINVAL if app
1051 * bitness is not supported.
1053 int ust_app_register(struct ust_register_msg
*msg
, int sock
)
1055 struct ust_app
*lta
;
1057 if ((msg
->bits_per_long
== 64 && ust_consumerd64_fd
== -EINVAL
)
1058 || (msg
->bits_per_long
== 32 && ust_consumerd32_fd
== -EINVAL
)) {
1059 ERR("Registration failed: application \"%s\" (pid: %d) has "
1060 "%d-bit long, but no consumerd for this long size is available.\n",
1061 msg
->name
, msg
->pid
, msg
->bits_per_long
);
1065 lta
= zmalloc(sizeof(struct ust_app
));
1071 lta
->ppid
= msg
->ppid
;
1072 lta
->uid
= msg
->uid
;
1073 lta
->gid
= msg
->gid
;
1074 lta
->bits_per_long
= msg
->bits_per_long
;
1075 lta
->v_major
= msg
->major
;
1076 lta
->v_minor
= msg
->minor
;
1077 strncpy(lta
->name
, msg
->name
, sizeof(lta
->name
));
1078 lta
->name
[16] = '\0';
1079 lta
->sessions
= hashtable_new(0);
1082 lta
->key
.pid
= msg
->pid
;
1083 hashtable_node_init(<a
->node
, (void *)((unsigned long)lta
->key
.pid
),
1085 lta
->key
.sock
= sock
;
1086 hashtable_node_init(<a
->key
.node
, (void *)((unsigned long)lta
->key
.sock
),
1090 hashtable_add_unique(ust_app_sock_key_map
, <a
->key
.node
);
1091 hashtable_add_unique(ust_app_ht
, <a
->node
);
1094 DBG("App registered with pid:%d ppid:%d uid:%d gid:%d sock:%d name:%s"
1095 " (version %d.%d)", lta
->key
.pid
, lta
->ppid
, lta
->uid
, lta
->gid
,
1096 lta
->key
.sock
, lta
->name
, lta
->v_major
, lta
->v_minor
);
1102 * Unregister app by removing it from the global traceable app list and freeing
1105 * The socket is already closed at this point so no close to sock.
1107 void ust_app_unregister(int sock
)
1109 struct ust_app
*lta
;
1110 struct cds_lfht_node
*node
;
1111 struct cds_lfht_iter iter
;
1115 lta
= find_app_by_sock(sock
);
1117 ERR("Unregister app sock %d not found!", sock
);
1121 DBG("PID %d unregistering with sock %d", lta
->key
.pid
, sock
);
1123 /* Get the node reference for a call_rcu */
1124 node
= hashtable_lookup(ust_app_ht
,
1125 (void *)((unsigned long) lta
->key
.pid
), sizeof(void *), &iter
);
1127 ERR("Unable to find app sock %d by pid %d", sock
, lta
->key
.pid
);
1131 ret
= hashtable_del(ust_app_ht
, &iter
);
1133 call_rcu(&node
->head
, delete_ust_app_rcu
);
1140 * Return traceable_app_count
1142 unsigned long ust_app_list_count(void)
1144 unsigned long count
;
1147 count
= hashtable_get_count(ust_app_ht
);
1154 * Fill events array with all events name of all registered apps.
1156 int ust_app_list_events(struct lttng_event
**events
)
1159 size_t nbmem
, count
= 0;
1160 struct cds_lfht_iter iter
;
1161 struct ust_app
*app
;
1162 struct lttng_event
*tmp
;
1164 nbmem
= UST_APP_EVENT_LIST_SIZE
;
1165 tmp
= zmalloc(nbmem
* sizeof(struct lttng_event
));
1167 PERROR("zmalloc ust app events");
1174 cds_lfht_for_each_entry(ust_app_ht
, &iter
, app
, node
) {
1175 handle
= ustctl_tracepoint_list(app
->key
.sock
);
1177 ERR("UST app list events getting handle failed for app pid %d",
1182 while ((ret
= ustctl_tracepoint_list_get(app
->key
.sock
, handle
,
1183 tmp
[count
].name
)) != -ENOENT
) {
1184 if (count
> nbmem
) {
1185 DBG2("Reallocating event list from %zu to %zu bytes", nbmem
,
1186 nbmem
+ UST_APP_EVENT_LIST_SIZE
);
1187 nbmem
+= UST_APP_EVENT_LIST_SIZE
;
1188 tmp
= realloc(tmp
, nbmem
);
1190 PERROR("realloc ust app events");
1196 tmp
[count
].type
= LTTNG_UST_TRACEPOINT
;
1197 tmp
[count
].pid
= app
->key
.pid
;
1198 tmp
[count
].enabled
= -1;
1206 DBG2("UST app list events done (%zu events)", count
);
1215 * Free and clean all traceable apps of the global list.
1217 void ust_app_clean_list(void)
1220 struct cds_lfht_node
*node
;
1221 struct cds_lfht_iter iter
;
1222 struct ust_app
*app
;
1224 DBG2("UST app cleaning registered apps hash table");
1228 cds_lfht_for_each_entry(ust_app_ht
, &iter
, app
, node
) {
1229 ret
= hashtable_del(ust_app_ht
, &iter
);
1231 call_rcu(&node
->head
, delete_ust_app_rcu
);
1234 hashtable_destroy(ust_app_ht
);
1235 hashtable_destroy(ust_app_sock_key_map
);
1241 * Init UST app hash table.
1243 void ust_app_ht_alloc(void)
1245 ust_app_ht
= hashtable_new(0);
1246 ust_app_sock_key_map
= hashtable_new(0);
1250 * For a specific UST session, disable the channel for all registered apps.
1252 int ust_app_disable_channel_glb(struct ltt_ust_session
*usess
,
1253 struct ltt_ust_channel
*uchan
)
1256 struct cds_lfht_iter iter
;
1257 struct cds_lfht_node
*ua_chan_node
;
1258 struct ust_app
*app
;
1259 struct ust_app_session
*ua_sess
;
1260 struct ust_app_channel
*ua_chan
;
1262 if (usess
== NULL
|| uchan
== NULL
) {
1263 ERR("Disabling UST global channel with NULL values");
1268 DBG2("UST app disabling channel %s from global domain for session uid %d",
1269 uchan
->name
, usess
->uid
);
1273 /* For every registered applications */
1274 cds_lfht_for_each_entry(ust_app_ht
, &iter
, app
, node
) {
1275 ua_sess
= lookup_session_by_app(usess
, app
);
1276 if (ua_sess
== NULL
) {
1281 ua_chan_node
= hashtable_lookup(ua_sess
->channels
,
1282 (void *)uchan
->name
, strlen(uchan
->name
), &iter
);
1283 /* If the session if found for the app, the channel must be there */
1284 assert(ua_chan_node
);
1286 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
1287 /* The channel must not be already disabled */
1288 assert(ua_chan
->enabled
== 1);
1290 /* Disable channel onto application */
1291 ret
= disable_ust_app_channel(ua_sess
, ua_chan
, app
);
1293 /* XXX: We might want to report this error at some point... */
1305 * For a specific UST session, enable the channel for all registered apps.
1307 int ust_app_enable_channel_glb(struct ltt_ust_session
*usess
,
1308 struct ltt_ust_channel
*uchan
)
1311 struct cds_lfht_iter iter
;
1312 struct ust_app
*app
;
1313 struct ust_app_session
*ua_sess
;
1315 if (usess
== NULL
|| uchan
== NULL
) {
1316 ERR("Adding UST global channel to NULL values");
1321 DBG2("UST app enabling channel %s to global domain for session uid %d",
1322 uchan
->name
, usess
->uid
);
1326 /* For every registered applications */
1327 cds_lfht_for_each_entry(ust_app_ht
, &iter
, app
, node
) {
1328 ua_sess
= lookup_session_by_app(usess
, app
);
1329 if (ua_sess
== NULL
) {
1333 /* Enable channel onto application */
1334 ret
= enable_ust_app_channel(ua_sess
, uchan
, app
);
1336 /* XXX: We might want to report this error at some point... */
1348 * Disable an event in a channel and for a specific session.
1350 int ust_app_disable_event_glb(struct ltt_ust_session
*usess
,
1351 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
)
1354 struct cds_lfht_iter iter
, uiter
;
1355 struct cds_lfht_node
*ua_chan_node
, *ua_event_node
;
1356 struct ust_app
*app
;
1357 struct ust_app_session
*ua_sess
;
1358 struct ust_app_channel
*ua_chan
;
1359 struct ust_app_event
*ua_event
;
1361 DBG("UST app disabling event %s for all apps in channel "
1362 "%s for session uid %d", uevent
->attr
.name
, uchan
->name
, usess
->uid
);
1366 /* For all registered applications */
1367 cds_lfht_for_each_entry(ust_app_ht
, &iter
, app
, node
) {
1368 ua_sess
= lookup_session_by_app(usess
, app
);
1369 if (ua_sess
== NULL
) {
1374 /* Lookup channel in the ust app session */
1375 ua_chan_node
= hashtable_lookup(ua_sess
->channels
,
1376 (void *)uchan
->name
, strlen(uchan
->name
), &uiter
);
1377 if (ua_chan_node
== NULL
) {
1378 DBG2("Channel %s not found in session uid %d for app pid %d."
1379 "Skipping", uchan
->name
, usess
->uid
, app
->key
.pid
);
1382 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
1384 ua_event_node
= hashtable_lookup(ua_chan
->events
,
1385 (void *)uevent
->attr
.name
, strlen(uevent
->attr
.name
), &uiter
);
1386 if (ua_event_node
== NULL
) {
1387 DBG2("Event %s not found in channel %s for app pid %d."
1388 "Skipping", uevent
->attr
.name
, uchan
->name
, app
->key
.pid
);
1391 ua_event
= caa_container_of(ua_event_node
, struct ust_app_event
, node
);
1393 ret
= disable_ust_app_event(ua_sess
, ua_chan
, ua_event
, app
);
1395 /* XXX: Report error someday... */
1406 * For a specific UST session and UST channel, the event for all
1409 int ust_app_disable_all_event_glb(struct ltt_ust_session
*usess
,
1410 struct ltt_ust_channel
*uchan
)
1413 struct cds_lfht_iter iter
, uiter
;
1414 struct cds_lfht_node
*ua_chan_node
;
1415 struct ust_app
*app
;
1416 struct ust_app_session
*ua_sess
;
1417 struct ust_app_channel
*ua_chan
;
1418 struct ust_app_event
*ua_event
;
1420 DBG("UST app disabling all event for all apps in channel "
1421 "%s for session uid %d", uchan
->name
, usess
->uid
);
1425 /* For all registered applications */
1426 cds_lfht_for_each_entry(ust_app_ht
, &iter
, app
, node
) {
1427 ua_sess
= lookup_session_by_app(usess
, app
);
1428 /* If ua_sess is NULL, there is a code flow error */
1431 /* Lookup channel in the ust app session */
1432 ua_chan_node
= hashtable_lookup(ua_sess
->channels
, (void *)uchan
->name
,
1433 strlen(uchan
->name
), &uiter
);
1434 /* If the channel is not found, there is a code flow error */
1435 assert(ua_chan_node
);
1437 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
1439 /* Disable each events of channel */
1440 cds_lfht_for_each_entry(ua_chan
->events
, &uiter
, ua_event
, node
) {
1441 ret
= disable_ust_app_event(ua_sess
, ua_chan
, ua_event
, app
);
1443 /* XXX: Report error someday... */
1455 * For a specific UST session, create the channel for all registered apps.
1457 int ust_app_create_channel_glb(struct ltt_ust_session
*usess
,
1458 struct ltt_ust_channel
*uchan
)
1461 struct cds_lfht_iter iter
;
1462 struct ust_app
*app
;
1463 struct ust_app_session
*ua_sess
;
1464 struct ust_app_channel
*ua_chan
;
1466 if (usess
== NULL
|| uchan
== NULL
) {
1467 ERR("Adding UST global channel to NULL values");
1472 DBG2("UST app adding channel %s to global domain for session uid %d",
1473 uchan
->name
, usess
->uid
);
1477 /* For every registered applications */
1478 cds_lfht_for_each_entry(ust_app_ht
, &iter
, app
, node
) {
1480 * Create session on the tracer side and add it to app session HT. Note
1481 * that if session exist, it will simply return a pointer to the ust
1484 ua_sess
= create_ust_app_session(usess
, app
);
1485 if (ua_sess
== NULL
) {
1489 /* Create channel onto application */
1490 ua_chan
= create_ust_app_channel(ua_sess
, uchan
, app
);
1491 if (ua_chan
== NULL
) {
1503 * Enable event for a specific session and channel on the tracer.
1505 int ust_app_enable_event_glb(struct ltt_ust_session
*usess
,
1506 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
)
1509 struct cds_lfht_iter iter
, uiter
;
1510 struct cds_lfht_node
*ua_chan_node
, *ua_event_node
;
1511 struct ust_app
*app
;
1512 struct ust_app_session
*ua_sess
;
1513 struct ust_app_channel
*ua_chan
;
1514 struct ust_app_event
*ua_event
;
1516 DBG("UST app enabling event %s for all apps for session uid %d",
1517 uevent
->attr
.name
, usess
->uid
);
1520 * NOTE: At this point, this function is called only if the session and
1521 * channel passed are already created for all apps. and enabled on the
1527 /* For all registered applications */
1528 cds_lfht_for_each_entry(ust_app_ht
, &iter
, app
, node
) {
1529 ua_sess
= lookup_session_by_app(usess
, app
);
1530 /* If ua_sess is NULL, there is a code flow error */
1533 /* Lookup channel in the ust app session */
1534 ua_chan_node
= hashtable_lookup(ua_sess
->channels
, (void *)uchan
->name
,
1535 strlen(uchan
->name
), &uiter
);
1536 /* If the channel is not found, there is a code flow error */
1537 assert(ua_chan_node
);
1539 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
1541 ua_event_node
= hashtable_lookup(ua_sess
->channels
,
1542 (void*)uevent
->attr
.name
, strlen(uevent
->attr
.name
), &uiter
);
1543 if (ua_event_node
== NULL
) {
1544 DBG3("UST app enable event %s not found. Skipping app",
1548 ua_event
= caa_container_of(ua_event_node
, struct ust_app_event
, node
);
1550 ret
= enable_ust_app_event(ua_sess
, ua_event
, app
);
1552 /* XXX: Report error someday... */
1563 * For a specific existing UST session and UST channel, creates the event for
1564 * all registered apps.
1566 int ust_app_create_event_glb(struct ltt_ust_session
*usess
,
1567 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
)
1570 struct cds_lfht_iter iter
, uiter
;
1571 struct cds_lfht_node
*ua_chan_node
;
1572 struct ust_app
*app
;
1573 struct ust_app_session
*ua_sess
;
1574 struct ust_app_channel
*ua_chan
;
1576 DBG("UST app creating event %s for all apps for session uid %d",
1577 uevent
->attr
.name
, usess
->uid
);
1580 * NOTE: At this point, this function is called only if the session and
1581 * channel passed are already created for all apps. and enabled on the
1587 /* For all registered applications */
1588 cds_lfht_for_each_entry(ust_app_ht
, &iter
, app
, node
) {
1589 ua_sess
= lookup_session_by_app(usess
, app
);
1590 /* If ua_sess is NULL, there is a code flow error */
1593 /* Lookup channel in the ust app session */
1594 ua_chan_node
= hashtable_lookup(ua_sess
->channels
, (void *)uchan
->name
,
1595 strlen(uchan
->name
), &uiter
);
1596 /* If the channel is not found, there is a code flow error */
1597 assert(ua_chan_node
);
1599 ua_chan
= caa_container_of(ua_chan_node
, struct ust_app_channel
, node
);
1601 ret
= create_ust_app_event(ua_sess
, ua_chan
, uevent
, app
);
1613 * Start tracing for a specific UST session and app.
1615 int ust_app_start_trace(struct ltt_ust_session
*usess
, struct ust_app
*app
)
1618 struct cds_lfht_iter iter
;
1619 struct ust_app_session
*ua_sess
;
1620 struct ust_app_channel
*ua_chan
;
1621 struct ltt_ust_stream
*ustream
;
1624 DBG("Starting tracing for ust app pid %d", app
->key
.pid
);
1628 ua_sess
= lookup_session_by_app(usess
, app
);
1629 if (ua_sess
== NULL
) {
1630 goto error_rcu_unlock
;
1633 /* Upon restart, we skip the setup, already done */
1634 if (ua_sess
->started
) {
1638 ret
= create_ust_app_metadata(ua_sess
, usess
->pathname
, app
);
1640 goto error_rcu_unlock
;
1643 /* For each channel */
1644 cds_lfht_for_each_entry(ua_sess
->channels
, &iter
, ua_chan
, node
) {
1645 /* Create all streams */
1647 /* Create UST stream */
1648 ustream
= zmalloc(sizeof(*ustream
));
1649 if (ustream
== NULL
) {
1650 PERROR("zmalloc ust stream");
1651 goto error_rcu_unlock
;
1654 ret
= ustctl_create_stream(app
->key
.sock
, ua_chan
->obj
,
1657 /* Got all streams */
1660 ustream
->handle
= ustream
->obj
->handle
;
1662 /* Order is important */
1663 cds_list_add_tail(&ustream
->list
, &ua_chan
->streams
.head
);
1664 ret
= snprintf(ustream
->pathname
, PATH_MAX
, "%s/%s_%u",
1665 ua_sess
->path
, ua_chan
->name
,
1666 ua_chan
->streams
.count
++);
1668 PERROR("asprintf UST create stream");
1671 DBG2("UST stream %d ready at %s", ua_chan
->streams
.count
,
1676 switch (app
->bits_per_long
) {
1678 consumerd_fd
= ust_consumerd64_fd
;
1681 consumerd_fd
= ust_consumerd32_fd
;
1685 goto error_rcu_unlock
;
1688 /* Setup UST consumer socket and send fds to it */
1689 ret
= ust_consumer_send_session(consumerd_fd
, ua_sess
);
1691 goto error_rcu_unlock
;
1693 ua_sess
->started
= 1;
1696 /* This start the UST tracing */
1697 ret
= ustctl_start_session(app
->key
.sock
, ua_sess
->handle
);
1699 ERR("Error starting tracing for app pid: %d", app
->key
.pid
);
1700 goto error_rcu_unlock
;
1705 /* Quiescent wait after starting trace */
1706 ustctl_wait_quiescent(app
->key
.sock
);
1716 * Stop tracing for a specific UST session and app.
1718 int ust_app_stop_trace(struct ltt_ust_session
*usess
, struct ust_app
*app
)
1721 struct ust_app_session
*ua_sess
;
1723 DBG("Stopping tracing for ust app pid %d", app
->key
.pid
);
1727 ua_sess
= lookup_session_by_app(usess
, app
);
1728 if (ua_sess
== NULL
) {
1729 /* Only malloc can failed so something is really wrong */
1730 goto error_rcu_unlock
;
1733 #if 0 /* only useful when periodical flush will be supported */
1734 /* need to keep a handle on shm in session for this. */
1735 /* Flush all buffers before stopping */
1736 ret
= ustctl_flush_buffer(usess
->sock
, usess
->metadata
->obj
);
1738 ERR("UST metadata flush failed");
1741 cds_list_for_each_entry(ustchan
, &usess
->channels
.head
, list
) {
1742 ret
= ustctl_flush_buffer(usess
->sock
, ustchan
->obj
);
1744 ERR("UST flush buffer error");
1749 /* This inhibits UST tracing */
1750 ret
= ustctl_stop_session(app
->key
.sock
, ua_sess
->handle
);
1752 ERR("Error stopping tracing for app pid: %d", app
->key
.pid
);
1753 goto error_rcu_unlock
;
1758 /* Quiescent wait after stopping trace */
1759 ustctl_wait_quiescent(app
->key
.sock
);
1769 * Destroy a specific UST session in apps.
1771 int ust_app_destroy_trace(struct ltt_ust_session
*usess
, struct ust_app
*app
)
1773 struct ust_app_session
*ua_sess
;
1774 struct lttng_ust_object_data obj
;
1775 struct cds_lfht_iter iter
;
1776 struct cds_lfht_node
*node
;
1779 DBG("Destroy tracing for ust app pid %d", app
->key
.pid
);
1783 __lookup_session_by_app(usess
, app
, &iter
);
1784 node
= hashtable_iter_get_node(&iter
);
1786 /* Only malloc can failed so something is really wrong */
1787 goto error_rcu_unlock
;
1789 ua_sess
= caa_container_of(node
, struct ust_app_session
, node
);
1790 ret
= hashtable_del(app
->sessions
, &iter
);
1792 delete_ust_app_session(app
->key
.sock
, ua_sess
);
1793 obj
.handle
= ua_sess
->handle
;
1796 obj
.memory_map_size
= 0;
1797 ustctl_release_object(app
->key
.sock
, &obj
);
1801 /* Quiescent wait after stopping trace */
1802 ustctl_wait_quiescent(app
->key
.sock
);
1812 * Start tracing for the UST session.
1814 int ust_app_start_trace_all(struct ltt_ust_session
*usess
)
1817 struct cds_lfht_iter iter
;
1818 struct ust_app
*app
;
1820 DBG("Starting all UST traces");
1824 cds_lfht_for_each_entry(ust_app_ht
, &iter
, app
, node
) {
1825 ret
= ust_app_start_trace(usess
, app
);
1827 /* Continue to next apps even on error */
1838 * Start tracing for the UST session.
1840 int ust_app_stop_trace_all(struct ltt_ust_session
*usess
)
1843 struct cds_lfht_iter iter
;
1844 struct ust_app
*app
;
1846 DBG("Stopping all UST traces");
1850 cds_lfht_for_each_entry(ust_app_ht
, &iter
, app
, node
) {
1851 ret
= ust_app_stop_trace(usess
, app
);
1853 /* Continue to next apps even on error */
1864 * Destroy app UST session.
1866 int ust_app_destroy_trace_all(struct ltt_ust_session
*usess
)
1869 struct cds_lfht_iter iter
;
1870 struct ust_app
*app
;
1872 DBG("Destroy all UST traces");
1876 cds_lfht_for_each_entry(ust_app_ht
, &iter
, app
, node
) {
1877 ret
= ust_app_destroy_trace(usess
, app
);
1879 /* Continue to next apps even on error */
1890 * Add channels/events from UST global domain to registered apps at sock.
1892 void ust_app_global_update(struct ltt_ust_session
*usess
, int sock
)
1895 struct cds_lfht_iter iter
;
1896 struct ust_app
*app
;
1897 struct ust_app_session
*ua_sess
;
1898 struct ust_app_channel
*ua_chan
;
1899 struct ust_app_event
*ua_event
;
1901 if (usess
== NULL
) {
1902 ERR("No UST session on global update. Returning");
1906 DBG2("UST app global update for app sock %d for session uid %d", sock
,
1911 app
= find_app_by_sock(sock
);
1913 ERR("Failed to update app sock %d", sock
);
1917 ua_sess
= create_ust_app_session(usess
, app
);
1918 if (ua_sess
== NULL
) {
1923 * We can iterate safely here over all UST app session sicne the create ust
1924 * app session above made a shadow copy of the UST global domain from the
1927 cds_lfht_for_each_entry(ua_sess
->channels
, &iter
, ua_chan
, node
) {
1928 ret
= create_ust_channel(app
, ua_sess
, ua_chan
);
1930 /* FIXME: Should we quit here or continue... */
1934 /* For each events */
1935 cds_lfht_for_each_entry(ua_chan
->events
, &iter
, ua_event
, node
) {
1936 ret
= create_ust_event(app
, ua_sess
, ua_chan
, ua_event
);
1938 /* FIXME: Should we quit here or continue... */
1944 if (usess
->start_trace
) {
1945 ret
= ust_app_start_trace(usess
, app
);
1950 DBG2("UST trace started for app pid %d", app
->key
.pid
);