+
+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 = NULL, *hostname = NULL;
+
+ 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()) {
+ goto end;
+ }
+ 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, hostname);
+ update_proc(proc, pid, tid, ppid, vpid, vtid, vppid, procname, hostname);
+
+ if (proc) {
+ free(proc->comm);
+ proc->comm = strdup(procname);
+ proc->pid = pid;
+ }
+
+end:
+ 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;
+}
+
+int *lookup_tid_list(int tid)
+{
+ if (!tid_filter_list)
+ return NULL;
+
+ return g_hash_table_lookup(tid_filter_list, (gpointer) &tid);
+}
+
+struct host *lookup_hostname_list(const char *hostname)
+{
+ if (!hostname || !global_host_list)
+ return NULL;
+
+ return g_hash_table_lookup(global_host_list, (gpointer) hostname);
+}
+
+int is_hostname_filtered(const char *hostname)
+{
+ struct host *host;
+
+ host = lookup_hostname_list(hostname);
+ if (host)
+ return host->filter;
+ return 0;
+}
+
+int *lookup_filter_tid_list(int tid)
+{
+ return g_hash_table_lookup(global_filter_list, (gpointer) &tid);
+}
+
+void add_filter_tid_list(struct processtop *proc)
+{
+ unsigned long *hash_tid;
+
+ hash_tid = malloc(sizeof(unsigned long));
+ *hash_tid = proc->tid;
+ g_hash_table_insert(global_filter_list,
+ (gpointer) (unsigned long) hash_tid, proc);
+}
+
+void remove_filter_tid_list(int tid)
+{
+ g_hash_table_remove(global_filter_list,
+ (gpointer) (unsigned long) &tid);
+}
+
+struct host *add_hostname_list(char *hostname, int filter)
+{
+ struct host *host;
+
+ host = lookup_hostname_list(hostname);
+ if (host)
+ return host;
+
+ host = g_new0(struct host, 1);
+ host->hostname = strdup(hostname);
+ host->filter = filter;
+ g_hash_table_insert(global_host_list,
+ (gpointer) host->hostname,
+ (gpointer) host);
+
+ return host;
+}
+
+void update_hostname_filter(struct host *host)
+{
+ struct processtop *tmp;
+ int i;
+
+ for (i = 0; i < lttngtop.process_table->len; i++) {
+ tmp = g_ptr_array_index(lttngtop.process_table, i);
+ if (tmp->host == host) {
+ if (host->filter)
+ add_filter_tid_list(tmp);
+ else
+ remove_filter_tid_list(tmp->tid);
+ }
+ }
+}
+
+char *lookup_procname(const char *procname)
+{
+ if (!procname || !global_procname_list)
+ return NULL;
+
+ return g_hash_table_lookup(global_procname_list, (gpointer) procname);
+}
+
+char *add_procname_list(char *procname, int filter)
+{
+ char *proc;
+
+ proc = lookup_procname(procname);
+ if (proc)
+ return proc;
+
+ proc = strdup(procname);
+ g_hash_table_insert(global_procname_list,
+ (gpointer) procname, (gpointer) procname);
+
+ return proc;
+}