From 1dec520a9e8e0654fa7fab2310a0191b2836d424 Mon Sep 17 00:00:00 2001 From: Julien Desfossez Date: Wed, 22 Feb 2012 21:13:53 -0500 Subject: [PATCH] wrapper to access context fields Signed-off-by: Julien Desfossez --- src/common.c | 65 ++++++++++++++++++++++++++++++++++ src/common.h | 4 +++ src/cputop.c | 8 +---- src/iostreamtop.c | 88 ++++++----------------------------------------- src/lttngtop.c | 18 +++++----- 5 files changed, 88 insertions(+), 95 deletions(-) diff --git a/src/common.c b/src/common.c index f628ed5..d9ec95b 100644 --- a/src/common.c +++ b/src/common.c @@ -16,6 +16,7 @@ * MA 02111-1307, USA. */ +#include #include #include #include "common.h" @@ -35,6 +36,70 @@ uint64_t get_cpu_id(struct bt_ctf_event *event) 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; diff --git a/src/common.h b/src/common.h index 8be30bb..12cb04d 100644 --- a/src/common.h +++ b/src/common.h @@ -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); +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 */ diff --git a/src/cputop.c b/src/cputop.c index 2cf1ea2..cdc1bdf 100644 --- a/src/cputop.c +++ b/src/cputop.c @@ -121,13 +121,7 @@ enum bt_cb_ret handle_sched_process_free(struct bt_ctf_event *call_data, 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(<tngtop, tid, comm, timestamp); return BT_CB_OK; diff --git a/src/iostreamtop.c b/src/iostreamtop.c index dfffd1d..4426d03 100644 --- a/src/iostreamtop.c +++ b/src/iostreamtop.c @@ -177,21 +177,8 @@ enum bt_cb_ret handle_exit_syscall(struct bt_ctf_event *call_data, 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); @@ -234,22 +221,8 @@ enum bt_cb_ret handle_sys_write(struct bt_ctf_event *call_data, 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, @@ -287,22 +260,8 @@ enum bt_cb_ret handle_sys_read(struct bt_ctf_event *call_data, 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, @@ -342,22 +301,8 @@ enum bt_cb_ret handle_sys_open(struct bt_ctf_event *call_data, 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, @@ -395,21 +340,8 @@ enum bt_cb_ret handle_sys_close(struct bt_ctf_event *call_data, 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); diff --git a/src/lttngtop.c b/src/lttngtop.c index 6bb03ac..0133fe3 100644 --- a/src/lttngtop.c +++ b/src/lttngtop.c @@ -257,25 +257,23 @@ enum bt_cb_ret fix_process_table(struct bt_ctf_event *call_data, 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; } - 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; } - 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; } - 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; } -- 2.34.1