int set_values_position(const LttvTracesetPosition *pos) { LttvTracesetPosition previous_pos; previous_pos.iter = pos->iter; previous_pos.bt_pos = bt_iter_get_pos(bt_ctf_get_iter(pos->iter)); /* Seek to the new desired position */ lttv_traceset_seek_to_position(pos); /*Read the event*/ struct bt_ctf_event *event = bt_ctf_iter_read_event(pos->iter); if(event != NULL){ ((LttvTracesetPosition *)pos)->timestamp = bt_ctf_get_timestamp(event); LttvEvent lttv_event; lttv_event.bt_event = event; ((LttvTracesetPosition *)pos)->cpu_id = lttv_traceset_get_cpuid_from_event(<tv_event); } else { /* The event is null */ return 0; } /* Reassign the previously saved position */ lttv_traceset_seek_to_position(&previous_pos); /*We must desallocate because the function bt_iter_get_pos() does a g_new */ bt_iter_free_pos(previous_pos.bt_pos); if (pos->timestamp == G_MAXUINT64) { return 0; } return 1; }
void lttv_event_to_string(LttvEvent *event, GString *a_string, gboolean field_names, gboolean long_version) { GString* processInfos = g_string_new(""); GString* fields = g_string_new(""); GString* cpuId_str = g_string_new(""); getProcessInfosFromEvent(event, processInfos); getFieldsFromEvent(event->bt_event, fields, field_names); getCPUIdFromEvent(event, cpuId_str); g_string_set_size(a_string,0); if(long_version){ g_string_append_printf(a_string,"%" PRIu64 " %s: ", bt_ctf_get_timestamp(event->bt_event), bt_ctf_event_name(event->bt_event)); } g_string_append_printf(a_string, "{ %s }", cpuId_str->str); if (strcmp("", processInfos->str) < 0) { g_string_append_printf(a_string, ", { %s }", processInfos->str); } if (strcmp("", fields->str) < 0) { g_string_append_printf(a_string, ", { %s }", fields->str); } g_string_free(fields, TRUE); g_string_free(processInfos, TRUE); g_string_free(cpuId_str, TRUE); }
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; } }
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) {