增加jemalloc工具类, 增加jemalloc内存统计分析 (#2885)

增加jemalloc工具类, 增加jemalloc内存统计分析
This commit is contained in:
alexliyu7352
2023-10-10 11:48:56 +08:00
committed by GitHub
parent db3f0147be
commit fdc00d5a02
3 changed files with 123 additions and 2 deletions

View File

@@ -22,10 +22,11 @@
#include <map>
#include <iostream>
#include "Common/JemallocUtil.h"
#include "Common/macros.h"
#include "System.h"
#include "Util/logger.h"
#include "Util/uv_errno.h"
#include "System.h"
#include "Common/macros.h"
using namespace std;
using namespace toolkit;
@@ -55,6 +56,16 @@ string System::execute(const string &cmd) {
static constexpr int MAX_STACK_FRAMES = 128;
static void save_jemalloc_stats() {
string jemalloc_status = JemallocUtil::get_malloc_stats();
if (jemalloc_status.empty()) {
return;
}
ofstream out(StrPrinter << exeDir() << "/jemalloc.json", ios::out | ios::binary | ios::trunc);
out << jemalloc_status;
out.flush();
}
static void sig_crash(int sig) {
signal(sig, SIG_DFL);
void *array[MAX_STACK_FRAMES];
@@ -149,6 +160,12 @@ void System::startDaemon(bool &kill_parent_if_failed) {
}
void System::systemSetup(){
#ifdef ENABLE_JEMALLOC_DUMP
//Save memory report when program exits
atexit(save_jemalloc_stats);
#endif //ENABLE_JEMALLOC_DUMP
#if !defined(_WIN32)
struct rlimit rlim,rlim_new;
if (getrlimit(RLIMIT_CORE, &rlim)==0) {