2 * Copyright (C) 2013 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;
71 unsigned long last_event_ts
= 0;
73 /* list of FDs available for being read with snapshots */
74 struct bt_mmap_stream_list mmap_list
;
75 GPtrArray
*lttng_consumer_stream_array
;
76 int sessiond_metadata
, consumerd_metadata
;
77 struct lttng_consumer_local_data
*ctx
= NULL
;
78 /* list of snapshots currently not consumed */
79 GPtrArray
*available_snapshots
;
80 sem_t metadata_available
;
83 int last_textdump_print_newline
= 1;
96 static struct poptOption long_options
[] = {
97 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
98 { "help", 'h', POPT_ARG_NONE
, NULL
, OPT_HELP
, NULL
, NULL
},
99 { "textdump", 't', POPT_ARG_NONE
, NULL
, OPT_TEXTDUMP
, NULL
, NULL
},
100 { "child", 'f', POPT_ARG_NONE
, NULL
, OPT_CHILD
, NULL
, NULL
},
101 { "pid", 'p', POPT_ARG_STRING
, &opt_tid
, OPT_PID
, NULL
, NULL
},
102 { "hostname", 'n', POPT_ARG_STRING
, &opt_hostname
, OPT_HOSTNAME
, NULL
, NULL
},
103 { "relay-hostname", 'r', POPT_ARG_STRING
, &opt_relay_hostname
,
104 OPT_RELAY_HOSTNAME
, NULL
, NULL
},
105 { "kprobes", 'k', POPT_ARG_STRING
, &opt_kprobes
, OPT_KPROBES
, NULL
, NULL
},
106 { NULL
, 0, 0, NULL
, 0, NULL
, NULL
},
109 #ifdef LTTNGTOP_MMAP_LIVE
110 static void handle_textdump_sigterm(int signal
)
113 lttng_destroy_session("test");
117 void *refresh_thread(void *p
)
121 sem_post(&pause_sem
);
123 sem_post(&end_trace_sem
);
124 sem_post(&goodtodisplay
);
125 sem_post(&goodtoupdate
);
128 if (!opt_input_path
) {
129 #ifdef LTTNGTOP_MMAP_LIVE
130 mmap_live_flush(mmap_list
);
133 sem_wait(&pause_sem
);
134 sem_post(&pause_sem
);
136 sleep(refresh_display
/NSEC_PER_SEC
);
140 void *ncurses_display(void *p
)
142 unsigned int current_display_index
= 0;
144 sem_wait(&bootstrap
);
146 * Prevent the 1 second delay when we hit ESC
153 sem_wait(&goodtodisplay
);
154 sem_wait(&pause_sem
);
157 sem_post(&pause_sem
);
163 copy
= g_ptr_array_index(copies
, current_display_index
);
165 display(current_display_index
++);
167 sem_post(&goodtoupdate
);
168 sem_post(&pause_sem
);
172 void print_fields(struct bt_ctf_event
*event
)
175 const struct bt_definition
*const * list
;
176 const struct bt_declaration
*l
;
177 const struct bt_definition
*scope
;
178 enum ctf_type_id type
;
181 scope
= bt_ctf_get_top_level_scope(event
, BT_EVENT_FIELDS
);
183 bt_ctf_get_field_list(event
, scope
, &list
, &cnt
);
184 for (i
= 0; i
< cnt
; i
++) {
187 printf("%s = ", bt_ctf_field_name(list
[i
]));
188 l
= bt_ctf_get_decl_from_def(list
[i
]);
189 type
= bt_ctf_field_type(l
);
190 if (type
== CTF_TYPE_INTEGER
) {
191 if (bt_ctf_get_int_signedness(l
) == 0)
192 printf("%" PRIu64
"", bt_ctf_get_uint64(list
[i
]));
194 printf("%" PRId64
"", bt_ctf_get_int64(list
[i
]));
195 } else if (type
== CTF_TYPE_STRING
) {
196 printf("%s", bt_ctf_get_string(list
[i
]));
197 } else if (type
== CTF_TYPE_ARRAY
) {
198 str
= bt_ctf_get_char_array(list
[i
]);
199 if (!bt_ctf_field_get_error() && str
)
206 * hook on each event to check the timestamp and refresh the display if
209 enum bt_cb_ret
print_timestamp(struct bt_ctf_event
*call_data
, void *private_data
)
211 unsigned long timestamp
;
213 uint64_t ts_nsec_start
;
216 const struct bt_definition
*scope
;
217 const char *hostname
, *procname
;
219 timestamp
= bt_ctf_get_timestamp(call_data
);
221 /* can happen in network live when tracing is idle */
222 if (timestamp
< last_event_ts
)
225 last_event_ts
= timestamp
;
227 start
= format_timestamp(timestamp
);
228 ts_nsec_start
= timestamp
% NSEC_PER_SEC
;
230 pid
= get_context_pid(call_data
);
231 if (pid
== -1ULL && opt_tid
) {
235 hostname
= get_context_hostname(call_data
);
236 if (opt_tid
|| opt_hostname
)
237 if (!lookup_filter_tid_list(pid
))
240 cpu_id
= get_cpu_id(call_data
);
241 procname
= get_context_comm(call_data
);
243 if ((strcmp(bt_ctf_event_name(call_data
), "exit_syscall") == 0) &&
244 !last_textdump_print_newline
) {
245 scope
= bt_ctf_get_top_level_scope(call_data
,
247 syscall_ret
= bt_ctf_get_int64(bt_ctf_get_field(call_data
,
249 printf("= %ld\n", syscall_ret
);
250 last_textdump_print_newline
= 1;
252 /* we might have lost the exit_syscall event, so need to
253 * print the newline in this case */
254 if (last_textdump_print_newline
== 0)
256 printf("%02d:%02d:%02d.%09" PRIu64
" (%s) (cpu %d) [%s (%d)] %s (",
257 start
.tm_hour
, start
.tm_min
, start
.tm_sec
,
258 ts_nsec_start
, hostname
, cpu_id
, procname
, pid
,
259 bt_ctf_event_name(call_data
));
260 print_fields(call_data
);
262 if (strncmp(bt_ctf_event_name(call_data
), "sys_", 4) != 0) {
264 last_textdump_print_newline
= 1;
266 last_textdump_print_newline
= 0;
273 return BT_CB_ERROR_STOP
;
275 return BT_CB_OK_STOP
;
278 enum bt_cb_ret
handle_kprobes(struct bt_ctf_event
*call_data
, void *private_data
)
281 struct kprobes
*kprobe
;
284 for (i
= 0; i
< lttngtop
.kprobes_table
->len
; i
++) {
285 kprobe
= g_ptr_array_index(lttngtop
.kprobes_table
, i
);
286 if (strcmp(bt_ctf_event_name(call_data
), kprobe
->probe_name
) == 0) {
295 * hook on each event to check the timestamp and refresh the display if
298 enum bt_cb_ret
check_timestamp(struct bt_ctf_event
*call_data
, void *private_data
)
300 unsigned long timestamp
;
302 timestamp
= bt_ctf_get_timestamp(call_data
);
303 if (timestamp
== -1ULL)
306 /* can happen in network live when tracing is idle */
307 if (timestamp
< last_event_ts
)
310 last_event_ts
= timestamp
;
312 if (last_display_update
== 0)
313 last_display_update
= timestamp
;
315 if (timestamp
- last_display_update
>= refresh_display
) {
316 sem_wait(&goodtoupdate
);
317 g_ptr_array_add(copies
, get_copy_lttngtop(last_display_update
,
319 sem_post(&goodtodisplay
);
320 sem_post(&bootstrap
);
321 last_display_update
= timestamp
;
326 fprintf(stderr
, "check_timestamp callback error\n");
327 return BT_CB_ERROR_STOP
;
330 return BT_CB_OK_STOP
;
334 * get_perf_counter : get or create and return a perf_counter struct for
335 * either a process or a cpu (only one of the 2 parameters mandatory)
337 struct perfcounter
*get_perf_counter(const char *name
, struct processtop
*proc
,
340 struct perfcounter
*ret
;
350 ret
= g_hash_table_lookup(table
, (gpointer
) name
);
354 ret
= g_new0(struct perfcounter
, 1);
355 /* by default, make it visible in the UI */
357 g_hash_table_insert(table
, (gpointer
) strdup(name
), ret
);
366 void update_perf_value(struct processtop
*proc
, struct cputime
*cpu
,
367 const char *name
, int value
)
369 struct perfcounter
*cpu_perf
, *process_perf
;
371 cpu_perf
= get_perf_counter(name
, NULL
, cpu
);
372 if (cpu_perf
->count
< value
) {
373 process_perf
= get_perf_counter(name
, proc
, NULL
);
374 process_perf
->count
+= value
- cpu_perf
->count
;
375 cpu_perf
->count
= value
;
379 void extract_perf_counter_scope(const struct bt_ctf_event
*event
,
380 const struct bt_definition
*scope
,
381 struct processtop
*proc
,
384 struct bt_definition
const * const *list
= NULL
;
385 const struct bt_definition
*field
;
387 struct perfcounter
*perfcounter
;
395 ret
= bt_ctf_get_field_list(event
, scope
, &list
, &count
);
402 g_hash_table_iter_init(&iter
, global_perf_liszt
);
403 while (g_hash_table_iter_next (&iter
, &key
, (gpointer
) &perfcounter
)) {
404 field
= bt_ctf_get_field(event
, scope
, (char *) key
);
406 int value
= bt_ctf_get_uint64(field
);
407 if (bt_ctf_field_get_error())
409 update_perf_value(proc
, cpu
, (char *) key
, value
);
417 void update_perf_counter(struct processtop
*proc
, const struct bt_ctf_event
*event
)
420 const struct bt_definition
*scope
;
422 cpu
= get_cpu(get_cpu_id(event
));
424 scope
= bt_ctf_get_top_level_scope(event
, BT_STREAM_EVENT_CONTEXT
);
425 extract_perf_counter_scope(event
, scope
, proc
, cpu
);
427 scope
= bt_ctf_get_top_level_scope(event
, BT_STREAM_PACKET_CONTEXT
);
428 extract_perf_counter_scope(event
, scope
, proc
, cpu
);
430 scope
= bt_ctf_get_top_level_scope(event
, BT_EVENT_CONTEXT
);
431 extract_perf_counter_scope(event
, scope
, proc
, cpu
);
434 enum bt_cb_ret
fix_process_table(struct bt_ctf_event
*call_data
,
437 int pid
, tid
, ppid
, vpid
, vtid
, vppid
;
438 char *comm
, *hostname
;
439 struct processtop
*parent
, *child
;
440 unsigned long timestamp
;
442 timestamp
= bt_ctf_get_timestamp(call_data
);
443 if (timestamp
== -1ULL)
446 pid
= get_context_pid(call_data
);
451 tid
= get_context_tid(call_data
);
455 ppid
= get_context_ppid(call_data
);
459 vpid
= get_context_vpid(call_data
);
463 vtid
= get_context_vtid(call_data
);
467 vppid
= get_context_vppid(call_data
);
471 comm
= get_context_comm(call_data
);
476 hostname
= get_context_hostname(call_data
);
478 /* find or create the current process */
479 child
= find_process_tid(<tngtop
, tid
, comm
);
481 child
= add_proc(<tngtop
, tid
, comm
, timestamp
, hostname
);
484 update_proc(child
, pid
, tid
, ppid
, vpid
, vtid
, vppid
, comm
, hostname
);
487 /* find or create the parent */
488 parent
= find_process_tid(<tngtop
, pid
, comm
);
490 parent
= add_proc(<tngtop
, pid
, comm
, timestamp
, hostname
);
495 /* attach the parent to the current process */
496 child
->threadparent
= parent
;
497 add_thread(parent
, child
);
500 update_perf_counter(child
, call_data
);
506 return BT_CB_ERROR_STOP
;
511 copies
= g_ptr_array_new();
512 global_perf_liszt
= g_hash_table_new(g_str_hash
, g_str_equal
);
513 global_filter_list
= g_hash_table_new(g_str_hash
, g_str_equal
);
514 global_host_list
= g_hash_table_new(g_str_hash
, g_str_equal
);
516 sem_init(&goodtodisplay
, 0, 0);
517 sem_init(&goodtoupdate
, 0, 1);
518 sem_init(&timer
, 0, 1);
519 sem_init(&bootstrap
, 0, 0);
520 sem_init(&pause_sem
, 0, 1);
521 sem_init(&end_trace_sem
, 0, 0);
523 reset_global_counters();
525 lttngtop
.nbthreads
= 0;
526 lttngtop
.nbfiles
= 0;
528 lttngtop
.process_hash_table
= g_hash_table_new(g_direct_hash
,
530 lttngtop
.process_table
= g_ptr_array_new();
531 lttngtop
.files_table
= g_ptr_array_new();
532 lttngtop
.cpu_table
= g_ptr_array_new();
539 fprintf(fp
, "LTTngTop %s\n\n", VERSION
);
540 fprintf(fp
, "Usage : lttngtop [OPTIONS] [TRACE]\n");
541 fprintf(fp
, " TRACE Path to the trace to analyse (no trace path for live tracing)\n");
542 fprintf(fp
, " -h, --help This help message\n");
543 fprintf(fp
, " -t, --textdump Display live events in text-only\n");
544 fprintf(fp
, " -p, --pid Comma-separated list of PIDs to display\n");
545 fprintf(fp
, " -f, --child Follow threads associated with selected PIDs\n");
546 fprintf(fp
, " -n, --hostname Comma-separated list of hostnames to display (require hostname context in trace)\n");
547 fprintf(fp
, " -k, --kprobes Comma-separated list of kprobes to insert (same format as lttng enable-event)\n");
551 * Parse probe options.
552 * Shamelessly stolen from lttng-tools :
553 * src/bin/lttng/commands/enable_events.c
555 static struct kprobes
*parse_probe_opts(char *opt
)
558 char name
[LTTNG_SYMBOL_NAME_LEN
];
559 struct kprobes
*kprobe
;
563 kprobe->probe_addr = 0;
564 kprobe->probe_offset = 0;
565 asprintf(&kprobe->probe_name, "probe_sys_open");
566 asprintf(&kprobe->symbol_name, "sys_open");
574 kprobe
= g_new0(struct kprobes
, 1);
576 /* Check for symbol+offset */
577 ret
= sscanf(opt
, "%[^'+']+%s", name
, s_hex
);
579 ret
= asprintf(&kprobe
->probe_name
, "probe_%s", name
);
580 ret
= asprintf(&kprobe
->symbol_name
, "%s", name
);
582 if (strlen(s_hex
) == 0) {
583 fprintf(stderr
, "Invalid probe offset %s", s_hex
);
587 kprobe
->probe_offset
= strtoul(s_hex
, NULL
, 0);
588 kprobe
->probe_addr
= 0;
592 /* Check for symbol */
593 if (isalpha(name
[0])) {
594 ret
= sscanf(opt
, "%s", name
);
596 ret
= asprintf(&kprobe
->probe_name
, "probe_%s", name
);
597 ret
= asprintf(&kprobe
->symbol_name
, "%s", name
);
598 kprobe
->probe_offset
= 0;
599 kprobe
->probe_addr
= 0;
604 /* Check for address */
605 ret
= sscanf(opt
, "%s", s_hex
);
607 if (strlen(s_hex
) == 0) {
608 fprintf(stderr
, "Invalid probe address %s", s_hex
);
612 ret
= asprintf(&kprobe
->probe_name
, "probe_%s", s_hex
);
613 kprobe
->probe_offset
= 0;
614 kprobe
->probe_addr
= strtoul(s_hex
, NULL
, 0);
626 * Return 0 if caller should continue, < 0 if caller should return
627 * error, > 0 if caller should exit without reporting error.
629 static int parse_options(int argc
, char **argv
)
638 pc
= poptGetContext(NULL
, argc
, (const char **) argv
, long_options
, 0);
639 poptReadDefaultConfig(pc
, 0);
641 while ((opt
= poptGetNextOpt(pc
)) != -1) {
645 ret
= 1; /* exit cleanly */
656 tid_filter_list
= g_hash_table_new(g_str_hash
,
658 tmp_str
= strtok(opt_tid
, ",");
660 tid
= malloc(sizeof(int));
661 *tid
= atoi(tmp_str
);
662 g_hash_table_insert(tid_filter_list
,
663 (gpointer
) tid
, tid
);
664 tmp_str
= strtok(NULL
, ",");
669 tmp_str
= strtok(opt_hostname
, ",");
671 add_hostname_list(tmp_str
, 1);
672 tmp_str
= strtok(NULL
, ",");
675 case OPT_RELAY_HOSTNAME
:
679 lttngtop
.kprobes_table
= g_ptr_array_new();
680 tmp_str
= strtok(opt_kprobes
, ",");
682 struct kprobes
*kprobe
;
684 kprobe
= parse_probe_opts(tmp_str
);
687 lttngtop
.kprobes_table
,
693 tmp_str
= strtok(NULL
, ",");
702 opt_input_path
= poptGetArg(pc
);
711 void iter_trace(struct bt_context
*bt_ctx
)
713 struct bt_ctf_iter
*iter
;
714 struct bt_iter_pos begin_pos
;
715 struct kprobes
*kprobe
;
716 const struct bt_ctf_event
*event
;
720 begin_pos
.type
= BT_SEEK_BEGIN
;
721 iter
= bt_ctf_iter_create(bt_ctx
, &begin_pos
, NULL
);
723 /* at each event, verify the status of the process table */
724 bt_ctf_iter_add_callback(iter
, 0, NULL
, 0,
728 bt_ctf_iter_add_callback(iter
, 0, NULL
, 0,
732 /* at each event check if we need to refresh */
733 bt_ctf_iter_add_callback(iter
, 0, NULL
, 0,
736 /* to handle the scheduling events */
737 bt_ctf_iter_add_callback(iter
,
738 g_quark_from_static_string("sched_switch"),
739 NULL
, 0, handle_sched_switch
, NULL
, NULL
, NULL
);
740 /* to clean up the process table */
741 bt_ctf_iter_add_callback(iter
,
742 g_quark_from_static_string("sched_process_free"),
743 NULL
, 0, handle_sched_process_free
, NULL
, NULL
, NULL
);
744 /* to get all the process from the statedumps */
745 bt_ctf_iter_add_callback(iter
,
746 g_quark_from_static_string(
747 "lttng_statedump_process_state"),
748 NULL
, 0, handle_statedump_process_state
,
752 bt_ctf_iter_add_callback(iter
,
753 g_quark_from_static_string("exit_syscall"),
754 NULL
, 0, handle_exit_syscall
, NULL
, NULL
, NULL
);
755 bt_ctf_iter_add_callback(iter
,
756 g_quark_from_static_string("sys_write"),
757 NULL
, 0, handle_sys_write
, NULL
, NULL
, NULL
);
758 bt_ctf_iter_add_callback(iter
,
759 g_quark_from_static_string("sys_read"),
760 NULL
, 0, handle_sys_read
, NULL
, NULL
, NULL
);
761 bt_ctf_iter_add_callback(iter
,
762 g_quark_from_static_string("sys_open"),
763 NULL
, 0, handle_sys_open
, NULL
, NULL
, NULL
);
764 bt_ctf_iter_add_callback(iter
,
765 g_quark_from_static_string("sys_close"),
766 NULL
, 0, handle_sys_close
, NULL
, NULL
, NULL
);
767 bt_ctf_iter_add_callback(iter
,
768 g_quark_from_static_string(
769 "lttng_statedump_file_descriptor"),
770 NULL
, 0, handle_statedump_file_descriptor
,
774 if (lttngtop
.kprobes_table
) {
775 for (i
= 0; i
< lttngtop
.kprobes_table
->len
; i
++) {
776 kprobe
= g_ptr_array_index(lttngtop
.kprobes_table
, i
);
777 bt_ctf_iter_add_callback(iter
,
778 g_quark_from_static_string(
780 NULL
, 0, handle_kprobes
,
786 while ((event
= bt_ctf_iter_read_event(iter
)) != NULL
) {
787 if (quit
|| reload_trace
)
789 ret
= bt_iter_next(bt_ctf_get_iter(iter
));
794 /* block until quit, we reached the end of the trace */
795 sem_wait(&end_trace_sem
);
798 bt_ctf_iter_destroy(iter
);
802 * bt_context_add_traces_recursive: Open a trace recursively
803 * (copied from BSD code in converter/babeltrace.c)
805 * Find each trace present in the subdirectory starting from the given
806 * path, and add them to the context. The packet_seek parameter can be
807 * NULL: this specify to use the default format packet_seek.
809 * Return: 0 on success, nonzero on failure.
810 * Unable to open toplevel: failure.
811 * Unable to open some subdirectory or file: warn and continue;
813 int bt_context_add_traces_recursive(struct bt_context
*ctx
, const char *path
,
814 const char *format_str
,
815 void (*packet_seek
)(struct bt_stream_pos
*pos
,
816 size_t offset
, int whence
))
821 char lpath
[PATH_MAX
];
822 char * const paths
[2] = { lpath
, NULL
};
826 * Need to copy path, because fts_open can change it.
827 * It is the pointer array, not the strings, that are constant.
829 strncpy(lpath
, path
, PATH_MAX
);
830 lpath
[PATH_MAX
- 1] = '\0';
832 tree
= fts_open(paths
, FTS_NOCHDIR
| FTS_LOGICAL
, 0);
834 fprintf(stderr
, "[error] [Context] Cannot traverse \"%s\" for reading.\n",
839 trace_ids
= g_array_new(FALSE
, TRUE
, sizeof(int));
841 while ((node
= fts_read(tree
))) {
844 if (!(node
->fts_info
& FTS_D
))
847 dirfd
= open(node
->fts_accpath
, 0);
849 fprintf(stderr
, "[error] [Context] Unable to open trace "
850 "directory file descriptor.\n");
854 metafd
= openat(dirfd
, "metadata", O_RDONLY
);
873 trace_id
= bt_context_add_trace(ctx
,
874 node
->fts_accpath
, format_str
,
875 packet_seek
, NULL
, NULL
);
877 fprintf(stderr
, "[warning] [Context] opening trace \"%s\" from %s "
878 "for reading.\n", node
->fts_accpath
, path
);
879 /* Allow to skip erroneous traces. */
882 g_array_append_val(trace_ids
, trace_id
);
886 g_array_free(trace_ids
, TRUE
);
893 static int check_field_requirements(const struct bt_ctf_field_decl
*const * field_list
,
894 int field_cnt
, int *tid_check
, int *pid_check
,
895 int *procname_check
, int *ppid_check
)
898 struct perfcounter
*global
;
901 for (j
= 0; j
< field_cnt
; j
++) {
902 name
= bt_ctf_get_decl_field_name(field_list
[j
]);
903 if (*tid_check
== 0) {
904 if (strncmp(name
, "tid", 3) == 0)
907 if (*pid_check
== 0) {
908 if (strncmp(name
, "pid", 3) == 0)
911 if (*ppid_check
== 0) {
912 if (strncmp(name
, "ppid", 4) == 0)
915 if (*procname_check
== 0) {
916 if (strncmp(name
, "procname", 8) == 0)
919 if (strncmp(name
, "perf_", 5) == 0) {
920 global
= g_hash_table_lookup(global_perf_liszt
, (gpointer
) name
);
922 global
= g_new0(struct perfcounter
, 1);
923 /* by default, sort on the first perf context */
924 if (g_hash_table_size(global_perf_liszt
) == 0)
927 g_hash_table_insert(global_perf_liszt
, (gpointer
) strdup(name
), global
);
932 if (*tid_check
== 1 && *pid_check
== 1 && *ppid_check
== 1 &&
933 *procname_check
== 1)
940 * check_requirements: check if the required context informations are available
942 * If each mandatory context information is available for at least in one
943 * event, return 0 otherwise return -1.
945 int check_requirements(struct bt_context
*ctx
)
947 unsigned int i
, evt_cnt
, field_cnt
;
948 struct bt_ctf_event_decl
*const * evt_list
;
949 const struct bt_ctf_field_decl
*const * field_list
;
952 int procname_check
= 0;
956 ret
= bt_ctf_get_event_decl_list(0, ctx
, &evt_list
, &evt_cnt
);
961 for (i
= 0; i
< evt_cnt
; i
++) {
962 bt_ctf_get_decl_fields(evt_list
[i
], BT_STREAM_EVENT_CONTEXT
,
963 &field_list
, &field_cnt
);
964 ret
= check_field_requirements(field_list
, field_cnt
,
965 &tid_check
, &pid_check
, &procname_check
,
968 bt_ctf_get_decl_fields(evt_list
[i
], BT_EVENT_CONTEXT
,
969 &field_list
, &field_cnt
);
970 ret
= check_field_requirements(field_list
, field_cnt
,
971 &tid_check
, &pid_check
, &procname_check
,
974 bt_ctf_get_decl_fields(evt_list
[i
], BT_STREAM_PACKET_CONTEXT
,
975 &field_list
, &field_cnt
);
976 ret
= check_field_requirements(field_list
, field_cnt
,
977 &tid_check
, &pid_check
, &procname_check
,
981 if (tid_check
== 0) {
983 fprintf(stderr
, "[error] missing tid context information\n");
985 if (pid_check
== 0) {
987 fprintf(stderr
, "[error] missing pid context information\n");
989 if (ppid_check
== 0) {
991 fprintf(stderr
, "[error] missing ppid context information\n");
993 if (procname_check
== 0) {
995 fprintf(stderr
, "[error] missing procname context information\n");
1002 int main(int argc
, char **argv
)
1005 struct bt_context
*bt_ctx
= NULL
;
1008 ret
= parse_options(argc
, argv
);
1010 fprintf(stdout
, "Error parsing options.\n\n");
1013 } else if (ret
> 0) {
1017 if (!opt_input_path
&& !remote_live
) {
1019 #ifdef LTTNGTOP_MMAP_LIVE
1021 signal(SIGTERM
, handle_textdump_sigterm
);
1022 signal(SIGINT
, handle_textdump_sigterm
);
1024 mmap_live_loop(bt_ctx
);
1025 pthread_join(timer_thread
, NULL
);
1027 pthread_join(display_thread
, NULL
);
1029 lttng_stop_tracing("test");
1030 lttng_destroy_session("test");
1034 fprintf(stderr
, "Mmap live support not compiled\n");
1036 #endif /* LTTNGTOP_MMAP_LIVE */
1037 } else if (!opt_input_path
&& remote_live
) {
1039 ret
= setup_network_live(opt_relay_hostname
);
1044 ret
= open_trace(&bt_ctx
);
1051 bt_ctx
= bt_context_create();
1052 ret
= bt_context_add_traces_recursive(bt_ctx
, opt_input_path
, "ctf", NULL
);
1054 fprintf(stderr
, "[error] Opening the trace\n");
1059 ret
= check_requirements(bt_ctx
);
1061 fprintf(stderr
, "[error] some mandatory contexts were missing, exiting.\n");
1064 if (!opt_textdump
) {
1065 pthread_create(&display_thread
, NULL
, ncurses_display
, (void *) NULL
);
1066 pthread_create(&timer_thread
, NULL
, refresh_thread
, (void *) NULL
);
1071 pthread_join(display_thread
, NULL
);
1073 pthread_join(timer_thread
, NULL
);
1077 bt_context_put(bt_ctx
);