+
+enum bt_cb_ret handle_statedump_process_state(struct bt_ctf_event *call_data,
+ void *private_data)
+{
+ const struct bt_definition *scope;
+ struct processtop *proc;
+ unsigned long timestamp;
+ int64_t pid, tid, ppid, vtid, vpid, vppid;
+ char *procname;
+
+ timestamp = bt_ctf_get_timestamp(call_data);
+ if (timestamp == -1ULL)
+ goto error;
+
+ scope = bt_ctf_get_top_level_scope(call_data,
+ BT_EVENT_FIELDS);
+ pid = bt_ctf_get_int64(bt_ctf_get_field(call_data,
+ scope, "_pid"));
+ if (bt_ctf_field_get_error()) {
+ fprintf(stderr, "Missing pid context info\n");
+ goto error;
+ }
+ ppid = bt_ctf_get_int64(bt_ctf_get_field(call_data,
+ scope, "_ppid"));
+ if (bt_ctf_field_get_error()) {
+ fprintf(stderr, "Missing ppid context info\n");
+ goto error;
+ }
+ tid = bt_ctf_get_int64(bt_ctf_get_field(call_data,
+ scope, "_tid"));
+ if (bt_ctf_field_get_error()) {
+ fprintf(stderr, "Missing tid context info\n");
+ goto error;
+ }
+ vtid = bt_ctf_get_int64(bt_ctf_get_field(call_data,
+ scope, "_vtid"));
+ if (bt_ctf_field_get_error()) {
+ fprintf(stderr, "Missing vtid context info\n");
+ goto error;
+ }
+ vpid = bt_ctf_get_int64(bt_ctf_get_field(call_data,
+ scope, "_vpid"));
+ if (bt_ctf_field_get_error()) {
+ fprintf(stderr, "Missing vpid context info\n");
+ goto error;
+ }
+ vppid = bt_ctf_get_int64(bt_ctf_get_field(call_data,
+ scope, "_vppid"));
+ if (bt_ctf_field_get_error()) {
+ fprintf(stderr, "Missing vppid context info\n");
+ goto error;
+ }
+
+ scope = bt_ctf_get_top_level_scope(call_data,
+ BT_EVENT_FIELDS);
+ procname = bt_ctf_get_char_array(bt_ctf_get_field(call_data,
+ scope, "_name"));
+ if (bt_ctf_field_get_error()) {
+ fprintf(stderr, "Missing process name context info\n");
+ goto error;
+ }
+
+ proc = find_process_tid(<tngtop, tid, procname);
+ if (proc == NULL)
+ proc = add_proc(<tngtop, tid, procname, timestamp);
+ update_proc(proc, pid, tid, ppid, vpid, vtid, vppid, procname);
+
+ if (proc) {
+ free(proc->comm);
+ proc->comm = strdup(procname);
+ proc->pid = pid;
+ }
+
+ return BT_CB_OK;
+
+error:
+ return BT_CB_ERROR_STOP;
+}
+
+struct tm format_timestamp(uint64_t timestamp)
+{
+ struct tm tm;
+ uint64_t ts_sec = 0, ts_nsec;
+ time_t time_s;
+
+ ts_nsec = timestamp;
+ ts_sec += ts_nsec / NSEC_PER_SEC;
+ ts_nsec = ts_nsec % NSEC_PER_SEC;
+
+ time_s = (time_t) ts_sec;
+
+ localtime_r(&time_s, &tm);
+
+ return tm;
+}