内存探测组件,预留热插拔。
This commit is contained in:
@@ -57,6 +57,7 @@ static void set_default_config(AppConfig *cfg)
|
||||
cfg->master_port = 8888;
|
||||
cfg->persistence = PERSIST_NONE;
|
||||
cfg->allocator = ALLOC_JEMALLOC;
|
||||
cfg->leak_mode = MEMLEAK_DETECT_OFF;
|
||||
}
|
||||
|
||||
/* ---- 字符串转枚举 ---- */
|
||||
@@ -90,9 +91,18 @@ static void parse_allocator(const char *s, AllocatorType *out)
|
||||
if (!s || !out) return;
|
||||
if (!strcasecmp(s, "jemalloc")) *out = ALLOC_JEMALLOC;
|
||||
else if (!strcasecmp(s, "malloc")) *out = ALLOC_MALLOC;
|
||||
else if (!strcasecmp(s, "mypool")) *out = ALLOC_MYPOOL;
|
||||
else *out = ALLOC_OTHER;
|
||||
}
|
||||
|
||||
static void parse_leakage(const char *s, MemLeakDetectMode *out)
|
||||
{
|
||||
if (!s || !out) return;
|
||||
if (!strcasecmp(s, "enable")) *out = MEMLEAK_DETECT_ON;
|
||||
else if (!strcasecmp(s, "disable")) *out = MEMLEAK_DETECT_OFF;
|
||||
else *out = MEMLEAK_DETECT_OFF;
|
||||
}
|
||||
|
||||
static int read_file_mmap(const char *filename, void **out_addr, size_t *out_len, int *out_fd) {
|
||||
if (!filename || !out_addr || !out_len || !out_fd) return -1;
|
||||
|
||||
@@ -174,11 +184,21 @@ const char *allocator_to_string(AllocatorType a)
|
||||
switch (a) {
|
||||
case ALLOC_JEMALLOC: return "jemalloc";
|
||||
case ALLOC_MALLOC: return "malloc";
|
||||
case ALLOC_MYPOOL: return "mypool";
|
||||
case ALLOC_OTHER: return "other";
|
||||
default: return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
const char *leakage_to_string(MemLeakDetectMode a)
|
||||
{
|
||||
switch (a) {
|
||||
case MEMLEAK_DETECT_ON: return "enable";
|
||||
case MEMLEAK_DETECT_OFF: return "disable";
|
||||
default: return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
/* ---- 主函数:从 XML 加载配置 ---- */
|
||||
|
||||
/* server 部分 */
|
||||
@@ -333,6 +353,15 @@ void memory_load(xmlNodePtr *root, AppConfig *out_cfg){
|
||||
xmlFree(txt);
|
||||
}
|
||||
}
|
||||
|
||||
xmlNodePtr leakage_node = find_child(mem, "leakage");
|
||||
if (leakage_node) {
|
||||
xmlChar *txt = xmlNodeGetContent(leakage_node);
|
||||
if (txt) {
|
||||
parse_leakage((char *)txt, &out_cfg->leak_mode);
|
||||
xmlFree(txt);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user