Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(203)

Unified Diff: third_party/tcmalloc/chromium/src/heap-profiler.cc

Issue 9667026: Revert 126020 - Experiment for updating the tcmalloc chromium branch to r144 (gperftools 2.0). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/tcmalloc/chromium/src/heap-profiler.cc
===================================================================
--- third_party/tcmalloc/chromium/src/heap-profiler.cc (revision 126022)
+++ third_party/tcmalloc/chromium/src/heap-profiler.cc (working copy)
@@ -55,7 +55,7 @@
#include <algorithm>
#include <string>
-#include <gperftools/heap-profiler.h>
+#include <google/heap-profiler.h>
#include "base/logging.h"
#include "base/basictypes.h" // for PRId64, among other things
@@ -63,8 +63,8 @@
#include "base/commandlineflags.h"
#include "malloc_hook-inl.h"
#include "tcmalloc_guard.h"
-#include <gperftools/malloc_hook.h>
-#include <gperftools/malloc_extension.h>
+#include <google/malloc_hook.h>
+#include <google/malloc_extension.h>
#include "base/spinlock.h"
#include "base/low_level_alloc.h"
#include "base/sysinfo.h" // for GetUniquePathFromEnv()
@@ -184,6 +184,29 @@
// Profile generation
//----------------------------------------------------------------------
+enum AddOrRemove { ADD, REMOVE };
+
+// Add or remove all MMap-allocated regions to/from *heap_profile.
+// Assumes heap_lock is held.
+static void AddRemoveMMapDataLocked(AddOrRemove mode) {
+ RAW_DCHECK(heap_lock.IsHeld(), "");
+ if (!FLAGS_mmap_profile || !is_on) return;
+ // MemoryRegionMap maintained all the data we need for all
+ // mmap-like allocations, so we just use it here:
+ MemoryRegionMap::LockHolder l;
+ for (MemoryRegionMap::RegionIterator r = MemoryRegionMap::BeginRegionLocked();
+ r != MemoryRegionMap::EndRegionLocked(); ++r) {
+ if (mode == ADD) {
+ heap_profile->RecordAllocWithStack(
+ reinterpret_cast<const void*>(r->start_addr),
+ r->end_addr - r->start_addr,
+ r->call_stack_depth, r->call_stack);
+ } else {
+ heap_profile->RecordFree(reinterpret_cast<void*>(r->start_addr));
+ }
+ }
+}
+
// Input must be a buffer of size at least 1MB.
static char* DoGetHeapProfileLocked(char* buf, int buflen) {
// We used to be smarter about estimating the required memory and
@@ -194,13 +217,16 @@
RAW_DCHECK(heap_lock.IsHeld(), "");
int bytes_written = 0;
if (is_on) {
- if (FLAGS_mmap_profile) {
- heap_profile->RefreshMMapData();
- }
+ HeapProfileTable::Stats const stats = heap_profile->total();
+ (void)stats; // avoid an unused-variable warning in non-debug mode.
+ AddRemoveMMapDataLocked(ADD);
bytes_written = heap_profile->FillOrderedProfile(buf, buflen - 1);
- if (FLAGS_mmap_profile) {
- heap_profile->ClearMMapData();
- }
+ // FillOrderedProfile should not reduce the set of active mmap-ed regions,
+ // hence MemoryRegionMap will let us remove everything we've added above:
+ AddRemoveMMapDataLocked(REMOVE);
+ RAW_DCHECK(stats.Equivalent(heap_profile->total()), "");
+ // if this fails, we somehow removed by AddRemoveMMapDataLocked
+ // more than we have added.
}
buf[bytes_written] = '\0';
RAW_DCHECK(bytes_written == strlen(buf), "");
@@ -315,12 +341,9 @@
// Record an allocation in the profile.
static void RecordAlloc(const void* ptr, size_t bytes, int skip_count) {
- // Take the stack trace outside the critical section.
- void* stack[HeapProfileTable::kMaxStackDepth];
- int depth = HeapProfileTable::GetCallerStackTrace(skip_count + 1, stack);
SpinLockHolder l(&heap_lock);
if (is_on) {
- heap_profile->RecordAlloc(ptr, bytes, depth, stack);
+ heap_profile->RecordAlloc(ptr, bytes, skip_count + 1);
MaybeDumpProfileLocked();
}
}
« no previous file with comments | « third_party/tcmalloc/chromium/src/heap-profile-table.cc ('k') | third_party/tcmalloc/chromium/src/internal_logging.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698