guint lttv_traceset_get_cpuid_from_event(LttvEvent *event) { unsigned long timestamp; unsigned int cpu_id; struct bt_ctf_event *ctf_event = event->bt_event; timestamp = bt_ctf_get_timestamp(ctf_event); if (timestamp == -1ULL) { return 0; } const struct bt_definition *scope = bt_ctf_get_top_level_scope(ctf_event, BT_STREAM_PACKET_CONTEXT); if (bt_ctf_field_get_error()) { return 0; } cpu_id = bt_ctf_get_uint64(bt_ctf_get_field(ctf_event, scope, "cpu_id")); if (bt_ctf_field_get_error()) { return 0; } else { return cpu_id; } }
void print_fields(struct bt_ctf_event *event, const char *procname, int pid) { unsigned int cnt, i; const struct bt_definition *const * list; const struct bt_declaration *l; const struct bt_definition *scope; enum ctf_type_id type; const char *str; struct processtop *current_proc; struct files *current_file; int fd, fd_value = -1; scope = bt_ctf_get_top_level_scope(event, BT_EVENT_FIELDS); bt_ctf_get_field_list(event, scope, &list, &cnt); for (i = 0; i < cnt; i++) { if (i != 0) fprintf(output, ", "); fprintf(output, "%s = ", bt_ctf_field_name(list[i])); l = bt_ctf_get_decl_from_def(list[i]); if (strncmp(bt_ctf_field_name(list[i]), "fd", 2) == 0) fd = 1; else fd = 0; type = bt_ctf_field_type(l); if (type == CTF_TYPE_INTEGER) { if (bt_ctf_get_int_signedness(l) == 0) { fd_value = bt_ctf_get_uint64(list[i]); fprintf(output, "%" PRIu64, bt_ctf_get_uint64(list[i])); } else { fd_value = bt_ctf_get_int64(list[i]); fprintf(output, "%" PRId64, bt_ctf_get_int64(list[i])); } } else if (type == CTF_TYPE_STRING) { fprintf(output, "%s", bt_ctf_get_string(list[i])); } else if (type == CTF_TYPE_ARRAY) { str = bt_ctf_get_char_array(list[i]); if (!bt_ctf_field_get_error() && str) fprintf(output, "%s", str); } if (fd) { current_proc = find_process_tid(<tngtop, pid, procname); if (!current_proc) continue; current_file = get_file(current_proc, fd_value); if (!current_file || !current_file->name) continue; fprintf(output, "<%s>", current_file->name); } } }
uint64_t get_cpu_id(const struct bt_ctf_event *event) { const struct definition *scope; uint64_t cpu_id; scope = bt_ctf_get_top_level_scope(event, BT_STREAM_PACKET_CONTEXT); cpu_id = bt_ctf_get_uint64(bt_ctf_get_field(event, scope, "cpu_id")); if (bt_ctf_field_get_error()) { fprintf(stderr, "[error] get cpu_id\n"); return -1ULL; } return cpu_id; }
char *get_context_comm(const struct bt_ctf_event *event) { const struct definition *scope; char *comm; scope = bt_ctf_get_top_level_scope(event, BT_STREAM_EVENT_CONTEXT); comm = bt_ctf_get_char_array(bt_ctf_get_field(event, scope, "_procname")); if (bt_ctf_field_get_error()) { fprintf(stderr, "Missing comm context info\n"); return NULL; } return comm; }
uint64_t get_context_ppid(const struct bt_ctf_event *event) { const struct definition *scope; uint64_t ppid; scope = bt_ctf_get_top_level_scope(event, BT_STREAM_EVENT_CONTEXT); ppid = bt_ctf_get_int64(bt_ctf_get_field(event, scope, "_ppid")); if (bt_ctf_field_get_error()) { fprintf(stderr, "Missing ppid context info\n"); return -1ULL; } return ppid; }
int getFieldsFromEvent(struct bt_ctf_event *ctf_event, GString* fields, gboolean field_names) { struct bt_definition const * const *list = NULL; unsigned int count; int i = 0, ret = 0; gboolean noError = TRUE; const struct bt_definition *scope; scope = bt_ctf_get_top_level_scope(ctf_event, BT_EVENT_FIELDS); if (!scope) { noError = FALSE; } if (noError) { ret = bt_ctf_get_field_list(ctf_event, scope, &list, &count); if (ret < 0) { noError = TRUE; } else { for (i = 0; i < count; i++) { if (i > 0) { g_string_append_printf(fields, ", "); } const char *name = bt_ctf_field_name(list[i]); if (field_names) { g_string_append_printf(fields, "%s = ", name); } getFields(ctf_event, list[i] ,fields); if (bt_ctf_field_get_error()) { continue; } } } } if (!noError) { ret = -1; } return ret; }
int getProcessInfosFromEvent(LttvEvent *event, GString* processInfos) { int pid=0, tid=0, ppid=0; const char *procname; unsigned long timestamp; int ret = 0; gboolean noError = TRUE; guint cpu; LttvTraceState *state = event->state; LttvProcessState *process; struct bt_ctf_event *ctf_event = event->bt_event; cpu = lttv_traceset_get_cpuid_from_event(event); process = state->running_process[cpu]; timestamp = bt_ctf_get_timestamp(ctf_event); pid = process->pid; tid = process->tgid; ppid = process->ppid; procname = g_quark_to_string(process->name); if (timestamp == -1ULL) { noError = FALSE; } #if 0 if (noError) { scope = bt_ctf_get_top_level_scope(ctf_event, BT_STREAM_EVENT_CONTEXT); if (bt_ctf_field_get_error()) { noError = FALSE; } } if (noError) { pid = bt_ctf_get_int64(bt_ctf_get_field(ctf_event, scope, "_pid")); if (bt_ctf_field_get_error()) { noError = FALSE; } } if (noError) { tid = bt_ctf_get_int64(bt_ctf_get_field(ctf_event, scope, "_tid")); if (bt_ctf_field_get_error()) { noError = FALSE; } } if (noError) { ppid = bt_ctf_get_int64(bt_ctf_get_field(ctf_event, scope, "_ppid")); if (bt_ctf_field_get_error()) { noError = FALSE; } } if (noError) { procname = bt_ctf_get_char_array(bt_ctf_get_field(ctf_event, scope, "_procname")); if (bt_ctf_field_get_error()) { noError = FALSE; } } #endif if (noError||1) { g_string_append_printf(processInfos, "%u, %u, %s, %u. %s, %s", pid, tid, procname, ppid, g_quark_to_string(process->state->t), g_quark_to_string(process->state->s)); } else { ret = -1; } return ret; }
/* * hook on each event to check the timestamp and refresh the display if * necessary */ 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; int syscall_exit = 0; 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_procname || 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 (((strncmp(bt_ctf_event_name(call_data), "exit_syscall", 12)) == 0) || ((strncmp(bt_ctf_event_name(call_data), "syscall_exit", 12)) == 0)) { syscall_exit = 1; } if (last_syscall && !syscall_exit) { 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) || (strncmp(bt_ctf_event_name(call_data), "syscall_entry", 13) == 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 (syscall_exit) {