TDengine/include/util/ttrace.h

76 lines
2.5 KiB
C
Raw Normal View History

2022-06-16 13:57:28 +00:00
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_TRACE_H_
#define _TD_TRACE_H_
2022-06-18 10:12:31 +00:00
#include <stdint.h>
2022-06-16 13:57:28 +00:00
#include <stdlib.h>
#ifdef __cplusplus
extern "C" {
#endif
2022-06-18 06:07:54 +00:00
#pragma(push, 1)
2022-06-18 09:23:55 +00:00
typedef struct STraceId {
2022-06-18 06:07:54 +00:00
int64_t rootId;
int64_t msgId;
} STraceId;
2022-06-16 13:57:28 +00:00
2022-06-18 06:07:54 +00:00
#pragma(pop)
2022-06-16 13:57:28 +00:00
2022-06-18 06:07:54 +00:00
#define TRACE_SET_ROOTID(traceId, root) \
do { \
(traceId)->rootId = root; \
} while (0);
2022-06-16 13:57:28 +00:00
2022-06-18 06:07:54 +00:00
#define TRACE_GET_ROOTID(traceId) (traceId)->rootId
2022-06-16 13:57:28 +00:00
2022-06-18 06:07:54 +00:00
#define TRACE_SET_MSGID(traceId, mId) \
do { \
(traceId)->msgId = mId; \
} while (0)
#define TRACE_GET_MSGID(traceId) (traceId)->msgId
2023-01-17 01:00:44 +00:00
//#define TRACE_TO_STR(traceId, buf) \
// do { \
// int64_t rootId = (traceId) != NULL ? (traceId)->rootId : 0; \
// int64_t msgId = (traceId) != NULL ? (traceId)->msgId : 0; \
// sprintf(buf, "0x%" PRIx64 ":0x%" PRIx64 "", rootId, msgId); \
// } while (0)
2022-06-16 13:57:28 +00:00
2023-01-17 01:00:44 +00:00
#define TRACE_TO_STR(_traceId, _buf) \
2023-01-16 15:58:45 +00:00
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 += 2; \
_t += titoa(rootId, 16, &_t[0]); \
2023-01-16 15:58:45 +00:00
_t[0] = ':'; \
_t[1] = '0'; \
_t[2] = 'x'; \
_t += 3; \
_t += titoa(msgId, 16, &_t[0]); \
2023-01-16 15:58:45 +00:00
} while (0)
2022-06-16 13:57:28 +00:00
#ifdef __cplusplus
}
#endif
#endif