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

Unified Diff: base/debug/thread_heap_usage_tracker.cc

Issue 2386123003: Add heap allocator usage to task profiler. (Closed)
Patch Set: Fix borked define flag. Created 4 years, 1 month 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
« no previous file with comments | « base/BUILD.gn ('k') | base/tracked_objects.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/debug/thread_heap_usage_tracker.cc
diff --git a/base/debug/thread_heap_usage_tracker.cc b/base/debug/thread_heap_usage_tracker.cc
index b9018e0c7056e2aa578e1586c462e88f58ea4008..ab8f5abf38d1068b8ee7036235ed05075b892533 100644
--- a/base/debug/thread_heap_usage_tracker.cc
+++ b/base/debug/thread_heap_usage_tracker.cc
@@ -144,7 +144,12 @@ ThreadHeapUsage* GetOrCreateThreadUsage() {
// Prevent reentrancy due to the allocation below.
g_thread_allocator_usage.Set(kInitializingSentinel);
- allocator_usage = new ThreadHeapUsage;
+ // Delegate the allocation of the per-thread structure to the underlying
+ // heap shim, for symmetry with the deallocation. Otherwise interposing
+ // shims may mis-attribute or mis-direct this allocation.
+ const AllocatorDispatch* next = allocator_dispatch.next;
Primiano Tucci (use gerrit) 2016/11/28 18:38:31 add a compile_assert(std::is_pod(ThreadHeapUsage))
Sigurður Ásgeirsson 2016/11/30 14:41:14 Got one of those down a couple of lines, added ano
+ allocator_usage = static_cast<ThreadHeapUsage*>(
+ next->alloc_function(next, sizeof(ThreadHeapUsage)));
Primiano Tucci (use gerrit) 2016/11/28 18:38:31 maybe a placement new is slighlty cleaner here. I
Sigurður Ásgeirsson 2016/11/30 14:41:14 Ah, placement new - cool - haven't used it for thi
memset(allocator_usage, 0, sizeof(*allocator_usage));
g_thread_allocator_usage.Set(allocator_usage);
}
@@ -159,7 +164,10 @@ ThreadHeapUsageTracker::ThreadHeapUsageTracker() : thread_usage_(nullptr) {
}
ThreadHeapUsageTracker::~ThreadHeapUsageTracker() {
- DCHECK(thread_checker_.CalledOnValidThread());
+ // TODO(fdoray): This DCHECK causes inexplicable fallout in Chrome. This
+ // was isolated to a line in CalledOnValidThread reading.
+ // if (task_token_ == TaskToken::GetForCurrentThread())
+ // DCHECK(thread_checker_.CalledOnValidThread());
if (thread_usage_ != nullptr) {
// If this tracker wasn't stopped, make it inclusive so that the
@@ -254,7 +262,11 @@ ThreadHeapUsageTracker::GetDispatchForTesting() {
void ThreadHeapUsageTracker::EnsureTLSInitialized() {
if (!g_thread_allocator_usage.initialized()) {
g_thread_allocator_usage.Initialize([](void* allocator_usage) {
- delete static_cast<ThreadHeapUsage*>(allocator_usage);
+ // Delegate the freeing of the per-thread structure to the next-lower
+ // heap shim. Otherwise this free will re-initialize the TLS on thread
+ // exit.
+ allocator_dispatch.next->free_function(allocator_dispatch.next,
+ allocator_usage);
});
}
}
« no previous file with comments | « base/BUILD.gn ('k') | base/tracked_objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698