Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
1128b122
T
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1185
Star
22015
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
1128b122
编写于
2月 17, 2023
作者:
D
dapan1121
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: add memory debug option
上级
d7d32559
变更
9
显示空白变更内容
内联
并排
Showing
9 changed file
with
83 addition
and
1 deletion
+83
-1
include/os/osMemory.h
include/os/osMemory.h
+2
-0
source/client/inc/clientInt.h
source/client/inc/clientInt.h
+4
-0
source/client/src/clientEnv.c
source/client/src/clientEnv.c
+12
-0
source/client/src/clientImpl.c
source/client/src/clientImpl.c
+4
-0
source/client/src/clientMain.c
source/client/src/clientMain.c
+2
-0
source/dnode/mgmt/exe/dmMain.c
source/dnode/mgmt/exe/dmMain.c
+17
-1
source/libs/command/inc/commandInt.h
source/libs/command/inc/commandInt.h
+2
-0
source/libs/command/src/command.c
source/libs/command/src/command.c
+14
-0
source/os/src/osMemory.c
source/os/src/osMemory.c
+26
-0
未找到文件。
include/os/osMemory.h
浏览文件 @
1128b122
...
@@ -33,6 +33,8 @@ extern "C" {
...
@@ -33,6 +33,8 @@ extern "C" {
#endif // if !defined(WINDOWS)
#endif // if !defined(WINDOWS)
int32_t
taosMemoryDbgInit
();
int32_t
taosMemoryDbgInitRestore
();
void
*
taosMemoryMalloc
(
int64_t
size
);
void
*
taosMemoryMalloc
(
int64_t
size
);
void
*
taosMemoryCalloc
(
int64_t
num
,
int64_t
size
);
void
*
taosMemoryCalloc
(
int64_t
num
,
int64_t
size
);
void
*
taosMemoryRealloc
(
void
*
ptr
,
int64_t
size
);
void
*
taosMemoryRealloc
(
void
*
ptr
,
int64_t
size
);
...
...
source/client/inc/clientInt.h
浏览文件 @
1128b122
...
@@ -151,6 +151,10 @@ typedef struct STscObj {
...
@@ -151,6 +151,10 @@ typedef struct STscObj {
SHashObj
*
pRequests
;
SHashObj
*
pRequests
;
}
STscObj
;
}
STscObj
;
typedef
struct
STscDbg
{
bool
memEnable
;
}
STscDbg
;
typedef
struct
SResultColumn
{
typedef
struct
SResultColumn
{
union
{
union
{
char
*
nullbitmap
;
// bitmap, one bit for each item in the list
char
*
nullbitmap
;
// bitmap, one bit for each item in the list
...
...
source/client/src/clientEnv.c
浏览文件 @
1128b122
...
@@ -33,6 +33,7 @@
...
@@ -33,6 +33,7 @@
#define TSC_VAR_NOT_RELEASE 1
#define TSC_VAR_NOT_RELEASE 1
#define TSC_VAR_RELEASED 0
#define TSC_VAR_RELEASED 0
STscDbg
tscDbg
=
{
0
};
SAppInfo
appInfo
;
SAppInfo
appInfo
;
int64_t
lastClusterId
=
0
;
int64_t
lastClusterId
=
0
;
int32_t
clientReqRefPool
=
-
1
;
int32_t
clientReqRefPool
=
-
1
;
...
@@ -515,6 +516,17 @@ void tscWriteCrashInfo(int signum, void *sigInfo, void *context) {
...
@@ -515,6 +516,17 @@ void tscWriteCrashInfo(int signum, void *sigInfo, void *context) {
}
}
void
taos_init_imp
(
void
)
{
void
taos_init_imp
(
void
)
{
#if defined(LINUX)
if
(
tscDbg
.
memEnable
)
{
int32_t
code
=
taosMemoryDbgInit
();
if
(
code
)
{
printf
(
"failed to init memory dbg, error:%s
\n
"
,
tstrerror
(
code
));
}
else
{
printf
(
"memory dbg enabled
\n
"
);
}
}
#endif
// In the APIs of other program language, taos_cleanup is not available yet.
// In the APIs of other program language, taos_cleanup is not available yet.
// So, to make sure taos_cleanup will be invoked to clean up the allocated resource to suppress the valgrind warning.
// So, to make sure taos_cleanup will be invoked to clean up the allocated resource to suppress the valgrind warning.
atexit
(
taos_cleanup
);
atexit
(
taos_cleanup
);
...
...
source/client/src/clientImpl.c
浏览文件 @
1128b122
...
@@ -2346,6 +2346,8 @@ TAOS_RES* taosQueryImpl(TAOS* taos, const char* sql, bool validateOnly) {
...
@@ -2346,6 +2346,8 @@ TAOS_RES* taosQueryImpl(TAOS* taos, const char* sql, bool validateOnly) {
return
NULL
;
return
NULL
;
}
}
tscDebug
(
"taos_query start with sql:%s"
,
sql
);
SSyncQueryParam
*
param
=
taosMemoryCalloc
(
1
,
sizeof
(
SSyncQueryParam
));
SSyncQueryParam
*
param
=
taosMemoryCalloc
(
1
,
sizeof
(
SSyncQueryParam
));
tsem_init
(
&
param
->
sem
,
0
,
0
);
tsem_init
(
&
param
->
sem
,
0
,
0
);
...
@@ -2360,6 +2362,8 @@ TAOS_RES* taosQueryImpl(TAOS* taos, const char* sql, bool validateOnly) {
...
@@ -2360,6 +2362,8 @@ TAOS_RES* taosQueryImpl(TAOS* taos, const char* sql, bool validateOnly) {
taosMemoryFree
(
param
);
taosMemoryFree
(
param
);
}
}
tscDebug
(
"taos_query end with sql:%s"
,
sql
);
return
pRequest
;
return
pRequest
;
}
}
...
...
source/client/src/clientMain.c
浏览文件 @
1128b122
...
@@ -884,7 +884,9 @@ void continueInsertFromCsv(SSqlCallbackWrapper *pWrapper, SRequestObj *pRequest)
...
@@ -884,7 +884,9 @@ void continueInsertFromCsv(SSqlCallbackWrapper *pWrapper, SRequestObj *pRequest)
void
taos_query_a
(
TAOS
*
taos
,
const
char
*
sql
,
__taos_async_fn_t
fp
,
void
*
param
)
{
void
taos_query_a
(
TAOS
*
taos
,
const
char
*
sql
,
__taos_async_fn_t
fp
,
void
*
param
)
{
int64_t
connId
=
*
(
int64_t
*
)
taos
;
int64_t
connId
=
*
(
int64_t
*
)
taos
;
tscDebug
(
"taos_query_a start with sql:%s"
,
sql
);
taosAsyncQueryImpl
(
connId
,
sql
,
fp
,
param
,
false
);
taosAsyncQueryImpl
(
connId
,
sql
,
fp
,
param
,
false
);
tscDebug
(
"taos_query_a end with sql:%s"
,
sql
);
}
}
void
taos_query_a_with_reqid
(
TAOS
*
taos
,
const
char
*
sql
,
__taos_async_fn_t
fp
,
void
*
param
,
int64_t
reqid
)
{
void
taos_query_a_with_reqid
(
TAOS
*
taos
,
const
char
*
sql
,
__taos_async_fn_t
fp
,
void
*
param
,
int64_t
reqid
)
{
...
...
source/dnode/mgmt/exe/dmMain.c
浏览文件 @
1128b122
...
@@ -29,6 +29,7 @@
...
@@ -29,6 +29,7 @@
#define DM_MACHINE_CODE "Get machine code."
#define DM_MACHINE_CODE "Get machine code."
#define DM_VERSION "Print program version."
#define DM_VERSION "Print program version."
#define DM_EMAIL "<support@taosdata.com>"
#define DM_EMAIL "<support@taosdata.com>"
#define DM_MEM_DBG "Enable memory debug"
// clang-format on
// clang-format on
static
struct
{
static
struct
{
#ifdef WINDOWS
#ifdef WINDOWS
...
@@ -37,6 +38,7 @@ static struct {
...
@@ -37,6 +38,7 @@ static struct {
bool
dumpConfig
;
bool
dumpConfig
;
bool
dumpSdb
;
bool
dumpSdb
;
bool
generateGrant
;
bool
generateGrant
;
bool
memDbg
;
bool
printAuth
;
bool
printAuth
;
bool
printVersion
;
bool
printVersion
;
bool
printHelp
;
bool
printHelp
;
...
@@ -166,8 +168,10 @@ static int32_t dmParseArgs(int32_t argc, char const *argv[]) {
...
@@ -166,8 +168,10 @@ static int32_t dmParseArgs(int32_t argc, char const *argv[]) {
}
else
if
(
strcmp
(
argv
[
i
],
"-e"
)
==
0
)
{
}
else
if
(
strcmp
(
argv
[
i
],
"-e"
)
==
0
)
{
global
.
envCmd
[
cmdEnvIndex
]
=
argv
[
++
i
];
global
.
envCmd
[
cmdEnvIndex
]
=
argv
[
++
i
];
cmdEnvIndex
++
;
cmdEnvIndex
++
;
}
else
if
(
strcmp
(
argv
[
i
],
"-dm"
)
==
0
)
{
global
.
memDbg
=
true
;
}
else
if
(
strcmp
(
argv
[
i
],
"-h"
)
==
0
||
strcmp
(
argv
[
i
],
"--help"
)
==
0
||
strcmp
(
argv
[
i
],
"--usage"
)
==
0
||
}
else
if
(
strcmp
(
argv
[
i
],
"-h"
)
==
0
||
strcmp
(
argv
[
i
],
"--help"
)
==
0
||
strcmp
(
argv
[
i
],
"--usage"
)
==
0
||
strcmp
(
argv
[
i
],
"-?"
))
{
strcmp
(
argv
[
i
],
"-?"
)
==
0
)
{
global
.
printHelp
=
true
;
global
.
printHelp
=
true
;
}
else
{
}
else
{
}
}
...
@@ -212,6 +216,7 @@ static void dmPrintHelp() {
...
@@ -212,6 +216,7 @@ static void dmPrintHelp() {
printf
(
"%s%s%s%s
\n
"
,
indent
,
"-e,"
,
indent
,
DM_ENV_CMD
);
printf
(
"%s%s%s%s
\n
"
,
indent
,
"-e,"
,
indent
,
DM_ENV_CMD
);
printf
(
"%s%s%s%s
\n
"
,
indent
,
"-E,"
,
indent
,
DM_ENV_FILE
);
printf
(
"%s%s%s%s
\n
"
,
indent
,
"-E,"
,
indent
,
DM_ENV_FILE
);
printf
(
"%s%s%s%s
\n
"
,
indent
,
"-k,"
,
indent
,
DM_MACHINE_CODE
);
printf
(
"%s%s%s%s
\n
"
,
indent
,
"-k,"
,
indent
,
DM_MACHINE_CODE
);
printf
(
"%s%s%s%s
\n
"
,
indent
,
"-dm,"
,
indent
,
DM_MEM_DBG
);
printf
(
"%s%s%s%s
\n
"
,
indent
,
"-V,"
,
indent
,
DM_VERSION
);
printf
(
"%s%s%s%s
\n
"
,
indent
,
"-V,"
,
indent
,
DM_VERSION
);
printf
(
"
\n\n
Report bugs to %s.
\n
"
,
DM_EMAIL
);
printf
(
"
\n\n
Report bugs to %s.
\n
"
,
DM_EMAIL
);
...
@@ -272,6 +277,17 @@ int mainWindows(int argc, char **argv) {
...
@@ -272,6 +277,17 @@ int mainWindows(int argc, char **argv) {
return
0
;
return
0
;
}
}
#if defined(LINUX)
if
(
global
.
memDbg
)
{
int32_t
code
=
taosMemoryDbgInit
();
if
(
code
)
{
printf
(
"failed to init memory dbg, error:%s
\n
"
,
tstrerror
(
code
));
return
code
;
}
printf
(
"memory dbg enabled
\n
"
);
}
#endif
if
(
dmInitLog
()
!=
0
)
{
if
(
dmInitLog
()
!=
0
)
{
printf
(
"failed to start since init log error
\n
"
);
printf
(
"failed to start since init log error
\n
"
);
taosCleanupArgs
();
taosCleanupArgs
();
...
...
source/libs/command/inc/commandInt.h
浏览文件 @
1128b122
...
@@ -101,6 +101,8 @@ extern "C" {
...
@@ -101,6 +101,8 @@ extern "C" {
#define COMMAND_SCHEDULE_POLICY "schedulePolicy"
#define COMMAND_SCHEDULE_POLICY "schedulePolicy"
#define COMMAND_ENABLE_RESCHEDULE "enableReSchedule"
#define COMMAND_ENABLE_RESCHEDULE "enableReSchedule"
#define COMMAND_CATALOG_DEBUG "catalogDebug"
#define COMMAND_CATALOG_DEBUG "catalogDebug"
#define COMMAND_ENABLE_MEM_DEBUG "enableMemDebug"
#define COMMAND_DISABLE_MEM_DEBUG "disableMemDebug"
typedef
struct
SExplainGroup
{
typedef
struct
SExplainGroup
{
int32_t
nodeNum
;
int32_t
nodeNum
;
...
...
source/libs/command/src/command.c
浏览文件 @
1128b122
...
@@ -687,6 +687,20 @@ static int32_t execAlterCmd(char* cmd, char* value, bool* processed) {
...
@@ -687,6 +687,20 @@ static int32_t execAlterCmd(char* cmd, char* value, bool* processed) {
code
=
schedulerEnableReSchedule
(
atoi
(
value
));
code
=
schedulerEnableReSchedule
(
atoi
(
value
));
}
else
if
(
0
==
strcasecmp
(
cmd
,
COMMAND_CATALOG_DEBUG
))
{
}
else
if
(
0
==
strcasecmp
(
cmd
,
COMMAND_CATALOG_DEBUG
))
{
code
=
ctgdHandleDbgCommand
(
value
);
code
=
ctgdHandleDbgCommand
(
value
);
}
else
if
(
0
==
strcasecmp
(
cmd
,
COMMAND_ENABLE_MEM_DEBUG
))
{
code
=
taosMemoryDbgInit
();
if
(
code
)
{
qError
(
"failed to init memory dbg, error:%s"
,
tstrerror
(
code
));
return
code
;
}
qInfo
(
"memory dbg enabled"
);
}
else
if
(
0
==
strcasecmp
(
cmd
,
COMMAND_DISABLE_MEM_DEBUG
))
{
code
=
taosMemoryDbgInitRestore
();
if
(
code
)
{
qError
(
"failed to restore from memory dbg, error:%s"
,
tstrerror
(
code
));
return
code
;
}
qInfo
(
"memory dbg disabled"
);
}
else
{
}
else
{
goto
_return
;
goto
_return
;
}
}
...
...
source/os/src/osMemory.c
浏览文件 @
1128b122
...
@@ -228,6 +228,32 @@ void taosPrintBackTrace() {
...
@@ -228,6 +228,32 @@ void taosPrintBackTrace() {
void
taosPrintBackTrace
()
{
return
;
}
void
taosPrintBackTrace
()
{
return
;
}
#endif
#endif
int32_t
taosMemoryDbgInit
()
{
#if defined(LINUX)
int
ret
=
mallopt
(
M_MMAP_THRESHOLD
,
0
);
if
(
0
==
ret
)
{
return
TAOS_SYSTEM_ERROR
(
errno
);
}
return
0
;
#else
return
TSDB_CODE_FAILED
;
#endif
}
int32_t
taosMemoryDbgInitRestore
()
{
#if defined(LINUX)
int
ret
=
mallopt
(
M_MMAP_THRESHOLD
,
128
*
1024
);
if
(
0
==
ret
)
{
return
TAOS_SYSTEM_ERROR
(
errno
);
}
return
0
;
#else
return
TSDB_CODE_FAILED
;
#endif
}
void
*
taosMemoryMalloc
(
int64_t
size
)
{
void
*
taosMemoryMalloc
(
int64_t
size
)
{
#ifdef USE_TD_MEMORY
#ifdef USE_TD_MEMORY
void
*
tmp
=
malloc
(
size
+
sizeof
(
TdMemoryInfo
));
void
*
tmp
=
malloc
(
size
+
sizeof
(
TdMemoryInfo
));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录