+enum bt_cb_ret textdump(struct bt_ctf_event *call_data, void *private_data)
+{
+ unsigned long timestamp;
+ uint64_t delta;
+ struct tm start;
+ uint64_t ts_nsec_start;
+ int pid, cpu_id, tid, ret, lookup, current_syscall = 0;
+ const struct bt_definition *scope;
+ const char *hostname, *procname;
+ struct cputime *cpu;
+ char *from_syscall = NULL;
+
+ timestamp = bt_ctf_get_timestamp(call_data);
+
+ /* can happen in network live when tracing is idle */
+ if (timestamp < last_event_ts)
+ goto end_stop;
+
+ last_event_ts = timestamp;
+
+ start = format_timestamp(timestamp);
+ ts_nsec_start = timestamp % NSEC_PER_SEC;
+
+ pid = get_context_pid(call_data);
+ if (pid == -1ULL && opt_tid) {
+ goto error;
+ }
+
+ tid = get_context_tid(call_data);
+
+ hostname = get_context_hostname(call_data);
+ if (opt_child)
+ lookup = pid;
+ else
+ lookup = tid;
+ if (opt_tid || opt_hostname || opt_exec_name) {
+ if (!lookup_filter_tid_list(lookup)) {
+ /* To display when a process of ours in getting scheduled in */
+ if (strcmp(bt_ctf_event_name(call_data), "sched_switch") == 0) {
+ int next_tid;
+
+ scope = bt_ctf_get_top_level_scope(call_data,
+ BT_EVENT_FIELDS);
+ next_tid = bt_ctf_get_int64(bt_ctf_get_field(call_data,
+ scope, "_next_tid"));
+ if (bt_ctf_field_get_error()) {
+ fprintf(stderr, "Missing next_tid field\n");
+ goto error;
+ }
+ if (!lookup_filter_tid_list(next_tid)) {
+ if (!opt_all)
+ goto end;
+ } else {
+ if (opt_all)
+ fprintf(output, "%c[1m", 27);
+ }
+ } else if (!opt_all) {
+ goto end;
+ }
+ } else {
+ if (opt_all)
+ fprintf(output, "%c[1m", 27);
+ }
+ }
+
+ if (last_syscall && (strncmp(bt_ctf_event_name(call_data),
+ "exit_syscall", 12)) != 0) {
+ last_syscall = NULL;
+ fprintf(output, " ...interrupted...\n");
+ }
+
+ cpu_id = get_cpu_id(call_data);
+ procname = get_context_comm(call_data);
+ if (strncmp(bt_ctf_event_name(call_data), "sys_", 4) == 0) {
+ cpu = get_cpu(cpu_id);
+ cpu->current_syscall = g_new0(struct syscall, 1);
+ cpu->current_syscall->name = strdup(bt_ctf_event_name(call_data));
+ cpu->current_syscall->ts_start = timestamp;
+ cpu->current_syscall->cpu_id = cpu_id;
+ last_syscall = cpu->current_syscall;
+ current_syscall = 1;
+ } else if ((strncmp(bt_ctf_event_name(call_data), "exit_syscall", 12)) == 0) {
+ struct tm start_ts;
+
+ /* Return code of a syscall if it was the last displayed event. */
+ if (last_syscall && last_syscall->ts_start == prev_ts) {
+ if (last_syscall->cpu_id == cpu_id) {
+ int64_t syscall_ret;
+
+ delta = timestamp - last_syscall->ts_start;
+ scope = bt_ctf_get_top_level_scope(call_data,
+ BT_EVENT_FIELDS);
+ syscall_ret = bt_ctf_get_int64(bt_ctf_get_field(call_data,
+ scope, "_ret"));
+
+ fprintf(output, "= %" PRId64 " (%" PRIu64 ".%09" PRIu64 "s)\n",
+ syscall_ret, delta / NSEC_PER_SEC,
+ delta % NSEC_PER_SEC);
+ last_syscall = NULL;
+ goto end;
+ } else {
+ last_syscall = NULL;
+ fprintf(output, " ...interrupted...\n");
+ }
+ }
+
+ cpu = get_cpu(cpu_id);
+ if (cpu->current_syscall) {
+ delta = timestamp - cpu->current_syscall->ts_start;
+ start_ts = format_timestamp(cpu->current_syscall->ts_start);
+ ret = asprintf(&from_syscall, " [from %02d:%02d:%02d.%09" PRIu64
+ " (+%" PRIu64 ".%09" PRIu64 ") (cpu %d) %s]",
+ start_ts.tm_hour, start_ts.tm_min, start_ts.tm_sec,
+ cpu->current_syscall->ts_start % NSEC_PER_SEC,
+ delta / NSEC_PER_SEC, delta % NSEC_PER_SEC,
+ cpu_id, cpu->current_syscall->name);
+ if (ret < 0) {
+ goto error;
+ }
+ free(cpu->current_syscall->name);
+ g_free(cpu->current_syscall);
+ cpu->current_syscall = NULL;
+ last_syscall = NULL;
+ }
+ }
+
+ if (prev_ts == 0)
+ prev_ts = timestamp;
+ delta = timestamp - prev_ts;
+ prev_ts = timestamp;
+
+ fprintf(output, "%02d:%02d:%02d.%09" PRIu64 " (+%" PRIu64 ".%09" PRIu64 ") %s%s"
+ "(cpu %d) [%s (%d/%d)] %s (",
+ start.tm_hour, start.tm_min, start.tm_sec,
+ ts_nsec_start, delta / NSEC_PER_SEC,
+ delta % NSEC_PER_SEC, (hostname) ? hostname : "",
+ (hostname) ? " ": "", cpu_id, procname, pid, tid,
+ bt_ctf_event_name(call_data));
+ print_fields(call_data, procname, pid);
+ fprintf(output, ")%s%c", (from_syscall) ? from_syscall : "",
+ (!current_syscall) ? '\n' : ' ');
+
+ free(from_syscall);
+ if (opt_all && (opt_tid || opt_hostname || opt_exec_name))
+ fprintf(output, "%c[0m", 27);
+
+end:
+ return BT_CB_OK;
+error:
+ return BT_CB_ERROR_STOP;
+end_stop:
+ return BT_CB_OK_STOP;
+}
+
+enum bt_cb_ret handle_kprobes(struct bt_ctf_event *call_data, void *private_data)
+{
+ int i;
+ struct kprobes *kprobe;
+
+ /* for kprobes */
+ for (i = 0; i < lttngtop.kprobes_table->len; i++) {
+ kprobe = g_ptr_array_index(lttngtop.kprobes_table, i);
+ if (strcmp(bt_ctf_event_name(call_data), kprobe->probe_name) == 0) {
+ kprobe->count++;
+ }
+ }
+
+ return BT_CB_OK;
+}
+
+/*
+ * hook on each event to check the timestamp and refresh the display if
+ * necessary
+ */
+enum bt_cb_ret check_timestamp(struct bt_ctf_event *call_data, void *private_data)