加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Avoid-static-initialization-of-pprof-path-for-symbol.patch 2.25 KB
一键复制 编辑 原始数据 按行查看 历史
hexiaowen 提交于 2019-09-30 10:51 . Package init
From 893bff51bcf220b724a812d340d878b5fb8ce911 Mon Sep 17 00:00:00 2001
From: Aliaksey Kandratsenka <alkondratenko@gmail.com>
Date: Sun, 26 Aug 2018 11:35:44 -0700
Subject: [PATCH 23/39] Avoid static initialization of pprof path for
symbolization.
This is one of the things that chrome's fork fixes, but with c++11 we
can do it even nicer. Proposed fix is to use c++11 local static
variable to ensure that pprof path is initialized once on as-needed
basis.
---
src/symbolize.cc | 20 +++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)
diff --git a/src/symbolize.cc b/src/symbolize.cc
index 88609ff..4c71010 100755
--- a/src/symbolize.cc
+++ b/src/symbolize.cc
@@ -67,15 +67,17 @@
using std::string;
using tcmalloc::DumpProcSelfMaps; // from sysinfo.h
-
-DEFINE_string(symbolize_pprof,
- EnvToString("PPROF_PATH", "pprof"),
- "Path to pprof to call for reporting function names.");
-
-// heap_profile_table_pprof may be referenced after destructors are
+// pprof may be used after destructors are
// called (since that's when leak-checking is done), so we make
// a more-permanent copy that won't ever get destroyed.
-static string* g_pprof_path = new string(FLAGS_symbolize_pprof);
+static char* get_pprof_path() {
+ static char* result = ([] () {
+ string pprof_string = EnvToString("PPROF_PATH", "pprof");
+ return strdup(pprof_string.c_str());
+ })();
+
+ return result;
+}
// Returns NULL if we're on an OS where we can't get the invocation name.
// Using a static var is ok because we're not called from a thread.
@@ -144,7 +146,7 @@ int SymbolTable::Symbolize() {
PrintError("Cannot figure out the name of this executable (argv0)");
return 0;
}
- if (access(g_pprof_path->c_str(), R_OK) != 0) {
+ if (access(get_pprof_path(), R_OK) != 0) {
PrintError("Cannot find 'pprof' (is PPROF_PATH set correctly?)");
return 0;
}
@@ -206,7 +208,7 @@ int SymbolTable::Symbolize() {
unsetenv("HEAPPROFILE");
unsetenv("HEAPCHECK");
unsetenv("PERFTOOLS_VERBOSE");
- execlp(g_pprof_path->c_str(), g_pprof_path->c_str(),
+ execlp(get_pprof_path(), get_pprof_path(),
"--symbols", argv0, NULL);
_exit(3); // if execvp fails, it's bad news for us
}
--
1.8.3.1
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化