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 #ifdef LTTNGTOP_MMAP_LIVE
43 #include <lttng/lttngtop-helper.h>
44 #include <babeltrace/lttngtopmmappacketseek.h>
45 #include "mmap-live.h"
46 #endif /* LTTNGTOP_MMAP_LIVE */
48 #include "lttngtoptypes.h"
50 #include "iostreamtop.h"
51 #include "cursesdisplay.h"
53 #include "network-live.h"
55 #include "lttng-index.h"
57 #define DEFAULT_FILE_ARRAY_SIZE 1
59 const char *opt_input_path
;
60 static int opt_textdump
;
65 struct lttngtop
*copy
;
66 pthread_t display_thread
;
67 pthread_t timer_thread
;
69 unsigned long refresh_display
= 1 * NSEC_PER_SEC
;
70 unsigned long last_display_update
= 0;
72 /* list of FDs available for being read with snapshots */
73 struct bt_mmap_stream_list mmap_list
;
74 GPtrArray
*lttng_consumer_stream_array
;
75 int sessiond_metadata
, consumerd_metadata
;
76 struct lttng_consumer_local_data
*ctx
= NULL
;
77 /* list of snapshots currently not consumed */
78 GPtrArray
*available_snapshots
;
79 sem_t metadata_available
;
82 int last_textdump_print_newline
= 1;
95 static struct poptOption long_options
[] = {
96 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
97 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
98 { "textdump", 't', POPT_ARG_NONE
, NULL
, OPT_TEXTDUMP
, NULL
, NULL
},
99 { "child", 'f', POPT_ARG_NONE
, NULL
, OPT_CHILD
, NULL
, NULL
},
100 { "pid", 'p', POPT_ARG_STRING
, &opt_tid
, OPT_PID
, NULL
, NULL
},
101 { "hostname", 'n', POPT_ARG_STRING
, &opt_hostname
, OPT_HOSTNAME
, NULL
, NULL
},
102 { "relay-hostname", 'r', POPT_ARG_STRING
, &opt_relay_hostname
,
103 OPT_RELAY_HOSTNAME
, NULL
, NULL
},
104 { "kprobes", 'k', POPT_ARG_STRING
, &opt_kprobes
, OPT_KPROBES
, NULL
, NULL
},
105 { NULL
, 0, 0, NULL
, 0, NULL
, NULL
},
108 static void handle_textdump_sigterm(int signal
)
111 lttng_destroy_session("test");
114 void *refresh_thread(void *p
)
118 sem_post(&pause_sem
);
120 sem_post(&end_trace_sem
);
121 sem_post(&goodtodisplay
);
122 sem_post(&goodtoupdate
);
125 if (!opt_input_path
) {
126 #ifdef LTTNGTOP_MMAP_LIVE
127 mmap_live_flush(mmap_list
);
130 sem_wait(&pause_sem
);
131 sem_post(&pause_sem
);
133 sleep(refresh_display
/NSEC_PER_SEC
);
137 void *ncurses_display(void *p
)
139 unsigned int current_display_index
= 0;
141 sem_wait(&bootstrap
);
143 * Prevent the 1 second delay when we hit ESC
150 sem_wait(&goodtodisplay
);
151 sem_wait(&pause_sem
);
154 sem_post(&pause_sem
);
160 copy
= g_ptr_array_index(copies
, current_display_index
);
162 display(current_display_index
++);
164 sem_post(&goodtoupdate
);
165 sem_post(&pause_sem
);
169 void print_fields(struct bt_ctf_event
*event
)
172 const struct bt_definition
*const * list
;
173 const struct bt_declaration
*l
;
174 const struct bt_definition
*scope
;
175 enum ctf_type_id type
;
178 scope
= bt_ctf_get_top_level_scope(event
, BT_EVENT_FIELDS
);
180 bt_ctf_get_field_list(event
, scope
, &list
, &cnt
);
181 for (i
= 0; i
< cnt
; i
++) {
184 printf("%s = ", bt_ctf_field_name(list
[i
]));
185 l
= bt_ctf_get_decl_from_def(list
[i
]);
186 type
= bt_ctf_field_type(l
);
187 if (type
== CTF_TYPE_INTEGER
) {
188 if (bt_ctf_get_int_signedness(l
) == 0)
189 printf("%" PRIu64
"", bt_ctf_get_uint64(list
[i
]));
191 printf("%" PRId64
"", bt_ctf_get_int64(list
[i
]));
192 } else if (type
== CTF_TYPE_STRING
) {
193 printf("%s", bt_ctf_get_string(list
[i
]));
194 } else if (type
== CTF_TYPE_ARRAY
) {
195 str
= bt_ctf_get_char_array(list
[i
]);
196 if (!bt_ctf_field_get_error() && str
)
203 * hook on each event to check the timestamp and refresh the display if
206 enum bt_cb_ret
print_timestamp(struct bt_ctf_event
*call_data
, void *private_data
)
208 unsigned long timestamp
;
210 uint64_t ts_nsec_start
;
213 const struct bt_definition
*scope
;
214 const char *hostname
, *procname
;
216 timestamp
= bt_ctf_get_timestamp(call_data
);
218 start
= format_timestamp(timestamp
);
219 ts_nsec_start
= timestamp
% NSEC_PER_SEC
;
221 pid
= get_context_pid(call_data
);
222 if (pid
== -1ULL && opt_tid
) {
226 hostname
= get_context_hostname(call_data
);
227 if (opt_tid
|| opt_hostname
)
228 if (!lookup_filter_tid_list(pid
))
231 cpu_id
= get_cpu_id(call_data
);
232 procname
= get_context_comm(call_data
);
234 if ((strcmp(bt_ctf_event_name(call_data
), "exit_syscall") == 0) &&
235 !last_textdump_print_newline
) {
236 scope
= bt_ctf_get_top_level_scope(call_data
,
238 syscall_ret
= bt_ctf_get_int64(bt_ctf_get_field(call_data
,
240 printf("= %ld\n", syscall_ret
);
241 last_textdump_print_newline
= 1;
243 /* we might have lost the exit_syscall event, so need to
244 * print the newline in this case */
245 if (last_textdump_print_newline
== 0)
247 printf("%02d:%02d:%02d.%09" PRIu64
" (%s) (cpu %d) [%s (%d)] %s (",
248 start
.tm_hour
, start
.tm_min
, start
.tm_sec
,
249 ts_nsec_start
, hostname
, cpu_id
, procname
, pid
,
250 bt_ctf_event_name(call_data
));
251 print_fields(call_data
);
253 if (strncmp(bt_ctf_event_name(call_data
), "sys_", 4) != 0) {
255 last_textdump_print_newline
= 1;
257 last_textdump_print_newline
= 0;
264 return BT_CB_ERROR_STOP
;
267 enum bt_cb_ret
handle_kprobes(struct bt_ctf_event
*call_data
, void *private_data
)
270 struct kprobes
*kprobe
;
273 for (i
= 0; i
< lttngtop
.kprobes_table
->len
; i
++) {
274 kprobe
= g_ptr_array_index(lttngtop
.kprobes_table
, i
);
275 if (strcmp(bt_ctf_event_name(call_data
), kprobe
->probe_name
) == 0) {
284 * hook on each event to check the timestamp and refresh the display if
287 enum bt_cb_ret
check_timestamp(struct bt_ctf_event
*call_data
, void *private_data
)
289 unsigned long timestamp
;
291 timestamp
= bt_ctf_get_timestamp(call_data
);
292 if (timestamp
== -1ULL)
295 if (last_display_update
== 0)
296 last_display_update
= timestamp
;
298 if (timestamp
- last_display_update
>= refresh_display
) {
299 sem_wait(&goodtoupdate
);
300 g_ptr_array_add(copies
, get_copy_lttngtop(last_display_update
,
302 sem_post(&goodtodisplay
);
303 sem_post(&bootstrap
);
304 last_display_update
= timestamp
;
309 fprintf(stderr
, "check_timestamp callback error\n");
310 return BT_CB_ERROR_STOP
;
314 * get_perf_counter : get or create and return a perf_counter struct for
315 * either a process or a cpu (only one of the 2 parameters mandatory)
317 struct perfcounter
*get_perf_counter(const char *name
, struct processtop
*proc
,
320 struct perfcounter
*ret
;
330 ret
= g_hash_table_lookup(table
, (gpointer
) name
);
334 ret
= g_new0(struct perfcounter
, 1);
335 /* by default, make it visible in the UI */
337 g_hash_table_insert(table
, (gpointer
) strdup(name
), ret
);
346 void update_perf_value(struct processtop
*proc
, struct cputime
*cpu
,
347 const char *name
, int value
)
349 struct perfcounter
*cpu_perf
, *process_perf
;
351 cpu_perf
= get_perf_counter(name
, NULL
, cpu
);
352 if (cpu_perf
->count
< value
) {
353 process_perf
= get_perf_counter(name
, proc
, NULL
);
354 process_perf
->count
+= value
- cpu_perf
->count
;
355 cpu_perf
->count
= value
;
359 void extract_perf_counter_scope(const struct bt_ctf_event
*event
,
360 const struct bt_definition
*scope
,
361 struct processtop
*proc
,
364 struct bt_definition
const * const *list
= NULL
;
365 const struct bt_definition
*field
;
367 struct perfcounter
*perfcounter
;
375 ret
= bt_ctf_get_field_list(event
, scope
, &list
, &count
);
382 g_hash_table_iter_init(&iter
, global_perf_liszt
);
383 while (g_hash_table_iter_next (&iter
, &key
, (gpointer
) &perfcounter
)) {
384 field
= bt_ctf_get_field(event
, scope
, (char *) key
);
386 int value
= bt_ctf_get_uint64(field
);
387 if (bt_ctf_field_get_error())
389 update_perf_value(proc
, cpu
, (char *) key
, value
);
397 void update_perf_counter(struct processtop
*proc
, const struct bt_ctf_event
*event
)
400 const struct bt_definition
*scope
;
402 cpu
= get_cpu(get_cpu_id(event
));
404 scope
= bt_ctf_get_top_level_scope(event
, BT_STREAM_EVENT_CONTEXT
);
405 extract_perf_counter_scope(event
, scope
, proc
, cpu
);
407 scope
= bt_ctf_get_top_level_scope(event
, BT_STREAM_PACKET_CONTEXT
);
408 extract_perf_counter_scope(event
, scope
, proc
, cpu
);
410 scope
= bt_ctf_get_top_level_scope(event
, BT_EVENT_CONTEXT
);
411 extract_perf_counter_scope(event
, scope
, proc
, cpu
);
414 enum bt_cb_ret
fix_process_table(struct bt_ctf_event
*call_data
,
417 int pid
, tid
, ppid
, vpid
, vtid
, vppid
;
418 char *comm
, *hostname
;
419 struct processtop
*parent
, *child
;
420 unsigned long timestamp
;
422 timestamp
= bt_ctf_get_timestamp(call_data
);
423 if (timestamp
== -1ULL)
426 pid
= get_context_pid(call_data
);
431 tid
= get_context_tid(call_data
);
435 ppid
= get_context_ppid(call_data
);
439 vpid
= get_context_vpid(call_data
);
443 vtid
= get_context_vtid(call_data
);
447 vppid
= get_context_vppid(call_data
);
451 comm
= get_context_comm(call_data
);
456 hostname
= get_context_hostname(call_data
);
458 /* find or create the current process */
459 child
= find_process_tid(<tngtop
, tid
, comm
);
461 child
= add_proc(<tngtop
, tid
, comm
, timestamp
, hostname
);
464 update_proc(child
, pid
, tid
, ppid
, vpid
, vtid
, vppid
, comm
, hostname
);
467 /* find or create the parent */
468 parent
= find_process_tid(<tngtop
, pid
, comm
);
470 parent
= add_proc(<tngtop
, pid
, comm
, timestamp
, hostname
);
475 /* attach the parent to the current process */
476 child
->threadparent
= parent
;
477 add_thread(parent
, child
);
480 update_perf_counter(child
, call_data
);
486 return BT_CB_ERROR_STOP
;
491 copies
= g_ptr_array_new();
492 global_perf_liszt
= g_hash_table_new(g_str_hash
, g_str_equal
);
493 global_filter_list
= g_hash_table_new(g_str_hash
, g_str_equal
);
494 global_host_list
= g_hash_table_new(g_str_hash
, g_str_equal
);
496 sem_init(&goodtodisplay
, 0, 0);
497 sem_init(&goodtoupdate
, 0, 1);
498 sem_init(&timer
, 0, 1);
499 sem_init(&bootstrap
, 0, 0);
500 sem_init(&pause_sem
, 0, 1);
501 sem_init(&end_trace_sem
, 0, 0);
503 reset_global_counters();
505 lttngtop
.nbthreads
= 0;
506 lttngtop
.nbfiles
= 0;
508 lttngtop
.process_hash_table
= g_hash_table_new(g_direct_hash
,
510 lttngtop
.process_table
= g_ptr_array_new();
511 lttngtop
.files_table
= g_ptr_array_new();
512 lttngtop
.cpu_table
= g_ptr_array_new();
519 fprintf(fp
, "LTTngTop %s\n\n", VERSION
);
520 fprintf(fp
, "Usage : lttngtop [OPTIONS] [TRACE]\n");
521 fprintf(fp
, " TRACE Path to the trace to analyse (no trace path for live tracing)\n");
522 fprintf(fp
, " -h, --help This help message\n");
523 fprintf(fp
, " -t, --textdump Display live events in text-only\n");
524 fprintf(fp
, " -p, --pid Comma-separated list of PIDs to display\n");
525 fprintf(fp
, " -f, --child Follow threads associated with selected PIDs\n");
526 fprintf(fp
, " -n, --hostname Comma-separated list of hostnames to display (require hostname context in trace)\n");
527 fprintf(fp
, " -k, --kprobes Comma-separated list of kprobes to insert (same format as lttng enable-event)\n");
531 * Parse probe options.
532 * Shamelessly stolen from lttng-tools :
533 * src/bin/lttng/commands/enable_events.c
535 static struct kprobes
*parse_probe_opts(char *opt
)
538 char name
[LTTNG_SYMBOL_NAME_LEN
];
539 struct kprobes
*kprobe
;
543 kprobe->probe_addr = 0;
544 kprobe->probe_offset = 0;
545 asprintf(&kprobe->probe_name, "probe_sys_open");
546 asprintf(&kprobe->symbol_name, "sys_open");
554 kprobe
= g_new0(struct kprobes
, 1);
556 /* Check for symbol+offset */
557 ret
= sscanf(opt
, "%[^'+']+%s", name
, s_hex
);
559 ret
= asprintf(&kprobe
->probe_name
, "probe_%s", name
);
560 ret
= asprintf(&kprobe
->symbol_name
, "%s", name
);
562 if (strlen(s_hex
) == 0) {
563 fprintf(stderr
, "Invalid probe offset %s", s_hex
);
567 kprobe
->probe_offset
= strtoul(s_hex
, NULL
, 0);
568 kprobe
->probe_addr
= 0;
572 /* Check for symbol */
573 if (isalpha(name
[0])) {
574 ret
= sscanf(opt
, "%s", name
);
576 ret
= asprintf(&kprobe
->probe_name
, "probe_%s", name
);
577 ret
= asprintf(&kprobe
->symbol_name
, "%s", name
);
578 kprobe
->probe_offset
= 0;
579 kprobe
->probe_addr
= 0;
584 /* Check for address */
585 ret
= sscanf(opt
, "%s", s_hex
);
587 if (strlen(s_hex
) == 0) {
588 fprintf(stderr
, "Invalid probe address %s", s_hex
);
592 ret
= asprintf(&kprobe
->probe_name
, "probe_%s", s_hex
);
593 kprobe
->probe_offset
= 0;
594 kprobe
->probe_addr
= strtoul(s_hex
, NULL
, 0);
606 * Return 0 if caller should continue, < 0 if caller should return
607 * error, > 0 if caller should exit without reporting error.
609 static int parse_options(int argc
, char **argv
)
618 pc
= poptGetContext(NULL
, argc
, (const char **) argv
, long_options
, 0);
619 poptReadDefaultConfig(pc
, 0);
621 while ((opt
= poptGetNextOpt(pc
)) != -1) {
625 ret
= 1; /* exit cleanly */
636 tid_filter_list
= g_hash_table_new(g_str_hash
,
638 tmp_str
= strtok(opt_tid
, ",");
640 tid
= malloc(sizeof(int));
641 *tid
= atoi(tmp_str
);
642 g_hash_table_insert(tid_filter_list
,
643 (gpointer
) tid
, tid
);
644 tmp_str
= strtok(NULL
, ",");
649 tmp_str
= strtok(opt_hostname
, ",");
651 add_hostname_list(tmp_str
, 1);
652 tmp_str
= strtok(NULL
, ",");
655 case OPT_RELAY_HOSTNAME
:
659 lttngtop
.kprobes_table
= g_ptr_array_new();
660 tmp_str
= strtok(opt_kprobes
, ",");
662 struct kprobes
*kprobe
;
664 kprobe
= parse_probe_opts(tmp_str
);
667 lttngtop
.kprobes_table
,
673 tmp_str
= strtok(NULL
, ",");
682 opt_input_path
= poptGetArg(pc
);
691 void iter_trace(struct bt_context
*bt_ctx
)
693 struct bt_ctf_iter
*iter
;
694 struct bt_iter_pos begin_pos
;
695 struct kprobes
*kprobe
;
696 const struct bt_ctf_event
*event
;
700 begin_pos
.type
= BT_SEEK_BEGIN
;
701 iter
= bt_ctf_iter_create(bt_ctx
, &begin_pos
, NULL
);
703 /* at each event, verify the status of the process table */
704 bt_ctf_iter_add_callback(iter
, 0, NULL
, 0,
708 bt_ctf_iter_add_callback(iter
, 0, NULL
, 0,
712 /* at each event check if we need to refresh */
713 bt_ctf_iter_add_callback(iter
, 0, NULL
, 0,
716 /* to handle the scheduling events */
717 bt_ctf_iter_add_callback(iter
,
718 g_quark_from_static_string("sched_switch"),
719 NULL
, 0, handle_sched_switch
, NULL
, NULL
, NULL
);
720 /* to clean up the process table */
721 bt_ctf_iter_add_callback(iter
,
722 g_quark_from_static_string("sched_process_free"),
723 NULL
, 0, handle_sched_process_free
, NULL
, NULL
, NULL
);
724 /* to get all the process from the statedumps */
725 bt_ctf_iter_add_callback(iter
,
726 g_quark_from_static_string(
727 "lttng_statedump_process_state"),
728 NULL
, 0, handle_statedump_process_state
,
732 bt_ctf_iter_add_callback(iter
,
733 g_quark_from_static_string("exit_syscall"),
734 NULL
, 0, handle_exit_syscall
, NULL
, NULL
, NULL
);
735 bt_ctf_iter_add_callback(iter
,
736 g_quark_from_static_string("sys_write"),
737 NULL
, 0, handle_sys_write
, NULL
, NULL
, NULL
);
738 bt_ctf_iter_add_callback(iter
,
739 g_quark_from_static_string("sys_read"),
740 NULL
, 0, handle_sys_read
, NULL
, NULL
, NULL
);
741 bt_ctf_iter_add_callback(iter
,
742 g_quark_from_static_string("sys_open"),
743 NULL
, 0, handle_sys_open
, NULL
, NULL
, NULL
);
744 bt_ctf_iter_add_callback(iter
,
745 g_quark_from_static_string("sys_close"),
746 NULL
, 0, handle_sys_close
, NULL
, NULL
, NULL
);
747 bt_ctf_iter_add_callback(iter
,
748 g_quark_from_static_string(
749 "lttng_statedump_file_descriptor"),
750 NULL
, 0, handle_statedump_file_descriptor
,
754 if (lttngtop
.kprobes_table
) {
755 for (i
= 0; i
< lttngtop
.kprobes_table
->len
; i
++) {
756 kprobe
= g_ptr_array_index(lttngtop
.kprobes_table
, i
);
757 bt_ctf_iter_add_callback(iter
,
758 g_quark_from_static_string(
760 NULL
, 0, handle_kprobes
,
766 while ((event
= bt_ctf_iter_read_event(iter
)) != NULL
) {
767 if (quit
|| reload_trace
)
769 ret
= bt_iter_next(bt_ctf_get_iter(iter
));
774 /* block until quit, we reached the end of the trace */
775 sem_wait(&end_trace_sem
);
778 bt_ctf_iter_destroy(iter
);
782 * bt_context_add_traces_recursive: Open a trace recursively
783 * (copied from BSD code in converter/babeltrace.c)
785 * Find each trace present in the subdirectory starting from the given
786 * path, and add them to the context. The packet_seek parameter can be
787 * NULL: this specify to use the default format packet_seek.
789 * Return: 0 on success, nonzero on failure.
790 * Unable to open toplevel: failure.
791 * Unable to open some subdirectory or file: warn and continue;
793 int bt_context_add_traces_recursive(struct bt_context
*ctx
, const char *path
,
794 const char *format_str
,
795 void (*packet_seek
)(struct bt_stream_pos
*pos
,
796 size_t offset
, int whence
))
801 char lpath
[PATH_MAX
];
802 char * const paths
[2] = { lpath
, NULL
};
806 * Need to copy path, because fts_open can change it.
807 * It is the pointer array, not the strings, that are constant.
809 strncpy(lpath
, path
, PATH_MAX
);
810 lpath
[PATH_MAX
- 1] = '\0';
812 tree
= fts_open(paths
, FTS_NOCHDIR
| FTS_LOGICAL
, 0);
814 fprintf(stderr
, "[error] [Context] Cannot traverse \"%s\" for reading.\n",
819 trace_ids
= g_array_new(FALSE
, TRUE
, sizeof(int));
821 while ((node
= fts_read(tree
))) {
824 if (!(node
->fts_info
& FTS_D
))
827 dirfd
= open(node
->fts_accpath
, 0);
829 fprintf(stderr
, "[error] [Context] Unable to open trace "
830 "directory file descriptor.\n");
834 metafd
= openat(dirfd
, "metadata", O_RDONLY
);
853 trace_id
= bt_context_add_trace(ctx
,
854 node
->fts_accpath
, format_str
,
855 packet_seek
, NULL
, NULL
);
857 fprintf(stderr
, "[warning] [Context] opening trace \"%s\" from %s "
858 "for reading.\n", node
->fts_accpath
, path
);
859 /* Allow to skip erroneous traces. */
862 g_array_append_val(trace_ids
, trace_id
);
866 g_array_free(trace_ids
, TRUE
);
873 static int check_field_requirements(const struct bt_ctf_field_decl
*const * field_list
,
874 int field_cnt
, int *tid_check
, int *pid_check
,
875 int *procname_check
, int *ppid_check
)
878 struct perfcounter
*global
;
881 for (j
= 0; j
< field_cnt
; j
++) {
882 name
= bt_ctf_get_decl_field_name(field_list
[j
]);
883 if (*tid_check
== 0) {
884 if (strncmp(name
, "tid", 3) == 0)
887 if (*pid_check
== 0) {
888 if (strncmp(name
, "pid", 3) == 0)
891 if (*ppid_check
== 0) {
892 if (strncmp(name
, "ppid", 4) == 0)
895 if (*procname_check
== 0) {
896 if (strncmp(name
, "procname", 8) == 0)
899 if (strncmp(name
, "perf_", 5) == 0) {
900 global
= g_hash_table_lookup(global_perf_liszt
, (gpointer
) name
);
902 global
= g_new0(struct perfcounter
, 1);
903 /* by default, sort on the first perf context */
904 if (g_hash_table_size(global_perf_liszt
) == 0)
907 g_hash_table_insert(global_perf_liszt
, (gpointer
) strdup(name
), global
);
912 if (*tid_check
== 1 && *pid_check
== 1 && *ppid_check
== 1 &&
913 *procname_check
== 1)
920 * check_requirements: check if the required context informations are available
922 * If each mandatory context information is available for at least in one
923 * event, return 0 otherwise return -1.
925 int check_requirements(struct bt_context
*ctx
)
927 unsigned int i
, evt_cnt
, field_cnt
;
928 struct bt_ctf_event_decl
*const * evt_list
;
929 const struct bt_ctf_field_decl
*const * field_list
;
932 int procname_check
= 0;
936 ret
= bt_ctf_get_event_decl_list(0, ctx
, &evt_list
, &evt_cnt
);
941 for (i
= 0; i
< evt_cnt
; i
++) {
942 bt_ctf_get_decl_fields(evt_list
[i
], BT_STREAM_EVENT_CONTEXT
,
943 &field_list
, &field_cnt
);
944 ret
= check_field_requirements(field_list
, field_cnt
,
945 &tid_check
, &pid_check
, &procname_check
,
948 bt_ctf_get_decl_fields(evt_list
[i
], BT_EVENT_CONTEXT
,
949 &field_list
, &field_cnt
);
950 ret
= check_field_requirements(field_list
, field_cnt
,
951 &tid_check
, &pid_check
, &procname_check
,
954 bt_ctf_get_decl_fields(evt_list
[i
], BT_STREAM_PACKET_CONTEXT
,
955 &field_list
, &field_cnt
);
956 ret
= check_field_requirements(field_list
, field_cnt
,
957 &tid_check
, &pid_check
, &procname_check
,
961 if (tid_check
== 0) {
963 fprintf(stderr
, "[error] missing tid context information\n");
965 if (pid_check
== 0) {
967 fprintf(stderr
, "[error] missing pid context information\n");
969 if (ppid_check
== 0) {
971 fprintf(stderr
, "[error] missing ppid context information\n");
973 if (procname_check
== 0) {
975 fprintf(stderr
, "[error] missing procname context information\n");
982 int main(int argc
, char **argv
)
985 struct bt_context
*bt_ctx
= NULL
;
988 ret
= parse_options(argc
, argv
);
990 fprintf(stdout
, "Error parsing options.\n\n");
993 } else if (ret
> 0) {
997 if (!opt_input_path
) {
999 signal(SIGTERM
, handle_textdump_sigterm
);
1000 signal(SIGINT
, handle_textdump_sigterm
);
1003 ret
= setup_network_live(opt_relay_hostname
);
1009 if (!opt_textdump
) {
1010 pthread_create(&display_thread
, NULL
, ncurses_display
, (void *) NULL
);
1011 pthread_create(&timer_thread
, NULL
, refresh_thread
, (void *) NULL
);
1014 ret
= open_trace(&bt_ctx
);
1019 ret
= check_requirements(bt_ctx
);
1021 fprintf(stderr
, "[error] some mandatory contexts were missing, exiting.\n");
1027 #ifdef LTTNGTOP_MMAP_LIVE
1028 mmap_live_loop(bt_ctx
);
1031 pthread_join(timer_thread
, NULL
);
1033 pthread_join(display_thread
, NULL
);
1035 lttng_stop_tracing("test");
1036 lttng_destroy_session("test");
1042 bt_ctx
= bt_context_create();
1043 ret
= bt_context_add_traces_recursive(bt_ctx
, opt_input_path
, "ctf", NULL
);
1045 fprintf(stderr
, "[error] Opening the trace\n");
1049 ret
= check_requirements(bt_ctx
);
1051 fprintf(stderr
, "[error] some mandatory contexts were missing, exiting.\n");
1054 pthread_create(&display_thread
, NULL
, ncurses_display
, (void *) NULL
);
1055 pthread_create(&timer_thread
, NULL
, refresh_thread
, (void *) NULL
);
1059 pthread_join(display_thread
, NULL
);
1061 pthread_join(timer_thread
, NULL
);
1066 bt_context_put(bt_ctx
);