Skip to content

Commit

Permalink
add heap profile for start be
Browse files Browse the repository at this point in the history
Signed-off-by: trueeyu <lxhhust350@qq.com>
  • Loading branch information
trueeyu committed Sep 6, 2023
1 parent cb07d99 commit b70f793
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
24 changes: 23 additions & 1 deletion be/src/storage/data_dir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#include "fs/fs.h"
#include "fs/fs_util.h"
#include "gutil/strings/substitute.h"
#include "http/action/pprof_actions.h"
#include "jemalloc/jemalloc.h"
#include "runtime/exec_env.h"
#include "service/backend_options.h"
#include "storage/olap_define.h"
Expand Down Expand Up @@ -232,6 +234,24 @@ std::string DataDir::get_root_path_from_schema_hash_path_in_trash(const std::str
.string();
}

void DataDir::_dump_heap_profile() {
std::string str;
std::stringstream tmp_prof_file_name;
tmp_prof_file_name << config::pprof_profile_dir << "/heap_profile." << getpid() << "." << rand();

// NOTE: Use fname to make the content which fname_cstr references to is still valid
// when je_mallctl is executing
auto fname = tmp_prof_file_name.str();
const char* fname_cstr = fname.c_str();
if (je_mallctl("prof.dump", nullptr, nullptr, &fname_cstr, sizeof(const char*)) == 0) {
std::ifstream f(fname_cstr);
str = std::string(std::istreambuf_iterator<char>(f), std::istreambuf_iterator<char>());
} else {
std::string str = "dump jemalloc prof file failed";
return;
}
}

// TODO(ygl): deal with rowsets and tablets when load failed
Status DataDir::load() {
LOG(INFO) << "start to load tablets from " << _path;
Expand All @@ -253,12 +273,14 @@ Status DataDir::load() {
dir_rowset_metas.push_back(rowset_meta);
return true;
};
_dump_heap_profile();
Status load_rowset_status = RowsetMetaManager::traverse_rowset_metas(_kv_store, load_rowset_func);
_dump_heap_profile();

if (!load_rowset_status.ok()) {
LOG(WARNING) << "errors when load rowset meta from meta env, skip this data dir:" << _path;
} else {
LOG(INFO) << "load rowset from meta finished, data dir: " << _path;
LOG(INFO) << "load rowset from meta finished, data dir: " << _path << ", size=" << dir_rowset_metas.size();
}

// load tablet
Expand Down
1 change: 1 addition & 0 deletions be/src/storage/data_dir.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class DataDir {
Status update_capacity();

private:
void _dump_heap_profile();
Status _init_data_dir();
Status _init_tmp_dir();
Status _init_meta(bool read_only = false);
Expand Down

0 comments on commit b70f793

Please sign in to comment.