Skip to content

Commit

Permalink
2
Browse files Browse the repository at this point in the history
  • Loading branch information
xinyiZzz committed Oct 11, 2024
1 parent ef8f105 commit 9ea7d22
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 42 deletions.
32 changes: 18 additions & 14 deletions be/src/http/default_path_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,24 +93,17 @@ void config_handler(const WebPageHandler::ArgumentMap& args, std::stringstream*
(*output) << "</pre>";
}

// Registered to handle "/profile".
void process_profile_handler(const WebPageHandler::ArgumentMap& args, std::stringstream* output) {
(*output) << "<h2 id=\"processProfileTitle\">Process Profile</h2>\n";
doris::ProcessProfile::instance()->refresh_profile();
(*output) << "<pre id=\"processProfile\">"
<< doris::ProcessProfile::instance()->print_process_profile() << "</pre>";

void memory_info_handler(std::stringstream* output) {
(*output) << "<h2>Memory Info</h2>\n";
(*output) << "<pre>";
(*output) << "<h4>Memory Documents</h4>\n"
(*output) << "<h4 id=\"memoryDocumentsTitle\">Memory Documents</h4>\n"
<< "<a "
"href=https://doris.apache.org/zh-CN/docs/dev/admin-manual/memory-management/"
"overview>Memory Management Overview</a>"
<< std::endl
"overview>Memory Management Overview</a>\n"
<< "<a "
"href=https://doris.apache.org/zh-CN/docs/dev/admin-manual/memory-management/"
"memory-issue-faq>Memory Issue FAQ</a>"
<< std::endl;
"memory-issue-faq>Memory Issue FAQ</a>\n"
<< "\n---\n";

(*output) << "<h4 id=\"memoryPropertiesTitle\">Memory Properties</h4>\n"
<< "System Physical Mem: "
Expand All @@ -128,7 +121,8 @@ void process_profile_handler(const WebPageHandler::ArgumentMap& args, std::strin
<< PrettyPrinter::print(MemInfo::cgroup_mem_limit(), TUnit::BYTES) << std::endl
<< "Cgroup Mem Usage: "
<< PrettyPrinter::print(MemInfo::cgroup_mem_usage(), TUnit::BYTES) << std::endl
<< "Cgroup Mem Refresh State: " << MemInfo::cgroup_mem_refresh_state() << std::endl;
<< "Cgroup Mem Refresh State: " << MemInfo::cgroup_mem_refresh_state() << std::endl
<< "\n---\n";

(*output) << "<h4 id=\"memoryOptionSettingsTitle\">Memory Option Settings</h4>\n";
{
Expand All @@ -141,6 +135,7 @@ void process_profile_handler(const WebPageHandler::ArgumentMap& args, std::strin
}
}
}
(*output) << "\n---\n";

(*output) << "<h4 id=\"jemallocProfilesTitle\">Jemalloc Profiles</h4>\n";
#if defined(ADDRESS_SANITIZER) || defined(LEAK_SANITIZER) || defined(THREAD_SANITIZER)
Expand All @@ -165,6 +160,15 @@ void process_profile_handler(const WebPageHandler::ArgumentMap& args, std::strin
(*output) << "</pre>";
}

// Registered to handle "/profile".
void process_profile_handler(const WebPageHandler::ArgumentMap& args, std::stringstream* output) {
(*output) << "<h2 id=\"processProfileTitle\">Process Profile</h2>\n";
doris::ProcessProfile::instance()->refresh_profile();
(*output) << "<pre id=\"processProfile\">"
<< doris::ProcessProfile::instance()->print_process_profile_no_root() << "</pre>";
memory_info_handler(output);
}

void display_tablets_callback(const WebPageHandler::ArgumentMap& args, EasyJson* ej) {
std::string tablet_num_to_return;
auto it = args.find("limit");
Expand All @@ -179,7 +183,7 @@ void display_tablets_callback(const WebPageHandler::ArgumentMap& args, EasyJson*
// Registered to handle "/mem_tracker", and prints out memory tracker information.
void mem_tracker_handler(const WebPageHandler::ArgumentMap& args, std::stringstream* output) {
(*output) << "<h2>mem_tracker webpage has been offline, please click <a "
"href=../profile>Process Profile</a></h2>\n";
"href=../profile>Process Profile</a>, see MemoryProfile and Memory Info</h2>\n";
}

void heap_handler(const WebPageHandler::ArgumentMap& args, std::stringstream* output) {
Expand Down
4 changes: 1 addition & 3 deletions be/src/runtime/memory/mem_tracker_limiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ namespace doris {

static bvar::Adder<int64_t> memory_memtrackerlimiter_cnt("memory_memtrackerlimiter_cnt");

std::atomic<long> mem_tracker_number_counter(0);
std::atomic<long> mem_tracker_limiter_group_counter(0);
constexpr auto GC_MAX_SEEK_TRACKER = 1000;

Expand All @@ -62,8 +61,7 @@ static RuntimeProfile::Counter* previously_canceling_tasks_counter =
MemTrackerLimiter::MemTrackerLimiter(Type type, const std::string& label, int64_t byte_limit) {
DCHECK_GE(byte_limit, -1);
_type = type;
// MemTrackerLimiter labels cannot be repeated, otherwise generation Runtime Profile will fail.
_label = fmt::format("{}_{}", label, mem_tracker_number_counter.fetch_add(1));
_label = label;
_limit = byte_limit;
if (_type == Type::GLOBAL) {
_group_num = 0;
Expand Down
59 changes: 37 additions & 22 deletions be/src/runtime/memory/memory_profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ static bvar::Adder<int64_t> memory_untracked_memory_bytes("memory_untracked_memo

MemoryProfile::MemoryProfile() {
_memory_overview_profile.set(std::make_unique<RuntimeProfile>("MemoryOverviewSnapshot"));
_global_memory_profile.set(std::make_unique<RuntimeProfile>("GlobalMemorySnapshot"));
_top_memory_tasks_profile.set(std::make_unique<RuntimeProfile>("TopMemoryTasksSnapshot"));
_tasks_memory_profile.set(std::make_unique<RuntimeProfile>("TasksMemorySnapshot"));
}

Expand All @@ -52,18 +54,16 @@ void MemoryProfile::refresh_memory_overview_profile() {
std::unique_ptr<RuntimeProfile> memory_overview_profile =
std::make_unique<RuntimeProfile>("MemoryOverviewSnapshot");
#endif
std::unique_ptr<RuntimeProfile> global_memory_profile =
std::make_unique<RuntimeProfile>("GlobalMemorySnapshot");
std::unique_ptr<RuntimeProfile> top_memory_tasks_profile =
std::make_unique<RuntimeProfile>("TopMemoryTasksSnapshot");

// 1. create profile
RuntimeProfile* basic_overview_profile =
memory_overview_profile->create_child("BasicOverview", true, false);
RuntimeProfile* top_memory_tasks_profile =
memory_overview_profile->create_child("TopMemoryTasks", true, false);
RuntimeProfile* global_memory_profile =
memory_overview_profile->create_child("GlobalMemory", true, false);
RuntimeProfile* untracked_memory_profile =
basic_overview_profile->create_child("UntrackedMemory", true, false);
memory_overview_profile->create_child("UntrackedMemory", true, false);
RuntimeProfile* tracked_memory_profile =
basic_overview_profile->create_child("TrackedMemory", true, false);
memory_overview_profile->create_child("TrackedMemory", true, false);
RuntimeProfile* tasks_memory_overview_profile =
tracked_memory_profile->create_child("TasksMemory", true, false);
RuntimeProfile* tasks_memory_overview_details_profile =
Expand All @@ -78,13 +78,13 @@ void MemoryProfile::refresh_memory_overview_profile() {
// 2. add counter
// 2.1 add process memory counter
RuntimeProfile::Counter* process_physical_memory_current_usage_counter =
ADD_COUNTER(basic_overview_profile, "PhysicalMemory(VmRSS)", TUnit::BYTES);
ADD_COUNTER(memory_overview_profile, "PhysicalMemory(VmRSS)", TUnit::BYTES);
RuntimeProfile::Counter* process_physical_memory_peak_usage_counter =
basic_overview_profile->AddHighWaterMarkCounter("PhysicalMemoryPeak", TUnit::BYTES);
memory_overview_profile->AddHighWaterMarkCounter("PhysicalMemoryPeak", TUnit::BYTES);
RuntimeProfile::Counter* process_virtual_memory_current_usage_counter =
ADD_COUNTER(basic_overview_profile, "VirtualMemory(VmSize)", TUnit::BYTES);
ADD_COUNTER(memory_overview_profile, "VirtualMemory(VmSize)", TUnit::BYTES);
RuntimeProfile::Counter* process_virtual_memory_peak_usage_counter =
basic_overview_profile->AddHighWaterMarkCounter("VirtualMemoryPeak", TUnit::BYTES);
memory_overview_profile->AddHighWaterMarkCounter("VirtualMemoryPeak", TUnit::BYTES);

// 2.2 add untracked memory counter
RuntimeProfile::Counter* untracked_memory_current_usage_counter =
Expand Down Expand Up @@ -233,10 +233,11 @@ void MemoryProfile::refresh_memory_overview_profile() {
}
}

MemTrackerLimiter::make_type_trackers_profile(global_memory_profile,
MemTrackerLimiter::make_type_trackers_profile(global_memory_profile.get(),
MemTrackerLimiter::Type::GLOBAL);

MemTrackerLimiter::make_top_consumption_tasks_tracker_profile(top_memory_tasks_profile, 15);
MemTrackerLimiter::make_top_consumption_tasks_tracker_profile(top_memory_tasks_profile.get(),
15);

COUNTER_SET(tasks_memory_current_usage_counter, tasks_trackers_mem_sum);
COUNTER_SET(tasks_memory_peak_usage_counter, tasks_trackers_mem_sum);
Expand Down Expand Up @@ -287,6 +288,8 @@ void MemoryProfile::refresh_memory_overview_profile() {

// 4. reset profile
_memory_overview_profile.set(std::move(memory_overview_profile));
_global_memory_profile.set(std::move(global_memory_profile));
_top_memory_tasks_profile.set(std::move(top_memory_tasks_profile));
}

void MemoryProfile::refresh_tasks_memory_profile() {
Expand All @@ -297,15 +300,27 @@ void MemoryProfile::refresh_tasks_memory_profile() {
}

void MemoryProfile::make_memory_profile(RuntimeProfile* profile) const {
RuntimeProfile* memory_profile_snapshot =
profile->create_child("MemoryProfileSnapshot", true, false);
RuntimeProfile* memory_profile_snapshot = profile->create_child("MemoryProfile", true, false);

auto memory_overview_version_ptr = _memory_overview_profile.get();
auto tasks_memory_version_ptr = _tasks_memory_profile.get();
RuntimeProfile* memory_overview_profile =
memory_profile_snapshot->create_child(memory_overview_version_ptr->name(), true, false);
memory_overview_profile->merge(const_cast<RuntimeProfile*>(memory_overview_version_ptr.get()));

auto global_memory_version_ptr = _global_memory_profile.get();
RuntimeProfile* global_memory_profile =
memory_profile_snapshot->create_child(global_memory_version_ptr->name(), true, false);
global_memory_profile->merge(const_cast<RuntimeProfile*>(global_memory_version_ptr.get()));

auto top_memory_tasks_version_ptr = _top_memory_tasks_profile.get();
RuntimeProfile* top_memory_tasks_profile = memory_profile_snapshot->create_child(
top_memory_tasks_version_ptr->name(), true, false);
top_memory_tasks_profile->merge(
const_cast<RuntimeProfile*>(top_memory_tasks_version_ptr.get()));

auto tasks_memory_version_ptr = _tasks_memory_profile.get();
RuntimeProfile* tasks_memory_profile =
memory_profile_snapshot->create_child(tasks_memory_version_ptr->name(), true, false);
memory_overview_profile->merge(const_cast<RuntimeProfile*>(memory_overview_version_ptr.get()));
tasks_memory_profile->merge(const_cast<RuntimeProfile*>(tasks_memory_version_ptr.get()));
}

Expand All @@ -328,10 +343,10 @@ int64_t MemoryProfile::other_current_usage() {
void MemoryProfile::print_log_process_usage() {
if (_enable_print_log_process_usage) {
_enable_print_log_process_usage = false;
std::string detail;
detail += "\nProcess Memory Summary: " + GlobalMemoryArbitrator::process_mem_log_str();
detail += "\n" + print_memory_overview_profile();
LOG(WARNING) << detail;
LOG(WARNING) << "Process Memory Summary: " + GlobalMemoryArbitrator::process_mem_log_str();
LOG(WARNING) << "\n" << print_memory_overview_profile();
LOG(WARNING) << "\n" << print_global_memory_profile();
LOG(WARNING) << "\n" << print_top_memory_tasks_profile();
}
}

Expand Down
18 changes: 17 additions & 1 deletion be/src/runtime/memory/memory_profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,29 @@ class MemoryProfile {
void make_memory_profile(RuntimeProfile* profile) const;

std::string print_memory_overview_profile() const {
std::stringstream ss;
auto version_ptr = _memory_overview_profile.get();
version_ptr->pretty_print(&ss);
return ss.str();
}

std::string print_global_memory_profile() const {
std::stringstream ss;
auto version_ptr = _global_memory_profile.get();
version_ptr->pretty_print(&ss);
return ss.str();
}

std::string print_top_memory_tasks_profile() const {
std::stringstream ss;
auto version_ptr = _top_memory_tasks_profile.get();
version_ptr->pretty_print(&ss);
return ss.str();
}

std::string print_tasks_memory_profile() const {
auto version_ptr = _tasks_memory_profile.get();
std::stringstream ss;
auto version_ptr = _tasks_memory_profile.get();
version_ptr->pretty_print(&ss);
return ss.str();
}
Expand All @@ -58,6 +72,8 @@ class MemoryProfile {

private:
MultiVersion<RuntimeProfile> _memory_overview_profile;
MultiVersion<RuntimeProfile> _global_memory_profile;
MultiVersion<RuntimeProfile> _top_memory_tasks_profile;
MultiVersion<RuntimeProfile> _tasks_memory_profile;

std::atomic<bool> _enable_print_log_process_usage {true};
Expand Down
3 changes: 1 addition & 2 deletions be/src/runtime/process_profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
namespace doris {

ProcessProfile::ProcessProfile() {
_process_profile.set(std::make_unique<RuntimeProfile>("ProcessProfile"));
_memory_profile = std::make_unique<MemoryProfile>();
}

Expand All @@ -38,8 +37,8 @@ void ProcessProfile::refresh_profile() {
std::unique_ptr<RuntimeProfile> process_profile =
std::make_unique<RuntimeProfile>("ProcessProfile");
_memory_profile->make_memory_profile(process_profile.get());
// TODO make other profile
_process_profile.set(std::move(process_profile));
// TODO make other profile
}

} // namespace doris
12 changes: 12 additions & 0 deletions be/src/runtime/process_profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ class ProcessProfile {
return ss.str();
}

std::string print_process_profile_no_root() const {
std::stringstream ss;
std::vector<RuntimeProfile*> profiles;
auto version_ptr = _process_profile.get();
auto* process_profile = const_cast<doris::RuntimeProfile*>(version_ptr.get());
process_profile->get_children(&profiles);
for (auto* profile : profiles) {
profile->pretty_print(&ss);
}
return ss.str();
}

MemoryProfile* memory_profile() { return _memory_profile.get(); }

private:
Expand Down

0 comments on commit 9ea7d22

Please sign in to comment.