mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-06-13 03:31:45 +08:00
增加jemalloc工具类, 增加jemalloc内存统计分析 (#2885)
增加jemalloc工具类, 增加jemalloc内存统计分析
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user