fix compat with babeltrace API change at commit 03798a93f959f6c694fe98f5647481947607c604
[lttngtop.git] / src / lttngtop.c
index 1da87ea7fba16dfb0de5106d00d12b95bbe3ad34..521e085ebd6dbd8996072de9a20cc907aa54089a 100644 (file)
@@ -121,7 +121,7 @@ enum bt_cb_ret check_timestamp(struct bt_ctf_event *call_data, void *private_dat
 {
        unsigned long timestamp;
 
-       timestamp = bt_ctf_get_timestamp(call_data);
+       timestamp = bt_ctf_get_real_timestamp(call_data);
        if (timestamp == -1ULL)
                goto error;
 
@@ -150,7 +150,7 @@ error:
 struct perfcounter *get_perf_counter(const char *name, struct processtop *proc,
                struct cputime *cpu)
 {
-       struct perfcounter *ret, *global;
+       struct perfcounter *ret;
        GHashTable *table;
 
        if (proc)
@@ -169,16 +169,6 @@ struct perfcounter *get_perf_counter(const char *name, struct processtop *proc,
        ret->visible = 1;
        g_hash_table_insert(table, (gpointer) strdup(name), ret);
 
-       global = g_hash_table_lookup(global_perf_liszt, (gpointer) name);
-       if (!global) {
-               global = g_new0(struct perfcounter, 1);
-               memcpy(global, ret, sizeof(struct perfcounter));
-               /* by default, sort on the first perf context */
-               if (g_hash_table_size(global_perf_liszt) == 0)
-                       global->sort = 1;
-               g_hash_table_insert(global_perf_liszt, (gpointer) strdup(name), global);
-       }
-
 end:
        return ret;
 
@@ -205,8 +195,12 @@ void extract_perf_counter_scope(const struct bt_ctf_event *event,
                struct cputime *cpu)
 {
        struct definition const * const *list = NULL;
+       const struct definition *field;
        unsigned int count;
-       int i, ret;
+       struct perfcounter *perfcounter;
+       GHashTableIter iter;
+       gpointer key;
+       int ret;
 
        if (!scope)
                goto end;
@@ -215,13 +209,17 @@ void extract_perf_counter_scope(const struct bt_ctf_event *event,
        if (ret < 0)
                goto end;
 
-       for (i = 0; i < count; i++) {
-               const char *name = bt_ctf_field_name(list[i]);
-               if (strncmp(name, "perf_", 5) == 0) {
-                       int value = bt_ctf_get_uint64(list[i]);
+       if (count == 0)
+               goto end;
+
+       g_hash_table_iter_init(&iter, global_perf_liszt);
+       while (g_hash_table_iter_next (&iter, &key, (gpointer) &perfcounter)) {
+               field = bt_ctf_get_field(event, scope, (char *) key);
+               if (field) {
+                       int value = bt_ctf_get_uint64(field);
                        if (bt_ctf_field_get_error())
                                continue;
-                       update_perf_value(proc, cpu, name, value);
+                       update_perf_value(proc, cpu, (char *) key, value);
                }
        }
 
@@ -254,30 +252,24 @@ enum bt_cb_ret fix_process_table(struct bt_ctf_event *call_data,
        struct processtop *parent, *child;
        unsigned long timestamp;
 
-       /* FIXME : display nice error when missing context pid, tid, ppid and comm */
-
-       timestamp = bt_ctf_get_timestamp(call_data);
+       timestamp = bt_ctf_get_real_timestamp(call_data);
        if (timestamp == -1ULL)
                goto error;
 
        pid = get_context_pid(call_data);
        if (pid == -1ULL) {
-//             fprintf(stderr, "Missing pid context info\n");
                goto error;
        }
        tid = get_context_tid(call_data);
        if (tid == -1ULL) {
-//             fprintf(stderr, "Missing tid context info\n");
                goto error;
        }
        ppid = get_context_ppid(call_data);
        if (ppid == -1ULL) {
-//             fprintf(stderr, "Missing ppid context info\n");
                goto error;
        }
        comm = get_context_comm(call_data);
        if (!comm) {
-//             fprintf(stderr, "Missing procname context info\n");
                goto error;
        }
 
@@ -359,19 +351,6 @@ static int parse_options(int argc, char **argv)
                                usage(stdout);
                                ret = 1;    /* exit cleanly */
                                goto end;
-                       case OPT_LIST:
-                       //      list_formats(stdout);
-                               ret = 1;
-                               goto end;
-                       case OPT_VERBOSE:
-//                             babeltrace_verbose = 1;
-                               break;
-                       case OPT_DEBUG:
-//                             babeltrace_debug = 1;
-                               break;
-                       case OPT_NAMES:
-//                             opt_field_names = 1;
-                               break;
                        default:
                                ret = -EINVAL;
                                goto end;
@@ -555,27 +534,40 @@ static int check_field_requirements(const struct bt_ctf_field_decl *const * fiel
                int *procname_check, int *ppid_check)
 {
        int j;
+       struct perfcounter *global;
+       const char *name;
 
        for (j = 0; j < field_cnt; j++) {
+               name = bt_ctf_get_decl_field_name(field_list[j]);
                if (*tid_check == 0) {
-                       if (strncmp(bt_ctf_get_decl_field_name(field_list[j]), "tid", 3) == 0) {
+                       if (strncmp(name, "tid", 3) == 0)
                                (*tid_check)++;
-                       }
                }
                if (*pid_check == 0) {
-                       if (strncmp(bt_ctf_get_decl_field_name(field_list[j]), "pid", 3) == 0)
+                       if (strncmp(name, "tid", 3) == 0)
                                (*pid_check)++;
                }
                if (*ppid_check == 0) {
-                       if (strncmp(bt_ctf_get_decl_field_name(field_list[j]), "ppid", 4) == 0)
+                       if (strncmp(name, "ppid", 4) == 0)
                                (*ppid_check)++;
                }
                if (*procname_check == 0) {
-                       if (strncmp(bt_ctf_get_decl_field_name(field_list[j]), "procname", 8) == 0)
+                       if (strncmp(name, "procname", 8) == 0)
                                (*procname_check)++;
                }
+               if (strncmp(name, "perf_", 5) == 0) {
+                       global = g_hash_table_lookup(global_perf_liszt, (gpointer) name);
+                       if (!global) {
+                               global = g_new0(struct perfcounter, 1);
+                               /* by default, sort on the first perf context */
+                               if (g_hash_table_size(global_perf_liszt) == 0)
+                                       global->sort = 1;
+                               global->visible = 1;
+                               g_hash_table_insert(global_perf_liszt, (gpointer) strdup(name), global);
+                       }
+               }
        }
-       /* if all checks are OK, no need to continue the checks */
+
        if (*tid_check == 1 && *pid_check == 1 && *ppid_check == 1 &&
                        *procname_check == 1)
                return 0;
@@ -607,24 +599,18 @@ int check_requirements(struct bt_context *ctx)
                ret = check_field_requirements(field_list, field_cnt,
                                &tid_check, &pid_check, &procname_check,
                                &ppid_check);
-               if (ret == 0)
-                       goto end;
 
                bt_ctf_get_decl_fields(evt_list[i], BT_EVENT_CONTEXT,
                                &field_list, &field_cnt);
                ret = check_field_requirements(field_list, field_cnt,
                                &tid_check, &pid_check, &procname_check,
                                &ppid_check);
-               if (ret == 0)
-                       goto end;
 
                bt_ctf_get_decl_fields(evt_list[i], BT_STREAM_PACKET_CONTEXT,
                                &field_list, &field_cnt);
                ret = check_field_requirements(field_list, field_cnt,
                                &tid_check, &pid_check, &procname_check,
                                &ppid_check);
-               if (ret == 0)
-                       goto end;
        }
 
        if (tid_check == 0) {
@@ -644,7 +630,6 @@ int check_requirements(struct bt_context *ctx)
                fprintf(stderr, "[error] missing procname context information\n");
        }
 
-end:
        return ret;
 }
 
This page took 0.024706 seconds and 4 git commands to generate.