From 893bff51bcf220b724a812d340d878b5fb8ce911 Mon Sep 17 00:00:00 2001 From: Aliaksey Kandratsenka 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