add option 'autoDump' for memory leak detection.
This commit is contained in:
parent
32abecfbc0
commit
fc6737ab04
|
@ -15,7 +15,7 @@ extern "C" {
|
||||||
* Signature: (Ljava/lang/String;)V
|
* Signature: (Ljava/lang/String;)V
|
||||||
*/
|
*/
|
||||||
JNIEXPORT void JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_detectMemoryLeakImp
|
JNIEXPORT void JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_detectMemoryLeakImp
|
||||||
(JNIEnv *, jclass, jstring);
|
(JNIEnv *, jclass, jstring, jboolean);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class: com_taosdata_jdbc_TSDBJNIConnector
|
* Class: com_taosdata_jdbc_TSDBJNIConnector
|
||||||
|
|
|
@ -111,13 +111,13 @@ void jniGetGlobalMethod(JNIEnv *env) {
|
||||||
jniTrace("native method register finished");
|
jniTrace("native method register finished");
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_detectMemoryLeakImp(JNIEnv *env, jobject jobj, jstring jPath) {
|
JNIEXPORT void JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_detectMemoryLeakImp(JNIEnv *env, jobject jobj, jstring jPath, jboolean jAutoDump) {
|
||||||
if (jPath != NULL) {
|
if (jPath != NULL) {
|
||||||
const char *path = (*env)->GetStringUTFChars(env, jPath, NULL);
|
const char *path = (*env)->GetStringUTFChars(env, jPath, NULL);
|
||||||
taos_detect_memory_leak(path);
|
taos_detect_memory_leak(path, !!jAutoDump);
|
||||||
(*env)->ReleaseStringUTFChars(env, jPath, path);
|
(*env)->ReleaseStringUTFChars(env, jPath, path);
|
||||||
} else {
|
} else {
|
||||||
taos_detect_memory_leak(NULL);
|
taos_detect_memory_leak(NULL, !!jAutoDump);
|
||||||
}
|
}
|
||||||
|
|
||||||
jniGetGlobalMethod(env);
|
jniGetGlobalMethod(env);
|
||||||
|
|
|
@ -187,7 +187,7 @@ static FORCE_INLINE void taosEncryptPass(uint8_t *inBuf, unsigned int inLen, cha
|
||||||
|
|
||||||
char *taosIpStr(uint32_t ipInt);
|
char *taosIpStr(uint32_t ipInt);
|
||||||
|
|
||||||
extern void taos_detect_memory_leak(const char* path);
|
extern void taos_detect_memory_leak(const char* path, bool autoDump);
|
||||||
extern void taos_dump_memory_leak();
|
extern void taos_dump_memory_leak();
|
||||||
|
|
||||||
#if TAOS_MEM_CHECK == 1
|
#if TAOS_MEM_CHECK == 1
|
||||||
|
|
|
@ -64,9 +64,9 @@ int main(int argc, char *argv[]) {
|
||||||
#if TAOS_MEM_CHECK == 2
|
#if TAOS_MEM_CHECK == 2
|
||||||
} else if (strcmp(argv[i], "--check-mem-leak") == 0) {
|
} else if (strcmp(argv[i], "--check-mem-leak") == 0) {
|
||||||
if ((i < argc - 1) && (argv[i+1][0] != '-')) {
|
if ((i < argc - 1) && (argv[i+1][0] != '-')) {
|
||||||
taos_detect_memory_leak(argv[++i]);
|
taos_detect_memory_leak(argv[++i], true);
|
||||||
} else {
|
} else {
|
||||||
taos_detect_memory_leak(NULL);
|
taos_detect_memory_leak(NULL, true);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -307,13 +307,15 @@ void taos_dump_memory_leak() {
|
||||||
|
|
||||||
static void dump_memory_leak_at_sig(int sig) {
|
static void dump_memory_leak_at_sig(int sig) {
|
||||||
fprintf(fpMemLeak, "signal %d received, exiting...\n", sig);
|
fprintf(fpMemLeak, "signal %d received, exiting...\n", sig);
|
||||||
taos_dump_memory_leak();
|
|
||||||
struct sigaction act = {0};
|
struct sigaction act = {0};
|
||||||
act.sa_handler = SIG_DFL;
|
act.sa_handler = SIG_DFL;
|
||||||
sigaction(sig, &act, NULL);
|
sigaction(sig, &act, NULL);
|
||||||
|
|
||||||
|
taos_dump_memory_leak();
|
||||||
}
|
}
|
||||||
|
|
||||||
void taos_detect_memory_leak(const char* path) {
|
void taos_detect_memory_leak(const char* path, bool autoDump) {
|
||||||
if (fpMemLeak != NULL) {
|
if (fpMemLeak != NULL) {
|
||||||
printf("memory leak detection already enabled.\n");
|
printf("memory leak detection already enabled.\n");
|
||||||
return;
|
return;
|
||||||
|
@ -326,13 +328,14 @@ void taos_detect_memory_leak(const char* path) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
atexit(taos_dump_memory_leak);
|
if (autoDump) {
|
||||||
|
atexit(taos_dump_memory_leak);
|
||||||
struct sigaction act = {0};
|
struct sigaction act = {0};
|
||||||
act.sa_handler = dump_memory_leak_at_sig;
|
act.sa_handler = dump_memory_leak_at_sig;
|
||||||
sigaction(SIGFPE, &act, NULL);
|
sigaction(SIGFPE, &act, NULL);
|
||||||
sigaction(SIGSEGV, &act, NULL);
|
sigaction(SIGSEGV, &act, NULL);
|
||||||
sigaction(SIGILL, &act, NULL);
|
sigaction(SIGILL, &act, NULL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -342,7 +345,7 @@ void taos_dump_memory_leak() {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
void taos_detect_memory_leak(const char* path) {
|
void taos_detect_memory_leak(const char* path, bool autoDump) {
|
||||||
printf("memory leak detection not enabled, please set 'TAOS_MEM_CHECK' to 2.");
|
printf("memory leak detection not enabled, please set 'TAOS_MEM_CHECK' to 2.");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
Loading…
Reference in New Issue