Commit d3a81abc authored by primiano's avatar primiano Committed by Commit bot

Allocator cleanup: allocator_extension call directly into tcmalloc

After crrev.com/1584893002 base/ can use directly allocator.
The grand plan is to dismantle all the indirection layer such that:
 - base is the only thing that knows about allocator-specific details.
 - non-base code uses only base abstractions and stops looking
   at USE_TCMALLOC build flags.

This CL, specifically, addresses the profiling-related methods moving
the tcmalloc-specific dependencies to base and base only.
Other parts of the codebase will be cleaned up in separate CLs.

Also this CL removes a stale base/debug/OWNERS. That file makes
no sense these days as tracing has been moved to base/trace_event/.

BUG=564618

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

Cr-Commit-Position: refs/heads/master@{#371335}
parent d372eb96
......@@ -6,34 +6,32 @@
#include "base/logging.h"
#if defined(USE_TCMALLOC)
#include "third_party/tcmalloc/chromium/src/gperftools/heap-profiler.h"
#include "third_party/tcmalloc/chromium/src/gperftools/malloc_extension.h"
#endif
namespace base {
namespace allocator {
namespace {
ReleaseFreeMemoryFunction g_release_free_memory_function = nullptr;
GetNumericPropertyFunction g_get_numeric_property_function = nullptr;
}
void ReleaseFreeMemory() {
if (g_release_free_memory_function)
g_release_free_memory_function();
#if defined(USE_TCMALLOC)
::MallocExtension::instance()->ReleaseFreeMemory();
#endif
}
bool GetNumericProperty(const char* name, size_t* value) {
return g_get_numeric_property_function &&
g_get_numeric_property_function(name, value);
}
void SetReleaseFreeMemoryFunction(
ReleaseFreeMemoryFunction release_free_memory_function) {
DCHECK(!g_release_free_memory_function);
g_release_free_memory_function = release_free_memory_function;
#if defined(USE_TCMALLOC)
return ::MallocExtension::instance()->GetNumericProperty(name, value);
#endif
return false;
}
void SetGetNumericPropertyFunction(
GetNumericPropertyFunction get_numeric_property_function) {
DCHECK(!g_get_numeric_property_function);
g_get_numeric_property_function = get_numeric_property_function;
bool IsHeapProfilerRunning() {
#if defined(USE_TCMALLOC)
return ::IsHeapProfilerRunning();
#endif
return false;
}
} // namespace allocator
......
......@@ -13,9 +13,6 @@
namespace base {
namespace allocator {
typedef void (*ReleaseFreeMemoryFunction)();
typedef bool (*GetNumericPropertyFunction)(const char* name, size_t* value);
// Request that the allocator release any free memory it knows about to the
// system.
BASE_EXPORT void ReleaseFreeMemory();
......@@ -26,20 +23,7 @@ BASE_EXPORT void ReleaseFreeMemory();
// |name| or |value| cannot be NULL
BASE_EXPORT bool GetNumericProperty(const char* name, size_t* value);
// These settings allow specifying a callback used to implement the allocator
// extension functions. These are optional, but if set they must only be set
// once. These will typically called in an allocator-specific initialization
// routine.
//
// No threading promises are made. The caller is responsible for making sure
// these pointers are set before any other threads attempt to call the above
// functions.
BASE_EXPORT void SetReleaseFreeMemoryFunction(
ReleaseFreeMemoryFunction release_free_memory_function);
BASE_EXPORT void SetGetNumericPropertyFunction(
GetNumericPropertyFunction get_numeric_property_function);
BASE_EXPORT bool IsHeapProfilerRunning();
} // namespace allocator
} // namespace base
......
per-file trace_event*=nduca@chromium.org
per-file trace_event*=dsinclair@chromium.org
per-file trace_event_android.cc=wangxianzhu@chromium.org
......@@ -56,6 +56,10 @@ void RestartProfilingAfterFork() {
ProfilerRegisterThread();
}
bool IsProfilingSupported() {
return true;
}
#else
void StartProfiling(const std::string& name) {
......@@ -74,6 +78,10 @@ bool BeingProfiled() {
void RestartProfilingAfterFork() {
}
bool IsProfilingSupported() {
return false;
}
#endif
#if !defined(OS_WIN)
......
......@@ -38,6 +38,9 @@ BASE_EXPORT void RestartProfilingAfterFork();
// Returns true iff this executable is instrumented with the Syzygy profiler.
BASE_EXPORT bool IsBinaryInstrumented();
// Returns true iff this executable supports profiling.
BASE_EXPORT bool IsProfilingSupported();
// There's a class of profilers that use "return address swizzling" to get a
// hook on function exits. This class of profilers uses some form of entry hook,
// like e.g. binary instrumentation, or a compiler flag, that calls a hook each
......
......@@ -10,6 +10,7 @@
#include "base/command_line.h"
#include "base/debug/debugging_flags.h"
#include "base/debug/profiler.h"
#include "base/macros.h"
#include "base/prefs/pref_service.h"
#include "build/build_config.h"
......@@ -1166,9 +1167,9 @@ void BrowserCommandController::UpdateCommandsForFullscreenMode() {
command_updater_.UpdateCommandEnabled(IDC_VIEW_PASSWORDS, show_main_ui);
command_updater_.UpdateCommandEnabled(IDC_ABOUT, show_main_ui);
command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, show_main_ui);
#if BUILDFLAG(ENABLE_PROFILING) && !defined(NO_TCMALLOC)
command_updater_.UpdateCommandEnabled(IDC_PROFILING_ENABLED, show_main_ui);
#endif
if (base::debug::IsProfilingSupported())
command_updater_.UpdateCommandEnabled(IDC_PROFILING_ENABLED, show_main_ui);
// Disable explicit fullscreen toggling when in metro snap mode.
bool fullscreen_enabled = window_state != WINDOW_STATE_METRO_SNAP;
......
......@@ -9,6 +9,7 @@
#include "base/command_line.h"
#include "base/debug/debugging_flags.h"
#include "base/debug/profiler.h"
#include "base/macros.h"
#include "base/metrics/histogram.h"
#include "base/prefs/pref_service.h"
......@@ -285,10 +286,10 @@ void ToolsMenuModel::Build(Browser* browser) {
AddSeparator(ui::NORMAL_SEPARATOR);
AddItemWithStringId(IDC_DEV_TOOLS, IDS_DEV_TOOLS);
#if BUILDFLAG(ENABLE_PROFILING) && !defined(NO_TCMALLOC)
AddSeparator(ui::NORMAL_SEPARATOR);
AddCheckItemWithStringId(IDC_PROFILING_ENABLED, IDS_PROFILING_ENABLED);
#endif
if (base::debug::IsProfilingSupported()) {
AddSeparator(ui::NORMAL_SEPARATOR);
AddCheckItemWithStringId(IDC_PROFILING_ENABLED, IDS_PROFILING_ENABLED);
}
}
////////////////////////////////////////////////////////////////////////////////
......
......@@ -417,16 +417,6 @@ class ContentMainRunnerImpl : public ContentMainRunner {
Shutdown();
}
#if defined(USE_TCMALLOC)
static bool GetNumericPropertyThunk(const char* name, size_t* value) {
return MallocExtension::instance()->GetNumericProperty(name, value);
}
static void ReleaseFreeMemoryThunk() {
MallocExtension::instance()->ReleaseFreeMemory();
}
#endif
int Initialize(const ContentMainParams& params) override {
ui_task_ = params.ui_task;
......@@ -455,10 +445,6 @@ class ContentMainRunnerImpl : public ContentMainRunner {
// For tcmalloc, we need to tell it to behave like new.
tc_set_new_mode(1);
// On windows, we've already set these thunks up in _heap_init()
base::allocator::SetGetNumericPropertyFunction(GetNumericPropertyThunk);
base::allocator::SetReleaseFreeMemoryFunction(ReleaseFreeMemoryThunk);
// Provide optional hook for monitoring allocation quantities on a
// per-thread basis. Only set the hook if the environment indicates this
// needs to be enabled.
......
......@@ -4,6 +4,7 @@
#include "content/browser/zygote_host/zygote_host_impl_linux.h"
#include "base/allocator/allocator_extension.h"
#include "base/files/file_enumerator.h"
#include "base/process/kill.h"
#include "base/process/memory.h"
......@@ -11,10 +12,6 @@
#include "content/public/browser/content_browser_client.h"
#include "sandbox/linux/suid/common/sandbox.h"
#if defined(USE_TCMALLOC)
#include "third_party/tcmalloc/chromium/src/gperftools/heap-profiler.h"
#endif
namespace content {
// static
......@@ -104,13 +101,12 @@ void ZygoteHostImpl::AdjustRendererOOMScore(base::ProcessHandle pid,
}
if (use_suid_sandbox_for_adj_oom_score_ && !selinux) {
#if defined(USE_TCMALLOC)
// If heap profiling is running, these processes are not exiting, at least
// on ChromeOS. The easiest thing to do is not launch them when profiling.
// TODO(stevenjb): Investigate further and fix.
if (IsHeapProfilerRunning())
if (base::allocator::IsHeapProfilerRunning())
return;
#endif
std::vector<std::string> adj_oom_score_cmdline;
adj_oom_score_cmdline.push_back(sandbox_binary_);
adj_oom_score_cmdline.push_back(sandbox::kAdjustOOMScoreSwitch);
......
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