wrapper to access context fields
authorJulien Desfossez <julien.desfossez@efficios.com>
Thu, 23 Feb 2012 02:13:53 +0000 (21:13 -0500)
committerJulien Desfossez <julien.desfossez@efficios.com>
Thu, 23 Feb 2012 02:13:53 +0000 (21:13 -0500)
Signed-off-by: Julien Desfossez <julien.desfossez@efficios.com>
src/common.c
src/common.h
src/cputop.c
src/iostreamtop.c
src/lttngtop.c

index f628ed56d5961673017aef03c3f256913b23f080..d9ec95b33281f07628cece74325414109647fac5 100644 (file)
@@ -16,6 +16,7 @@
  * MA 02111-1307, USA.
  */
 
  * MA 02111-1307, USA.
  */
 
+#include <babeltrace/ctf/events.h>
 #include <stdlib.h>
 #include <string.h>
 #include "common.h"
 #include <stdlib.h>
 #include <string.h>
 #include "common.h"
@@ -35,6 +36,70 @@ uint64_t get_cpu_id(struct bt_ctf_event *event)
        return cpu_id;
 }
 
        return cpu_id;
 }
 
+uint64_t get_context_tid(struct bt_ctf_event *event)
+{
+       struct definition *scope;
+       uint64_t tid;
+
+       scope = bt_ctf_get_top_level_scope(event, BT_STREAM_EVENT_CONTEXT);
+       tid = bt_ctf_get_int64(bt_ctf_get_field(event,
+                               scope, "_tid"));
+       if (bt_ctf_field_get_error()) {
+               fprintf(stderr, "Missing tid context info\n");
+               return -1ULL;
+       }
+
+       return tid;
+}
+
+uint64_t get_context_pid(struct bt_ctf_event *event)
+{
+       struct definition *scope;
+       uint64_t pid;
+
+       scope = bt_ctf_get_top_level_scope(event, BT_STREAM_EVENT_CONTEXT);
+       pid = bt_ctf_get_int64(bt_ctf_get_field(event,
+                               scope, "_pid"));
+       if (bt_ctf_field_get_error()) {
+               fprintf(stderr, "Missing pid context info\n");
+               return -1ULL;
+       }
+
+       return pid;
+}
+
+uint64_t get_context_ppid(struct bt_ctf_event *event)
+{
+       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;
+}
+
+char *get_context_comm(struct bt_ctf_event *event)
+{
+       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;
+}
+
 struct processtop *find_process_tid(struct lttngtop *ctx, int tid, char *comm)
 {
        gint i;
 struct processtop *find_process_tid(struct lttngtop *ctx, int tid, char *comm)
 {
        gint i;
index 8be30bbb1951afe6e0fefd52fcf80b6a4cc4c845..12cb04dfed36fb44943f6aa4ad7d3716060dbcee 100644 (file)
@@ -54,5 +54,9 @@ struct perfcounter *get_perf_counter(const char *name, struct processtop *proc,
 
 /* common field access functions */
 uint64_t get_cpu_id(struct bt_ctf_event *event);
 
 /* common field access functions */
 uint64_t get_cpu_id(struct bt_ctf_event *event);
+uint64_t get_context_tid(struct bt_ctf_event *event);
+uint64_t get_context_pid(struct bt_ctf_event *event);
+uint64_t get_context_ppid(struct bt_ctf_event *event);
+char *get_context_comm(struct bt_ctf_event *event);
 
 #endif /* _COMMON_H */
 
 #endif /* _COMMON_H */
index 2cf1ea25880ae8bd46e44684eded71004bd8c136..cdc1bdf1e0251875e008b231cf0db6b7fb37c328 100644 (file)
@@ -121,13 +121,7 @@ enum bt_cb_ret handle_sched_process_free(struct bt_ctf_event *call_data,
                goto error;
        }
 
                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;
-       }
-
+       tid = get_context_tid(call_data);
        death_proc(&lttngtop, tid, comm, timestamp);
 
        return BT_CB_OK;
        death_proc(&lttngtop, tid, comm, timestamp);
 
        return BT_CB_OK;
index dfffd1d81512e3b993a2ca4201d62a7e6bbde2b1..4426d03c27ca243f32c52731114a4fd300018855 100644 (file)
@@ -177,21 +177,8 @@ enum bt_cb_ret handle_exit_syscall(struct bt_ctf_event *call_data,
        if (timestamp == -1ULL)
                goto error;
 
        if (timestamp == -1ULL)
                goto error;
 
-       scope = bt_ctf_get_top_level_scope(call_data,
-                       BT_STREAM_EVENT_CONTEXT);
-       comm = bt_ctf_get_char_array(bt_ctf_get_field(call_data,
-                               scope, "_procname"));
-       if (bt_ctf_field_get_error()) {
-               fprintf(stderr, "Missing procname 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;
-       }
+       comm = get_context_comm(call_data);
+       tid = get_context_tid(call_data);
 
        scope = bt_ctf_get_top_level_scope(call_data,
                        BT_EVENT_FIELDS);
 
        scope = bt_ctf_get_top_level_scope(call_data,
                        BT_EVENT_FIELDS);
@@ -234,22 +221,8 @@ enum bt_cb_ret handle_sys_write(struct bt_ctf_event *call_data,
        if (timestamp == -1ULL)
                goto error;
 
        if (timestamp == -1ULL)
                goto error;
 
-       scope = bt_ctf_get_top_level_scope(call_data,
-                       BT_STREAM_EVENT_CONTEXT);
-       comm = bt_ctf_get_char_array(bt_ctf_get_field(call_data,
-                               scope, "_procname"));
-       if (bt_ctf_field_get_error()) {
-               fprintf(stderr, "Missing procname 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;
-       }
-
+       comm = get_context_comm(call_data);
+       tid = get_context_tid(call_data);
        cpu_id = get_cpu_id(call_data);
 
        scope = bt_ctf_get_top_level_scope(call_data,
        cpu_id = get_cpu_id(call_data);
 
        scope = bt_ctf_get_top_level_scope(call_data,
@@ -287,22 +260,8 @@ enum bt_cb_ret handle_sys_read(struct bt_ctf_event *call_data,
        if (timestamp == -1ULL)
                goto error;
 
        if (timestamp == -1ULL)
                goto error;
 
-       scope = bt_ctf_get_top_level_scope(call_data,
-                       BT_STREAM_EVENT_CONTEXT);
-       comm = bt_ctf_get_char_array(bt_ctf_get_field(call_data,
-                               scope, "_procname"));
-       if (bt_ctf_field_get_error()) {
-               fprintf(stderr, "Missing procname 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;
-       }
-
+       comm = get_context_comm(call_data);
+       tid = get_context_tid(call_data);
        cpu_id = get_cpu_id(call_data);
 
        scope = bt_ctf_get_top_level_scope(call_data,
        cpu_id = get_cpu_id(call_data);
 
        scope = bt_ctf_get_top_level_scope(call_data,
@@ -342,22 +301,8 @@ enum bt_cb_ret handle_sys_open(struct bt_ctf_event *call_data,
        if (timestamp == -1ULL)
                goto error;
 
        if (timestamp == -1ULL)
                goto error;
 
-       scope = bt_ctf_get_top_level_scope(call_data,
-                       BT_STREAM_EVENT_CONTEXT);
-       comm = bt_ctf_get_char_array(bt_ctf_get_field(call_data,
-                               scope, "_procname"));
-       if (bt_ctf_field_get_error()) {
-               fprintf(stderr, "Missing procname 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;
-       }
-
+       comm = get_context_comm(call_data);
+       tid = get_context_tid(call_data);
        cpu_id = get_cpu_id(call_data);
 
        scope = bt_ctf_get_top_level_scope(call_data,
        cpu_id = get_cpu_id(call_data);
 
        scope = bt_ctf_get_top_level_scope(call_data,
@@ -395,21 +340,8 @@ enum bt_cb_ret handle_sys_close(struct bt_ctf_event *call_data,
        if (timestamp == -1ULL)
                goto error;
 
        if (timestamp == -1ULL)
                goto error;
 
-       scope = bt_ctf_get_top_level_scope(call_data,
-                       BT_STREAM_EVENT_CONTEXT);
-       comm = bt_ctf_get_char_array(bt_ctf_get_field(call_data,
-                               scope, "_procname"));
-       if (bt_ctf_field_get_error()) {
-               fprintf(stderr, "Missing procname 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;
-       }
+       comm = get_context_comm(call_data);
+       tid = get_context_tid(call_data);
 
        scope = bt_ctf_get_top_level_scope(call_data,
                        BT_EVENT_FIELDS);
 
        scope = bt_ctf_get_top_level_scope(call_data,
                        BT_EVENT_FIELDS);
index 6bb03ac760c20c1a3f9daa121475af0c7fd72b70..0133fe3666ba304cdcabdc9bea38b8a300dc30ef 100644 (file)
@@ -257,25 +257,23 @@ enum bt_cb_ret fix_process_table(struct bt_ctf_event *call_data,
        if (timestamp == -1ULL)
                goto error;
 
        if (timestamp == -1ULL)
                goto error;
 
-       scope = bt_ctf_get_top_level_scope(call_data, BT_STREAM_EVENT_CONTEXT);
-
-       pid = bt_ctf_get_int64(bt_ctf_get_field(call_data, scope, "_pid"));
-       if (bt_ctf_field_get_error()) {
+       pid = get_context_pid(call_data);
+       if (pid == -1ULL) {
 //             fprintf(stderr, "Missing pid context info\n");
                goto error;
        }
 //             fprintf(stderr, "Missing pid context info\n");
                goto error;
        }
-       tid = bt_ctf_get_int64(bt_ctf_get_field(call_data, scope, "_tid"));
-       if (bt_ctf_field_get_error()) {
+       tid = get_context_tid(call_data);
+       if (tid == -1ULL) {
 //             fprintf(stderr, "Missing tid context info\n");
                goto error;
        }
 //             fprintf(stderr, "Missing tid context info\n");
                goto error;
        }
-       ppid = bt_ctf_get_int64(bt_ctf_get_field(call_data, scope, "_ppid"));
-       if (bt_ctf_field_get_error()) {
+       ppid = get_context_ppid(call_data);
+       if (ppid == -1ULL) {
 //             fprintf(stderr, "Missing ppid context info\n");
                goto error;
        }
 //             fprintf(stderr, "Missing ppid context info\n");
                goto error;
        }
-       comm = bt_ctf_get_char_array(bt_ctf_get_field(call_data, scope, "_procname"));
-       if (bt_ctf_field_get_error()) {
+       comm = get_context_comm(call_data);
+       if (!comm) {
 //             fprintf(stderr, "Missing procname context info\n");
                goto error;
        }
 //             fprintf(stderr, "Missing procname context info\n");
                goto error;
        }
This page took 0.026844 seconds and 4 git commands to generate.