-int setup_live_tracing()
-{
- struct lttng_domain dom;
- struct lttng_channel chan;
- char *channel_name = "mmapchan";
- struct lttng_event ev;
- int ret = 0;
- char *command_sock_path = "/tmp/consumerd_sock";
- static pthread_t threads[2]; /* recv_fd, poll */
- struct lttng_event_context kctxpid, kctxcomm, kctxppid, kctxtid;
-
- struct lttng_handle *handle;
-
- BT_INIT_LIST_HEAD(&mmap_list.head);
-
- lttng_consumer_stream_array = g_ptr_array_new();
-
- if ((ret = setup_consumer(command_sock_path, threads, ctx)) < 0) {
- fprintf(stderr,"error setting up consumer\n");
- goto error;
- }
-
- available_snapshots = g_ptr_array_new();
-
- /* setup the session */
- dom.type = LTTNG_DOMAIN_KERNEL;
-
- ret = unlink("/tmp/livesession");
-
- lttng_destroy_session("test");
- if ((ret = lttng_create_session("test", "/tmp/livesession")) < 0) {
- fprintf(stderr,"error creating the session : %s\n",
- helper_lttcomm_get_readable_code(ret));
- goto error;
- }
-
- if ((handle = lttng_create_handle("test", &dom)) == NULL) {
- fprintf(stderr,"error creating handle\n");
- goto error_session;
- }
-
- /*
- * FIXME : need to let the
- * helper_lttng_consumer_thread_receive_fds create the
- * socket.
- * Cleaner solution ?
- */
- while (access(command_sock_path, F_OK)) {
- sleep(0.1);
- }
-
- if ((ret = lttng_register_consumer(handle, command_sock_path)) < 0) {
- fprintf(stderr,"error registering consumer : %s\n",
- helper_lttcomm_get_readable_code(ret));
- goto error_session;
- }
-
- strcpy(chan.name, channel_name);
- chan.attr.overwrite = 0;
- if (opt_tid && opt_textdump) {
- chan.attr.subbuf_size = 32768;
- chan.attr.num_subbuf = 8;
- } else {
- chan.attr.subbuf_size = 1048576; /* 1MB */
- chan.attr.num_subbuf = 4;
- }
- chan.attr.switch_timer_interval = 0;
- chan.attr.read_timer_interval = 200;
- chan.attr.output = LTTNG_EVENT_MMAP;
-
- if ((ret = lttng_enable_channel(handle, &chan)) < 0) {
- fprintf(stderr,"error creating channel : %s\n",
- helper_lttcomm_get_readable_code(ret));
- goto error_session;
- }
-
- memset(&ev, '\0', sizeof(struct lttng_event));
- //sprintf(ev.name, "sched_switch");
- ev.type = LTTNG_EVENT_TRACEPOINT;
- if ((ret = lttng_enable_event(handle, &ev, channel_name)) < 0) {
- fprintf(stderr,"error enabling event : %s\n",
- helper_lttcomm_get_readable_code(ret));
- goto error_session;
- }
-
- memset(&ev, '\0', sizeof(struct lttng_event));
- ev.type = LTTNG_EVENT_SYSCALL;
- if ((ret = lttng_enable_event(handle, &ev, channel_name)) < 0) {
- fprintf(stderr,"error enabling syscalls : %s\n",
- helper_lttcomm_get_readable_code(ret));
- goto error_session;
- }
-
- if (lttngtop.kprobes_table) {
- ret = enable_kprobes(handle, channel_name);
- if (ret < 0) {
- goto error_session;
- }
- }
-
- kctxpid.ctx = LTTNG_EVENT_CONTEXT_PID;
- lttng_add_context(handle, &kctxpid, NULL, NULL);
- kctxtid.ctx = LTTNG_EVENT_CONTEXT_TID;
- lttng_add_context(handle, &kctxtid, NULL, NULL);
- kctxppid.ctx = LTTNG_EVENT_CONTEXT_PPID;
- lttng_add_context(handle, &kctxppid, NULL, NULL);
- kctxcomm.ctx = LTTNG_EVENT_CONTEXT_PROCNAME;
- lttng_add_context(handle, &kctxcomm, NULL, NULL);
- kctxpid.ctx = LTTNG_EVENT_CONTEXT_VPID;
- lttng_add_context(handle, &kctxpid, NULL, NULL);
- kctxtid.ctx = LTTNG_EVENT_CONTEXT_VTID;
- lttng_add_context(handle, &kctxtid, NULL, NULL);
- kctxtid.ctx = LTTNG_EVENT_CONTEXT_HOSTNAME;
- lttng_add_context(handle, &kctxtid, NULL, NULL);
-
- if ((ret = lttng_start_tracing("test")) < 0) {
- fprintf(stderr,"error starting tracing : %s\n",
- helper_lttcomm_get_readable_code(ret));
- goto error_session;
- }
-
- helper_kernctl_buffer_flush(consumerd_metadata);
-
- /* block until metadata is ready */
- sem_init(&metadata_available, 0, 0);
-
- return 0;
-
-error_session:
- lttng_destroy_session("test");
-error:
- return -1;
-}
-
-int main(int argc, char **argv)