c3596aa23f697a5c487ddf0004b03e578b279f96
[lttngtop.git] / src / lttngtop.c
1 /*
2 * Copyright (C) 2013 Julien Desfossez
3 *
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;
7 *
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.
12 *
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.
16 */
17
18 #define _GNU_SOURCE
19 #include <config.h>
20 #include <stdio.h>
21 #include <stdint.h>
22 #include <babeltrace/babeltrace.h>
23 #include <babeltrace/ctf/events.h>
24 #include <babeltrace/ctf/callbacks.h>
25 #include <babeltrace/ctf/iterator.h>
26 #include <fcntl.h>
27 #include <pthread.h>
28 #include <popt.h>
29 #include <stdlib.h>
30 #include <ftw.h>
31 #include <dirent.h>
32 #include <ctype.h>
33 #include <sys/stat.h>
34 #include <unistd.h>
35 #include <string.h>
36 #include <errno.h>
37 #include <sys/types.h>
38 #include <fts.h>
39 #include <assert.h>
40 #include <sys/mman.h>
41 #include <sys/wait.h>
42 #include <lttng/lttng.h>
43
44 #ifdef LTTNGTOP_MMAP_LIVE
45 #include <lttng/lttngtop-helper.h>
46 #include <babeltrace/lttngtopmmappacketseek.h>
47 #include "mmap-live.h"
48 #endif /* LTTNGTOP_MMAP_LIVE */
49
50 #include "lttngtoptypes.h"
51 #include "cputop.h"
52 #include "iostreamtop.h"
53 #include "common.h"
54 #include "network-live.h"
55 #include "lttng-session.h"
56
57 #ifdef HAVE_LIBNCURSES
58 #include "cursesdisplay.h"
59 #endif
60
61 #define NET_URL_PREFIX "net://"
62 #define NET4_URL_PREFIX "net4://"
63 #define NET6_URL_PREFIX "net6://"
64
65 #define DEFAULT_FILE_ARRAY_SIZE 1
66
67 const char *opt_input_path;
68 int opt_textdump;
69 int opt_child;
70 int opt_begin;
71 int opt_all;
72
73 int quit = 0;
74 /* We need at least one valid trace to start processing. */
75 int valid_trace = 0;
76
77 struct lttngtop *copy;
78 pthread_t display_thread;
79 pthread_t timer_thread;
80
81 unsigned long refresh_display = 1 * NSEC_PER_SEC;
82 unsigned long last_display_update = 0;
83 unsigned long last_event_ts = 0;
84 struct syscall *last_syscall;
85
86 /* list of FDs available for being read with snapshots */
87 struct bt_mmap_stream_list mmap_list;
88 GPtrArray *lttng_consumer_stream_array;
89 int sessiond_metadata, consumerd_metadata;
90 struct lttng_consumer_local_data *ctx = NULL;
91 /* list of snapshots currently not consumed */
92 GPtrArray *available_snapshots;
93 sem_t metadata_available;
94 int reload_trace = 0;
95
96 uint64_t prev_ts = 0;
97
98 enum {
99 OPT_NONE = 0,
100 OPT_HELP,
101 OPT_TEXTDUMP,
102 OPT_PID,
103 OPT_CHILD,
104 OPT_PROCNAME,
105 OPT_RELAY_HOSTNAME,
106 OPT_KPROBES,
107 OPT_BEGIN,
108 OPT_ALL,
109 OPT_OUTPUT_FILE,
110 OPT_VERBOSE,
111 OPT_GUI_TEST,
112 OPT_CREATE_LOCAL_SESSION,
113 OPT_CREATE_LIVE_SESSION,
114 };
115
116 static struct poptOption long_options[] = {
117 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
118 { "help", 'h', POPT_ARG_NONE, NULL, OPT_HELP, NULL, NULL },
119 { "textdump", 't', POPT_ARG_NONE, NULL, OPT_TEXTDUMP, NULL, NULL },
120 { "child", 'f', POPT_ARG_NONE, NULL, OPT_CHILD, NULL, NULL },
121 { "begin", 'b', POPT_ARG_NONE, NULL, OPT_BEGIN, NULL, NULL },
122 { "pid", 'p', POPT_ARG_STRING, &opt_tid, OPT_PID, NULL, NULL },
123 { "procname", 'n', POPT_ARG_STRING, &opt_procname, OPT_PROCNAME, NULL, NULL },
124 { "relay-hostname", 'r', POPT_ARG_STRING, &opt_relay_hostname,
125 OPT_RELAY_HOSTNAME, NULL, NULL },
126 { "kprobes", 'k', POPT_ARG_STRING, &opt_kprobes, OPT_KPROBES, NULL, NULL },
127 { "all", 'a', POPT_ARG_NONE, NULL, OPT_ALL, NULL, NULL },
128 { "output", 'o', POPT_ARG_STRING, &opt_output, OPT_OUTPUT_FILE, NULL, NULL },
129 { "verbose", 'v', POPT_ARG_NONE, NULL, OPT_VERBOSE, NULL, NULL },
130 { "gui-test", 'g', POPT_ARG_NONE, NULL, OPT_GUI_TEST, NULL, NULL },
131 { "create-local-session", 0, POPT_ARG_NONE, NULL, OPT_CREATE_LOCAL_SESSION, NULL, NULL },
132 { "create-live-session", 0, POPT_ARG_NONE, NULL, OPT_CREATE_LIVE_SESSION, NULL, NULL },
133 { NULL, 0, 0, NULL, 0, NULL, NULL },
134 };
135
136 #ifdef LTTNGTOP_MMAP_LIVE
137 static void handle_textdump_sigterm(int signal)
138 {
139 quit = 1;
140 lttng_destroy_session("test");
141 }
142 #endif
143
144 void *refresh_thread(void *p)
145 {
146 while (1) {
147 if (quit) {
148 sem_post(&pause_sem);
149 sem_post(&timer);
150 sem_post(&end_trace_sem);
151 sem_post(&goodtodisplay);
152 sem_post(&goodtoupdate);
153 pthread_exit(0);
154 }
155 if (!opt_input_path) {
156 #ifdef LTTNGTOP_MMAP_LIVE
157 mmap_live_flush(mmap_list);
158 #endif
159 }
160 sem_wait(&pause_sem);
161 sem_post(&pause_sem);
162 sem_post(&timer);
163 sleep(refresh_display/NSEC_PER_SEC);
164 }
165 }
166
167 #ifdef HAVE_LIBNCURSES
168 void *ncurses_display(void *p)
169 {
170 unsigned int current_display_index = 0;
171
172 sem_wait(&bootstrap);
173 /*
174 * Prevent the 1 second delay when we hit ESC
175 */
176 ESCDELAY = 0;
177 init_ncurses();
178
179 while (1) {
180 sem_wait(&timer);
181 sem_wait(&goodtodisplay);
182 sem_wait(&pause_sem);
183
184 if (quit) {
185 sem_post(&pause_sem);
186 sem_post(&timer);
187 reset_ncurses();
188 pthread_exit(0);
189 }
190
191 copy = g_ptr_array_index(copies, current_display_index);
192 assert(copy);
193 display(current_display_index++);
194
195 sem_post(&goodtoupdate);
196 sem_post(&pause_sem);
197 }
198 }
199 #endif /* HAVE_LIBNCURSES */
200
201 void print_fields(struct bt_ctf_event *event, const char *procname,
202 int pid)
203 {
204 unsigned int cnt, i;
205 const struct bt_definition *const * list;
206 const struct bt_declaration *l;
207 const struct bt_definition *scope;
208 enum ctf_type_id type;
209 const char *str;
210 struct processtop *current_proc;
211 struct files *current_file;
212 int fd, fd_value = -1;
213
214 scope = bt_ctf_get_top_level_scope(event, BT_EVENT_FIELDS);
215
216 bt_ctf_get_field_list(event, scope, &list, &cnt);
217 for (i = 0; i < cnt; i++) {
218 if (i != 0)
219 fprintf(output, ", ");
220 fprintf(output, "%s = ", bt_ctf_field_name(list[i]));
221 l = bt_ctf_get_decl_from_def(list[i]);
222 if (strncmp(bt_ctf_field_name(list[i]), "fd", 2) == 0)
223 fd = 1;
224 else
225 fd = 0;
226 type = bt_ctf_field_type(l);
227 if (type == CTF_TYPE_INTEGER) {
228 if (bt_ctf_get_int_signedness(l) == 0) {
229 fd_value = bt_ctf_get_uint64(list[i]);
230 fprintf(output, "%" PRIu64, bt_ctf_get_uint64(list[i]));
231 } else {
232 fd_value = bt_ctf_get_int64(list[i]);
233 fprintf(output, "%" PRId64, bt_ctf_get_int64(list[i]));
234 }
235 } else if (type == CTF_TYPE_STRING) {
236 fprintf(output, "%s", bt_ctf_get_string(list[i]));
237 } else if (type == CTF_TYPE_ARRAY) {
238 str = bt_ctf_get_char_array(list[i]);
239 if (!bt_ctf_field_get_error() && str)
240 fprintf(output, "%s", str);
241 }
242 if (fd) {
243 current_proc = find_process_tid(&lttngtop, pid, procname);
244 if (!current_proc)
245 continue;
246 current_file = get_file(current_proc, fd_value);
247 if (!current_file || !current_file->name)
248 continue;
249 fprintf(output, "<%s>", current_file->name);
250 }
251 }
252 }
253
254 /*
255 * hook on each event to check the timestamp and refresh the display if
256 * necessary
257 */
258 enum bt_cb_ret textdump(struct bt_ctf_event *call_data, void *private_data)
259 {
260 unsigned long timestamp;
261 uint64_t delta;
262 struct tm start;
263 uint64_t ts_nsec_start;
264 int pid, cpu_id, tid, ret, lookup, current_syscall = 0;
265 const struct bt_definition *scope;
266 const char *hostname, *procname;
267 struct cputime *cpu;
268 char *from_syscall = NULL;
269 int syscall_exit = 0;
270
271 timestamp = bt_ctf_get_timestamp(call_data);
272
273 /* can happen in network live when tracing is idle */
274 if (timestamp < last_event_ts)
275 goto end_stop;
276
277 last_event_ts = timestamp;
278
279 start = format_timestamp(timestamp);
280 ts_nsec_start = timestamp % NSEC_PER_SEC;
281
282 pid = get_context_pid(call_data);
283 if (pid == -1ULL && opt_tid) {
284 goto error;
285 }
286
287 tid = get_context_tid(call_data);
288
289 hostname = get_context_hostname(call_data);
290 if (opt_child)
291 lookup = pid;
292 else
293 lookup = tid;
294 if (opt_tid || opt_procname || opt_exec_name) {
295 if (!lookup_filter_tid_list(lookup)) {
296 /* To display when a process of ours in getting scheduled in */
297 if (strcmp(bt_ctf_event_name(call_data), "sched_switch") == 0) {
298 int next_tid;
299
300 scope = bt_ctf_get_top_level_scope(call_data,
301 BT_EVENT_FIELDS);
302 next_tid = bt_ctf_get_int64(bt_ctf_get_field(call_data,
303 scope, "_next_tid"));
304 if (bt_ctf_field_get_error()) {
305 fprintf(stderr, "Missing next_tid field\n");
306 goto error;
307 }
308 if (!lookup_filter_tid_list(next_tid)) {
309 if (!opt_all)
310 goto end;
311 } else {
312 if (opt_all)
313 fprintf(output, "%c[1m", 27);
314 }
315 } else if (!opt_all) {
316 goto end;
317 }
318 } else {
319 if (opt_all)
320 fprintf(output, "%c[1m", 27);
321 }
322 }
323
324 if (((strncmp(bt_ctf_event_name(call_data),
325 "exit_syscall", 12)) == 0) ||
326 ((strncmp(bt_ctf_event_name(call_data),
327 "syscall_exit", 12)) == 0)) {
328 syscall_exit = 1;
329 }
330
331 if (last_syscall && !syscall_exit) {
332 last_syscall = NULL;
333 fprintf(output, " ...interrupted...\n");
334 }
335
336 cpu_id = get_cpu_id(call_data);
337 procname = get_context_comm(call_data);
338 if ((strncmp(bt_ctf_event_name(call_data), "sys_", 4) == 0) ||
339 (strncmp(bt_ctf_event_name(call_data), "syscall_entry", 13) == 0)){
340 cpu = get_cpu(cpu_id);
341 cpu->current_syscall = g_new0(struct syscall, 1);
342 cpu->current_syscall->name = strdup(bt_ctf_event_name(call_data));
343 cpu->current_syscall->ts_start = timestamp;
344 cpu->current_syscall->cpu_id = cpu_id;
345 last_syscall = cpu->current_syscall;
346 current_syscall = 1;
347 } else if (syscall_exit) {
348 struct tm start_ts;
349
350 /* Return code of a syscall if it was the last displayed event. */
351 if (last_syscall && last_syscall->ts_start == prev_ts) {
352 if (last_syscall->cpu_id == cpu_id) {
353 int64_t syscall_ret;
354
355 delta = timestamp - last_syscall->ts_start;
356 scope = bt_ctf_get_top_level_scope(call_data,
357 BT_EVENT_FIELDS);
358 syscall_ret = bt_ctf_get_int64(bt_ctf_get_field(call_data,
359 scope, "_ret"));
360
361 fprintf(output, "= %" PRId64 " (%" PRIu64 ".%09" PRIu64 "s)\n",
362 syscall_ret, delta / NSEC_PER_SEC,
363 delta % NSEC_PER_SEC);
364 last_syscall = NULL;
365 goto end;
366 } else {
367 last_syscall = NULL;
368 fprintf(output, " ...interrupted...\n");
369 }
370 }
371
372 cpu = get_cpu(cpu_id);
373 if (cpu->current_syscall) {
374 delta = timestamp - cpu->current_syscall->ts_start;
375 start_ts = format_timestamp(cpu->current_syscall->ts_start);
376 ret = asprintf(&from_syscall, " [from %02d:%02d:%02d.%09" PRIu64
377 " (+%" PRIu64 ".%09" PRIu64 ") (cpu %d) %s]",
378 start_ts.tm_hour, start_ts.tm_min, start_ts.tm_sec,
379 cpu->current_syscall->ts_start % NSEC_PER_SEC,
380 delta / NSEC_PER_SEC, delta % NSEC_PER_SEC,
381 cpu_id, cpu->current_syscall->name);
382 if (ret < 0) {
383 goto error;
384 }
385 free(cpu->current_syscall->name);
386 g_free(cpu->current_syscall);
387 cpu->current_syscall = NULL;
388 last_syscall = NULL;
389 }
390 }
391
392 if (prev_ts == 0)
393 prev_ts = timestamp;
394 delta = timestamp - prev_ts;
395 prev_ts = timestamp;
396
397 fprintf(output, "%02d:%02d:%02d.%09" PRIu64 " (+%" PRIu64 ".%09" PRIu64 ") %s%s"
398 "(cpu %d) [%s (%d/%d)] %s (",
399 start.tm_hour, start.tm_min, start.tm_sec,
400 ts_nsec_start, delta / NSEC_PER_SEC,
401 delta % NSEC_PER_SEC, (hostname) ? hostname : "",
402 (hostname) ? " ": "", cpu_id, procname, pid, tid,
403 bt_ctf_event_name(call_data));
404 print_fields(call_data, procname, pid);
405 fprintf(output, ")%s%c", (from_syscall) ? from_syscall : "",
406 (!current_syscall) ? '\n' : ' ');
407
408 free(from_syscall);
409 if (opt_all && (opt_tid || opt_procname || opt_exec_name))
410 fprintf(output, "%c[0m", 27);
411
412 end:
413 return BT_CB_OK;
414 error:
415 return BT_CB_ERROR_STOP;
416 end_stop:
417 return BT_CB_OK_STOP;
418 }
419
420 enum bt_cb_ret handle_kprobes(struct bt_ctf_event *call_data, void *private_data)
421 {
422 int i;
423 struct kprobes *kprobe;
424
425 /* for kprobes */
426 for (i = 0; i < lttngtop.kprobes_table->len; i++) {
427 kprobe = g_ptr_array_index(lttngtop.kprobes_table, i);
428 if (strcmp(bt_ctf_event_name(call_data), kprobe->probe_name) == 0) {
429 kprobe->count++;
430 }
431 }
432
433 return BT_CB_OK;
434 }
435
436 /*
437 * hook on each event to check the timestamp and refresh the display if
438 * necessary
439 */
440 enum bt_cb_ret check_timestamp(struct bt_ctf_event *call_data, void *private_data)
441 {
442 unsigned long timestamp;
443
444 timestamp = bt_ctf_get_timestamp(call_data);
445 if (timestamp == -1ULL)
446 goto error;
447
448 /* can happen in network live when tracing is idle */
449 if (timestamp < last_event_ts)
450 goto end_stop;
451
452 last_event_ts = timestamp;
453
454 if (last_display_update == 0)
455 last_display_update = timestamp;
456
457 if (timestamp - last_display_update >= refresh_display) {
458 sem_wait(&goodtoupdate);
459 g_ptr_array_add(copies, get_copy_lttngtop(last_display_update,
460 timestamp));
461 sem_post(&goodtodisplay);
462 sem_post(&bootstrap);
463 last_display_update = timestamp;
464 }
465 return BT_CB_OK;
466
467 error:
468 fprintf(stderr, "check_timestamp callback error\n");
469 return BT_CB_ERROR_STOP;
470
471 end_stop:
472 return BT_CB_OK_STOP;
473 }
474
475 /*
476 * get_perf_counter : get or create and return a perf_counter struct for
477 * either a process or a cpu (only one of the 2 parameters mandatory)
478 */
479 struct perfcounter *get_perf_counter(const char *name, struct processtop *proc,
480 struct cputime *cpu)
481 {
482 struct perfcounter *ret;
483 GHashTable *table;
484
485 if (proc)
486 table = proc->perf;
487 else if (cpu)
488 table = cpu->perf;
489 else
490 goto error;
491
492 ret = g_hash_table_lookup(table, (gpointer) name);
493 if (ret)
494 goto end;
495
496 ret = g_new0(struct perfcounter, 1);
497 /* by default, make it visible in the UI */
498 ret->visible = 1;
499 g_hash_table_insert(table, (gpointer) strdup(name), ret);
500
501 end:
502 return ret;
503
504 error:
505 return NULL;
506 }
507
508 void update_perf_value(struct processtop *proc, struct cputime *cpu,
509 const char *name, int value)
510 {
511 struct perfcounter *cpu_perf, *process_perf;
512
513 cpu_perf = get_perf_counter(name, NULL, cpu);
514 if (cpu_perf->count < value) {
515 process_perf = get_perf_counter(name, proc, NULL);
516 process_perf->count += value - cpu_perf->count;
517 cpu_perf->count = value;
518 }
519 }
520
521 void extract_perf_counter_scope(const struct bt_ctf_event *event,
522 const struct bt_definition *scope,
523 struct processtop *proc,
524 struct cputime *cpu)
525 {
526 struct bt_definition const * const *list = NULL;
527 const struct bt_definition *field;
528 unsigned int count;
529 struct perfcounter *perfcounter;
530 GHashTableIter iter;
531 gpointer key;
532 int ret;
533
534 if (!scope)
535 goto end;
536
537 ret = bt_ctf_get_field_list(event, scope, &list, &count);
538 if (ret < 0)
539 goto end;
540
541 if (count == 0)
542 goto end;
543
544 g_hash_table_iter_init(&iter, global_perf_liszt);
545 while (g_hash_table_iter_next (&iter, &key, (gpointer) &perfcounter)) {
546 field = bt_ctf_get_field(event, scope, (char *) key);
547 if (field) {
548 int value = bt_ctf_get_uint64(field);
549 if (bt_ctf_field_get_error())
550 continue;
551 update_perf_value(proc, cpu, (char *) key, value);
552 }
553 }
554
555 end:
556 return;
557 }
558
559 void update_perf_counter(struct processtop *proc, const struct bt_ctf_event *event)
560 {
561 struct cputime *cpu;
562 const struct bt_definition *scope;
563
564 cpu = get_cpu(get_cpu_id(event));
565
566 scope = bt_ctf_get_top_level_scope(event, BT_STREAM_EVENT_CONTEXT);
567 extract_perf_counter_scope(event, scope, proc, cpu);
568
569 scope = bt_ctf_get_top_level_scope(event, BT_STREAM_PACKET_CONTEXT);
570 extract_perf_counter_scope(event, scope, proc, cpu);
571
572 scope = bt_ctf_get_top_level_scope(event, BT_EVENT_CONTEXT);
573 extract_perf_counter_scope(event, scope, proc, cpu);
574 }
575
576 enum bt_cb_ret fix_process_table(struct bt_ctf_event *call_data,
577 void *private_data)
578 {
579 int pid, tid, ppid, vpid, vtid, vppid;
580 char *comm, *hostname;
581 struct processtop *parent, *child;
582 unsigned long timestamp;
583
584 timestamp = bt_ctf_get_timestamp(call_data);
585 if (timestamp == -1ULL)
586 goto error;
587
588 pid = get_context_pid(call_data);
589 if (pid == -1ULL) {
590 goto error;
591 }
592
593 tid = get_context_tid(call_data);
594 if (tid == -1ULL) {
595 goto error;
596 }
597 ppid = get_context_ppid(call_data);
598 if (ppid == -1ULL) {
599 goto end;
600 }
601 vpid = get_context_vpid(call_data);
602 if (pid == -1ULL) {
603 vpid = -1;
604 }
605 vtid = get_context_vtid(call_data);
606 if (tid == -1ULL) {
607 vtid = -1;
608 }
609 vppid = get_context_vppid(call_data);
610 if (ppid == -1ULL) {
611 vppid = -1;
612 }
613 comm = get_context_comm(call_data);
614 if (!comm) {
615 goto error;
616 }
617 /* optional */
618 hostname = get_context_hostname(call_data);
619
620 /* find or create the current process */
621 child = find_process_tid(&lttngtop, tid, comm);
622 if (!child)
623 child = add_proc(&lttngtop, tid, comm, timestamp, hostname);
624 if (!child)
625 goto end;
626 update_proc(child, pid, tid, ppid, vpid, vtid, vppid, comm, hostname);
627
628 if (opt_procname && lookup_procname(comm) &&
629 !lookup_filter_tid_list(tid)) {
630 int *tmp_tid;
631
632 tmp_tid = malloc(sizeof(int));
633 *tmp_tid = tid;
634 printf("ADDING %s %d\n", comm, tid);
635 g_hash_table_insert(global_filter_list,
636 (gpointer) tmp_tid, tmp_tid);
637 }
638
639 if (pid != tid) {
640 /* find or create the parent */
641 parent = find_process_tid(&lttngtop, pid, comm);
642 if (!parent) {
643 parent = add_proc(&lttngtop, pid, comm, timestamp, hostname);
644 if (parent)
645 parent->pid = pid;
646 }
647
648 /* attach the parent to the current process */
649 child->threadparent = parent;
650 add_thread(parent, child);
651 }
652
653 update_perf_counter(child, call_data);
654
655 end:
656 return BT_CB_OK;
657
658 error:
659 return BT_CB_ERROR_STOP;
660 }
661
662 void init_lttngtop()
663 {
664 copies = g_ptr_array_new();
665 global_perf_liszt = g_hash_table_new(g_str_hash, g_str_equal);
666 global_filter_list = g_hash_table_new(g_str_hash, g_str_equal);
667 global_host_list = g_hash_table_new(g_str_hash, g_str_equal);
668 global_procname_list = g_hash_table_new(g_str_hash, g_str_equal);
669 tid_filter_list = g_hash_table_new(g_str_hash,
670 g_str_equal);
671
672 sem_init(&goodtodisplay, 0, 0);
673 sem_init(&goodtoupdate, 0, 1);
674 sem_init(&timer, 0, 1);
675 sem_init(&bootstrap, 0, 0);
676 sem_init(&pause_sem, 0, 1);
677 sem_init(&end_trace_sem, 0, 0);
678
679 reset_global_counters();
680 lttngtop.nbproc = 0;
681 lttngtop.nbthreads = 0;
682 lttngtop.nbfiles = 0;
683
684 lttngtop.process_hash_table = g_hash_table_new(g_direct_hash,
685 g_direct_equal);
686 lttngtop.process_table = g_ptr_array_new();
687 lttngtop.files_table = g_ptr_array_new();
688 lttngtop.cpu_table = g_ptr_array_new();
689
690 toggle_filter = -1;
691 }
692
693 void usage(FILE *fp)
694 {
695 fprintf(fp, "LTTngTop %s\n\n", VERSION);
696 fprintf(fp, "Usage : lttngtop [OPTIONS] TRACE\n");
697 fprintf(fp, " TRACE Path to the trace to analyse (-r for network live tracing, nothing for mmap live streaming)\n");
698 fprintf(fp, " -h, --help This help message\n");
699 fprintf(fp, " -t, --textdump Display live events in text-only\n");
700 fprintf(fp, " -p, --pid Comma-separated list of PIDs to display\n");
701 fprintf(fp, " -f, --child Follow threads associated with selected PIDs\n");
702 fprintf(fp, " -n, --procname Comma-separated list of procnames to display (require procname context in trace)\n");
703 fprintf(fp, " -a, --all In textdump mode, display all events but write in bold the processes we are interested in (-f, -p and -n)\n");
704 fprintf(fp, " -k, --kprobes Comma-separated list of kprobes to insert (same format as lttng enable-event)\n");
705 fprintf(fp, " -r, --relay-hostname Network live streaming : hostname of the lttng-relayd (default port)\n");
706 fprintf(fp, " -b, --begin Network live streaming : read the trace for the beginning of the recording\n");
707 fprintf(fp, " -o, --output <filename> In textdump, output the log in <filename>\n");
708 fprintf(fp, " -g, --gui-test Test if the ncurses support is compiled in (return 0 if it is)\n");
709 fprintf(fp, " --create-local-session Setup a LTTng local session with all the right parameters\n");
710 fprintf(fp, " --create-live-session Setup a LTTng live session on localhost with all the right parameters\n");
711 }
712
713 /*
714 * Parse probe options.
715 * Shamelessly stolen from lttng-tools :
716 * src/bin/lttng/commands/enable_events.c
717 */
718 static struct kprobes *parse_probe_opts(char *opt)
719 {
720 char s_hex[19];
721 char name[LTTNG_SYMBOL_NAME_LEN];
722 struct kprobes *kprobe;
723 int ret;
724
725 /*
726 kprobe->probe_addr = 0;
727 kprobe->probe_offset = 0;
728 asprintf(&kprobe->probe_name, "probe_sys_open");
729 asprintf(&kprobe->symbol_name, "sys_open");
730 */
731
732 if (opt == NULL) {
733 kprobe = NULL;
734 goto end;
735 }
736
737 kprobe = g_new0(struct kprobes, 1);
738
739 /* Check for symbol+offset */
740 ret = sscanf(opt, "%[^'+']+%s", name, s_hex);
741 if (ret == 2) {
742 ret = asprintf(&kprobe->probe_name, "probe_%s", name);
743 ret = asprintf(&kprobe->symbol_name, "%s", name);
744
745 if (strlen(s_hex) == 0) {
746 fprintf(stderr, "Invalid probe offset %s", s_hex);
747 ret = -1;
748 goto end;
749 }
750 kprobe->probe_offset = strtoul(s_hex, NULL, 0);
751 kprobe->probe_addr = 0;
752 goto end;
753 }
754
755 /* Check for symbol */
756 if (isalpha(name[0])) {
757 ret = sscanf(opt, "%s", name);
758 if (ret == 1) {
759 ret = asprintf(&kprobe->probe_name, "probe_%s", name);
760 ret = asprintf(&kprobe->symbol_name, "%s", name);
761 kprobe->probe_offset = 0;
762 kprobe->probe_addr = 0;
763 goto end;
764 }
765 }
766
767 /* Check for address */
768 ret = sscanf(opt, "%s", s_hex);
769 if (ret > 0) {
770 if (strlen(s_hex) == 0) {
771 fprintf(stderr, "Invalid probe address %s", s_hex);
772 ret = -1;
773 goto end;
774 }
775 ret = asprintf(&kprobe->probe_name, "probe_%s", s_hex);
776 kprobe->probe_offset = 0;
777 kprobe->probe_addr = strtoul(s_hex, NULL, 0);
778 goto end;
779 }
780
781 /* No match */
782 kprobe = NULL;
783
784 end:
785 return kprobe;
786 }
787
788 /*
789 * Return 0 if caller should continue, < 0 if caller should return
790 * error, > 0 if caller should exit without reporting error.
791 */
792 static int parse_options(int argc, char **argv)
793 {
794 poptContext pc;
795 int opt, ret = 0;
796 char *tmp_str;
797 int *tid;
798 int i;
799
800 remote_live = 0;
801
802 pc = poptGetContext(NULL, argc, (const char **) argv, long_options, 0);
803 poptReadDefaultConfig(pc, 0);
804
805 while ((opt = poptGetNextOpt(pc)) != -1) {
806 switch (opt) {
807 case OPT_HELP:
808 usage(stdout);
809 ret = 1; /* exit cleanly */
810 goto end;
811 case OPT_GUI_TEST:
812 #ifdef HAVE_LIBNCURSES
813 exit(EXIT_SUCCESS);
814 #else
815 exit(EXIT_FAILURE);
816 #endif
817 goto end;
818 case OPT_CREATE_LOCAL_SESSION:
819 ret = create_local_session();
820 exit(ret);
821 case OPT_CREATE_LIVE_SESSION:
822 ret = create_live_local_session(NULL, NULL, 1);
823 exit(ret);
824 case OPT_TEXTDUMP:
825 opt_textdump = 1;
826 break;
827 case OPT_ALL:
828 opt_all = 1;
829 break;
830 case OPT_CHILD:
831 opt_child = 1;
832 break;
833 case OPT_PID:
834 toggle_filter = 1;
835 tmp_str = strtok(opt_tid, ",");
836 while (tmp_str) {
837 tid = malloc(sizeof(int));
838 *tid = atoi(tmp_str);
839 g_hash_table_insert(tid_filter_list,
840 (gpointer) tid, tid);
841 tmp_str = strtok(NULL, ",");
842 }
843 break;
844 case OPT_BEGIN:
845 /* start reading the live trace from the beginning */
846 opt_begin = 1;
847 break;
848 case OPT_PROCNAME:
849 toggle_filter = 1;
850 tmp_str = strtok(opt_procname, ",");
851 while (tmp_str) {
852 add_procname_list(tmp_str, 1);
853 tmp_str = strtok(NULL, ",");
854 }
855 break;
856 case OPT_RELAY_HOSTNAME:
857 remote_live = 1;
858 break;
859 case OPT_KPROBES:
860 lttngtop.kprobes_table = g_ptr_array_new();
861 tmp_str = strtok(opt_kprobes, ",");
862 while (tmp_str) {
863 struct kprobes *kprobe;
864
865 kprobe = parse_probe_opts(tmp_str);
866 if (kprobe) {
867 g_ptr_array_add(
868 lttngtop.kprobes_table,
869 kprobe);
870 } else {
871 ret = -EINVAL;
872 goto end;
873 }
874 tmp_str = strtok(NULL, ",");
875 }
876 break;
877 case OPT_OUTPUT_FILE:
878 break;
879 case OPT_VERBOSE:
880 babeltrace_verbose = 1;
881 break;
882 default:
883 ret = -EINVAL;
884 goto end;
885 }
886 }
887
888 opt_exec_name = NULL;
889 opt_exec_argv = NULL;
890 for (i = 0; i < argc; i++) {
891 if (argv[i][0] == '-' && argv[i][1] == '-') {
892 opt_exec_name = argv[i + 1];
893 opt_exec_argv = &argv[i + 1];
894 break;
895 }
896 }
897 if (!opt_exec_name) {
898 opt_input_path = poptGetArg(pc);
899 }
900 if (!opt_output) {
901 opt_output = strdup("/dev/stdout");
902 }
903 output = fopen(opt_output, "w");
904 if (!output) {
905 perror("Error opening output file");
906 ret = -1;
907 goto end;
908 }
909
910 end:
911 if (pc) {
912 poptFreeContext(pc);
913 }
914 return ret;
915 }
916
917 void iter_trace(struct bt_context *bt_ctx)
918 {
919 struct bt_ctf_iter *iter;
920 struct bt_iter_pos begin_pos;
921 struct kprobes *kprobe;
922 const struct bt_ctf_event *event;
923 int i;
924 int ret = 0;
925
926 begin_pos.type = BT_SEEK_BEGIN;
927 iter = bt_ctf_iter_create(bt_ctx, &begin_pos, NULL);
928
929 /* at each event, verify the status of the process table */
930 bt_ctf_iter_add_callback(iter, 0, NULL, 0,
931 fix_process_table,
932 NULL, NULL, NULL);
933 /* to handle the follow child option */
934 bt_ctf_iter_add_callback(iter,
935 g_quark_from_static_string("sched_process_fork"),
936 NULL, 0, handle_sched_process_fork, NULL, NULL, NULL);
937 /* to clean up the process table */
938 bt_ctf_iter_add_callback(iter,
939 g_quark_from_static_string("sched_process_free"),
940 NULL, 0, handle_sched_process_free, NULL, NULL, NULL);
941 /* to get all the process from the statedumps */
942 bt_ctf_iter_add_callback(iter,
943 g_quark_from_static_string(
944 "lttng_statedump_process_state"),
945 NULL, 0, handle_statedump_process_state,
946 NULL, NULL, NULL);
947 bt_ctf_iter_add_callback(iter,
948 g_quark_from_static_string(
949 "lttng_statedump_file_descriptor"),
950 NULL, 0, handle_statedump_file_descriptor,
951 NULL, NULL, NULL);
952 bt_ctf_iter_add_callback(iter,
953 g_quark_from_static_string("sys_open"),
954 NULL, 0, handle_sys_open, NULL, NULL, NULL);
955 bt_ctf_iter_add_callback(iter,
956 g_quark_from_static_string("syscall_entry_open"),
957 NULL, 0, handle_sys_open, NULL, NULL, NULL);
958
959 bt_ctf_iter_add_callback(iter,
960 g_quark_from_static_string("sys_socket"),
961 NULL, 0, handle_sys_socket, NULL, NULL, NULL);
962 bt_ctf_iter_add_callback(iter,
963 g_quark_from_static_string("syscall_entry_socket"),
964 NULL, 0, handle_sys_socket, NULL, NULL, NULL);
965
966 bt_ctf_iter_add_callback(iter,
967 g_quark_from_static_string("sys_close"),
968 NULL, 0, handle_sys_close, NULL, NULL, NULL);
969 bt_ctf_iter_add_callback(iter,
970 g_quark_from_static_string("syscall_entry_close"),
971 NULL, 0, handle_sys_close, NULL, NULL, NULL);
972
973 bt_ctf_iter_add_callback(iter,
974 g_quark_from_static_string("exit_syscall"),
975 NULL, 0, handle_exit_syscall, NULL, NULL, NULL);
976 bt_ctf_iter_add_callback(iter,
977 g_quark_from_static_string("syscall_exit_open"),
978 NULL, 0, handle_exit_syscall, NULL, NULL, NULL);
979 bt_ctf_iter_add_callback(iter,
980 g_quark_from_static_string("syscall_exit_socket"),
981 NULL, 0, handle_exit_syscall, NULL, NULL, NULL);
982 bt_ctf_iter_add_callback(iter,
983 g_quark_from_static_string("syscall_exit_close"),
984 NULL, 0, handle_exit_syscall, NULL, NULL, NULL);
985 if (opt_textdump) {
986 bt_ctf_iter_add_callback(iter, 0, NULL, 0,
987 textdump,
988 NULL, NULL, NULL);
989 } else {
990 /* at each event check if we need to refresh */
991 bt_ctf_iter_add_callback(iter, 0, NULL, 0,
992 check_timestamp,
993 NULL, NULL, NULL);
994 /* to handle the scheduling events */
995 bt_ctf_iter_add_callback(iter,
996 g_quark_from_static_string("sched_switch"),
997 NULL, 0, handle_sched_switch, NULL, NULL, NULL);
998 /* for IO top */
999 bt_ctf_iter_add_callback(iter,
1000 g_quark_from_static_string("sys_write"),
1001 NULL, 0, handle_sys_write, NULL, NULL, NULL);
1002 bt_ctf_iter_add_callback(iter,
1003 g_quark_from_static_string("syscall_entry_write"),
1004 NULL, 0, handle_sys_write, NULL, NULL, NULL);
1005 bt_ctf_iter_add_callback(iter,
1006 g_quark_from_static_string("syscall_exit_write"),
1007 NULL, 0, handle_exit_syscall, NULL, NULL, NULL);
1008
1009 bt_ctf_iter_add_callback(iter,
1010 g_quark_from_static_string("sys_read"),
1011 NULL, 0, handle_sys_read, NULL, NULL, NULL);
1012 bt_ctf_iter_add_callback(iter,
1013 g_quark_from_static_string("syscall_entry_read"),
1014 NULL, 0, handle_sys_read, NULL, NULL, NULL);
1015 bt_ctf_iter_add_callback(iter,
1016 g_quark_from_static_string("syscall_exit_read"),
1017 NULL, 0, handle_exit_syscall, NULL, NULL, NULL);
1018
1019 /* for kprobes */
1020 if (lttngtop.kprobes_table) {
1021 for (i = 0; i < lttngtop.kprobes_table->len; i++) {
1022 kprobe = g_ptr_array_index(lttngtop.kprobes_table, i);
1023 bt_ctf_iter_add_callback(iter,
1024 g_quark_from_static_string(
1025 kprobe->probe_name),
1026 NULL, 0, handle_kprobes,
1027 NULL, NULL, NULL);
1028 }
1029 }
1030 }
1031
1032 if (opt_exec_name) {
1033 pid_t pid;
1034
1035 pid = fork();
1036 if (pid == 0) {
1037 execvpe(opt_exec_name, opt_exec_argv, opt_exec_env);
1038 exit(EXIT_SUCCESS);
1039 } else if (pid > 0) {
1040 opt_exec_pid = pid;
1041 g_hash_table_insert(tid_filter_list,
1042 (gpointer) &pid,
1043 &pid);
1044 } else {
1045 perror("fork");
1046 exit(EXIT_FAILURE);
1047 }
1048 }
1049
1050 while ((event = bt_ctf_iter_read_event(iter)) != NULL) {
1051 if (quit || reload_trace)
1052 goto end_iter;
1053 ret = bt_iter_next(bt_ctf_get_iter(iter));
1054 if (ret < 0)
1055 goto end_iter;
1056 }
1057
1058 /* block until quit, we reached the end of the trace */
1059 sem_wait(&end_trace_sem);
1060
1061 end_iter:
1062 bt_ctf_iter_destroy(iter);
1063 }
1064
1065 /*
1066 * bt_context_add_traces_recursive: Open a trace recursively
1067 * (copied from BSD code in converter/babeltrace.c)
1068 *
1069 * Find each trace present in the subdirectory starting from the given
1070 * path, and add them to the context. The packet_seek parameter can be
1071 * NULL: this specify to use the default format packet_seek.
1072 *
1073 * Return: 0 on success, nonzero on failure.
1074 * Unable to open toplevel: failure.
1075 * Unable to open some subdirectory or file: warn and continue;
1076 */
1077 int bt_context_add_traces_recursive(struct bt_context *ctx, const char *path,
1078 const char *format_str,
1079 void (*packet_seek)(struct bt_stream_pos *pos,
1080 size_t offset, int whence))
1081 {
1082 FTS *tree;
1083 FTSENT *node;
1084 GArray *trace_ids;
1085 char lpath[PATH_MAX];
1086 char * const paths[2] = { lpath, NULL };
1087 int ret = -1;
1088
1089 if ((strncmp(path, NET4_URL_PREFIX, sizeof(NET4_URL_PREFIX) - 1)) == 0 ||
1090 (strncmp(path, NET6_URL_PREFIX, sizeof(NET6_URL_PREFIX) - 1)) == 0 ||
1091 (strncmp(path, NET_URL_PREFIX, sizeof(NET_URL_PREFIX) - 1)) == 0) {
1092 ret = bt_context_add_trace(ctx,
1093 path, format_str, packet_seek, NULL, NULL);
1094 if (ret < 0) {
1095 fprintf(stderr, "[warning] [Context] cannot open trace \"%s\" "
1096 "for reading.\n", path);
1097 /* Allow to skip erroneous traces. */
1098 ret = 1; /* partial error */
1099 }
1100 return ret;
1101 }
1102 /*
1103 * Need to copy path, because fts_open can change it.
1104 * It is the pointer array, not the strings, that are constant.
1105 */
1106 strncpy(lpath, path, PATH_MAX);
1107 lpath[PATH_MAX - 1] = '\0';
1108
1109 tree = fts_open(paths, FTS_NOCHDIR | FTS_LOGICAL, 0);
1110 if (tree == NULL) {
1111 fprintf(stderr, "[error] [Context] Cannot traverse \"%s\" for reading.\n",
1112 path);
1113 return -EINVAL;
1114 }
1115
1116 trace_ids = g_array_new(FALSE, TRUE, sizeof(int));
1117
1118 while ((node = fts_read(tree))) {
1119 int dirfd, metafd;
1120
1121 if (!(node->fts_info & FTS_D))
1122 continue;
1123
1124 dirfd = open(node->fts_accpath, 0);
1125 if (dirfd < 0) {
1126 fprintf(stderr, "[error] [Context] Unable to open trace "
1127 "directory file descriptor.\n");
1128 ret = dirfd;
1129 goto error;
1130 }
1131 metafd = openat(dirfd, "metadata", O_RDONLY);
1132 if (metafd < 0) {
1133 close(dirfd);
1134 continue;
1135 } else {
1136 int trace_id;
1137
1138 ret = close(metafd);
1139 if (ret < 0) {
1140 perror("close");
1141 goto error;
1142 }
1143 ret = close(dirfd);
1144 if (ret < 0) {
1145 perror("close");
1146 goto error;
1147 }
1148
1149 trace_id = bt_context_add_trace(ctx,
1150 node->fts_accpath, format_str,
1151 packet_seek, NULL, NULL);
1152 if (trace_id < 0) {
1153 fprintf(stderr, "[warning] [Context] opening trace \"%s\" from %s "
1154 "for reading.\n", node->fts_accpath, path);
1155 /* Allow to skip erroneous traces. */
1156 continue;
1157 }
1158 g_array_append_val(trace_ids, trace_id);
1159 }
1160 }
1161
1162 g_array_free(trace_ids, TRUE);
1163 return ret;
1164
1165 error:
1166 return ret;
1167 }
1168
1169 static int check_field_requirements(const struct bt_ctf_field_decl *const * field_list,
1170 int field_cnt, int *tid_check, int *pid_check,
1171 int *procname_check, int *ppid_check)
1172 {
1173 int j;
1174 struct perfcounter *global;
1175 const char *name;
1176
1177 for (j = 0; j < field_cnt; j++) {
1178 name = bt_ctf_get_decl_field_name(field_list[j]);
1179 if (*tid_check == 0) {
1180 if (strncmp(name, "tid", 3) == 0)
1181 (*tid_check)++;
1182 }
1183 if (*pid_check == 0) {
1184 if (strncmp(name, "pid", 3) == 0)
1185 (*pid_check)++;
1186 }
1187 if (*ppid_check == 0) {
1188 if (strncmp(name, "ppid", 4) == 0)
1189 (*ppid_check)++;
1190 }
1191 if (*procname_check == 0) {
1192 if (strncmp(name, "procname", 8) == 0)
1193 (*procname_check)++;
1194 }
1195 if (strncmp(name, "perf_", 5) == 0) {
1196 global = g_hash_table_lookup(global_perf_liszt, (gpointer) name);
1197 if (!global) {
1198 global = g_new0(struct perfcounter, 1);
1199 /* by default, sort on the first perf context */
1200 if (g_hash_table_size(global_perf_liszt) == 0)
1201 global->sort = 1;
1202 global->visible = 1;
1203 g_hash_table_insert(global_perf_liszt, (gpointer) strdup(name), global);
1204 }
1205 }
1206 }
1207
1208 if (*tid_check == 1 && *pid_check == 1 && *ppid_check == 1 &&
1209 *procname_check == 1)
1210 return 0;
1211
1212 return -1;
1213 }
1214
1215 /*
1216 * check_requirements: check if the required context informations are available
1217 *
1218 * If each mandatory context information is available for at least in one
1219 * event, return 0 otherwise return -1.
1220 */
1221 int check_requirements(struct bt_context *ctx)
1222 {
1223 unsigned int i, evt_cnt, field_cnt;
1224 struct bt_ctf_event_decl *const * evt_list;
1225 const struct bt_ctf_field_decl *const * field_list;
1226 int tid_check = 0;
1227 int pid_check = 0;
1228 int procname_check = 0;
1229 int ppid_check = 0;
1230 int ret = 0;
1231
1232 ret = bt_ctf_get_event_decl_list(0, ctx, &evt_list, &evt_cnt);
1233 if (ret < 0) {
1234 goto end;
1235 }
1236
1237 for (i = 0; i < evt_cnt; i++) {
1238 bt_ctf_get_decl_fields(evt_list[i], BT_STREAM_EVENT_CONTEXT,
1239 &field_list, &field_cnt);
1240 ret = check_field_requirements(field_list, field_cnt,
1241 &tid_check, &pid_check, &procname_check,
1242 &ppid_check);
1243
1244 bt_ctf_get_decl_fields(evt_list[i], BT_EVENT_CONTEXT,
1245 &field_list, &field_cnt);
1246 ret = check_field_requirements(field_list, field_cnt,
1247 &tid_check, &pid_check, &procname_check,
1248 &ppid_check);
1249
1250 bt_ctf_get_decl_fields(evt_list[i], BT_STREAM_PACKET_CONTEXT,
1251 &field_list, &field_cnt);
1252 ret = check_field_requirements(field_list, field_cnt,
1253 &tid_check, &pid_check, &procname_check,
1254 &ppid_check);
1255 }
1256
1257 if (tid_check == 0) {
1258 ret = -1;
1259 fprintf(stderr, "[error] missing tid context information\n");
1260 }
1261 if (pid_check == 0) {
1262 ret = -1;
1263 fprintf(stderr, "[error] missing pid context information\n");
1264 }
1265 if (ppid_check == 0) {
1266 ret = -1;
1267 fprintf(stderr, "[error] missing ppid context information\n");
1268 }
1269 if (procname_check == 0) {
1270 ret = -1;
1271 fprintf(stderr, "[error] missing procname context information\n");
1272 }
1273 if (ret == 0) {
1274 valid_trace = 1;
1275 }
1276
1277 end:
1278 return ret;
1279 }
1280
1281 static void handle_sigchild(int signal)
1282 {
1283 int status;
1284
1285 waitpid(opt_exec_pid, &status, 0);
1286 }
1287
1288 int main(int argc, char **argv, char **envp)
1289 {
1290 int ret;
1291 struct bt_context *bt_ctx = NULL;
1292 char *live_session_name = NULL;
1293
1294 init_lttngtop();
1295 ret = parse_options(argc, argv);
1296 if (ret < 0) {
1297 fprintf(stdout, "Error parsing options.\n\n");
1298 usage(stdout);
1299 exit(EXIT_FAILURE);
1300 } else if (ret > 0) {
1301 exit(EXIT_SUCCESS);
1302 }
1303
1304 if (opt_exec_name) {
1305 opt_exec_env = envp;
1306 signal(SIGCHLD, handle_sigchild);
1307 }
1308
1309 if (!opt_input_path && !remote_live && !opt_exec_name) {
1310 /* mmap live */
1311 ret = create_live_local_session(&opt_relay_hostname,
1312 &live_session_name, 0);
1313 if (ret < 0)
1314 goto end;
1315 remote_live = 1;
1316 }
1317 if (!opt_input_path && remote_live) {
1318 /* network live */
1319 bt_ctx = bt_context_create();
1320 ret = bt_context_add_traces_recursive(bt_ctx, opt_relay_hostname,
1321 "lttng-live", NULL);
1322 if (ret < 0) {
1323 fprintf(stderr, "[error] Opening the trace\n");
1324 goto end;
1325 }
1326 } else {
1327 bt_ctx = bt_context_create();
1328 ret = bt_context_add_traces_recursive(bt_ctx, opt_input_path, "ctf", NULL);
1329 if (ret < 0) {
1330 fprintf(stderr, "[error] Opening the trace\n");
1331 goto end;
1332 }
1333
1334 ret = check_requirements(bt_ctx);
1335 if (ret < 0 && !valid_trace) {
1336 fprintf(stderr, "[error] some mandatory contexts "
1337 "were missing, exiting.\n");
1338 //goto end;
1339 }
1340
1341 if (!opt_textdump) {
1342 #ifdef HAVE_LIBNCURSES
1343 pthread_create(&display_thread, NULL, ncurses_display,
1344 (void *) NULL);
1345 pthread_create(&timer_thread, NULL, refresh_thread,
1346 (void *) NULL);
1347 #else
1348 printf("Ncurses support not compiled, please install "
1349 "the missing dependencies and recompile\n");
1350 goto end;
1351 #endif
1352 }
1353
1354 iter_trace(bt_ctx);
1355 }
1356
1357
1358 pthread_join(display_thread, NULL);
1359 quit = 1;
1360 pthread_join(timer_thread, NULL);
1361
1362 ret = 0;
1363
1364 end:
1365 if (bt_ctx)
1366 bt_context_put(bt_ctx);
1367
1368 if (live_session_name) {
1369 ret = destroy_live_local_session(live_session_name);
1370 if (ret < 0) {
1371 fprintf(stderr, "Error destroying %s\n", live_session_name);
1372 }
1373 }
1374
1375 return ret;
1376 }
This page took 0.059216 seconds and 3 git commands to generate.