From 7425820c216f18fd4d781af61beb5217f24d8cc5 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Mon, 16 Jan 2023 23:58:45 +0800 Subject: [PATCH] refactor: do some internal refactor. --- include/util/ttrace.h | 14 ++++++++++++++ include/util/tutil.h | 2 +- source/client/src/clientImpl.c | 2 +- source/dnode/vnode/src/tsdb/tsdbFile.c | 6 +++--- source/util/src/tutil.c | 2 +- 5 files changed, 20 insertions(+), 6 deletions(-) diff --git a/include/util/ttrace.h b/include/util/ttrace.h index 579768228a..6d40971cc2 100644 --- a/include/util/ttrace.h +++ b/include/util/ttrace.h @@ -52,6 +52,20 @@ typedef struct STraceId { sprintf(buf, "0x%" PRIx64 ":0x%" PRIx64 "", rootId, msgId); \ } while (0) +#define TRACE_TO_STR_(_traceId, _buf) \ + do { \ + int64_t rootId = (_traceId) != NULL ? (_traceId)->rootId : 0; \ + int64_t msgId = (_traceId) != NULL ? (_traceId)->msgId : 0; \ + char* _t = _buf; \ + _t[0] = '0'; \ + _t[1] = 'x'; \ + _t += titoa(rootId, 16, &_t[2]); \ + _t[0] = ':'; \ + _t[1] = '0'; \ + _t[2] = 'x'; \ + _t += titoa(msgId, 16, &_t[3]); \ + } while (0) + #ifdef __cplusplus } #endif diff --git a/include/util/tutil.h b/include/util/tutil.h index 513806459d..e0801e5295 100644 --- a/include/util/tutil.h +++ b/include/util/tutil.h @@ -47,7 +47,7 @@ int32_t taosByteArrayToHexStr(char bytes[], int32_t len, char hexstr[]); int32_t taosHexStrToByteArray(char hexstr[], char bytes[]); int32_t tintToHex(uint64_t val, char hex[]); -int32_t tintToStr(uint64_t val, size_t radix, char str[]); +int32_t titoa(uint64_t val, size_t radix, char str[]); char *taosIpStr(uint32_t ipInt); uint32_t ip2uint(const char *const ip_addr); diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index 53acafeeaa..7ed95a40e2 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -1371,7 +1371,7 @@ int32_t doProcessMsgFromServer(void* param) { STraceId* trace = &pMsg->info.traceId; char tbuf[40] = {0}; - TRACE_TO_STR(trace, tbuf); + TRACE_TO_STR_(trace, tbuf); tscDebug("processMsgFromServer handle %p, message: %s, size:%d, code: %s, gtid: %s", pMsg->info.handle, TMSG_INFO(pMsg->msgType), pMsg->contLen, tstrerror(pMsg->code), tbuf); diff --git a/source/dnode/vnode/src/tsdb/tsdbFile.c b/source/dnode/vnode/src/tsdb/tsdbFile.c index 5b27497998..faf335a62c 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFile.c +++ b/source/dnode/vnode/src/tsdb/tsdbFile.c @@ -108,15 +108,15 @@ void tsdbHeadFileName(STsdb *pTsdb, SDiskID did, int32_t fid, SHeadFile *pHeadF, *(p++) = TD_DIRSEP[0]; *(p++) = 'v'; - p += tintToStr(TD_VID(pTsdb->pVnode), 10, p); + p += titoa(TD_VID(pTsdb->pVnode), 10, p); *(p++) = 'f'; - p += tintToStr(fid, 10, p); + p += titoa(fid, 10, p); memcpy(p, "ver", 3); p += 3; - p += tintToStr(pHeadF->commitID, 10, p); + p += titoa(pHeadF->commitID, 10, p); memcpy(p, ".head", 5); p[5] = 0; } diff --git a/source/util/src/tutil.c b/source/util/src/tutil.c index 780dfe9105..8beda55c79 100644 --- a/source/util/src/tutil.c +++ b/source/util/src/tutil.c @@ -336,7 +336,7 @@ int32_t tintToHex(uint64_t val, char hex[]) { return j; } -int32_t tintToStr(uint64_t val, size_t radix, char str[]) { +int32_t titoa(uint64_t val, size_t radix, char str[]) { if (radix < 2 || radix > 16) { return 0; }