From 0cf270910a9a09b5bb7d398e1898a6fc202d6823 Mon Sep 17 00:00:00 2001 From: Konrad Sztyber Date: Wed, 16 Jun 2021 13:27:49 +0200 Subject: [PATCH] lib/trace: add argument variable in _spdk_trace_record It makes the code more readable. Additionally, to avoid partial updates to an entry, the check for the number of arguments was moved before it's filled in. Signed-off-by: Konrad Sztyber Change-Id: I9ba01b1bcdc29267571badaebd4a9b34ffd7f728 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/8404 Tested-by: SPDK CI Jenkins Community-CI: Mellanox Build Bot Reviewed-by: Tomasz Zawadzki Reviewed-by: Jim Harris Reviewed-by: Ziye Yang --- lib/trace/trace.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/trace/trace.c b/lib/trace/trace.c index 4ec53e85c..582ad7ba0 100644 --- a/lib/trace/trace.c +++ b/lib/trace/trace.c @@ -58,6 +58,7 @@ _spdk_trace_record(uint64_t tsc, uint16_t tpoint_id, uint16_t poller_id, uint32_ struct spdk_trace_history *lcore_history; struct spdk_trace_entry *next_entry; struct spdk_trace_tpoint *tpoint; + struct spdk_trace_argument *argument; const char *strval; unsigned lcore, i, offset; uint64_t intval; @@ -75,6 +76,13 @@ _spdk_trace_record(uint64_t tsc, uint16_t tpoint_id, uint16_t poller_id, uint32_ lcore_history->tpoint_count[tpoint_id]++; + tpoint = &g_trace_flags->tpoint[tpoint_id]; + /* Make sure that the number of arguments passed matches tracepoint definition */ + if (tpoint->num_args != num_args) { + assert(0 && "Unexpected number of tracepoint arguments"); + return; + } + /* Get next entry index in the circular buffer */ next_entry = get_trace_entry(lcore_history, lcore_history->next_entry); next_entry->tsc = tsc; @@ -83,19 +91,13 @@ _spdk_trace_record(uint64_t tsc, uint16_t tpoint_id, uint16_t poller_id, uint32_ next_entry->size = size; next_entry->object_id = object_id; - tpoint = &g_trace_flags->tpoint[tpoint_id]; - /* Make sure that the number of arguments passed match tracepoint definition */ - if (tpoint->num_args != num_args) { - assert(0 && "Unexpected number of tracepoint arguments"); - return; - } - va_start(vl, num_args); for (i = 0, offset = 0; i < tpoint->num_args; ++i) { - switch (tpoint->args[i].type) { + argument = &tpoint->args[i]; + switch (argument->type) { case SPDK_TRACE_ARG_TYPE_STR: strval = va_arg(vl, const char *); - snprintf(&next_entry->args[offset], tpoint->args[i].size, "%s", strval); + snprintf(&next_entry->args[offset], argument->size, "%s", strval); break; case SPDK_TRACE_ARG_TYPE_INT: case SPDK_TRACE_ARG_TYPE_PTR: @@ -107,7 +109,7 @@ _spdk_trace_record(uint64_t tsc, uint16_t tpoint_id, uint16_t poller_id, uint32_ break; } - offset += tpoint->args[i].size; + offset += argument->size; } va_end(vl);