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