Commit 4ee52987 authored by thakis@chromium.org's avatar thakis@chromium.org

tcmalloc: Let DEFINE_string define const char*s.

DEFINE_string is used in 3 files in tcmalloc, but we only compile one of
these.  In this one file, the string is converted to char every time it's used,
and since the string is used after global destructors have run it needs to be
copied to a second string in a static initializer.

Instead of all that silliness, just let DEFINE_string define a const char*
(like it does in v8 or webrtc).

BUG=94925
R=willchan@chromium.org

Review URL: https://codereview.chromium.org/286953011

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@271307 0039d316-1c4b-4281-b951-d872f2087c98
parent a04be055
...@@ -95,3 +95,5 @@ Modifications: ...@@ -95,3 +95,5 @@ Modifications:
- Fix sprintf formatting warning in MaybeDumpProfileLocked - Fix sprintf formatting warning in MaybeDumpProfileLocked
- Added tc_malloc_skip_new_handler. - Added tc_malloc_skip_new_handler.
- Fix logging issues in android - Fix logging issues in android
- Changed DEFINE_foo macros to ignore envname unless ENABLE_PROFILING is defined
- Changed DEFINE_string to define const char*s instead of strings
...@@ -59,13 +59,13 @@ ...@@ -59,13 +59,13 @@
#endif #endif
#define DECLARE_VARIABLE(type, name) \ #define DECLARE_VARIABLE(type, name) \
namespace FLAG__namespace_do_not_use_directly_use_DECLARE_##type##_instead { \ namespace FLAG__namespace_do_not_use_directly_use_DECLARE_##type##_instead {\
extern PERFTOOLS_DLL_DECL type FLAGS_##name; \ extern PERFTOOLS_DLL_DECL type FLAGS_##name; \
} \ } \
using FLAG__namespace_do_not_use_directly_use_DECLARE_##type##_instead::FLAGS_##name using FLAG__namespace_do_not_use_directly_use_DECLARE_##type##_instead::FLAGS_##name
#define DEFINE_VARIABLE(type, name, value, meaning) \ #define DEFINE_VARIABLE(type, name, value, meaning) \
namespace FLAG__namespace_do_not_use_directly_use_DECLARE_##type##_instead { \ namespace FLAG__namespace_do_not_use_directly_use_DECLARE_##type##_instead {\
PERFTOOLS_DLL_DECL type FLAGS_##name(value); \ PERFTOOLS_DLL_DECL type FLAGS_##name(value); \
char FLAGS_no##name; \ char FLAGS_no##name; \
} \ } \
...@@ -100,16 +100,15 @@ ...@@ -100,16 +100,15 @@
#define DEFINE_double(name, value, meaning) \ #define DEFINE_double(name, value, meaning) \
DEFINE_VARIABLE(double, name, value, meaning) DEFINE_VARIABLE(double, name, value, meaning)
// Special case for string, because we have to specify the namespace // Special case for string, because of the pointer type.
// std::string, which doesn't play nicely with our FLAG__namespace hackery.
#define DECLARE_string(name) \ #define DECLARE_string(name) \
namespace FLAG__namespace_do_not_use_directly_use_DECLARE_string_instead { \ namespace FLAG__namespace_do_not_use_directly_use_DECLARE_string_instead { \
extern std::string FLAGS_##name; \ extern const char* FLAGS_##name; \
} \ } \
using FLAG__namespace_do_not_use_directly_use_DECLARE_string_instead::FLAGS_##name using FLAG__namespace_do_not_use_directly_use_DECLARE_string_instead::FLAGS_##name
#define DEFINE_string(name, value, meaning) \ #define DEFINE_string(name, value, meaning) \
namespace FLAG__namespace_do_not_use_directly_use_DECLARE_string_instead { \ namespace FLAG__namespace_do_not_use_directly_use_DECLARE_string_instead { \
std::string FLAGS_##name(value); \ const char* FLAGS_##name = value; \
char FLAGS_no##name; \ char FLAGS_no##name; \
} \ } \
using FLAG__namespace_do_not_use_directly_use_DECLARE_string_instead::FLAGS_##name using FLAG__namespace_do_not_use_directly_use_DECLARE_string_instead::FLAGS_##name
......
...@@ -68,11 +68,6 @@ DEFINE_string(symbolize_pprof, ...@@ -68,11 +68,6 @@ DEFINE_string(symbolize_pprof,
EnvToString("PPROF_PATH", "pprof"), EnvToString("PPROF_PATH", "pprof"),
"Path to pprof to call for reporting function names."); "Path to pprof to call for reporting function names.");
// heap_profile_table_pprof may be referenced 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);
// Returns NULL if we're on an OS where we can't get the invocation name. // 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. // Using a static var is ok because we're not called from a thread.
static char* GetProgramInvocationName() { static char* GetProgramInvocationName() {
...@@ -129,7 +124,7 @@ int SymbolTable::Symbolize() { ...@@ -129,7 +124,7 @@ int SymbolTable::Symbolize() {
PrintError("Cannot figure out the name of this executable (argv0)"); PrintError("Cannot figure out the name of this executable (argv0)");
return 0; return 0;
} }
if (access(g_pprof_path->c_str(), R_OK) != 0) { if (access(FLAGS_symbolize_pprof, R_OK) != 0) {
PrintError("Cannot find 'pprof' (is PPROF_PATH set correctly?)"); PrintError("Cannot find 'pprof' (is PPROF_PATH set correctly?)");
return 0; return 0;
} }
...@@ -191,7 +186,7 @@ int SymbolTable::Symbolize() { ...@@ -191,7 +186,7 @@ int SymbolTable::Symbolize() {
unsetenv("HEAPPROFILE"); unsetenv("HEAPPROFILE");
unsetenv("HEAPCHECK"); unsetenv("HEAPCHECK");
unsetenv("PERFTOOLS_VERBOSE"); unsetenv("PERFTOOLS_VERBOSE");
execlp(g_pprof_path->c_str(), g_pprof_path->c_str(), execlp(FLAGS_symbolize_pprof, FLAGS_symbolize_pprof,
"--symbols", argv0, NULL); "--symbols", argv0, NULL);
_exit(3); // if execvp fails, it's bad news for us _exit(3); // if execvp fails, it's bad news for us
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment