From dd1c38cc680e4e8ca2642e93bf289072bff7fc3d Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Thu, 25 Apr 2019 05:48:01 -0700 Subject: [PATCH] trace: allow arg1 to represent a string This requires changing arg1_is_ptr to arg1_type. We will use this to print the first 8 characters of a blobfs filename when collecting event trace data. Signed-off-by: Jim Harris Change-Id: I1b321d99145e82b42dcf6d901ce9d6298158edae Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/452259 Reviewed-by: Ben Walker Reviewed-by: Changpeng Liu Reviewed-by: Ziye Yang Reviewed-by: Darek Stojaczyk Reviewed-by: Shuhei Matsumoto Tested-by: SPDK CI Jenkins --- app/trace/trace.cpp | 23 ++++++++++++++++++----- include/spdk/trace.h | 10 +++++++--- lib/trace/trace_flags.c | 4 ++-- test/unit/lib/bdev/bdev.c/bdev_ut.c | 2 +- test/unit/lib/bdev/mt/bdev.c/bdev_ut.c | 2 +- test/unit/lib/bdev/part.c/part_ut.c | 2 +- test/unit/lib/nvmf/rdma.c/rdma_ut.c | 2 +- test/unit/lib/nvmf/tcp.c/tcp_ut.c | 2 +- 8 files changed, 32 insertions(+), 15 deletions(-) diff --git a/app/trace/trace.cpp b/app/trace/trace.cpp index f9ad27d41..cc1b26adf 100644 --- a/app/trace/trace.cpp +++ b/app/trace/trace.cpp @@ -109,6 +109,13 @@ print_uint64(const char *arg_string, uint64_t arg) printf("%-7.7s%-16jd ", arg_string, arg); } +static void +print_string(const char *arg_string, uint64_t arg) +{ + char *str = (char *)&arg; + printf("%-7.7s%.8s ", arg_string, str); +} + static void print_size(uint32_t size) { @@ -132,17 +139,23 @@ print_float(const char *arg_string, float arg) } static void -print_arg(bool arg_is_ptr, const char *arg_string, uint64_t arg) +print_arg(uint8_t arg_type, const char *arg_string, uint64_t arg) { if (arg_string[0] == 0) { printf("%24s", ""); return; } - if (arg_is_ptr) { + switch (arg_type) { + case SPDK_TRACE_ARG_TYPE_PTR: print_ptr(arg_string, arg); - } else { + break; + case SPDK_TRACE_ARG_TYPE_INT: print_uint64(arg_string, arg); + break; + case SPDK_TRACE_ARG_TYPE_STR: + print_string(arg_string, arg); + break; } } @@ -176,7 +189,7 @@ print_event(struct spdk_trace_entry *e, uint64_t tsc_rate, printf("%-*s ", (int)sizeof(d->name), d->name); print_size(e->size); - print_arg(d->arg1_is_ptr, d->arg1_name, e->arg1); + print_arg(d->arg1_type, d->arg1_name, e->arg1); if (d->new_object) { print_object_id(d->object_type, stats->index[e->object_id]); } else if (d->object_type != OBJECT_NONE) { @@ -195,7 +208,7 @@ print_event(struct spdk_trace_entry *e, uint64_t tsc_rate, printf("id: N/A"); } } else if (e->object_id != 0) { - print_arg(true, "object: ", e->object_id); + print_arg(SPDK_TRACE_ARG_TYPE_PTR, "object: ", e->object_id); } printf("\n"); } diff --git a/include/spdk/trace.h b/include/spdk/trace.h index ed85a0b39..ae83f09ae 100644 --- a/include/spdk/trace.h +++ b/include/spdk/trace.h @@ -76,6 +76,10 @@ struct spdk_trace_object { #define SPDK_TRACE_MAX_TPOINT_ID (SPDK_TRACE_MAX_GROUP_ID * 64) #define SPDK_TPOINT_ID(group, tpoint) ((group * 64) + tpoint) +#define SPDK_TRACE_ARG_TYPE_INT 0 +#define SPDK_TRACE_ARG_TYPE_PTR 1 +#define SPDK_TRACE_ARG_TYPE_STR 2 + struct spdk_trace_tpoint { char name[44]; char short_name[4]; @@ -83,7 +87,7 @@ struct spdk_trace_tpoint { uint8_t owner_type; uint8_t object_type; uint8_t new_object; - uint8_t arg1_is_ptr; + uint8_t arg1_type; uint8_t reserved; char arg1_name[8]; }; @@ -331,13 +335,13 @@ void spdk_trace_register_object(uint8_t type, char id_prefix); * \param owner_type Owner type for the tpoint. * \param object_type Object type for the tpoint. * \param new_object New object for the tpoint. - * \param arg1_is_ptr This argument indicates whether argument1 is a pointer. + * \param arg1_type Type of arg1. * \param arg1_name Name of argument. */ void spdk_trace_register_description(const char *name, const char *short_name, uint16_t tpoint_id, uint8_t owner_type, uint8_t object_type, uint8_t new_object, - uint8_t arg1_is_ptr, const char *arg1_name); + uint8_t arg1_type, const char *arg1_name); struct spdk_trace_register_fn *spdk_trace_get_first_register_fn(void); diff --git a/lib/trace/trace_flags.c b/lib/trace/trace_flags.c index ec460021a..1c8d86248 100644 --- a/lib/trace/trace_flags.c +++ b/lib/trace/trace_flags.c @@ -240,7 +240,7 @@ void spdk_trace_register_description(const char *name, const char *short_name, uint16_t tpoint_id, uint8_t owner_type, uint8_t object_type, uint8_t new_object, - uint8_t arg1_is_ptr, const char *arg1_name) + uint8_t arg1_type, const char *arg1_name) { struct spdk_trace_tpoint *tpoint; @@ -256,7 +256,7 @@ spdk_trace_register_description(const char *name, const char *short_name, tpoint->object_type = object_type; tpoint->owner_type = owner_type; tpoint->new_object = new_object; - tpoint->arg1_is_ptr = arg1_is_ptr; + tpoint->arg1_type = arg1_type; snprintf(tpoint->arg1_name, sizeof(tpoint->arg1_name), "%s", arg1_name); } diff --git a/test/unit/lib/bdev/bdev.c/bdev_ut.c b/test/unit/lib/bdev/bdev.c/bdev_ut.c index dcdd90296..99f10a16a 100644 --- a/test/unit/lib/bdev/bdev.c/bdev_ut.c +++ b/test/unit/lib/bdev/bdev.c/bdev_ut.c @@ -55,7 +55,7 @@ DEFINE_STUB_V(spdk_trace_register_object, (uint8_t type, char id_prefix)); DEFINE_STUB_V(spdk_trace_register_description, (const char *name, const char *short_name, uint16_t tpoint_id, uint8_t owner_type, uint8_t object_type, uint8_t new_object, - uint8_t arg1_is_ptr, const char *arg1_name)); + uint8_t arg1_type, const char *arg1_name)); DEFINE_STUB_V(_spdk_trace_record, (uint64_t tsc, uint16_t tpoint_id, uint16_t poller_id, uint32_t size, uint64_t object_id, uint64_t arg1)); DEFINE_STUB(spdk_notify_send, uint64_t, (const char *type, const char *ctx), 0); diff --git a/test/unit/lib/bdev/mt/bdev.c/bdev_ut.c b/test/unit/lib/bdev/mt/bdev.c/bdev_ut.c index 0766af688..d4c1db5ed 100644 --- a/test/unit/lib/bdev/mt/bdev.c/bdev_ut.c +++ b/test/unit/lib/bdev/mt/bdev.c/bdev_ut.c @@ -57,7 +57,7 @@ DEFINE_STUB_V(spdk_trace_register_object, (uint8_t type, char id_prefix)); DEFINE_STUB_V(spdk_trace_register_description, (const char *name, const char *short_name, uint16_t tpoint_id, uint8_t owner_type, uint8_t object_type, uint8_t new_object, - uint8_t arg1_is_ptr, const char *arg1_name)); + uint8_t arg1_type, const char *arg1_name)); DEFINE_STUB_V(_spdk_trace_record, (uint64_t tsc, uint16_t tpoint_id, uint16_t poller_id, uint32_t size, uint64_t object_id, uint64_t arg1)); DEFINE_STUB(spdk_notify_send, uint64_t, (const char *type, const char *ctx), 0); diff --git a/test/unit/lib/bdev/part.c/part_ut.c b/test/unit/lib/bdev/part.c/part_ut.c index b983c77d1..ca42f799f 100644 --- a/test/unit/lib/bdev/part.c/part_ut.c +++ b/test/unit/lib/bdev/part.c/part_ut.c @@ -58,7 +58,7 @@ DEFINE_STUB_V(spdk_trace_register_object, (uint8_t type, char id_prefix)); DEFINE_STUB_V(spdk_trace_register_description, (const char *name, const char *short_name, uint16_t tpoint_id, uint8_t owner_type, uint8_t object_type, uint8_t new_object, - uint8_t arg1_is_ptr, const char *arg1_name)); + uint8_t arg1_type, const char *arg1_name)); DEFINE_STUB_V(_spdk_trace_record, (uint64_t tsc, uint16_t tpoint_id, uint16_t poller_id, uint32_t size, uint64_t object_id, uint64_t arg1)); DEFINE_STUB(spdk_notify_send, uint64_t, (const char *type, const char *ctx), 0); diff --git a/test/unit/lib/nvmf/rdma.c/rdma_ut.c b/test/unit/lib/nvmf/rdma.c/rdma_ut.c index 63d20a5d0..7484d7f83 100644 --- a/test/unit/lib/nvmf/rdma.c/rdma_ut.c +++ b/test/unit/lib/nvmf/rdma.c/rdma_ut.c @@ -67,7 +67,7 @@ DEFINE_STUB_V(spdk_trace_add_register_fn, (struct spdk_trace_register_fn *reg_fn DEFINE_STUB_V(spdk_trace_register_object, (uint8_t type, char id_prefix)); DEFINE_STUB_V(spdk_trace_register_description, (const char *name, const char *short_name, uint16_t tpoint_id, uint8_t owner_type, uint8_t object_type, uint8_t new_object, - uint8_t arg1_is_ptr, const char *arg1_name)); + uint8_t arg1_type, const char *arg1_name)); DEFINE_STUB_V(_spdk_trace_record, (uint64_t tsc, uint16_t tpoint_id, uint16_t poller_id, uint32_t size, uint64_t object_id, uint64_t arg1)); diff --git a/test/unit/lib/nvmf/tcp.c/tcp_ut.c b/test/unit/lib/nvmf/tcp.c/tcp_ut.c index 8a7a573e6..0710c1560 100644 --- a/test/unit/lib/nvmf/tcp.c/tcp_ut.c +++ b/test/unit/lib/nvmf/tcp.c/tcp_ut.c @@ -183,7 +183,7 @@ void spdk_trace_register_description(const char *name, const char *short_name, uint16_t tpoint_id, uint8_t owner_type, uint8_t object_type, uint8_t new_object, - uint8_t arg1_is_ptr, const char *arg1_name) + uint8_t arg1_type, const char *arg1_name) { }