Commit 991cb5db authored by Gabriel Marin's avatar Gabriel Marin Committed by Commit Bot

tcmalloc: Add build flag to select new tcmalloc version

We are trying to uprev the tcmalloc version used in Chromium.
As part of the transition to a new tcmalloc, we plan to run experiments
with the new tcmalloc on a small number of boards before we enable the
new version globally.

This CL adds a build flag to select between the two tcmalloc versions at
build time. By default, the old tcmalloc version is used.

BUG=724399,b:70905156

Change-Id: I6839bba721b0d2a5f3515e7346bff418b0155221
Reviewed-on: https://chromium-review.googlesource.com/1130672Reviewed-by: default avatarDirk Pranke <dpranke@chromium.org>
Reviewed-by: default avatarAlbert J. Wong <ajwong@chromium.org>
Reviewed-by: default avatarWill Harris <wfh@chromium.org>
Commit-Queue: Gabriel Marin <gmx@chromium.org>
Cr-Commit-Position: refs/heads/master@{#577320}
parent ecaf0b2e
......@@ -74,7 +74,11 @@ config("tcmalloc_flags") {
if (use_allocator == "tcmalloc") {
# tcmalloc currently won't compile on Android.
source_set("tcmalloc") {
tcmalloc_dir = "//third_party/tcmalloc/gperftools-2.0/chromium"
if (use_new_tcmalloc) {
tcmalloc_dir = "//third_party/tcmalloc/chromium"
} else {
tcmalloc_dir = "//third_party/tcmalloc/gperftools-2.0/chromium"
}
# Don't check tcmalloc's includes. These files include various files like
# base/foo.h and they actually refer to tcmalloc's forked copy of base
......@@ -214,7 +218,9 @@ if (use_allocator == "tcmalloc") {
configs -= [ "//build/config/compiler:afdo" ]
}
deps = []
deps = [
":buildflags",
]
if (enable_profiling) {
sources += [
......@@ -272,7 +278,10 @@ if (use_allocator == "tcmalloc") {
buildflag_header("buildflags") {
header = "buildflags.h"
flags = [ "USE_ALLOCATOR_SHIM=$use_allocator_shim" ]
flags = [
"USE_ALLOCATOR_SHIM=$use_allocator_shim",
"USE_NEW_TCMALLOC=$use_new_tcmalloc",
]
}
# Used to shim malloc symbols on Android. see //base/allocator/README.md.
......
......@@ -3,14 +3,20 @@
// found in the LICENSE file.
#include "base/allocator/allocator_extension.h"
#include "base/allocator/buildflags.h"
#include "base/logging.h"
#if defined(USE_TCMALLOC)
#if BUILDFLAG(USE_NEW_TCMALLOC)
#include "third_party/tcmalloc/chromium/src/gperftools/heap-profiler.h"
#include "third_party/tcmalloc/chromium/src/gperftools/malloc_extension.h"
#include "third_party/tcmalloc/chromium/src/gperftools/malloc_hook.h"
#else
#include "third_party/tcmalloc/gperftools-2.0/chromium/src/gperftools/heap-profiler.h"
#include "third_party/tcmalloc/gperftools-2.0/chromium/src/gperftools/malloc_extension.h"
#include "third_party/tcmalloc/gperftools-2.0/chromium/src/gperftools/malloc_hook.h"
#endif
#endif
namespace base {
namespace allocator {
......
......@@ -4,8 +4,15 @@
#include "base/allocator/allocator_shim.h"
#include "base/allocator/allocator_shim_internals.h"
#include "base/allocator/buildflags.h"
#if BUILDFLAG(USE_NEW_TCMALLOC)
#include "third_party/tcmalloc/chromium/src/config.h"
#include "third_party/tcmalloc/chromium/src/gperftools/tcmalloc.h"
#else
#include "third_party/tcmalloc/gperftools-2.0/chromium/src/config.h"
#include "third_party/tcmalloc/gperftools-2.0/chromium/src/gperftools/tcmalloc.h"
#endif
namespace {
......
......@@ -13,8 +13,22 @@
#pragma GCC optimize ("no-auto-profile")
#endif
#include "base/allocator/buildflags.h"
#if BUILDFLAG(USE_NEW_TCMALLOC)
#if defined(TCMALLOC_FOR_DEBUGALLOCATION)
#include "third_party/tcmalloc/chromium/src/debugallocation.cc"
#else
#include "third_party/tcmalloc/chromium/src/tcmalloc.cc"
#endif
#else
#if defined(TCMALLOC_FOR_DEBUGALLOCATION)
#include "third_party/tcmalloc/gperftools-2.0/chromium/src/debugallocation.cc"
#else
#include "third_party/tcmalloc/gperftools-2.0/chromium/src/tcmalloc.cc"
#endif
#endif
......@@ -6,6 +6,7 @@
#include <string>
#include "base/allocator/buildflags.h"
#include "base/debug/debugging_buildflags.h"
#include "base/process/process_handle.h"
#include "base/strings/string_number_conversions.h"
......@@ -19,9 +20,15 @@
// TODO(peria): Enable profiling on Windows.
#if BUILDFLAG(ENABLE_PROFILING) && !defined(NO_TCMALLOC) && !defined(OS_WIN)
#if BUILDFLAG(USE_NEW_TCMALLOC)
#include "third_party/tcmalloc/chromium/src/gperftools/profiler.h"
#else
#include "third_party/tcmalloc/gperftools-2.0/chromium/src/gperftools/profiler.h"
#endif
#endif
namespace base {
namespace debug {
......
......@@ -18,9 +18,14 @@
#include "build/build_config.h"
#if defined(USE_TCMALLOC)
#if BUILDFLAG(USE_NEW_TCMALLOC)
#include "third_party/tcmalloc/chromium/src/config.h"
#include "third_party/tcmalloc/chromium/src/gperftools/tcmalloc.h"
#else
#include "third_party/tcmalloc/gperftools-2.0/chromium/src/config.h"
#include "third_party/tcmalloc/gperftools-2.0/chromium/src/gperftools/tcmalloc.h"
#endif
#endif
namespace base {
......
......@@ -32,6 +32,9 @@ declare_args() {
# Partition alloc is included by default except iOS.
use_partition_alloc = !is_ios
# Use the new tcmalloc. It's relevant only when use_allocator == "tcmalloc".
use_new_tcmalloc = false
}
if (is_nacl) {
......
......@@ -2,12 +2,19 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//build/config/allocator.gni")
import("//build/config/compiler/compiler.gni")
executable("addr2line-pdb") {
sources = [
"gperftools-2.0/chromium/src/windows/addr2line-pdb.c",
]
if (use_new_tcmalloc) {
sources = [
"chromium/src/windows/addr2line-pdb.c",
]
} else {
sources = [
"gperftools-2.0/chromium/src/windows/addr2line-pdb.c",
]
}
configs -= [ "//build/config/compiler:chromium_code" ]
configs += [ "//build/config/compiler:no_chromium_code" ]
......
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