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
;
54 static int opt_textdump
;
59 struct lttngtop
*copy
;
60 pthread_t display_thread
;
61 pthread_t timer_thread
;
63 unsigned long refresh_display
= 1 * NSEC_PER_SEC
;
64 unsigned long last_display_update
= 0;
66 /* list of FDs available for being read with snapshots */
67 struct mmap_stream_list mmap_list
;
68 GPtrArray
*lttng_consumer_stream_array
;
69 int sessiond_metadata
, consumerd_metadata
;
70 struct lttng_consumer_local_data
*ctx
= NULL
;
71 /* list of snapshots currently not consumed */
72 GPtrArray
*available_snapshots
;
73 sem_t metadata_available
;
84 static struct poptOption long_options
[] = {
85 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
86 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
87 { "textdump", 't', POPT_ARG_NONE
, NULL
, OPT_TEXTDUMP
, NULL
, NULL
},
88 { "child", 'f', POPT_ARG_NONE
, NULL
, OPT_CHILD
, NULL
, NULL
},
89 { "pid", 'p', POPT_ARG_INT
, &opt_pid
, OPT_PID
, NULL
, NULL
},
90 { NULL
, 0, 0, NULL
, 0, NULL
, NULL
},
93 static void handle_textdump_sigterm(int signal
)
96 lttng_destroy_session("test");
99 void *refresh_thread(void *p
)
101 struct mmap_stream
*mmap_info
;
105 sem_post(&pause_sem
);
107 sem_post(&end_trace_sem
);
108 sem_post(&goodtodisplay
);
109 sem_post(&goodtoupdate
);
112 if (!opt_input_path
) {
113 bt_list_for_each_entry(mmap_info
, &mmap_list
.head
, list
)
114 helper_kernctl_buffer_flush(mmap_info
->fd
);
116 sem_wait(&pause_sem
);
117 sem_post(&pause_sem
);
119 sleep(refresh_display
/NSEC_PER_SEC
);
123 void *ncurses_display(void *p
)
125 unsigned int current_display_index
= 0;
127 sem_wait(&bootstrap
);
129 * Prevent the 1 second delay when we hit ESC
136 sem_wait(&goodtodisplay
);
137 sem_wait(&pause_sem
);
140 sem_post(&pause_sem
);
146 copy
= g_ptr_array_index(copies
, current_display_index
);
148 display(current_display_index
++);
150 sem_post(&goodtoupdate
);
151 sem_post(&pause_sem
);
156 * hook on each event to check the timestamp and refresh the display if
159 enum bt_cb_ret
print_timestamp(struct bt_ctf_event
*call_data
, void *private_data
)
161 unsigned long timestamp
;
163 uint64_t ts_nsec_start
;
166 const struct definition
*scope
;
168 timestamp
= bt_ctf_get_timestamp(call_data
);
170 start
= format_timestamp(timestamp
);
171 ts_nsec_start
= timestamp
% NSEC_PER_SEC
;
173 pid
= get_context_pid(call_data
);
174 if (pid
== -1ULL && opt_pid
) {
178 if (opt_pid
&& opt_pid
!= pid
)
181 if (strcmp(bt_ctf_event_name(call_data
), "exit_syscall") == 0) {
182 scope
= bt_ctf_get_top_level_scope(call_data
,
184 syscall_ret
= bt_ctf_get_int64(bt_ctf_get_field(call_data
,
186 printf("= %ld\n", syscall_ret
);
188 printf("%02d:%02d:%02d.%09" PRIu64
" %d : %s ", start
.tm_hour
,
189 start
.tm_min
, start
.tm_sec
, ts_nsec_start
,
190 pid
, bt_ctf_event_name(call_data
));
196 return BT_CB_ERROR_STOP
;
200 * hook on each event to check the timestamp and refresh the display if
203 enum bt_cb_ret
check_timestamp(struct bt_ctf_event
*call_data
, void *private_data
)
205 unsigned long timestamp
;
207 timestamp
= bt_ctf_get_timestamp(call_data
);
208 if (timestamp
== -1ULL)
211 if (last_display_update
== 0)
212 last_display_update
= timestamp
;
214 if (timestamp
- last_display_update
>= refresh_display
) {
215 sem_wait(&goodtoupdate
);
216 g_ptr_array_add(copies
, get_copy_lttngtop(last_display_update
,
218 sem_post(&goodtodisplay
);
219 sem_post(&bootstrap
);
220 last_display_update
= timestamp
;
225 fprintf(stderr
, "check_timestamp callback error\n");
226 return BT_CB_ERROR_STOP
;
230 * get_perf_counter : get or create and return a perf_counter struct for
231 * either a process or a cpu (only one of the 2 parameters mandatory)
233 struct perfcounter
*get_perf_counter(const char *name
, struct processtop
*proc
,
236 struct perfcounter
*ret
;
246 ret
= g_hash_table_lookup(table
, (gpointer
) name
);
250 ret
= g_new0(struct perfcounter
, 1);
251 /* by default, make it visible in the UI */
253 g_hash_table_insert(table
, (gpointer
) strdup(name
), ret
);
262 void update_perf_value(struct processtop
*proc
, struct cputime
*cpu
,
263 const char *name
, int value
)
265 struct perfcounter
*cpu_perf
, *process_perf
;
267 cpu_perf
= get_perf_counter(name
, NULL
, cpu
);
268 if (cpu_perf
->count
< value
) {
269 process_perf
= get_perf_counter(name
, proc
, NULL
);
270 process_perf
->count
+= value
- cpu_perf
->count
;
271 cpu_perf
->count
= value
;
275 void extract_perf_counter_scope(const struct bt_ctf_event
*event
,
276 const struct bt_definition
*scope
,
277 struct processtop
*proc
,
280 struct bt_definition
const * const *list
= NULL
;
281 const struct bt_definition
*field
;
283 struct perfcounter
*perfcounter
;
291 ret
= bt_ctf_get_field_list(event
, scope
, &list
, &count
);
298 g_hash_table_iter_init(&iter
, global_perf_liszt
);
299 while (g_hash_table_iter_next (&iter
, &key
, (gpointer
) &perfcounter
)) {
300 field
= bt_ctf_get_field(event
, scope
, (char *) key
);
302 int value
= bt_ctf_get_uint64(field
);
303 if (bt_ctf_field_get_error())
305 update_perf_value(proc
, cpu
, (char *) key
, value
);
313 void update_perf_counter(struct processtop
*proc
, const struct bt_ctf_event
*event
)
316 const struct bt_definition
*scope
;
318 cpu
= get_cpu(get_cpu_id(event
));
320 scope
= bt_ctf_get_top_level_scope(event
, BT_STREAM_EVENT_CONTEXT
);
321 extract_perf_counter_scope(event
, scope
, proc
, cpu
);
323 scope
= bt_ctf_get_top_level_scope(event
, BT_STREAM_PACKET_CONTEXT
);
324 extract_perf_counter_scope(event
, scope
, proc
, cpu
);
326 scope
= bt_ctf_get_top_level_scope(event
, BT_EVENT_CONTEXT
);
327 extract_perf_counter_scope(event
, scope
, proc
, cpu
);
330 enum bt_cb_ret
fix_process_table(struct bt_ctf_event
*call_data
,
333 int pid
, tid
, ppid
, vpid
, vtid
, vppid
;
335 struct processtop
*parent
, *child
;
336 unsigned long timestamp
;
338 timestamp
= bt_ctf_get_timestamp(call_data
);
339 if (timestamp
== -1ULL)
342 pid
= get_context_pid(call_data
);
347 tid
= get_context_tid(call_data
);
351 ppid
= get_context_ppid(call_data
);
355 vpid
= get_context_vpid(call_data
);
359 vtid
= get_context_vtid(call_data
);
363 vppid
= get_context_vppid(call_data
);
367 comm
= get_context_comm(call_data
);
372 /* find or create the current process */
373 child
= find_process_tid(<tngtop
, tid
, comm
);
375 child
= add_proc(<tngtop
, tid
, comm
, timestamp
);
378 update_proc(child
, pid
, tid
, ppid
, vpid
, vtid
, vppid
, comm
);
381 /* find or create the parent */
382 parent
= find_process_tid(<tngtop
, pid
, comm
);
384 parent
= add_proc(<tngtop
, pid
, comm
, timestamp
);
389 /* attach the parent to the current process */
390 child
->threadparent
= parent
;
391 add_thread(parent
, child
);
394 update_perf_counter(child
, call_data
);
400 return BT_CB_ERROR_STOP
;
405 copies
= g_ptr_array_new();
406 global_perf_liszt
= g_hash_table_new(g_str_hash
, g_str_equal
);
408 sem_init(&goodtodisplay
, 0, 0);
409 sem_init(&goodtoupdate
, 0, 1);
410 sem_init(&timer
, 0, 1);
411 sem_init(&bootstrap
, 0, 0);
412 sem_init(&pause_sem
, 0, 1);
413 sem_init(&end_trace_sem
, 0, 0);
415 reset_global_counters();
417 lttngtop
.nbthreads
= 0;
418 lttngtop
.nbfiles
= 0;
420 lttngtop
.process_hash_table
= g_hash_table_new(g_direct_hash
,
422 lttngtop
.process_table
= g_ptr_array_new();
423 lttngtop
.files_table
= g_ptr_array_new();
424 lttngtop
.cpu_table
= g_ptr_array_new();
429 fprintf(fp
, "LTTngTop %s\n\n", VERSION
);
430 fprintf(fp
, "Usage : lttngtop /path/to/trace\n");
434 * Return 0 if caller should continue, < 0 if caller should return
435 * error, > 0 if caller should exit without reporting error.
437 static int parse_options(int argc
, char **argv
)
442 pc
= poptGetContext(NULL
, argc
, (const char **) argv
, long_options
, 0);
443 poptReadDefaultConfig(pc
, 0);
445 while ((opt
= poptGetNextOpt(pc
)) != -1) {
449 ret
= 1; /* exit cleanly */
467 opt_input_path
= poptGetArg(pc
);
476 void iter_trace(struct bt_context
*bt_ctx
)
478 struct bt_ctf_iter
*iter
;
479 struct bt_iter_pos begin_pos
;
480 const struct bt_ctf_event
*event
;
483 begin_pos
.type
= BT_SEEK_BEGIN
;
484 iter
= bt_ctf_iter_create(bt_ctx
, &begin_pos
, NULL
);
487 bt_ctf_iter_add_callback(iter
, 0, NULL
, 0,
491 /* at each event check if we need to refresh */
492 bt_ctf_iter_add_callback(iter
, 0, NULL
, 0,
495 /* at each event, verify the status of the process table */
496 bt_ctf_iter_add_callback(iter
, 0, NULL
, 0,
499 /* to handle the scheduling events */
500 bt_ctf_iter_add_callback(iter
,
501 g_quark_from_static_string("sched_switch"),
502 NULL
, 0, handle_sched_switch
, NULL
, NULL
, NULL
);
503 /* to clean up the process table */
504 bt_ctf_iter_add_callback(iter
,
505 g_quark_from_static_string("sched_process_free"),
506 NULL
, 0, handle_sched_process_free
, NULL
, NULL
, NULL
);
507 /* to get all the process from the statedumps */
508 bt_ctf_iter_add_callback(iter
,
509 g_quark_from_static_string(
510 "lttng_statedump_process_state"),
511 NULL
, 0, handle_statedump_process_state
,
515 bt_ctf_iter_add_callback(iter
,
516 g_quark_from_static_string("exit_syscall"),
517 NULL
, 0, handle_exit_syscall
, NULL
, NULL
, NULL
);
518 bt_ctf_iter_add_callback(iter
,
519 g_quark_from_static_string("sys_write"),
520 NULL
, 0, handle_sys_write
, NULL
, NULL
, NULL
);
521 bt_ctf_iter_add_callback(iter
,
522 g_quark_from_static_string("sys_read"),
523 NULL
, 0, handle_sys_read
, NULL
, NULL
, NULL
);
524 bt_ctf_iter_add_callback(iter
,
525 g_quark_from_static_string("sys_open"),
526 NULL
, 0, handle_sys_open
, NULL
, NULL
, NULL
);
527 bt_ctf_iter_add_callback(iter
,
528 g_quark_from_static_string("sys_close"),
529 NULL
, 0, handle_sys_close
, NULL
, NULL
, NULL
);
530 bt_ctf_iter_add_callback(iter
,
531 g_quark_from_static_string(
532 "lttng_statedump_file_descriptor"),
533 NULL
, 0, handle_statedump_file_descriptor
,
537 while ((event
= bt_ctf_iter_read_event(iter
, NULL
)) != NULL
) {
538 if (quit
|| reload_trace
)
540 ret
= bt_iter_next(bt_ctf_get_iter(iter
));
545 /* block until quit, we reached the end of the trace */
546 sem_wait(&end_trace_sem
);
549 bt_ctf_iter_destroy(iter
);
553 * bt_context_add_traces_recursive: Open a trace recursively
554 * (copied from BSD code in converter/babeltrace.c)
556 * Find each trace present in the subdirectory starting from the given
557 * path, and add them to the context. The packet_seek parameter can be
558 * NULL: this specify to use the default format packet_seek.
560 * Return: 0 on success, nonzero on failure.
561 * Unable to open toplevel: failure.
562 * Unable to open some subdirectory or file: warn and continue;
564 int bt_context_add_traces_recursive(struct bt_context
*ctx
, const char *path
,
565 const char *format_str
,
566 void (*packet_seek
)(struct bt_stream_pos
*pos
,
567 size_t offset
, int whence
))
572 char lpath
[PATH_MAX
];
573 char * const paths
[2] = { lpath
, NULL
};
577 * Need to copy path, because fts_open can change it.
578 * It is the pointer array, not the strings, that are constant.
580 strncpy(lpath
, path
, PATH_MAX
);
581 lpath
[PATH_MAX
- 1] = '\0';
583 tree
= fts_open(paths
, FTS_NOCHDIR
| FTS_LOGICAL
, 0);
585 fprintf(stderr
, "[error] [Context] Cannot traverse \"%s\" for reading.\n",
590 trace_ids
= g_array_new(FALSE
, TRUE
, sizeof(int));
592 while ((node
= fts_read(tree
))) {
595 if (!(node
->fts_info
& FTS_D
))
598 dirfd
= open(node
->fts_accpath
, 0);
600 fprintf(stderr
, "[error] [Context] Unable to open trace "
601 "directory file descriptor.\n");
605 metafd
= openat(dirfd
, "metadata", O_RDONLY
);
624 trace_id
= bt_context_add_trace(ctx
,
625 node
->fts_accpath
, format_str
,
626 packet_seek
, NULL
, NULL
);
628 fprintf(stderr
, "[warning] [Context] opening trace \"%s\" from %s "
629 "for reading.\n", node
->fts_accpath
, path
);
630 /* Allow to skip erroneous traces. */
633 g_array_append_val(trace_ids
, trace_id
);
637 g_array_free(trace_ids
, TRUE
);
644 static int check_field_requirements(const struct bt_ctf_field_decl
*const * field_list
,
645 int field_cnt
, int *tid_check
, int *pid_check
,
646 int *procname_check
, int *ppid_check
)
649 struct perfcounter
*global
;
652 for (j
= 0; j
< field_cnt
; j
++) {
653 name
= bt_ctf_get_decl_field_name(field_list
[j
]);
654 if (*tid_check
== 0) {
655 if (strncmp(name
, "tid", 3) == 0)
658 if (*pid_check
== 0) {
659 if (strncmp(name
, "pid", 3) == 0)
662 if (*ppid_check
== 0) {
663 if (strncmp(name
, "ppid", 4) == 0)
666 if (*procname_check
== 0) {
667 if (strncmp(name
, "procname", 8) == 0)
670 if (strncmp(name
, "perf_", 5) == 0) {
671 global
= g_hash_table_lookup(global_perf_liszt
, (gpointer
) name
);
673 global
= g_new0(struct perfcounter
, 1);
674 /* by default, sort on the first perf context */
675 if (g_hash_table_size(global_perf_liszt
) == 0)
678 g_hash_table_insert(global_perf_liszt
, (gpointer
) strdup(name
), global
);
683 if (*tid_check
== 1 && *pid_check
== 1 && *ppid_check
== 1 &&
684 *procname_check
== 1)
691 * check_requirements: check if the required context informations are available
693 * If each mandatory context information is available for at least in one
694 * event, return 0 otherwise return -1.
696 int check_requirements(struct bt_context
*ctx
)
698 unsigned int i
, evt_cnt
, field_cnt
;
699 struct bt_ctf_event_decl
*const * evt_list
;
700 const struct bt_ctf_field_decl
*const * field_list
;
703 int procname_check
= 0;
707 bt_ctf_get_event_decl_list(0, ctx
, &evt_list
, &evt_cnt
);
708 for (i
= 0; i
< evt_cnt
; i
++) {
709 bt_ctf_get_decl_fields(evt_list
[i
], BT_STREAM_EVENT_CONTEXT
,
710 &field_list
, &field_cnt
);
711 ret
= check_field_requirements(field_list
, field_cnt
,
712 &tid_check
, &pid_check
, &procname_check
,
715 bt_ctf_get_decl_fields(evt_list
[i
], BT_EVENT_CONTEXT
,
716 &field_list
, &field_cnt
);
717 ret
= check_field_requirements(field_list
, field_cnt
,
718 &tid_check
, &pid_check
, &procname_check
,
721 bt_ctf_get_decl_fields(evt_list
[i
], BT_STREAM_PACKET_CONTEXT
,
722 &field_list
, &field_cnt
);
723 ret
= check_field_requirements(field_list
, field_cnt
,
724 &tid_check
, &pid_check
, &procname_check
,
728 if (tid_check
== 0) {
730 fprintf(stderr
, "[error] missing tid context information\n");
732 if (pid_check
== 0) {
734 fprintf(stderr
, "[error] missing pid context information\n");
736 if (ppid_check
== 0) {
738 fprintf(stderr
, "[error] missing ppid context information\n");
740 if (procname_check
== 0) {
742 fprintf(stderr
, "[error] missing procname context information\n");
748 ssize_t
read_subbuffer(struct lttng_consumer_stream
*kconsumerd_fd
,
749 struct lttng_consumer_local_data
*ctx
)
754 int infd
= helper_get_lttng_consumer_stream_wait_fd(kconsumerd_fd
);
756 if (helper_get_lttng_consumer_stream_output(kconsumerd_fd
) == LTTNG_EVENT_SPLICE
) {
757 /* Get the next subbuffer */
758 err
= helper_kernctl_get_next_subbuf(infd
);
761 perror("Reserving sub buffer failed (everything is normal, "
762 "it is due to concurrency)");
765 /* read the whole subbuffer */
766 err
= helper_kernctl_get_padded_subbuf_size(infd
, &len
);
769 perror("Getting sub-buffer len failed.");
773 /* splice the subbuffer to the tracefile */
774 ret
= helper_lttng_consumer_on_read_subbuffer_splice(ctx
, kconsumerd_fd
, len
);
777 * display the error but continue processing to try
778 * to release the subbuffer
780 fprintf(stderr
,"Error splicing to tracefile\n");
782 err
= helper_kernctl_put_next_subbuf(infd
);
785 perror("Reserving sub buffer failed (everything is normal, "
786 "it is due to concurrency)");
789 sem_post(&metadata_available
);
796 int on_update_fd(int key
, uint32_t state
)
798 /* let the lib handle the metadata FD */
799 if (key
== sessiond_metadata
)
804 int on_recv_fd(struct lttng_consumer_stream
*kconsumerd_fd
)
807 struct mmap_stream
*new_mmap_stream
;
809 /* Opening the tracefile in write mode */
810 if (helper_get_lttng_consumer_stream_path_name(kconsumerd_fd
) != NULL
) {
811 ret
= open(helper_get_lttng_consumer_stream_path_name(kconsumerd_fd
),
812 O_WRONLY
|O_CREAT
|O_TRUNC
, S_IRWXU
|S_IRWXG
|S_IRWXO
);
817 helper_set_lttng_consumer_stream_out_fd(kconsumerd_fd
, ret
);
820 if (helper_get_lttng_consumer_stream_output(kconsumerd_fd
) == LTTNG_EVENT_MMAP
) {
821 new_mmap_stream
= malloc(sizeof(struct mmap_stream
));
822 new_mmap_stream
->fd
= helper_get_lttng_consumer_stream_wait_fd(
824 bt_list_add(&new_mmap_stream
->list
, &mmap_list
.head
);
826 g_ptr_array_add(lttng_consumer_stream_array
, kconsumerd_fd
);
827 /* keep mmap FDs internally */
830 consumerd_metadata
= helper_get_lttng_consumer_stream_wait_fd(kconsumerd_fd
);
831 sessiond_metadata
= helper_get_lttng_consumer_stream_key(kconsumerd_fd
);
841 void live_consume(struct bt_context
**bt_ctx
)
846 sem_wait(&metadata_available
);
847 if (access("/tmp/livesession/kernel/metadata", F_OK
) != 0) {
848 fprintf(stderr
,"no metadata\n");
851 metadata_fp
= fopen("/tmp/livesession/kernel/metadata", "r");
853 *bt_ctx
= bt_context_create();
854 ret
= bt_context_add_trace(*bt_ctx
, NULL
, "ctf",
855 lttngtop_ctf_packet_seek
, &mmap_list
, metadata_fp
);
857 printf("Error adding trace\n");
865 int setup_consumer(char *command_sock_path
, pthread_t
*threads
,
866 struct lttng_consumer_local_data
*ctx
)
870 ctx
= helper_lttng_consumer_create(HELPER_LTTNG_CONSUMER_KERNEL
,
871 read_subbuffer
, NULL
, on_recv_fd
, on_update_fd
);
875 unlink(command_sock_path
);
876 helper_lttng_consumer_set_command_sock_path(ctx
, command_sock_path
);
877 helper_lttng_consumer_init();
879 /* Create the thread to manage the receive of fd */
880 ret
= pthread_create(&threads
[0], NULL
, helper_lttng_consumer_thread_receive_fds
,
883 perror("pthread_create receive fd");
886 /* Create thread to manage the polling/writing of traces */
887 ret
= pthread_create(&threads
[1], NULL
, helper_lttng_consumer_thread_poll_fds
,
890 perror("pthread_create poll fd");
898 int setup_live_tracing()
900 struct lttng_domain dom
;
901 struct lttng_channel chan
;
902 char *channel_name
= "mmapchan";
903 struct lttng_event ev
;
905 char *command_sock_path
= "/tmp/consumerd_sock";
906 static pthread_t threads
[2]; /* recv_fd, poll */
907 struct lttng_event_context kctxpid
, kctxcomm
, kctxppid
, kctxtid
;
909 struct lttng_handle
*handle
;
911 BT_INIT_LIST_HEAD(&mmap_list
.head
);
913 lttng_consumer_stream_array
= g_ptr_array_new();
915 if ((ret
= setup_consumer(command_sock_path
, threads
, ctx
)) < 0) {
916 fprintf(stderr
,"error setting up consumer\n");
920 available_snapshots
= g_ptr_array_new();
922 /* setup the session */
923 dom
.type
= LTTNG_DOMAIN_KERNEL
;
925 ret
= unlink("/tmp/livesession");
927 lttng_destroy_session("test");
928 if ((ret
= lttng_create_session("test", "/tmp/livesession")) < 0) {
929 fprintf(stderr
,"error creating the session : %s\n",
930 helper_lttcomm_get_readable_code(ret
));
934 if ((handle
= lttng_create_handle("test", &dom
)) == NULL
) {
935 fprintf(stderr
,"error creating handle\n");
940 * FIXME : need to let the
941 * helper_lttng_consumer_thread_receive_fds create the
945 while (access(command_sock_path
, F_OK
)) {
949 if ((ret
= lttng_register_consumer(handle
, command_sock_path
)) < 0) {
950 fprintf(stderr
,"error registering consumer : %s\n",
951 helper_lttcomm_get_readable_code(ret
));
955 strcpy(chan
.name
, channel_name
);
956 chan
.attr
.overwrite
= 0;
957 if (opt_pid
&& opt_textdump
) {
958 chan
.attr
.subbuf_size
= 32768;
959 chan
.attr
.num_subbuf
= 8;
961 chan
.attr
.subbuf_size
= 1048576; /* 1MB */
962 chan
.attr
.num_subbuf
= 4;
964 chan
.attr
.switch_timer_interval
= 0;
965 chan
.attr
.read_timer_interval
= 200;
966 chan
.attr
.output
= LTTNG_EVENT_MMAP
;
968 if ((ret
= lttng_enable_channel(handle
, &chan
)) < 0) {
969 fprintf(stderr
,"error creating channel : %s\n",
970 helper_lttcomm_get_readable_code(ret
));
974 memset(&ev
, '\0', sizeof(struct lttng_event
));
975 //sprintf(ev.name, "sched_switch");
977 ev
.type
= LTTNG_EVENT_TRACEPOINT
;
978 if ((ret
= lttng_enable_event(handle
, &ev
, channel_name
)) < 0) {
979 fprintf(stderr
,"error enabling event : %s\n",
980 helper_lttcomm_get_readable_code(ret
));
985 ev
.type
= LTTNG_EVENT_SYSCALL
;
986 if ((ret
= lttng_enable_event(handle
, &ev
, channel_name
)) < 0) {
987 fprintf(stderr
,"error enabling syscalls : %s\n",
988 helper_lttcomm_get_readable_code(ret
));
992 kctxpid
.ctx
= LTTNG_EVENT_CONTEXT_PID
;
993 lttng_add_context(handle
, &kctxpid
, NULL
, NULL
);
994 kctxtid
.ctx
= LTTNG_EVENT_CONTEXT_TID
;
995 lttng_add_context(handle
, &kctxtid
, NULL
, NULL
);
997 kctxppid
.ctx
= LTTNG_EVENT_CONTEXT_PPID
;
998 lttng_add_context(handle
, &kctxppid
, NULL
, NULL
);
999 kctxcomm
.ctx
= LTTNG_EVENT_CONTEXT_PROCNAME
;
1000 lttng_add_context(handle
, &kctxcomm
, NULL
, NULL
);
1001 kctxpid
.ctx
= LTTNG_EVENT_CONTEXT_VPID
;
1002 lttng_add_context(handle
, &kctxpid
, NULL
, NULL
);
1003 kctxtid
.ctx
= LTTNG_EVENT_CONTEXT_VTID
;
1004 lttng_add_context(handle
, &kctxtid
, NULL
, NULL
);
1007 if ((ret
= lttng_start_tracing("test")) < 0) {
1008 fprintf(stderr
,"error starting tracing : %s\n",
1009 helper_lttcomm_get_readable_code(ret
));
1013 helper_kernctl_buffer_flush(consumerd_metadata
);
1015 /* block until metadata is ready */
1016 sem_init(&metadata_available
, 0, 0);
1021 lttng_destroy_session("test");
1026 int main(int argc
, char **argv
)
1029 struct bt_context
*bt_ctx
= NULL
;
1030 struct mmap_stream
*mmap_info
;
1031 unsigned long mmap_len
;
1033 ret
= parse_options(argc
, argv
);
1035 fprintf(stdout
, "Error parsing options.\n\n");
1038 } else if (ret
> 0) {
1042 if (!opt_input_path
) {
1044 signal(SIGTERM
, handle_textdump_sigterm
);
1045 signal(SIGINT
, handle_textdump_sigterm
);
1047 ret
= setup_live_tracing();
1052 if (!opt_textdump
) {
1053 pthread_create(&display_thread
, NULL
, ncurses_display
, (void *) NULL
);
1054 pthread_create(&timer_thread
, NULL
, refresh_thread
, (void *) NULL
);
1058 live_consume(&bt_ctx
);
1060 ret
= bt_context_remove_trace(bt_ctx
, 0);
1062 fprintf(stderr
, "error removing trace\n");
1064 bt_context_put(bt_ctx
);
1068 * since we receive all FDs every time there is an
1069 * update and the FD number is different every time,
1070 * we don't know which one are valid.
1071 * so we check if all FDs are usable with a simple
1074 bt_list_for_each_entry(mmap_info
, &mmap_list
.head
, list
) {
1075 ret
= helper_kernctl_get_mmap_len(mmap_info
->fd
, &mmap_len
);
1077 bt_list_del(&mmap_info
->list
);
1080 sem_post(&metadata_available
);
1083 pthread_join(timer_thread
, NULL
);
1085 pthread_join(display_thread
, NULL
);
1087 lttng_stop_tracing("test");
1088 lttng_destroy_session("test");
1094 bt_ctx
= bt_context_create();
1095 ret
= bt_context_add_traces_recursive(bt_ctx
, opt_input_path
, "ctf", NULL
);
1097 fprintf(stderr
, "[error] Opening the trace\n");
1101 ret
= check_requirements(bt_ctx
);
1103 fprintf(stderr
, "[error] some mandatory contexts were missing, exiting.\n");
1106 pthread_create(&display_thread
, NULL
, ncurses_display
, (void *) NULL
);
1107 pthread_create(&timer_thread
, NULL
, refresh_thread
, (void *) NULL
);
1111 pthread_join(display_thread
, NULL
);
1113 pthread_join(timer_thread
, NULL
);
1118 bt_context_put(bt_ctx
);