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
;
60 struct lttngtop
*copy
;
61 pthread_t display_thread
;
62 pthread_t timer_thread
;
64 unsigned long refresh_display
= 1 * NSEC_PER_SEC
;
65 unsigned long last_display_update
= 0;
67 /* list of FDs available for being read with snapshots */
68 struct mmap_stream_list mmap_list
;
69 GPtrArray
*lttng_consumer_stream_array
;
70 int sessiond_metadata
, consumerd_metadata
;
71 struct lttng_consumer_local_data
*ctx
= NULL
;
72 /* list of snapshots currently not consumed */
73 GPtrArray
*available_snapshots
;
74 sem_t metadata_available
;
85 static struct poptOption long_options
[] = {
86 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
87 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
88 { "textdump", 't', POPT_ARG_NONE
, NULL
, OPT_TEXTDUMP
, NULL
, NULL
},
89 { "child", 'f', POPT_ARG_NONE
, NULL
, OPT_CHILD
, NULL
, NULL
},
90 { "pid", 'p', POPT_ARG_INT
, &opt_pid
, OPT_PID
, NULL
, NULL
},
91 { NULL
, 0, 0, NULL
, 0, NULL
, NULL
},
94 void *refresh_thread(void *p
)
96 struct mmap_stream
*mmap_info
;
100 sem_post(&pause_sem
);
102 sem_post(&end_trace_sem
);
103 sem_post(&goodtodisplay
);
104 sem_post(&goodtoupdate
);
107 if (!opt_input_path
) {
108 bt_list_for_each_entry(mmap_info
, &mmap_list
.head
, list
)
109 helper_kernctl_buffer_flush(mmap_info
->fd
);
111 sem_wait(&pause_sem
);
112 sem_post(&pause_sem
);
114 sleep(refresh_display
/NSEC_PER_SEC
);
118 void *ncurses_display(void *p
)
120 unsigned int current_display_index
= 0;
122 sem_wait(&bootstrap
);
124 * Prevent the 1 second delay when we hit ESC
131 sem_wait(&goodtodisplay
);
132 sem_wait(&pause_sem
);
135 sem_post(&pause_sem
);
141 copy
= g_ptr_array_index(copies
, current_display_index
);
143 display(current_display_index
++);
145 sem_post(&goodtoupdate
);
146 sem_post(&pause_sem
);
151 * hook on each event to check the timestamp and refresh the display if
154 enum bt_cb_ret
print_timestamp(struct bt_ctf_event
*call_data
, void *private_data
)
156 unsigned long timestamp
;
158 uint64_t ts_nsec_start
;
161 timestamp
= bt_ctf_get_timestamp(call_data
);
163 start
= format_timestamp(timestamp
);
164 ts_nsec_start
= timestamp
% NSEC_PER_SEC
;
166 pid
= get_context_pid(call_data
);
167 if (pid
== -1ULL && opt_pid
) {
171 if (opt_pid
&& opt_pid
!= pid
)
174 printf("%02d:%02d:%02d.%09" PRIu64
" %d : %s\n", start
.tm_hour
,
175 start
.tm_min
, start
.tm_sec
, ts_nsec_start
,
176 pid
, bt_ctf_event_name(call_data
));
181 return BT_CB_ERROR_STOP
;
185 * hook on each event to check the timestamp and refresh the display if
188 enum bt_cb_ret
check_timestamp(struct bt_ctf_event
*call_data
, void *private_data
)
190 unsigned long timestamp
;
192 timestamp
= bt_ctf_get_timestamp(call_data
);
193 if (timestamp
== -1ULL)
196 if (last_display_update
== 0)
197 last_display_update
= timestamp
;
199 if (timestamp
- last_display_update
>= refresh_display
) {
200 sem_wait(&goodtoupdate
);
201 g_ptr_array_add(copies
, get_copy_lttngtop(last_display_update
,
203 sem_post(&goodtodisplay
);
204 sem_post(&bootstrap
);
205 last_display_update
= timestamp
;
210 fprintf(stderr
, "check_timestamp callback error\n");
211 return BT_CB_ERROR_STOP
;
215 * get_perf_counter : get or create and return a perf_counter struct for
216 * either a process or a cpu (only one of the 2 parameters mandatory)
218 struct perfcounter
*get_perf_counter(const char *name
, struct processtop
*proc
,
221 struct perfcounter
*ret
;
231 ret
= g_hash_table_lookup(table
, (gpointer
) name
);
235 ret
= g_new0(struct perfcounter
, 1);
236 /* by default, make it visible in the UI */
238 g_hash_table_insert(table
, (gpointer
) strdup(name
), ret
);
247 void update_perf_value(struct processtop
*proc
, struct cputime
*cpu
,
248 const char *name
, int value
)
250 struct perfcounter
*cpu_perf
, *process_perf
;
252 cpu_perf
= get_perf_counter(name
, NULL
, cpu
);
253 if (cpu_perf
->count
< value
) {
254 process_perf
= get_perf_counter(name
, proc
, NULL
);
255 process_perf
->count
+= value
- cpu_perf
->count
;
256 cpu_perf
->count
= value
;
260 void extract_perf_counter_scope(const struct bt_ctf_event
*event
,
261 const struct bt_definition
*scope
,
262 struct processtop
*proc
,
265 struct bt_definition
const * const *list
= NULL
;
266 const struct bt_definition
*field
;
268 struct perfcounter
*perfcounter
;
276 ret
= bt_ctf_get_field_list(event
, scope
, &list
, &count
);
283 g_hash_table_iter_init(&iter
, global_perf_liszt
);
284 while (g_hash_table_iter_next (&iter
, &key
, (gpointer
) &perfcounter
)) {
285 field
= bt_ctf_get_field(event
, scope
, (char *) key
);
287 int value
= bt_ctf_get_uint64(field
);
288 if (bt_ctf_field_get_error())
290 update_perf_value(proc
, cpu
, (char *) key
, value
);
298 void update_perf_counter(struct processtop
*proc
, const struct bt_ctf_event
*event
)
301 const struct bt_definition
*scope
;
303 cpu
= get_cpu(get_cpu_id(event
));
305 scope
= bt_ctf_get_top_level_scope(event
, BT_STREAM_EVENT_CONTEXT
);
306 extract_perf_counter_scope(event
, scope
, proc
, cpu
);
308 scope
= bt_ctf_get_top_level_scope(event
, BT_STREAM_PACKET_CONTEXT
);
309 extract_perf_counter_scope(event
, scope
, proc
, cpu
);
311 scope
= bt_ctf_get_top_level_scope(event
, BT_EVENT_CONTEXT
);
312 extract_perf_counter_scope(event
, scope
, proc
, cpu
);
315 enum bt_cb_ret
fix_process_table(struct bt_ctf_event
*call_data
,
318 int pid
, tid
, ppid
, vpid
, vtid
, vppid
;
320 struct processtop
*parent
, *child
;
321 unsigned long timestamp
;
323 timestamp
= bt_ctf_get_timestamp(call_data
);
324 if (timestamp
== -1ULL)
327 pid
= get_context_pid(call_data
);
331 tid
= get_context_tid(call_data
);
335 ppid
= get_context_ppid(call_data
);
339 vpid
= get_context_vpid(call_data
);
343 vtid
= get_context_vtid(call_data
);
347 vppid
= get_context_vppid(call_data
);
351 comm
= get_context_comm(call_data
);
356 /* find or create the current process */
357 child
= find_process_tid(<tngtop
, tid
, comm
);
359 child
= add_proc(<tngtop
, tid
, comm
, timestamp
);
360 update_proc(child
, pid
, tid
, ppid
, vpid
, vtid
, vppid
, comm
);
363 /* find or create the parent */
364 parent
= find_process_tid(<tngtop
, pid
, comm
);
366 parent
= add_proc(<tngtop
, pid
, comm
, timestamp
);
370 /* attach the parent to the current process */
371 child
->threadparent
= parent
;
372 add_thread(parent
, child
);
375 update_perf_counter(child
, call_data
);
380 return BT_CB_ERROR_STOP
;
385 copies
= g_ptr_array_new();
386 global_perf_liszt
= g_hash_table_new(g_str_hash
, g_str_equal
);
388 sem_init(&goodtodisplay
, 0, 0);
389 sem_init(&goodtoupdate
, 0, 1);
390 sem_init(&timer
, 0, 1);
391 sem_init(&bootstrap
, 0, 0);
392 sem_init(&pause_sem
, 0, 1);
393 sem_init(&end_trace_sem
, 0, 0);
395 reset_global_counters();
397 lttngtop
.nbthreads
= 0;
398 lttngtop
.nbfiles
= 0;
400 lttngtop
.process_hash_table
= g_hash_table_new(g_direct_hash
,
402 lttngtop
.process_table
= g_ptr_array_new();
403 lttngtop
.files_table
= g_ptr_array_new();
404 lttngtop
.cpu_table
= g_ptr_array_new();
409 fprintf(fp
, "LTTngTop %s\n\n", VERSION
);
410 fprintf(fp
, "Usage : lttngtop /path/to/trace\n");
414 * Return 0 if caller should continue, < 0 if caller should return
415 * error, > 0 if caller should exit without reporting error.
417 static int parse_options(int argc
, char **argv
)
422 pc
= poptGetContext(NULL
, argc
, (const char **) argv
, long_options
, 0);
423 poptReadDefaultConfig(pc
, 0);
425 while ((opt
= poptGetNextOpt(pc
)) != -1) {
429 ret
= 1; /* exit cleanly */
447 opt_input_path
= poptGetArg(pc
);
456 void iter_trace(struct bt_context
*bt_ctx
)
458 struct bt_ctf_iter
*iter
;
459 struct bt_iter_pos begin_pos
;
460 const struct bt_ctf_event
*event
;
463 begin_pos
.type
= BT_SEEK_BEGIN
;
464 iter
= bt_ctf_iter_create(bt_ctx
, &begin_pos
, NULL
);
468 printf("PID : %d, Child : %d\n", opt_pid
, opt_child
);
470 bt_ctf_iter_add_callback(iter
, 0, NULL
, 0,
474 /* at each event check if we need to refresh */
475 bt_ctf_iter_add_callback(iter
, 0, NULL
, 0,
478 /* at each event, verify the status of the process table */
479 bt_ctf_iter_add_callback(iter
, 0, NULL
, 0,
482 /* to handle the scheduling events */
483 bt_ctf_iter_add_callback(iter
,
484 g_quark_from_static_string("sched_switch"),
485 NULL
, 0, handle_sched_switch
, NULL
, NULL
, NULL
);
486 /* to clean up the process table */
487 bt_ctf_iter_add_callback(iter
,
488 g_quark_from_static_string("sched_process_free"),
489 NULL
, 0, handle_sched_process_free
, NULL
, NULL
, NULL
);
490 /* to get all the process from the statedumps */
491 bt_ctf_iter_add_callback(iter
,
492 g_quark_from_static_string(
493 "lttng_statedump_process_state"),
494 NULL
, 0, handle_statedump_process_state
,
498 bt_ctf_iter_add_callback(iter
,
499 g_quark_from_static_string("exit_syscall"),
500 NULL
, 0, handle_exit_syscall
, NULL
, NULL
, NULL
);
501 bt_ctf_iter_add_callback(iter
,
502 g_quark_from_static_string("sys_write"),
503 NULL
, 0, handle_sys_write
, NULL
, NULL
, NULL
);
504 bt_ctf_iter_add_callback(iter
,
505 g_quark_from_static_string("sys_read"),
506 NULL
, 0, handle_sys_read
, NULL
, NULL
, NULL
);
507 bt_ctf_iter_add_callback(iter
,
508 g_quark_from_static_string("sys_open"),
509 NULL
, 0, handle_sys_open
, NULL
, NULL
, NULL
);
510 bt_ctf_iter_add_callback(iter
,
511 g_quark_from_static_string("sys_close"),
512 NULL
, 0, handle_sys_close
, NULL
, NULL
, NULL
);
513 bt_ctf_iter_add_callback(iter
,
514 g_quark_from_static_string(
515 "lttng_statedump_file_descriptor"),
516 NULL
, 0, handle_statedump_file_descriptor
,
520 while ((event
= bt_ctf_iter_read_event(iter
, NULL
)) != NULL
) {
521 if (quit
|| reload_trace
)
523 ret
= bt_iter_next(bt_ctf_get_iter(iter
));
528 /* block until quit, we reached the end of the trace */
529 sem_wait(&end_trace_sem
);
532 bt_ctf_iter_destroy(iter
);
536 * bt_context_add_traces_recursive: Open a trace recursively
537 * (copied from BSD code in converter/babeltrace.c)
539 * Find each trace present in the subdirectory starting from the given
540 * path, and add them to the context. The packet_seek parameter can be
541 * NULL: this specify to use the default format packet_seek.
543 * Return: 0 on success, nonzero on failure.
544 * Unable to open toplevel: failure.
545 * Unable to open some subdirectory or file: warn and continue;
547 int bt_context_add_traces_recursive(struct bt_context
*ctx
, const char *path
,
548 const char *format_str
,
549 void (*packet_seek
)(struct bt_stream_pos
*pos
,
550 size_t offset
, int whence
))
555 char lpath
[PATH_MAX
];
556 char * const paths
[2] = { lpath
, NULL
};
560 * Need to copy path, because fts_open can change it.
561 * It is the pointer array, not the strings, that are constant.
563 strncpy(lpath
, path
, PATH_MAX
);
564 lpath
[PATH_MAX
- 1] = '\0';
566 tree
= fts_open(paths
, FTS_NOCHDIR
| FTS_LOGICAL
, 0);
568 fprintf(stderr
, "[error] [Context] Cannot traverse \"%s\" for reading.\n",
573 trace_ids
= g_array_new(FALSE
, TRUE
, sizeof(int));
575 while ((node
= fts_read(tree
))) {
578 if (!(node
->fts_info
& FTS_D
))
581 dirfd
= open(node
->fts_accpath
, 0);
583 fprintf(stderr
, "[error] [Context] Unable to open trace "
584 "directory file descriptor.\n");
588 metafd
= openat(dirfd
, "metadata", O_RDONLY
);
607 trace_id
= bt_context_add_trace(ctx
,
608 node
->fts_accpath
, format_str
,
609 packet_seek
, NULL
, NULL
);
611 fprintf(stderr
, "[warning] [Context] opening trace \"%s\" from %s "
612 "for reading.\n", node
->fts_accpath
, path
);
613 /* Allow to skip erroneous traces. */
616 g_array_append_val(trace_ids
, trace_id
);
620 g_array_free(trace_ids
, TRUE
);
627 static int check_field_requirements(const struct bt_ctf_field_decl
*const * field_list
,
628 int field_cnt
, int *tid_check
, int *pid_check
,
629 int *procname_check
, int *ppid_check
)
632 struct perfcounter
*global
;
635 for (j
= 0; j
< field_cnt
; j
++) {
636 name
= bt_ctf_get_decl_field_name(field_list
[j
]);
637 if (*tid_check
== 0) {
638 if (strncmp(name
, "tid", 3) == 0)
641 if (*pid_check
== 0) {
642 if (strncmp(name
, "pid", 3) == 0)
645 if (*ppid_check
== 0) {
646 if (strncmp(name
, "ppid", 4) == 0)
649 if (*procname_check
== 0) {
650 if (strncmp(name
, "procname", 8) == 0)
653 if (strncmp(name
, "perf_", 5) == 0) {
654 global
= g_hash_table_lookup(global_perf_liszt
, (gpointer
) name
);
656 global
= g_new0(struct perfcounter
, 1);
657 /* by default, sort on the first perf context */
658 if (g_hash_table_size(global_perf_liszt
) == 0)
661 g_hash_table_insert(global_perf_liszt
, (gpointer
) strdup(name
), global
);
666 if (*tid_check
== 1 && *pid_check
== 1 && *ppid_check
== 1 &&
667 *procname_check
== 1)
674 * check_requirements: check if the required context informations are available
676 * If each mandatory context information is available for at least in one
677 * event, return 0 otherwise return -1.
679 int check_requirements(struct bt_context
*ctx
)
681 unsigned int i
, evt_cnt
, field_cnt
;
682 struct bt_ctf_event_decl
*const * evt_list
;
683 const struct bt_ctf_field_decl
*const * field_list
;
686 int procname_check
= 0;
690 bt_ctf_get_event_decl_list(0, ctx
, &evt_list
, &evt_cnt
);
691 for (i
= 0; i
< evt_cnt
; i
++) {
692 bt_ctf_get_decl_fields(evt_list
[i
], BT_STREAM_EVENT_CONTEXT
,
693 &field_list
, &field_cnt
);
694 ret
= check_field_requirements(field_list
, field_cnt
,
695 &tid_check
, &pid_check
, &procname_check
,
698 bt_ctf_get_decl_fields(evt_list
[i
], BT_EVENT_CONTEXT
,
699 &field_list
, &field_cnt
);
700 ret
= check_field_requirements(field_list
, field_cnt
,
701 &tid_check
, &pid_check
, &procname_check
,
704 bt_ctf_get_decl_fields(evt_list
[i
], BT_STREAM_PACKET_CONTEXT
,
705 &field_list
, &field_cnt
);
706 ret
= check_field_requirements(field_list
, field_cnt
,
707 &tid_check
, &pid_check
, &procname_check
,
711 if (tid_check
== 0) {
713 fprintf(stderr
, "[error] missing tid context information\n");
715 if (pid_check
== 0) {
717 fprintf(stderr
, "[error] missing pid context information\n");
719 if (ppid_check
== 0) {
721 fprintf(stderr
, "[error] missing ppid context information\n");
723 if (procname_check
== 0) {
725 fprintf(stderr
, "[error] missing procname context information\n");
731 ssize_t
read_subbuffer(struct lttng_consumer_stream
*kconsumerd_fd
,
732 struct lttng_consumer_local_data
*ctx
)
737 int infd
= helper_get_lttng_consumer_stream_wait_fd(kconsumerd_fd
);
739 if (helper_get_lttng_consumer_stream_output(kconsumerd_fd
) == LTTNG_EVENT_SPLICE
) {
740 /* Get the next subbuffer */
741 err
= helper_kernctl_get_next_subbuf(infd
);
744 perror("Reserving sub buffer failed (everything is normal, "
745 "it is due to concurrency)");
748 /* read the whole subbuffer */
749 err
= helper_kernctl_get_padded_subbuf_size(infd
, &len
);
752 perror("Getting sub-buffer len failed.");
756 /* splice the subbuffer to the tracefile */
757 ret
= helper_lttng_consumer_on_read_subbuffer_splice(ctx
, kconsumerd_fd
, len
);
760 * display the error but continue processing to try
761 * to release the subbuffer
763 fprintf(stderr
,"Error splicing to tracefile\n");
765 err
= helper_kernctl_put_next_subbuf(infd
);
768 perror("Reserving sub buffer failed (everything is normal, "
769 "it is due to concurrency)");
772 sem_post(&metadata_available
);
779 int on_update_fd(int key
, uint32_t state
)
781 /* let the lib handle the metadata FD */
782 if (key
== sessiond_metadata
)
787 int on_recv_fd(struct lttng_consumer_stream
*kconsumerd_fd
)
790 struct mmap_stream
*new_mmap_stream
;
792 /* Opening the tracefile in write mode */
793 if (helper_get_lttng_consumer_stream_path_name(kconsumerd_fd
) != NULL
) {
794 ret
= open(helper_get_lttng_consumer_stream_path_name(kconsumerd_fd
),
795 O_WRONLY
|O_CREAT
|O_TRUNC
, S_IRWXU
|S_IRWXG
|S_IRWXO
);
800 helper_set_lttng_consumer_stream_out_fd(kconsumerd_fd
, ret
);
803 if (helper_get_lttng_consumer_stream_output(kconsumerd_fd
) == LTTNG_EVENT_MMAP
) {
804 new_mmap_stream
= malloc(sizeof(struct mmap_stream
));
805 new_mmap_stream
->fd
= helper_get_lttng_consumer_stream_wait_fd(
807 bt_list_add(&new_mmap_stream
->list
, &mmap_list
.head
);
809 g_ptr_array_add(lttng_consumer_stream_array
, kconsumerd_fd
);
810 /* keep mmap FDs internally */
813 consumerd_metadata
= helper_get_lttng_consumer_stream_wait_fd(kconsumerd_fd
);
814 sessiond_metadata
= helper_get_lttng_consumer_stream_key(kconsumerd_fd
);
824 void live_consume(struct bt_context
**bt_ctx
)
829 sem_wait(&metadata_available
);
830 if (access("/tmp/livesession/kernel/metadata", F_OK
) != 0) {
831 fprintf(stderr
,"no metadata\n");
834 metadata_fp
= fopen("/tmp/livesession/kernel/metadata", "r");
836 *bt_ctx
= bt_context_create();
837 ret
= bt_context_add_trace(*bt_ctx
, NULL
, "ctf",
838 lttngtop_ctf_packet_seek
, &mmap_list
, metadata_fp
);
840 printf("Error adding trace\n");
848 int setup_consumer(char *command_sock_path
, pthread_t
*threads
,
849 struct lttng_consumer_local_data
*ctx
)
853 ctx
= helper_lttng_consumer_create(HELPER_LTTNG_CONSUMER_KERNEL
,
854 read_subbuffer
, NULL
, on_recv_fd
, on_update_fd
);
858 unlink(command_sock_path
);
859 helper_lttng_consumer_set_command_sock_path(ctx
, command_sock_path
);
860 helper_lttng_consumer_init();
862 /* Create the thread to manage the receive of fd */
863 ret
= pthread_create(&threads
[0], NULL
, helper_lttng_consumer_thread_receive_fds
,
866 perror("pthread_create receive fd");
869 /* Create thread to manage the polling/writing of traces */
870 ret
= pthread_create(&threads
[1], NULL
, helper_lttng_consumer_thread_poll_fds
,
873 perror("pthread_create poll fd");
881 int setup_live_tracing()
883 struct lttng_domain dom
;
884 struct lttng_channel chan
;
885 char *channel_name
= "mmapchan";
886 struct lttng_event ev
;
888 char *command_sock_path
= "/tmp/consumerd_sock";
889 static pthread_t threads
[2]; /* recv_fd, poll */
890 struct lttng_event_context kctxpid
, kctxcomm
, kctxppid
, kctxtid
;
892 struct lttng_handle
*handle
;
894 BT_INIT_LIST_HEAD(&mmap_list
.head
);
896 lttng_consumer_stream_array
= g_ptr_array_new();
898 if ((ret
= setup_consumer(command_sock_path
, threads
, ctx
)) < 0) {
899 fprintf(stderr
,"error setting up consumer\n");
903 available_snapshots
= g_ptr_array_new();
905 /* setup the session */
906 dom
.type
= LTTNG_DOMAIN_KERNEL
;
908 ret
= unlink("/tmp/livesession");
910 lttng_destroy_session("test");
911 if ((ret
= lttng_create_session("test", "/tmp/livesession")) < 0) {
912 fprintf(stderr
,"error creating the session : %s\n",
913 helper_lttcomm_get_readable_code(ret
));
917 if ((handle
= lttng_create_handle("test", &dom
)) == NULL
) {
918 fprintf(stderr
,"error creating handle\n");
923 * FIXME : need to let the
924 * helper_lttng_consumer_thread_receive_fds create the
928 while (access(command_sock_path
, F_OK
)) {
932 if ((ret
= lttng_register_consumer(handle
, command_sock_path
)) < 0) {
933 fprintf(stderr
,"error registering consumer : %s\n",
934 helper_lttcomm_get_readable_code(ret
));
938 strcpy(chan
.name
, channel_name
);
939 chan
.attr
.overwrite
= 0;
940 // chan.attr.subbuf_size = 32768;
941 chan
.attr
.subbuf_size
= 1048576; /* 1MB */
942 chan
.attr
.num_subbuf
= 4;
943 chan
.attr
.switch_timer_interval
= 0;
944 chan
.attr
.read_timer_interval
= 200;
945 chan
.attr
.output
= LTTNG_EVENT_MMAP
;
947 if ((ret
= lttng_enable_channel(handle
, &chan
)) < 0) {
948 fprintf(stderr
,"error creating channel : %s\n",
949 helper_lttcomm_get_readable_code(ret
));
953 memset(&ev
, '\0', sizeof(struct lttng_event
));
954 //sprintf(ev.name, "sched_switch");
955 ev
.type
= LTTNG_EVENT_TRACEPOINT
;
956 if ((ret
= lttng_enable_event(handle
, &ev
, channel_name
)) < 0) {
957 fprintf(stderr
,"error enabling event : %s\n",
958 helper_lttcomm_get_readable_code(ret
));
962 ev
.type
= LTTNG_EVENT_SYSCALL
;
963 if ((ret
= lttng_enable_event(handle
, &ev
, channel_name
)) < 0) {
964 fprintf(stderr
,"error enabling syscalls : %s\n",
965 helper_lttcomm_get_readable_code(ret
));
969 kctxpid
.ctx
= LTTNG_EVENT_CONTEXT_PID
;
970 lttng_add_context(handle
, &kctxpid
, NULL
, NULL
);
971 kctxppid
.ctx
= LTTNG_EVENT_CONTEXT_PPID
;
972 lttng_add_context(handle
, &kctxppid
, NULL
, NULL
);
973 kctxcomm
.ctx
= LTTNG_EVENT_CONTEXT_PROCNAME
;
974 lttng_add_context(handle
, &kctxcomm
, NULL
, NULL
);
975 kctxtid
.ctx
= LTTNG_EVENT_CONTEXT_TID
;
976 lttng_add_context(handle
, &kctxtid
, NULL
, NULL
);
977 kctxpid
.ctx
= LTTNG_EVENT_CONTEXT_VPID
;
978 lttng_add_context(handle
, &kctxpid
, NULL
, NULL
);
979 kctxtid
.ctx
= LTTNG_EVENT_CONTEXT_VTID
;
980 lttng_add_context(handle
, &kctxtid
, NULL
, NULL
);
982 if ((ret
= lttng_start_tracing("test")) < 0) {
983 fprintf(stderr
,"error starting tracing : %s\n",
984 helper_lttcomm_get_readable_code(ret
));
988 helper_kernctl_buffer_flush(consumerd_metadata
);
990 /* block until metadata is ready */
991 sem_init(&metadata_available
, 0, 0);
996 lttng_destroy_session("test");
1001 int main(int argc
, char **argv
)
1004 struct bt_context
*bt_ctx
= NULL
;
1005 struct mmap_stream
*mmap_info
;
1006 unsigned long mmap_len
;
1008 ret
= parse_options(argc
, argv
);
1010 fprintf(stdout
, "Error parsing options.\n\n");
1013 } else if (ret
> 0) {
1017 if (!opt_input_path
) {
1018 ret
= setup_live_tracing();
1023 if (!opt_textdump
) {
1024 pthread_create(&display_thread
, NULL
, ncurses_display
, (void *) NULL
);
1025 pthread_create(&timer_thread
, NULL
, refresh_thread
, (void *) NULL
);
1029 live_consume(&bt_ctx
);
1031 ret
= bt_context_remove_trace(bt_ctx
, 0);
1033 fprintf(stderr
, "error removing trace\n");
1035 bt_context_put(bt_ctx
);
1039 * since we receive all FDs every time there is an
1040 * update and the FD number is different every time,
1041 * we don't know which one are valid.
1042 * so we check if all FDs are usable with a simple
1045 bt_list_for_each_entry(mmap_info
, &mmap_list
.head
, list
) {
1046 ret
= helper_kernctl_get_mmap_len(mmap_info
->fd
, &mmap_len
);
1048 bt_list_del(&mmap_info
->list
);
1051 sem_post(&metadata_available
);
1054 pthread_join(timer_thread
, NULL
);
1056 pthread_join(display_thread
, NULL
);
1058 lttng_stop_tracing("test");
1059 lttng_destroy_session("test");
1065 bt_ctx
= bt_context_create();
1066 ret
= bt_context_add_traces_recursive(bt_ctx
, opt_input_path
, "ctf", NULL
);
1068 fprintf(stderr
, "[error] Opening the trace\n");
1072 ret
= check_requirements(bt_ctx
);
1074 fprintf(stderr
, "[error] some mandatory contexts were missing, exiting.\n");
1077 pthread_create(&display_thread
, NULL
, ncurses_display
, (void *) NULL
);
1078 pthread_create(&timer_thread
, NULL
, refresh_thread
, (void *) NULL
);
1082 pthread_join(display_thread
, NULL
);
1084 pthread_join(timer_thread
, NULL
);
1089 bt_context_put(bt_ctx
);