Commit | Line | Data |
---|---|---|
1fc22eb4 | 1 | /* |
863dc485 | 2 | * Copyright (C) 2013 Julien Desfossez |
1fc22eb4 JD |
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 | * | |
71bd7ce1 AM |
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. | |
1fc22eb4 JD |
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> | |
3ba84bed | 25 | #include <babeltrace/ctf/iterator.h> |
1fc22eb4 JD |
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> | |
85db4618 | 39 | #include <assert.h> |
16b22a0f JD |
40 | #include <sys/mman.h> |
41 | #include <lttng/lttng.h> | |
b1acd2b3 | 42 | #ifdef LTTNGTOP_MMAP_LIVE |
16b22a0f | 43 | #include <lttng/lttngtop-helper.h> |
c78f2cdc | 44 | #include <babeltrace/lttngtopmmappacketseek.h> |
b1acd2b3 JD |
45 | #include "mmap-live.h" |
46 | #endif /* LTTNGTOP_MMAP_LIVE */ | |
1fc22eb4 JD |
47 | |
48 | #include "lttngtoptypes.h" | |
49 | #include "cputop.h" | |
50 | #include "iostreamtop.h" | |
51 | #include "cursesdisplay.h" | |
52 | #include "common.h" | |
b1acd2b3 JD |
53 | #include "network-live.h" |
54 | ||
55 | #include "lttng-index.h" | |
1fc22eb4 JD |
56 | |
57 | #define DEFAULT_FILE_ARRAY_SIZE 1 | |
58 | ||
59 | const char *opt_input_path; | |
32b70e07 | 60 | static int opt_textdump; |
32b70e07 | 61 | static int opt_child; |
1fc22eb4 | 62 | |
ae9e85c7 JD |
63 | int quit = 0; |
64 | ||
1fc22eb4 JD |
65 | struct lttngtop *copy; |
66 | pthread_t display_thread; | |
67 | pthread_t timer_thread; | |
68 | ||
69 | unsigned long refresh_display = 1 * NSEC_PER_SEC; | |
70 | unsigned long last_display_update = 0; | |
863dc485 | 71 | unsigned long last_event_ts = 0; |
1fc22eb4 | 72 | |
16b22a0f | 73 | /* list of FDs available for being read with snapshots */ |
b1acd2b3 | 74 | struct bt_mmap_stream_list mmap_list; |
16b22a0f JD |
75 | GPtrArray *lttng_consumer_stream_array; |
76 | int sessiond_metadata, consumerd_metadata; | |
4e6aeb3d JD |
77 | struct lttng_consumer_local_data *ctx = NULL; |
78 | /* list of snapshots currently not consumed */ | |
79 | GPtrArray *available_snapshots; | |
80 | sem_t metadata_available; | |
050f9cf9 | 81 | int reload_trace = 0; |
16b22a0f | 82 | |
57bff788 JD |
83 | int last_textdump_print_newline = 1; |
84 | ||
1fc22eb4 JD |
85 | enum { |
86 | OPT_NONE = 0, | |
87 | OPT_HELP, | |
6777529d | 88 | OPT_TEXTDUMP, |
32b70e07 JD |
89 | OPT_PID, |
90 | OPT_CHILD, | |
c8d75a13 | 91 | OPT_HOSTNAME, |
b1acd2b3 | 92 | OPT_RELAY_HOSTNAME, |
f16e36fc | 93 | OPT_KPROBES, |
1fc22eb4 JD |
94 | }; |
95 | ||
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 }, | |
6777529d | 99 | { "textdump", 't', POPT_ARG_NONE, NULL, OPT_TEXTDUMP, NULL, NULL }, |
32b70e07 | 100 | { "child", 'f', POPT_ARG_NONE, NULL, OPT_CHILD, NULL, NULL }, |
57bff788 | 101 | { "pid", 'p', POPT_ARG_STRING, &opt_tid, OPT_PID, NULL, NULL }, |
c8d75a13 | 102 | { "hostname", 'n', POPT_ARG_STRING, &opt_hostname, OPT_HOSTNAME, NULL, NULL }, |
b1acd2b3 JD |
103 | { "relay-hostname", 'r', POPT_ARG_STRING, &opt_relay_hostname, |
104 | OPT_RELAY_HOSTNAME, NULL, NULL }, | |
f16e36fc | 105 | { "kprobes", 'k', POPT_ARG_STRING, &opt_kprobes, OPT_KPROBES, NULL, NULL }, |
1fc22eb4 JD |
106 | { NULL, 0, 0, NULL, 0, NULL, NULL }, |
107 | }; | |
108 | ||
863dc485 | 109 | #ifdef LTTNGTOP_MMAP_LIVE |
24797198 JD |
110 | static void handle_textdump_sigterm(int signal) |
111 | { | |
112 | quit = 1; | |
113 | lttng_destroy_session("test"); | |
114 | } | |
863dc485 | 115 | #endif |
24797198 | 116 | |
1fc22eb4 JD |
117 | void *refresh_thread(void *p) |
118 | { | |
119 | while (1) { | |
ae9e85c7 JD |
120 | if (quit) { |
121 | sem_post(&pause_sem); | |
122 | sem_post(&timer); | |
1402044a | 123 | sem_post(&end_trace_sem); |
ae9e85c7 | 124 | sem_post(&goodtodisplay); |
1402044a | 125 | sem_post(&goodtoupdate); |
ae9e85c7 JD |
126 | pthread_exit(0); |
127 | } | |
1402044a | 128 | if (!opt_input_path) { |
b1acd2b3 JD |
129 | #ifdef LTTNGTOP_MMAP_LIVE |
130 | mmap_live_flush(mmap_list); | |
131 | #endif | |
1402044a | 132 | } |
1fc22eb4 JD |
133 | sem_wait(&pause_sem); |
134 | sem_post(&pause_sem); | |
135 | sem_post(&timer); | |
136 | sleep(refresh_display/NSEC_PER_SEC); | |
137 | } | |
138 | } | |
139 | ||
140 | void *ncurses_display(void *p) | |
141 | { | |
142 | unsigned int current_display_index = 0; | |
143 | ||
144 | sem_wait(&bootstrap); | |
b332d28f JD |
145 | /* |
146 | * Prevent the 1 second delay when we hit ESC | |
147 | */ | |
148 | ESCDELAY = 0; | |
1fc22eb4 JD |
149 | init_ncurses(); |
150 | ||
151 | while (1) { | |
152 | sem_wait(&timer); | |
153 | sem_wait(&goodtodisplay); | |
154 | sem_wait(&pause_sem); | |
155 | ||
ae9e85c7 | 156 | if (quit) { |
33572a17 JD |
157 | sem_post(&pause_sem); |
158 | sem_post(&timer); | |
ae9e85c7 JD |
159 | reset_ncurses(); |
160 | pthread_exit(0); | |
161 | } | |
162 | ||
1fc22eb4 | 163 | copy = g_ptr_array_index(copies, current_display_index); |
85db4618 JD |
164 | assert(copy); |
165 | display(current_display_index++); | |
1fc22eb4 JD |
166 | |
167 | sem_post(&goodtoupdate); | |
168 | sem_post(&pause_sem); | |
1fc22eb4 JD |
169 | } |
170 | } | |
171 | ||
575cc4fd JD |
172 | void print_fields(struct bt_ctf_event *event) |
173 | { | |
174 | unsigned int cnt, i; | |
b1acd2b3 JD |
175 | const struct bt_definition *const * list; |
176 | const struct bt_declaration *l; | |
177 | const struct bt_definition *scope; | |
575cc4fd JD |
178 | enum ctf_type_id type; |
179 | const char *str; | |
180 | ||
181 | scope = bt_ctf_get_top_level_scope(event, BT_EVENT_FIELDS); | |
182 | ||
183 | bt_ctf_get_field_list(event, scope, &list, &cnt); | |
184 | for (i = 0; i < cnt; i++) { | |
185 | if (i != 0) | |
186 | printf(", "); | |
187 | printf("%s = ", bt_ctf_field_name(list[i])); | |
9498e78c JD |
188 | l = bt_ctf_get_decl_from_def(list[i]); |
189 | type = bt_ctf_field_type(l); | |
575cc4fd | 190 | if (type == CTF_TYPE_INTEGER) { |
9498e78c | 191 | if (bt_ctf_get_int_signedness(l) == 0) |
575cc4fd JD |
192 | printf("%" PRIu64 "", bt_ctf_get_uint64(list[i])); |
193 | else | |
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]); | |
fbbda4da | 199 | if (!bt_ctf_field_get_error() && str) |
575cc4fd JD |
200 | printf("%s", str); |
201 | } | |
202 | } | |
203 | } | |
204 | ||
6112d0d4 JD |
205 | /* |
206 | * hook on each event to check the timestamp and refresh the display if | |
207 | * necessary | |
208 | */ | |
209 | enum bt_cb_ret print_timestamp(struct bt_ctf_event *call_data, void *private_data) | |
210 | { | |
211 | unsigned long timestamp; | |
212 | struct tm start; | |
b520ab45 | 213 | uint64_t ts_nsec_start; |
575cc4fd | 214 | int pid, cpu_id; |
d2d680e0 | 215 | int64_t syscall_ret; |
b1acd2b3 | 216 | const struct bt_definition *scope; |
575cc4fd | 217 | const char *hostname, *procname; |
6112d0d4 | 218 | |
6112d0d4 JD |
219 | timestamp = bt_ctf_get_timestamp(call_data); |
220 | ||
863dc485 JD |
221 | /* can happen in network live when tracing is idle */ |
222 | if (timestamp < last_event_ts) | |
223 | goto end_stop; | |
224 | ||
225 | last_event_ts = timestamp; | |
226 | ||
b520ab45 | 227 | start = format_timestamp(timestamp); |
6112d0d4 JD |
228 | ts_nsec_start = timestamp % NSEC_PER_SEC; |
229 | ||
32b70e07 | 230 | pid = get_context_pid(call_data); |
57bff788 | 231 | if (pid == -1ULL && opt_tid) { |
32b70e07 JD |
232 | goto error; |
233 | } | |
234 | ||
c8d75a13 | 235 | hostname = get_context_hostname(call_data); |
da4353bb JD |
236 | if (opt_tid || opt_hostname) |
237 | if (!lookup_filter_tid_list(pid)) | |
238 | goto end; | |
239 | ||
575cc4fd JD |
240 | cpu_id = get_cpu_id(call_data); |
241 | procname = get_context_comm(call_data); | |
242 | ||
f16e36fc JD |
243 | if ((strcmp(bt_ctf_event_name(call_data), "exit_syscall") == 0) && |
244 | !last_textdump_print_newline) { | |
d2d680e0 JD |
245 | scope = bt_ctf_get_top_level_scope(call_data, |
246 | BT_EVENT_FIELDS); | |
247 | syscall_ret = bt_ctf_get_int64(bt_ctf_get_field(call_data, | |
248 | scope, "_ret")); | |
249 | printf("= %ld\n", syscall_ret); | |
57bff788 | 250 | last_textdump_print_newline = 1; |
d2d680e0 | 251 | } else { |
57bff788 JD |
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) | |
255 | printf("\n"); | |
575cc4fd JD |
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); | |
261 | printf(") "); | |
fbbda4da | 262 | if (strncmp(bt_ctf_event_name(call_data), "sys_", 4) != 0) { |
575cc4fd | 263 | printf("\n"); |
fbbda4da JD |
264 | last_textdump_print_newline = 1; |
265 | } else { | |
266 | last_textdump_print_newline = 0; | |
575cc4fd | 267 | } |
d2d680e0 | 268 | } |
6112d0d4 | 269 | |
32b70e07 | 270 | end: |
6112d0d4 | 271 | return BT_CB_OK; |
32b70e07 JD |
272 | error: |
273 | return BT_CB_ERROR_STOP; | |
863dc485 JD |
274 | end_stop: |
275 | return BT_CB_OK_STOP; | |
6112d0d4 JD |
276 | } |
277 | ||
246d5992 JD |
278 | enum bt_cb_ret handle_kprobes(struct bt_ctf_event *call_data, void *private_data) |
279 | { | |
280 | int i; | |
281 | struct kprobes *kprobe; | |
282 | ||
283 | /* for kprobes */ | |
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) { | |
287 | kprobe->count++; | |
288 | } | |
289 | } | |
290 | ||
291 | return BT_CB_OK; | |
292 | } | |
293 | ||
1fc22eb4 JD |
294 | /* |
295 | * hook on each event to check the timestamp and refresh the display if | |
296 | * necessary | |
297 | */ | |
4adc8274 | 298 | enum bt_cb_ret check_timestamp(struct bt_ctf_event *call_data, void *private_data) |
1fc22eb4 JD |
299 | { |
300 | unsigned long timestamp; | |
301 | ||
c78f2cdc | 302 | timestamp = bt_ctf_get_timestamp(call_data); |
1fc22eb4 JD |
303 | if (timestamp == -1ULL) |
304 | goto error; | |
305 | ||
863dc485 JD |
306 | /* can happen in network live when tracing is idle */ |
307 | if (timestamp < last_event_ts) | |
308 | goto end_stop; | |
309 | ||
310 | last_event_ts = timestamp; | |
311 | ||
1fc22eb4 JD |
312 | if (last_display_update == 0) |
313 | last_display_update = timestamp; | |
314 | ||
315 | if (timestamp - last_display_update >= refresh_display) { | |
316 | sem_wait(&goodtoupdate); | |
317 | g_ptr_array_add(copies, get_copy_lttngtop(last_display_update, | |
318 | timestamp)); | |
319 | sem_post(&goodtodisplay); | |
320 | sem_post(&bootstrap); | |
321 | last_display_update = timestamp; | |
322 | } | |
323 | return BT_CB_OK; | |
324 | ||
325 | error: | |
326 | fprintf(stderr, "check_timestamp callback error\n"); | |
327 | return BT_CB_ERROR_STOP; | |
863dc485 JD |
328 | |
329 | end_stop: | |
330 | return BT_CB_OK_STOP; | |
1fc22eb4 JD |
331 | } |
332 | ||
333 | /* | |
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) | |
336 | */ | |
337 | struct perfcounter *get_perf_counter(const char *name, struct processtop *proc, | |
338 | struct cputime *cpu) | |
339 | { | |
bb6d72a2 | 340 | struct perfcounter *ret; |
1fc22eb4 JD |
341 | GHashTable *table; |
342 | ||
343 | if (proc) | |
344 | table = proc->perf; | |
345 | else if (cpu) | |
346 | table = cpu->perf; | |
347 | else | |
348 | goto error; | |
349 | ||
350 | ret = g_hash_table_lookup(table, (gpointer) name); | |
351 | if (ret) | |
352 | goto end; | |
353 | ||
559c9f86 | 354 | ret = g_new0(struct perfcounter, 1); |
1fc22eb4 JD |
355 | /* by default, make it visible in the UI */ |
356 | ret->visible = 1; | |
85db4618 | 357 | g_hash_table_insert(table, (gpointer) strdup(name), ret); |
1fc22eb4 | 358 | |
1fc22eb4 JD |
359 | end: |
360 | return ret; | |
361 | ||
362 | error: | |
363 | return NULL; | |
364 | } | |
365 | ||
366 | void update_perf_value(struct processtop *proc, struct cputime *cpu, | |
367 | const char *name, int value) | |
368 | { | |
369 | struct perfcounter *cpu_perf, *process_perf; | |
370 | ||
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; | |
376 | } | |
377 | } | |
378 | ||
4adc8274 | 379 | void extract_perf_counter_scope(const struct bt_ctf_event *event, |
2e0a1190 | 380 | const struct bt_definition *scope, |
1fc22eb4 JD |
381 | struct processtop *proc, |
382 | struct cputime *cpu) | |
383 | { | |
2e0a1190 JD |
384 | struct bt_definition const * const *list = NULL; |
385 | const struct bt_definition *field; | |
1fc22eb4 | 386 | unsigned int count; |
bb6d72a2 JD |
387 | struct perfcounter *perfcounter; |
388 | GHashTableIter iter; | |
389 | gpointer key; | |
390 | int ret; | |
1fc22eb4 JD |
391 | |
392 | if (!scope) | |
393 | goto end; | |
394 | ||
395 | ret = bt_ctf_get_field_list(event, scope, &list, &count); | |
396 | if (ret < 0) | |
397 | goto end; | |
398 | ||
bb6d72a2 JD |
399 | if (count == 0) |
400 | goto end; | |
401 | ||
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); | |
405 | if (field) { | |
406 | int value = bt_ctf_get_uint64(field); | |
1fc22eb4 JD |
407 | if (bt_ctf_field_get_error()) |
408 | continue; | |
bb6d72a2 | 409 | update_perf_value(proc, cpu, (char *) key, value); |
1fc22eb4 JD |
410 | } |
411 | } | |
412 | ||
413 | end: | |
414 | return; | |
415 | } | |
416 | ||
4adc8274 | 417 | void update_perf_counter(struct processtop *proc, const struct bt_ctf_event *event) |
1fc22eb4 | 418 | { |
1fc22eb4 | 419 | struct cputime *cpu; |
2e0a1190 | 420 | const struct bt_definition *scope; |
1fc22eb4 | 421 | |
d67167cd | 422 | cpu = get_cpu(get_cpu_id(event)); |
1fc22eb4 JD |
423 | |
424 | scope = bt_ctf_get_top_level_scope(event, BT_STREAM_EVENT_CONTEXT); | |
425 | extract_perf_counter_scope(event, scope, proc, cpu); | |
426 | ||
427 | scope = bt_ctf_get_top_level_scope(event, BT_STREAM_PACKET_CONTEXT); | |
428 | extract_perf_counter_scope(event, scope, proc, cpu); | |
429 | ||
430 | scope = bt_ctf_get_top_level_scope(event, BT_EVENT_CONTEXT); | |
431 | extract_perf_counter_scope(event, scope, proc, cpu); | |
1fc22eb4 JD |
432 | } |
433 | ||
4adc8274 | 434 | enum bt_cb_ret fix_process_table(struct bt_ctf_event *call_data, |
1fc22eb4 JD |
435 | void *private_data) |
436 | { | |
1402044a | 437 | int pid, tid, ppid, vpid, vtid, vppid; |
c8d75a13 | 438 | char *comm, *hostname; |
1fc22eb4 | 439 | struct processtop *parent, *child; |
1fc22eb4 JD |
440 | unsigned long timestamp; |
441 | ||
c78f2cdc | 442 | timestamp = bt_ctf_get_timestamp(call_data); |
1fc22eb4 JD |
443 | if (timestamp == -1ULL) |
444 | goto error; | |
445 | ||
1dec520a JD |
446 | pid = get_context_pid(call_data); |
447 | if (pid == -1ULL) { | |
1fc22eb4 JD |
448 | goto error; |
449 | } | |
96aa77de | 450 | |
1dec520a JD |
451 | tid = get_context_tid(call_data); |
452 | if (tid == -1ULL) { | |
1fc22eb4 JD |
453 | goto error; |
454 | } | |
1dec520a JD |
455 | ppid = get_context_ppid(call_data); |
456 | if (ppid == -1ULL) { | |
1fc22eb4 JD |
457 | goto error; |
458 | } | |
1402044a JD |
459 | vpid = get_context_vpid(call_data); |
460 | if (pid == -1ULL) { | |
461 | vpid = -1; | |
462 | } | |
463 | vtid = get_context_vtid(call_data); | |
464 | if (tid == -1ULL) { | |
465 | vtid = -1; | |
466 | } | |
467 | vppid = get_context_vppid(call_data); | |
468 | if (ppid == -1ULL) { | |
469 | vppid = -1; | |
470 | } | |
1dec520a JD |
471 | comm = get_context_comm(call_data); |
472 | if (!comm) { | |
1fc22eb4 JD |
473 | goto error; |
474 | } | |
c8d75a13 JD |
475 | /* optional */ |
476 | hostname = get_context_hostname(call_data); | |
1fc22eb4 JD |
477 | |
478 | /* find or create the current process */ | |
479 | child = find_process_tid(<tngtop, tid, comm); | |
480 | if (!child) | |
906c08f6 | 481 | child = add_proc(<tngtop, tid, comm, timestamp, hostname); |
96aa77de JD |
482 | if (!child) |
483 | goto end; | |
c8d75a13 | 484 | update_proc(child, pid, tid, ppid, vpid, vtid, vppid, comm, hostname); |
1fc22eb4 JD |
485 | |
486 | if (pid != tid) { | |
487 | /* find or create the parent */ | |
488 | parent = find_process_tid(<tngtop, pid, comm); | |
489 | if (!parent) { | |
906c08f6 | 490 | parent = add_proc(<tngtop, pid, comm, timestamp, hostname); |
96aa77de JD |
491 | if (parent) |
492 | parent->pid = pid; | |
1fc22eb4 JD |
493 | } |
494 | ||
495 | /* attach the parent to the current process */ | |
496 | child->threadparent = parent; | |
497 | add_thread(parent, child); | |
498 | } | |
499 | ||
500 | update_perf_counter(child, call_data); | |
501 | ||
96aa77de | 502 | end: |
1fc22eb4 JD |
503 | return BT_CB_OK; |
504 | ||
505 | error: | |
506 | return BT_CB_ERROR_STOP; | |
507 | } | |
508 | ||
509 | void init_lttngtop() | |
510 | { | |
511 | copies = g_ptr_array_new(); | |
0d91c12a | 512 | global_perf_liszt = g_hash_table_new(g_str_hash, g_str_equal); |
da4353bb | 513 | global_filter_list = g_hash_table_new(g_str_hash, g_str_equal); |
114cae59 | 514 | global_host_list = g_hash_table_new(g_str_hash, g_str_equal); |
1fc22eb4 JD |
515 | |
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); | |
522 | ||
e05a35a6 JD |
523 | reset_global_counters(); |
524 | lttngtop.nbproc = 0; | |
525 | lttngtop.nbthreads = 0; | |
526 | lttngtop.nbfiles = 0; | |
527 | ||
30b646c4 JD |
528 | lttngtop.process_hash_table = g_hash_table_new(g_direct_hash, |
529 | g_direct_equal); | |
1fc22eb4 JD |
530 | lttngtop.process_table = g_ptr_array_new(); |
531 | lttngtop.files_table = g_ptr_array_new(); | |
532 | lttngtop.cpu_table = g_ptr_array_new(); | |
da4353bb JD |
533 | |
534 | toggle_filter = -1; | |
1fc22eb4 JD |
535 | } |
536 | ||
c263c4eb | 537 | void usage(FILE *fp) |
1fc22eb4 | 538 | { |
c263c4eb | 539 | fprintf(fp, "LTTngTop %s\n\n", VERSION); |
c8d75a13 JD |
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"); | |
241ba90a | 547 | fprintf(fp, " -k, --kprobes Comma-separated list of kprobes to insert (same format as lttng enable-event)\n"); |
1fc22eb4 JD |
548 | } |
549 | ||
f16e36fc JD |
550 | /* |
551 | * Parse probe options. | |
552 | * Shamelessly stolen from lttng-tools : | |
553 | * src/bin/lttng/commands/enable_events.c | |
554 | */ | |
555 | static struct kprobes *parse_probe_opts(char *opt) | |
556 | { | |
557 | char s_hex[19]; | |
558 | char name[LTTNG_SYMBOL_NAME_LEN]; | |
559 | struct kprobes *kprobe; | |
560 | int ret; | |
561 | ||
562 | /* | |
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"); | |
567 | */ | |
568 | ||
569 | if (opt == NULL) { | |
570 | kprobe = NULL; | |
571 | goto end; | |
572 | } | |
573 | ||
574 | kprobe = g_new0(struct kprobes, 1); | |
575 | ||
576 | /* Check for symbol+offset */ | |
577 | ret = sscanf(opt, "%[^'+']+%s", name, s_hex); | |
578 | if (ret == 2) { | |
b1acd2b3 JD |
579 | ret = asprintf(&kprobe->probe_name, "probe_%s", name); |
580 | ret = asprintf(&kprobe->symbol_name, "%s", name); | |
f16e36fc JD |
581 | |
582 | if (strlen(s_hex) == 0) { | |
583 | fprintf(stderr, "Invalid probe offset %s", s_hex); | |
584 | ret = -1; | |
585 | goto end; | |
586 | } | |
587 | kprobe->probe_offset = strtoul(s_hex, NULL, 0); | |
588 | kprobe->probe_addr = 0; | |
589 | goto end; | |
590 | } | |
591 | ||
592 | /* Check for symbol */ | |
593 | if (isalpha(name[0])) { | |
594 | ret = sscanf(opt, "%s", name); | |
595 | if (ret == 1) { | |
b1acd2b3 JD |
596 | ret = asprintf(&kprobe->probe_name, "probe_%s", name); |
597 | ret = asprintf(&kprobe->symbol_name, "%s", name); | |
f16e36fc JD |
598 | kprobe->probe_offset = 0; |
599 | kprobe->probe_addr = 0; | |
600 | goto end; | |
601 | } | |
602 | } | |
603 | ||
604 | /* Check for address */ | |
605 | ret = sscanf(opt, "%s", s_hex); | |
606 | if (ret > 0) { | |
607 | if (strlen(s_hex) == 0) { | |
608 | fprintf(stderr, "Invalid probe address %s", s_hex); | |
609 | ret = -1; | |
610 | goto end; | |
611 | } | |
b1acd2b3 | 612 | ret = asprintf(&kprobe->probe_name, "probe_%s", s_hex); |
f16e36fc JD |
613 | kprobe->probe_offset = 0; |
614 | kprobe->probe_addr = strtoul(s_hex, NULL, 0); | |
615 | goto end; | |
616 | } | |
617 | ||
618 | /* No match */ | |
619 | kprobe = NULL; | |
620 | ||
621 | end: | |
622 | return kprobe; | |
623 | } | |
624 | ||
1fc22eb4 JD |
625 | /* |
626 | * Return 0 if caller should continue, < 0 if caller should return | |
627 | * error, > 0 if caller should exit without reporting error. | |
628 | */ | |
629 | static int parse_options(int argc, char **argv) | |
630 | { | |
631 | poptContext pc; | |
632 | int opt, ret = 0; | |
57bff788 JD |
633 | char *tmp_str; |
634 | int *tid; | |
1fc22eb4 | 635 | |
b1acd2b3 JD |
636 | remote_live = 0; |
637 | ||
1fc22eb4 JD |
638 | pc = poptGetContext(NULL, argc, (const char **) argv, long_options, 0); |
639 | poptReadDefaultConfig(pc, 0); | |
640 | ||
641 | while ((opt = poptGetNextOpt(pc)) != -1) { | |
642 | switch (opt) { | |
643 | case OPT_HELP: | |
644 | usage(stdout); | |
645 | ret = 1; /* exit cleanly */ | |
646 | goto end; | |
6777529d JD |
647 | case OPT_TEXTDUMP: |
648 | opt_textdump = 1; | |
32b70e07 JD |
649 | break; |
650 | case OPT_CHILD: | |
651 | opt_textdump = 1; | |
652 | opt_child = 1; | |
653 | break; | |
654 | case OPT_PID: | |
da4353bb | 655 | toggle_filter = 1; |
ea5d1dc9 | 656 | tid_filter_list = g_hash_table_new(g_str_hash, |
c8d75a13 | 657 | g_str_equal); |
57bff788 JD |
658 | tmp_str = strtok(opt_tid, ","); |
659 | while (tmp_str) { | |
660 | tid = malloc(sizeof(int)); | |
661 | *tid = atoi(tmp_str); | |
ea5d1dc9 | 662 | g_hash_table_insert(tid_filter_list, |
c8d75a13 JD |
663 | (gpointer) tid, tid); |
664 | tmp_str = strtok(NULL, ","); | |
665 | } | |
666 | break; | |
667 | case OPT_HOSTNAME: | |
da4353bb | 668 | toggle_filter = 1; |
c8d75a13 JD |
669 | tmp_str = strtok(opt_hostname, ","); |
670 | while (tmp_str) { | |
467097ac | 671 | add_hostname_list(tmp_str, 1); |
57bff788 JD |
672 | tmp_str = strtok(NULL, ","); |
673 | } | |
32b70e07 | 674 | break; |
b1acd2b3 JD |
675 | case OPT_RELAY_HOSTNAME: |
676 | remote_live = 1; | |
677 | break; | |
f16e36fc JD |
678 | case OPT_KPROBES: |
679 | lttngtop.kprobes_table = g_ptr_array_new(); | |
680 | tmp_str = strtok(opt_kprobes, ","); | |
681 | while (tmp_str) { | |
682 | struct kprobes *kprobe; | |
683 | ||
684 | kprobe = parse_probe_opts(tmp_str); | |
685 | if (kprobe) { | |
686 | g_ptr_array_add( | |
687 | lttngtop.kprobes_table, | |
688 | kprobe); | |
689 | } else { | |
690 | ret = -EINVAL; | |
691 | goto end; | |
692 | } | |
693 | tmp_str = strtok(NULL, ","); | |
694 | } | |
695 | break; | |
1fc22eb4 JD |
696 | default: |
697 | ret = -EINVAL; | |
698 | goto end; | |
699 | } | |
700 | } | |
701 | ||
702 | opt_input_path = poptGetArg(pc); | |
16b22a0f | 703 | |
1fc22eb4 JD |
704 | end: |
705 | if (pc) { | |
706 | poptFreeContext(pc); | |
707 | } | |
708 | return ret; | |
709 | } | |
710 | ||
711 | void iter_trace(struct bt_context *bt_ctx) | |
712 | { | |
713 | struct bt_ctf_iter *iter; | |
714 | struct bt_iter_pos begin_pos; | |
246d5992 | 715 | struct kprobes *kprobe; |
4adc8274 | 716 | const struct bt_ctf_event *event; |
246d5992 | 717 | int i; |
1fc22eb4 JD |
718 | int ret = 0; |
719 | ||
720 | begin_pos.type = BT_SEEK_BEGIN; | |
721 | iter = bt_ctf_iter_create(bt_ctx, &begin_pos, NULL); | |
722 | ||
da4353bb JD |
723 | /* at each event, verify the status of the process table */ |
724 | bt_ctf_iter_add_callback(iter, 0, NULL, 0, | |
725 | fix_process_table, | |
726 | NULL, NULL, NULL); | |
6777529d JD |
727 | if (opt_textdump) { |
728 | bt_ctf_iter_add_callback(iter, 0, NULL, 0, | |
729 | print_timestamp, | |
730 | NULL, NULL, NULL); | |
731 | } else { | |
732 | /* at each event check if we need to refresh */ | |
733 | bt_ctf_iter_add_callback(iter, 0, NULL, 0, | |
734 | check_timestamp, | |
735 | NULL, NULL, NULL); | |
6777529d JD |
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, | |
749 | NULL, NULL, NULL); | |
750 | ||
751 | /* for IO top */ | |
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( | |
ceb3a221 | 769 | "lttng_statedump_file_descriptor"), |
6777529d JD |
770 | NULL, 0, handle_statedump_file_descriptor, |
771 | NULL, NULL, NULL); | |
246d5992 JD |
772 | |
773 | /* for kprobes */ | |
da4353bb JD |
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( | |
779 | kprobe->probe_name), | |
780 | NULL, 0, handle_kprobes, | |
781 | NULL, NULL, NULL); | |
782 | } | |
246d5992 | 783 | } |
6777529d JD |
784 | } |
785 | ||
fbbda4da | 786 | while ((event = bt_ctf_iter_read_event(iter)) != NULL) { |
050f9cf9 | 787 | if (quit || reload_trace) |
ae9e85c7 | 788 | goto end_iter; |
1fc22eb4 JD |
789 | ret = bt_iter_next(bt_ctf_get_iter(iter)); |
790 | if (ret < 0) | |
791 | goto end_iter; | |
792 | } | |
793 | ||
794 | /* block until quit, we reached the end of the trace */ | |
795 | sem_wait(&end_trace_sem); | |
796 | ||
797 | end_iter: | |
06570214 | 798 | bt_ctf_iter_destroy(iter); |
1fc22eb4 JD |
799 | } |
800 | ||
801 | /* | |
802 | * bt_context_add_traces_recursive: Open a trace recursively | |
803 | * (copied from BSD code in converter/babeltrace.c) | |
804 | * | |
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. | |
808 | * | |
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; | |
812 | */ | |
813 | int bt_context_add_traces_recursive(struct bt_context *ctx, const char *path, | |
814 | const char *format_str, | |
2e0a1190 | 815 | void (*packet_seek)(struct bt_stream_pos *pos, |
1fc22eb4 JD |
816 | size_t offset, int whence)) |
817 | { | |
818 | FTS *tree; | |
819 | FTSENT *node; | |
820 | GArray *trace_ids; | |
821 | char lpath[PATH_MAX]; | |
822 | char * const paths[2] = { lpath, NULL }; | |
0d567cf1 | 823 | int ret = -1; |
1fc22eb4 JD |
824 | |
825 | /* | |
826 | * Need to copy path, because fts_open can change it. | |
827 | * It is the pointer array, not the strings, that are constant. | |
828 | */ | |
829 | strncpy(lpath, path, PATH_MAX); | |
830 | lpath[PATH_MAX - 1] = '\0'; | |
831 | ||
832 | tree = fts_open(paths, FTS_NOCHDIR | FTS_LOGICAL, 0); | |
833 | if (tree == NULL) { | |
834 | fprintf(stderr, "[error] [Context] Cannot traverse \"%s\" for reading.\n", | |
835 | path); | |
836 | return -EINVAL; | |
837 | } | |
838 | ||
839 | trace_ids = g_array_new(FALSE, TRUE, sizeof(int)); | |
840 | ||
841 | while ((node = fts_read(tree))) { | |
842 | int dirfd, metafd; | |
843 | ||
844 | if (!(node->fts_info & FTS_D)) | |
845 | continue; | |
846 | ||
847 | dirfd = open(node->fts_accpath, 0); | |
848 | if (dirfd < 0) { | |
849 | fprintf(stderr, "[error] [Context] Unable to open trace " | |
850 | "directory file descriptor.\n"); | |
851 | ret = dirfd; | |
852 | goto error; | |
853 | } | |
854 | metafd = openat(dirfd, "metadata", O_RDONLY); | |
855 | if (metafd < 0) { | |
7314c855 JD |
856 | close(dirfd); |
857 | ret = -1; | |
858 | continue; | |
1fc22eb4 JD |
859 | } else { |
860 | int trace_id; | |
861 | ||
862 | ret = close(metafd); | |
863 | if (ret < 0) { | |
864 | perror("close"); | |
865 | goto error; | |
866 | } | |
867 | ret = close(dirfd); | |
868 | if (ret < 0) { | |
869 | perror("close"); | |
870 | goto error; | |
871 | } | |
872 | ||
873 | trace_id = bt_context_add_trace(ctx, | |
874 | node->fts_accpath, format_str, | |
875 | packet_seek, NULL, NULL); | |
876 | if (trace_id < 0) { | |
0d567cf1 | 877 | fprintf(stderr, "[warning] [Context] opening trace \"%s\" from %s " |
1fc22eb4 | 878 | "for reading.\n", node->fts_accpath, path); |
0d567cf1 JD |
879 | /* Allow to skip erroneous traces. */ |
880 | continue; | |
1fc22eb4 JD |
881 | } |
882 | g_array_append_val(trace_ids, trace_id); | |
883 | } | |
884 | } | |
885 | ||
886 | g_array_free(trace_ids, TRUE); | |
0d567cf1 | 887 | return ret; |
1fc22eb4 JD |
888 | |
889 | error: | |
890 | return ret; | |
891 | } | |
892 | ||
4553b4d1 | 893 | static int check_field_requirements(const struct bt_ctf_field_decl *const * field_list, |
a54d0d2c JD |
894 | int field_cnt, int *tid_check, int *pid_check, |
895 | int *procname_check, int *ppid_check) | |
896 | { | |
897 | int j; | |
bb6d72a2 JD |
898 | struct perfcounter *global; |
899 | const char *name; | |
a54d0d2c JD |
900 | |
901 | for (j = 0; j < field_cnt; j++) { | |
bb6d72a2 | 902 | name = bt_ctf_get_decl_field_name(field_list[j]); |
a54d0d2c | 903 | if (*tid_check == 0) { |
bb6d72a2 | 904 | if (strncmp(name, "tid", 3) == 0) |
a54d0d2c | 905 | (*tid_check)++; |
a54d0d2c JD |
906 | } |
907 | if (*pid_check == 0) { | |
da401e9c | 908 | if (strncmp(name, "pid", 3) == 0) |
a54d0d2c JD |
909 | (*pid_check)++; |
910 | } | |
911 | if (*ppid_check == 0) { | |
bb6d72a2 | 912 | if (strncmp(name, "ppid", 4) == 0) |
a54d0d2c JD |
913 | (*ppid_check)++; |
914 | } | |
915 | if (*procname_check == 0) { | |
bb6d72a2 | 916 | if (strncmp(name, "procname", 8) == 0) |
a54d0d2c JD |
917 | (*procname_check)++; |
918 | } | |
bb6d72a2 JD |
919 | if (strncmp(name, "perf_", 5) == 0) { |
920 | global = g_hash_table_lookup(global_perf_liszt, (gpointer) name); | |
921 | if (!global) { | |
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) | |
925 | global->sort = 1; | |
926 | global->visible = 1; | |
927 | g_hash_table_insert(global_perf_liszt, (gpointer) strdup(name), global); | |
928 | } | |
929 | } | |
a54d0d2c | 930 | } |
bb6d72a2 | 931 | |
a54d0d2c JD |
932 | if (*tid_check == 1 && *pid_check == 1 && *ppid_check == 1 && |
933 | *procname_check == 1) | |
934 | return 0; | |
935 | ||
936 | return -1; | |
937 | } | |
938 | ||
939 | /* | |
940 | * check_requirements: check if the required context informations are available | |
941 | * | |
942 | * If each mandatory context information is available for at least in one | |
943 | * event, return 0 otherwise return -1. | |
a54d0d2c JD |
944 | */ |
945 | int check_requirements(struct bt_context *ctx) | |
946 | { | |
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; | |
950 | int tid_check = 0; | |
951 | int pid_check = 0; | |
952 | int procname_check = 0; | |
953 | int ppid_check = 0; | |
954 | int ret = 0; | |
955 | ||
b1acd2b3 JD |
956 | ret = bt_ctf_get_event_decl_list(0, ctx, &evt_list, &evt_cnt); |
957 | if (ret < 0) { | |
958 | goto end; | |
959 | } | |
960 | ||
a54d0d2c JD |
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, | |
966 | &ppid_check); | |
a54d0d2c JD |
967 | |
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, | |
972 | &ppid_check); | |
a54d0d2c JD |
973 | |
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, | |
978 | &ppid_check); | |
a54d0d2c JD |
979 | } |
980 | ||
981 | if (tid_check == 0) { | |
982 | ret = -1; | |
983 | fprintf(stderr, "[error] missing tid context information\n"); | |
984 | } | |
985 | if (pid_check == 0) { | |
986 | ret = -1; | |
987 | fprintf(stderr, "[error] missing pid context information\n"); | |
988 | } | |
989 | if (ppid_check == 0) { | |
990 | ret = -1; | |
991 | fprintf(stderr, "[error] missing ppid context information\n"); | |
992 | } | |
993 | if (procname_check == 0) { | |
994 | ret = -1; | |
995 | fprintf(stderr, "[error] missing procname context information\n"); | |
996 | } | |
997 | ||
16b22a0f JD |
998 | end: |
999 | return ret; | |
1000 | } | |
1001 | ||
1fc22eb4 JD |
1002 | int main(int argc, char **argv) |
1003 | { | |
1004 | int ret; | |
1005 | struct bt_context *bt_ctx = NULL; | |
1006 | ||
957eed46 | 1007 | init_lttngtop(); |
1fc22eb4 JD |
1008 | ret = parse_options(argc, argv); |
1009 | if (ret < 0) { | |
1010 | fprintf(stdout, "Error parsing options.\n\n"); | |
1011 | usage(stdout); | |
1012 | exit(EXIT_FAILURE); | |
1013 | } else if (ret > 0) { | |
1014 | exit(EXIT_SUCCESS); | |
1015 | } | |
1016 | ||
863dc485 JD |
1017 | if (!opt_input_path && !remote_live) { |
1018 | /* mmap live */ | |
1019 | #ifdef LTTNGTOP_MMAP_LIVE | |
24797198 JD |
1020 | if (opt_textdump) { |
1021 | signal(SIGTERM, handle_textdump_sigterm); | |
1022 | signal(SIGINT, handle_textdump_sigterm); | |
1023 | } | |
b1acd2b3 | 1024 | mmap_live_loop(bt_ctx); |
ae9e85c7 | 1025 | pthread_join(timer_thread, NULL); |
eb677852 JD |
1026 | quit = 1; |
1027 | pthread_join(display_thread, NULL); | |
6777529d | 1028 | |
c78f2cdc | 1029 | lttng_stop_tracing("test"); |
c78f2cdc JD |
1030 | lttng_destroy_session("test"); |
1031 | ||
1fc22eb4 | 1032 | goto end; |
863dc485 JD |
1033 | #else |
1034 | fprintf(stderr, "Mmap live support not compiled\n"); | |
1035 | goto end; | |
1036 | #endif /* LTTNGTOP_MMAP_LIVE */ | |
1037 | } else if (!opt_input_path && remote_live) { | |
1038 | /* network live */ | |
1039 | ret = setup_network_live(opt_relay_hostname); | |
1040 | if (ret < 0) { | |
1041 | goto end; | |
1042 | } | |
1043 | ||
1044 | ret = open_trace(&bt_ctx); | |
1045 | if (ret < 0) { | |
1046 | goto end; | |
1047 | } | |
16b22a0f | 1048 | } else { |
957eed46 | 1049 | //init_lttngtop(); |
16b22a0f JD |
1050 | |
1051 | bt_ctx = bt_context_create(); | |
1052 | ret = bt_context_add_traces_recursive(bt_ctx, opt_input_path, "ctf", NULL); | |
1053 | if (ret < 0) { | |
1054 | fprintf(stderr, "[error] Opening the trace\n"); | |
1055 | goto end; | |
1056 | } | |
863dc485 | 1057 | } |
1fc22eb4 | 1058 | |
863dc485 JD |
1059 | ret = check_requirements(bt_ctx); |
1060 | if (ret < 0) { | |
1061 | fprintf(stderr, "[error] some mandatory contexts were missing, exiting.\n"); | |
1062 | goto end; | |
1063 | } | |
1064 | if (!opt_textdump) { | |
16b22a0f JD |
1065 | pthread_create(&display_thread, NULL, ncurses_display, (void *) NULL); |
1066 | pthread_create(&timer_thread, NULL, refresh_thread, (void *) NULL); | |
863dc485 | 1067 | } |
1fc22eb4 | 1068 | |
863dc485 | 1069 | iter_trace(bt_ctx); |
1fc22eb4 | 1070 | |
863dc485 JD |
1071 | pthread_join(display_thread, NULL); |
1072 | quit = 1; | |
1073 | pthread_join(timer_thread, NULL); | |
1fc22eb4 JD |
1074 | |
1075 | end: | |
16b22a0f JD |
1076 | if (bt_ctx) |
1077 | bt_context_put(bt_ctx); | |
1078 | ||
1fc22eb4 JD |
1079 | return 0; |
1080 | } |