This is an automated email from the ASF dual-hosted git repository.
guangmingchen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brpc.git
The following commit(s) were added to refs/heads/master by this push:
new 54c65702 Limit the extra options of jemalloc profiler (#3101)
54c65702 is described below
commit 54c65702f2bf92493facb6f0439a2b84da13b489
Author: Bright Chen <[email protected]>
AuthorDate: Fri Sep 26 19:46:56 2025 +0800
Limit the extra options of jemalloc profiler (#3101)
* Limit the extra options of jemalloc profiler
* Add warning log
---
src/brpc/details/jemalloc_profiler.cpp | 34 ++++++++++++++++++++++++++++++----
1 file changed, 30 insertions(+), 4 deletions(-)
diff --git a/src/brpc/details/jemalloc_profiler.cpp
b/src/brpc/details/jemalloc_profiler.cpp
index c14d5490..fdd06fb4 100644
--- a/src/brpc/details/jemalloc_profiler.cpp
+++ b/src/brpc/details/jemalloc_profiler.cpp
@@ -166,6 +166,23 @@ static int JeProfileReset(size_t lg_sample) {
return 0;
}
+// https://github.com/jemalloc/jemalloc/blob/5.3.0/bin/jeprof.in#L211-L222
+static const std::unordered_set<const char*> g_extra_options_set = {
+ "inuse_space", "inuse_objects", "alloc_space",
+ "alloc_objects", "show_bytes", "drop_negative",
+ "total_delay", "contentions", "mean_delay"
+};
+
+std::string GlobalExtraOptionsString() {
+ std::string result;
+ result.reserve(64);
+ for (const auto& option : g_extra_options_set) {
+ result.append(option);
+ result.append(" ");
+ }
+ return result;
+}
+
void JeControlProfile(Controller* cntl) {
const brpc::URI& uri = cntl->http_request().uri();
//
http:ip:port/pprof/heap?display=(text|svg|stats|flamegraph)&extra_options=(inuse_space|inuse_objects..)
@@ -228,13 +245,20 @@ void JeControlProfile(Controller* cntl) {
}
const std::string process_file(process_path, len);
- std::string cmd_str = jeprof + " " + process_file + " " + prof_name;
+ std::string cmd_str = butil::string_printf(
+ "%s %s %s", jeprof.c_str(), process_file.c_str(), prof_name.c_str());
// https://github.com/jemalloc/jemalloc/blob/5.3.0/bin/jeprof.in#L211-L222
// e.g: inuse_space, contentions
const std::string* uri_extra_options = uri.GetQuery("extra_options");
if (uri_extra_options != nullptr && !uri_extra_options->empty()) {
- cmd_str += " --" + *uri_extra_options + " ";
+ if (g_extra_options_set.count(uri_extra_options->c_str()) > 0) {
+ butil::string_appendf(&cmd_str, " --%s",
uri_extra_options->c_str());
+ } else {
+ static std::string g_options_str = GlobalExtraOptionsString();
+ LOG(WARNING) << "Unsupported jemalloc options=" <<
*uri_extra_options
+ << ", only support [" << g_options_str << "]";
+ }
}
bool display_img = false;
@@ -244,12 +268,14 @@ void JeControlProfile(Controller* cntl) {
} else if (*uri_display == "flamegraph") {
const char* flamegraph_tool = getenv("FLAMEGRAPH_PL_PATH");
if (!flamegraph_tool) {
- LOG(WARNING) << " display: " << *uri_display << " invalid, env
FLAMEGRAPH_PL_PATH invalid";
+ LOG(WARNING) << " display: " << *uri_display
+ << " invalid, env FLAMEGRAPH_PL_PATH invalid";
buf.append("\ndisplay:" + *uri_display + " invalid, env
FLAMEGRAPH_PL_PATH invalid");
return;
}
const int width_size = FLAGS_max_flame_graph_width > 0 ?
FLAGS_max_flame_graph_width : 1200;
- cmd_str += " --collapsed | " + std::string(flamegraph_tool) + "
--colors mem --width " + std::to_string(width_size);
+ butil::string_appendf(&cmd_str, " --collapsed | %s --colors mem
--width %d",
+ flamegraph_tool, width_size);
display_img = true;
} else if (*uri_display == "text") {
cmd_str += " --text ";
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]