2 * Copyright (C) 2011-2012 Julien Desfossez
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 as
6 * 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.
22 #include <babeltrace/babeltrace.h>
23 #include <babeltrace/ctf/events.h>
24 #include <babeltrace/ctf/callbacks.h>
25 #include <babeltrace/ctf/iterator.h>
37 #include <sys/types.h>
41 #include <lttng/lttng.h>
42 #include <lttng/lttngtop-helper.h>
43 #include <babeltrace/lttngtopmmappacketseek.h>
45 #include "lttngtoptypes.h"
47 #include "iostreamtop.h"
48 #include "cursesdisplay.h"
51 #define DEFAULT_FILE_ARRAY_SIZE 1
53 const char *opt_input_path
;
58 struct lttngtop
*copy
;
59 pthread_t display_thread
;
60 pthread_t timer_thread
;
62 unsigned long refresh_display
= 1 * NSEC_PER_SEC
;
63 unsigned long last_display_update
= 0;
65 /* list of FDs available for being read with snapshots */
66 struct mmap_stream_list mmap_list
;
67 GPtrArray
*lttng_consumer_stream_array
;
68 int sessiond_metadata
, consumerd_metadata
;
69 struct lttng_consumer_local_data
*ctx
= NULL
;
70 /* list of snapshots currently not consumed */
71 GPtrArray
*available_snapshots
;
72 sem_t metadata_available
;
75 int metadata_ready
= 0;
83 static struct poptOption long_options
[] = {
84 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
85 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
86 { "textdump", 't', POPT_ARG_NONE
, NULL
, OPT_TEXTDUMP
, NULL
, NULL
},
87 { NULL
, 0, 0, NULL
, 0, NULL
, NULL
},
90 void *refresh_thread(void *p
)
92 struct mmap_stream
*mmap_info
;
98 sem_post(&goodtodisplay
);
101 bt_list_for_each_entry(mmap_info
, &mmap_list
.head
, list
)
102 helper_kernctl_buffer_flush(mmap_info
->fd
);
103 sem_wait(&pause_sem
);
104 sem_post(&pause_sem
);
106 sleep(refresh_display
/NSEC_PER_SEC
);
110 void *ncurses_display(void *p
)
112 unsigned int current_display_index
= 0;
114 sem_wait(&bootstrap
);
116 * Prevent the 1 second delay when we hit ESC
123 sem_wait(&goodtodisplay
);
124 sem_wait(&pause_sem
);
127 sem_post(&pause_sem
);
133 copy
= g_ptr_array_index(copies
, current_display_index
);
135 display(current_display_index
++);
137 sem_post(&goodtoupdate
);
138 sem_post(&pause_sem
);
143 * hook on each event to check the timestamp and refresh the display if
146 enum bt_cb_ret
print_timestamp(struct bt_ctf_event
*call_data
, void *private_data
)
148 unsigned long timestamp
;
150 uint64_t ts_nsec_start
;
152 timestamp
= bt_ctf_get_timestamp(call_data
);
154 start
= format_timestamp(timestamp
);
155 ts_nsec_start
= timestamp
% NSEC_PER_SEC
;
157 printf("%02d:%02d:%02d.%09" PRIu64
" %s\n", start
.tm_hour
,
158 start
.tm_min
, start
.tm_sec
, ts_nsec_start
,
159 bt_ctf_event_name(call_data
));
165 * hook on each event to check the timestamp and refresh the display if
168 enum bt_cb_ret
check_timestamp(struct bt_ctf_event
*call_data
, void *private_data
)
170 unsigned long timestamp
;
172 timestamp
= bt_ctf_get_timestamp(call_data
);
173 if (timestamp
== -1ULL)
176 if (last_display_update
== 0)
177 last_display_update
= timestamp
;
179 if (timestamp
- last_display_update
>= refresh_display
) {
180 sem_wait(&goodtoupdate
);
181 g_ptr_array_add(copies
, get_copy_lttngtop(last_display_update
,
183 sem_post(&goodtodisplay
);
184 sem_post(&bootstrap
);
185 last_display_update
= timestamp
;
190 fprintf(stderr
, "check_timestamp callback error\n");
191 return BT_CB_ERROR_STOP
;
195 * get_perf_counter : get or create and return a perf_counter struct for
196 * either a process or a cpu (only one of the 2 parameters mandatory)
198 struct perfcounter
*get_perf_counter(const char *name
, struct processtop
*proc
,
201 struct perfcounter
*ret
;
211 ret
= g_hash_table_lookup(table
, (gpointer
) name
);
215 ret
= g_new0(struct perfcounter
, 1);
216 /* by default, make it visible in the UI */
218 g_hash_table_insert(table
, (gpointer
) strdup(name
), ret
);
227 void update_perf_value(struct processtop
*proc
, struct cputime
*cpu
,
228 const char *name
, int value
)
230 struct perfcounter
*cpu_perf
, *process_perf
;
232 cpu_perf
= get_perf_counter(name
, NULL
, cpu
);
233 if (cpu_perf
->count
< value
) {
234 process_perf
= get_perf_counter(name
, proc
, NULL
);
235 process_perf
->count
+= value
- cpu_perf
->count
;
236 cpu_perf
->count
= value
;
240 void extract_perf_counter_scope(const struct bt_ctf_event
*event
,
241 const struct definition
*scope
,
242 struct processtop
*proc
,
245 struct definition
const * const *list
= NULL
;
246 const struct definition
*field
;
248 struct perfcounter
*perfcounter
;
256 ret
= bt_ctf_get_field_list(event
, scope
, &list
, &count
);
263 g_hash_table_iter_init(&iter
, global_perf_liszt
);
264 while (g_hash_table_iter_next (&iter
, &key
, (gpointer
) &perfcounter
)) {
265 field
= bt_ctf_get_field(event
, scope
, (char *) key
);
267 int value
= bt_ctf_get_uint64(field
);
268 if (bt_ctf_field_get_error())
270 update_perf_value(proc
, cpu
, (char *) key
, value
);
278 void update_perf_counter(struct processtop
*proc
, const struct bt_ctf_event
*event
)
281 const struct definition
*scope
;
283 cpu
= get_cpu(get_cpu_id(event
));
285 scope
= bt_ctf_get_top_level_scope(event
, BT_STREAM_EVENT_CONTEXT
);
286 extract_perf_counter_scope(event
, scope
, proc
, cpu
);
288 scope
= bt_ctf_get_top_level_scope(event
, BT_STREAM_PACKET_CONTEXT
);
289 extract_perf_counter_scope(event
, scope
, proc
, cpu
);
291 scope
= bt_ctf_get_top_level_scope(event
, BT_EVENT_CONTEXT
);
292 extract_perf_counter_scope(event
, scope
, proc
, cpu
);
295 enum bt_cb_ret
fix_process_table(struct bt_ctf_event
*call_data
,
300 struct processtop
*parent
, *child
;
301 unsigned long timestamp
;
303 timestamp
= bt_ctf_get_timestamp(call_data
);
304 if (timestamp
== -1ULL)
307 pid
= get_context_pid(call_data
);
311 tid
= get_context_tid(call_data
);
315 ppid
= get_context_ppid(call_data
);
319 comm
= get_context_comm(call_data
);
324 /* find or create the current process */
325 child
= find_process_tid(<tngtop
, tid
, comm
);
327 child
= add_proc(<tngtop
, tid
, comm
, timestamp
);
328 update_proc(child
, pid
, tid
, ppid
, comm
);
331 /* find or create the parent */
332 parent
= find_process_tid(<tngtop
, pid
, comm
);
334 parent
= add_proc(<tngtop
, pid
, comm
, timestamp
);
338 /* attach the parent to the current process */
339 child
->threadparent
= parent
;
340 add_thread(parent
, child
);
343 update_perf_counter(child
, call_data
);
348 return BT_CB_ERROR_STOP
;
353 copies
= g_ptr_array_new();
354 global_perf_liszt
= g_hash_table_new(g_str_hash
, g_str_equal
);
356 sem_init(&goodtodisplay
, 0, 0);
357 sem_init(&goodtoupdate
, 0, 1);
358 sem_init(&timer
, 0, 1);
359 sem_init(&bootstrap
, 0, 0);
360 sem_init(&pause_sem
, 0, 1);
361 sem_init(&end_trace_sem
, 0, 0);
363 reset_global_counters();
365 lttngtop
.nbthreads
= 0;
366 lttngtop
.nbfiles
= 0;
368 lttngtop
.process_hash_table
= g_hash_table_new(g_direct_hash
,
370 lttngtop
.process_table
= g_ptr_array_new();
371 lttngtop
.files_table
= g_ptr_array_new();
372 lttngtop
.cpu_table
= g_ptr_array_new();
377 fprintf(fp
, "LTTngTop %s\n\n", VERSION
);
378 fprintf(fp
, "Usage : lttngtop /path/to/trace\n");
382 * Return 0 if caller should continue, < 0 if caller should return
383 * error, > 0 if caller should exit without reporting error.
385 static int parse_options(int argc
, char **argv
)
390 pc
= poptGetContext(NULL
, argc
, (const char **) argv
, long_options
, 0);
391 poptReadDefaultConfig(pc
, 0);
393 while ((opt
= poptGetNextOpt(pc
)) != -1) {
397 ret
= 1; /* exit cleanly */
408 opt_input_path
= poptGetArg(pc
);
417 void iter_trace(struct bt_context
*bt_ctx
)
419 struct bt_ctf_iter
*iter
;
420 struct bt_iter_pos begin_pos
;
421 const struct bt_ctf_event
*event
;
424 begin_pos
.type
= BT_SEEK_BEGIN
;
425 iter
= bt_ctf_iter_create(bt_ctx
, &begin_pos
, NULL
);
428 bt_ctf_iter_add_callback(iter
, 0, NULL
, 0,
432 /* at each event check if we need to refresh */
433 bt_ctf_iter_add_callback(iter
, 0, NULL
, 0,
436 /* at each event, verify the status of the process table */
437 bt_ctf_iter_add_callback(iter
, 0, NULL
, 0,
440 /* to handle the scheduling events */
441 bt_ctf_iter_add_callback(iter
,
442 g_quark_from_static_string("sched_switch"),
443 NULL
, 0, handle_sched_switch
, NULL
, NULL
, NULL
);
444 /* to clean up the process table */
445 bt_ctf_iter_add_callback(iter
,
446 g_quark_from_static_string("sched_process_free"),
447 NULL
, 0, handle_sched_process_free
, NULL
, NULL
, NULL
);
448 /* to get all the process from the statedumps */
449 bt_ctf_iter_add_callback(iter
,
450 g_quark_from_static_string(
451 "lttng_statedump_process_state"),
452 NULL
, 0, handle_statedump_process_state
,
456 bt_ctf_iter_add_callback(iter
,
457 g_quark_from_static_string("exit_syscall"),
458 NULL
, 0, handle_exit_syscall
, NULL
, NULL
, NULL
);
459 bt_ctf_iter_add_callback(iter
,
460 g_quark_from_static_string("sys_write"),
461 NULL
, 0, handle_sys_write
, NULL
, NULL
, NULL
);
462 bt_ctf_iter_add_callback(iter
,
463 g_quark_from_static_string("sys_read"),
464 NULL
, 0, handle_sys_read
, NULL
, NULL
, NULL
);
465 bt_ctf_iter_add_callback(iter
,
466 g_quark_from_static_string("sys_open"),
467 NULL
, 0, handle_sys_open
, NULL
, NULL
, NULL
);
468 bt_ctf_iter_add_callback(iter
,
469 g_quark_from_static_string("sys_close"),
470 NULL
, 0, handle_sys_close
, NULL
, NULL
, NULL
);
471 bt_ctf_iter_add_callback(iter
,
472 g_quark_from_static_string(
473 "lttng_statedump_file_descriptor"),
474 NULL
, 0, handle_statedump_file_descriptor
,
478 while (((event
= bt_ctf_iter_read_event(iter
)) != NULL
)) {
481 ret
= bt_iter_next(bt_ctf_get_iter(iter
));
486 /* block until quit, we reached the end of the trace */
487 sem_wait(&end_trace_sem
);
490 bt_ctf_iter_destroy(iter
);
494 * bt_context_add_traces_recursive: Open a trace recursively
495 * (copied from BSD code in converter/babeltrace.c)
497 * Find each trace present in the subdirectory starting from the given
498 * path, and add them to the context. The packet_seek parameter can be
499 * NULL: this specify to use the default format packet_seek.
501 * Return: 0 on success, nonzero on failure.
502 * Unable to open toplevel: failure.
503 * Unable to open some subdirectory or file: warn and continue;
505 int bt_context_add_traces_recursive(struct bt_context
*ctx
, const char *path
,
506 const char *format_str
,
507 void (*packet_seek
)(struct stream_pos
*pos
,
508 size_t offset
, int whence
))
513 char lpath
[PATH_MAX
];
514 char * const paths
[2] = { lpath
, NULL
};
518 * Need to copy path, because fts_open can change it.
519 * It is the pointer array, not the strings, that are constant.
521 strncpy(lpath
, path
, PATH_MAX
);
522 lpath
[PATH_MAX
- 1] = '\0';
524 tree
= fts_open(paths
, FTS_NOCHDIR
| FTS_LOGICAL
, 0);
526 fprintf(stderr
, "[error] [Context] Cannot traverse \"%s\" for reading.\n",
531 trace_ids
= g_array_new(FALSE
, TRUE
, sizeof(int));
533 while ((node
= fts_read(tree
))) {
536 if (!(node
->fts_info
& FTS_D
))
539 dirfd
= open(node
->fts_accpath
, 0);
541 fprintf(stderr
, "[error] [Context] Unable to open trace "
542 "directory file descriptor.\n");
546 metafd
= openat(dirfd
, "metadata", O_RDONLY
);
565 trace_id
= bt_context_add_trace(ctx
,
566 node
->fts_accpath
, format_str
,
567 packet_seek
, NULL
, NULL
);
569 fprintf(stderr
, "[warning] [Context] opening trace \"%s\" from %s "
570 "for reading.\n", node
->fts_accpath
, path
);
571 /* Allow to skip erroneous traces. */
574 g_array_append_val(trace_ids
, trace_id
);
578 g_array_free(trace_ids
, TRUE
);
585 static int check_field_requirements(const struct bt_ctf_field_decl
*const * field_list
,
586 int field_cnt
, int *tid_check
, int *pid_check
,
587 int *procname_check
, int *ppid_check
)
590 struct perfcounter
*global
;
593 for (j
= 0; j
< field_cnt
; j
++) {
594 name
= bt_ctf_get_decl_field_name(field_list
[j
]);
595 if (*tid_check
== 0) {
596 if (strncmp(name
, "tid", 3) == 0)
599 if (*pid_check
== 0) {
600 if (strncmp(name
, "tid", 3) == 0)
603 if (*ppid_check
== 0) {
604 if (strncmp(name
, "ppid", 4) == 0)
607 if (*procname_check
== 0) {
608 if (strncmp(name
, "procname", 8) == 0)
611 if (strncmp(name
, "perf_", 5) == 0) {
612 global
= g_hash_table_lookup(global_perf_liszt
, (gpointer
) name
);
614 global
= g_new0(struct perfcounter
, 1);
615 /* by default, sort on the first perf context */
616 if (g_hash_table_size(global_perf_liszt
) == 0)
619 g_hash_table_insert(global_perf_liszt
, (gpointer
) strdup(name
), global
);
624 if (*tid_check
== 1 && *pid_check
== 1 && *ppid_check
== 1 &&
625 *procname_check
== 1)
632 * check_requirements: check if the required context informations are available
634 * If each mandatory context information is available for at least in one
635 * event, return 0 otherwise return -1.
637 int check_requirements(struct bt_context
*ctx
)
639 unsigned int i
, evt_cnt
, field_cnt
;
640 struct bt_ctf_event_decl
*const * evt_list
;
641 const struct bt_ctf_field_decl
*const * field_list
;
644 int procname_check
= 0;
648 bt_ctf_get_event_decl_list(0, ctx
, &evt_list
, &evt_cnt
);
649 for (i
= 0; i
< evt_cnt
; i
++) {
650 bt_ctf_get_decl_fields(evt_list
[i
], BT_STREAM_EVENT_CONTEXT
,
651 &field_list
, &field_cnt
);
652 ret
= check_field_requirements(field_list
, field_cnt
,
653 &tid_check
, &pid_check
, &procname_check
,
656 bt_ctf_get_decl_fields(evt_list
[i
], BT_EVENT_CONTEXT
,
657 &field_list
, &field_cnt
);
658 ret
= check_field_requirements(field_list
, field_cnt
,
659 &tid_check
, &pid_check
, &procname_check
,
662 bt_ctf_get_decl_fields(evt_list
[i
], BT_STREAM_PACKET_CONTEXT
,
663 &field_list
, &field_cnt
);
664 ret
= check_field_requirements(field_list
, field_cnt
,
665 &tid_check
, &pid_check
, &procname_check
,
669 if (tid_check
== 0) {
671 fprintf(stderr
, "[error] missing tid context information\n");
673 if (pid_check
== 0) {
675 fprintf(stderr
, "[error] missing pid context information\n");
677 if (ppid_check
== 0) {
679 fprintf(stderr
, "[error] missing ppid context information\n");
681 if (procname_check
== 0) {
683 fprintf(stderr
, "[error] missing procname context information\n");
689 ssize_t
read_subbuffer(struct lttng_consumer_stream
*kconsumerd_fd
,
690 struct lttng_consumer_local_data
*ctx
)
695 int infd
= helper_get_lttng_consumer_stream_wait_fd(kconsumerd_fd
);
697 if (helper_get_lttng_consumer_stream_output(kconsumerd_fd
) == LTTNG_EVENT_SPLICE
) {
698 /* Get the next subbuffer */
699 err
= helper_kernctl_get_next_subbuf(infd
);
702 perror("Reserving sub buffer failed (everything is normal, "
703 "it is due to concurrency)");
706 /* read the whole subbuffer */
707 err
= helper_kernctl_get_padded_subbuf_size(infd
, &len
);
710 perror("Getting sub-buffer len failed.");
714 /* splice the subbuffer to the tracefile */
715 ret
= helper_lttng_consumer_on_read_subbuffer_splice(ctx
, kconsumerd_fd
, len
);
718 * display the error but continue processing to try
719 * to release the subbuffer
721 fprintf(stderr
,"Error splicing to tracefile\n");
723 err
= helper_kernctl_put_next_subbuf(infd
);
726 perror("Reserving sub buffer failed (everything is normal, "
727 "it is due to concurrency)");
730 sem_post(&metadata_available
);
737 int on_update_fd(int key
, uint32_t state
)
739 /* let the lib handle the metadata FD */
740 if (key
== sessiond_metadata
)
745 int on_recv_fd(struct lttng_consumer_stream
*kconsumerd_fd
)
748 struct mmap_stream
*new_mmap_stream
;
750 /* Opening the tracefile in write mode */
751 if (helper_get_lttng_consumer_stream_path_name(kconsumerd_fd
) != NULL
) {
752 ret
= open(helper_get_lttng_consumer_stream_path_name(kconsumerd_fd
),
753 O_WRONLY
|O_CREAT
|O_TRUNC
, S_IRWXU
|S_IRWXG
|S_IRWXO
);
758 helper_set_lttng_consumer_stream_out_fd(kconsumerd_fd
, ret
);
761 if (helper_get_lttng_consumer_stream_output(kconsumerd_fd
) == LTTNG_EVENT_MMAP
) {
762 new_mmap_stream
= malloc(sizeof(struct mmap_stream
));
763 new_mmap_stream
->fd
= helper_get_lttng_consumer_stream_wait_fd(
765 bt_list_add(&new_mmap_stream
->list
, &mmap_list
.head
);
767 g_ptr_array_add(lttng_consumer_stream_array
, kconsumerd_fd
);
768 /* keep mmap FDs internally */
771 consumerd_metadata
= helper_get_lttng_consumer_stream_wait_fd(kconsumerd_fd
);
772 sessiond_metadata
= helper_get_lttng_consumer_stream_key(kconsumerd_fd
);
780 void live_consume(struct bt_context
**bt_ctx
)
784 if (!metadata_ready
) {
785 sem_wait(&metadata_available
);
786 if (access("/tmp/livesession/kernel/metadata", F_OK
) != 0) {
787 fprintf(stderr
,"no metadata\n");
791 metadata_fp
= fopen("/tmp/livesession/kernel/metadata", "r");
795 *bt_ctx
= bt_context_create();
796 ret
= bt_context_add_trace(*bt_ctx
, NULL
, "ctf",
797 lttngtop_ctf_packet_seek
, &mmap_list
, metadata_fp
);
799 printf("Error adding trace\n");
809 int setup_consumer(char *command_sock_path
, pthread_t
*threads
,
810 struct lttng_consumer_local_data
*ctx
)
814 ctx
= helper_lttng_consumer_create(HELPER_LTTNG_CONSUMER_KERNEL
,
815 read_subbuffer
, NULL
, on_recv_fd
, on_update_fd
);
819 unlink(command_sock_path
);
820 helper_lttng_consumer_set_command_sock_path(ctx
, command_sock_path
);
821 helper_lttng_consumer_init();
823 /* Create the thread to manage the receive of fd */
824 ret
= pthread_create(&threads
[0], NULL
, helper_lttng_consumer_thread_receive_fds
,
827 perror("pthread_create receive fd");
830 /* Create thread to manage the polling/writing of traces */
831 ret
= pthread_create(&threads
[1], NULL
, helper_lttng_consumer_thread_poll_fds
,
834 perror("pthread_create poll fd");
842 void *setup_live_tracing()
844 struct lttng_domain dom
;
845 struct lttng_channel chan
;
846 char *channel_name
= "mmapchan";
847 struct lttng_event ev
;
849 char *command_sock_path
= "/tmp/consumerd_sock";
850 static pthread_t threads
[2]; /* recv_fd, poll */
851 struct lttng_event_context kctxpid
, kctxcomm
, kctxppid
, kctxtid
;
853 struct lttng_handle
*handle
;
855 BT_INIT_LIST_HEAD(&mmap_list
.head
);
857 lttng_consumer_stream_array
= g_ptr_array_new();
859 if ((ret
= setup_consumer(command_sock_path
, threads
, ctx
)) < 0) {
860 fprintf(stderr
,"error setting up consumer\n");
864 available_snapshots
= g_ptr_array_new();
866 /* setup the session */
867 dom
.type
= LTTNG_DOMAIN_KERNEL
;
869 ret
= unlink("/tmp/livesession");
871 lttng_destroy_session("test");
872 if ((ret
= lttng_create_session("test", "/tmp/livesession")) < 0) {
873 fprintf(stderr
,"error creating the session : %s\n",
874 helper_lttcomm_get_readable_code(ret
));
878 if ((handle
= lttng_create_handle("test", &dom
)) == NULL
) {
879 fprintf(stderr
,"error creating handle\n");
883 if ((ret
= lttng_register_consumer(handle
, command_sock_path
)) < 0) {
884 fprintf(stderr
,"error registering consumer : %s\n",
885 helper_lttcomm_get_readable_code(ret
));
889 strcpy(chan
.name
, channel_name
);
890 chan
.attr
.overwrite
= 0;
891 // chan.attr.subbuf_size = 32768;
892 chan
.attr
.subbuf_size
= 1048576; /* 1MB */
893 chan
.attr
.num_subbuf
= 4;
894 chan
.attr
.switch_timer_interval
= 0;
895 chan
.attr
.read_timer_interval
= 200;
896 chan
.attr
.output
= LTTNG_EVENT_MMAP
;
898 if ((ret
= lttng_enable_channel(handle
, &chan
)) < 0) {
899 fprintf(stderr
,"error creating channel : %s\n",
900 helper_lttcomm_get_readable_code(ret
));
904 memset(&ev
, '\0', sizeof(struct lttng_event
));
905 //sprintf(ev.name, "sched_switch");
906 ev
.type
= LTTNG_EVENT_TRACEPOINT
;
907 if ((ret
= lttng_enable_event(handle
, &ev
, channel_name
)) < 0) {
908 fprintf(stderr
,"error enabling event : %s\n",
909 helper_lttcomm_get_readable_code(ret
));
913 ev
.type
= LTTNG_EVENT_SYSCALL
;
914 if ((ret
= lttng_enable_event(handle
, &ev
, channel_name
)) < 0) {
915 fprintf(stderr
,"error enabling syscalls : %s\n",
916 helper_lttcomm_get_readable_code(ret
));
920 kctxpid
.ctx
= LTTNG_EVENT_CONTEXT_PID
;
921 lttng_add_context(handle
, &kctxpid
, NULL
, NULL
);
922 kctxppid
.ctx
= LTTNG_EVENT_CONTEXT_PPID
;
923 lttng_add_context(handle
, &kctxppid
, NULL
, NULL
);
924 kctxcomm
.ctx
= LTTNG_EVENT_CONTEXT_PROCNAME
;
925 lttng_add_context(handle
, &kctxcomm
, NULL
, NULL
);
926 kctxtid
.ctx
= LTTNG_EVENT_CONTEXT_TID
;
927 lttng_add_context(handle
, &kctxtid
, NULL
, NULL
);
929 if ((ret
= lttng_start_tracing("test")) < 0) {
930 fprintf(stderr
,"error starting tracing : %s\n",
931 helper_lttcomm_get_readable_code(ret
));
935 helper_kernctl_buffer_flush(consumerd_metadata
);
937 /* block until metadata is ready */
938 sem_init(&metadata_available
, 0, 0);
944 int main(int argc
, char **argv
)
947 struct bt_context
*bt_ctx
= NULL
;
949 ret
= parse_options(argc
, argv
);
951 fprintf(stdout
, "Error parsing options.\n\n");
954 } else if (ret
> 0) {
958 if (!opt_input_path
) {
959 setup_live_tracing();
962 pthread_create(&display_thread
, NULL
, ncurses_display
, (void *) NULL
);
963 pthread_create(&timer_thread
, NULL
, refresh_thread
, (void *) NULL
);
965 live_consume(&bt_ctx
);
968 pthread_join(timer_thread
, NULL
);
970 pthread_join(display_thread
, NULL
);
972 lttng_stop_tracing("test");
973 lttng_destroy_session("test");
979 bt_ctx
= bt_context_create();
980 ret
= bt_context_add_traces_recursive(bt_ctx
, opt_input_path
, "ctf", NULL
);
982 fprintf(stderr
, "[error] Opening the trace\n");
986 ret
= check_requirements(bt_ctx
);
988 fprintf(stderr
, "[error] some mandatory contexts were missing, exiting.\n");
991 pthread_create(&display_thread
, NULL
, ncurses_display
, (void *) NULL
);
992 pthread_create(&timer_thread
, NULL
, refresh_thread
, (void *) NULL
);
996 pthread_join(display_thread
, NULL
);
998 pthread_join(timer_thread
, NULL
);
1003 bt_context_put(bt_ctx
);