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

Issue 2163783003: Implement a ScopedThreadHeapUsage class to allow profiling per-thread heap usage. (Closed)

Created:
4 years, 5 months ago by Sigurður Ásgeirsson
Modified:
4 years, 3 months ago
CC:
chromium-reviews
Base URL:
https://chromium.googlesource.com/chromium/src.git@shim-default
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

Implement a ScopedThreadHeapUsage class to allow profiling per-thread heap usage. This uses the generic allocator shim to hook into heap allocations. When disabled and unused, there is no runtime penalty for this. When heap tracing is enabled, there's a small accounting overhead for every allocation. Instantiating a ScopedThreadHeapUsage instance carries O(1) cost, whether or not heap tracing is enabled. BUG=644385 Committed: https://crrev.com/46e1b077586d5b91f9abb7a6a8f9eb6558a584bd Cr-Commit-Position: refs/heads/master@{#417601}

Patch Set 1 #

Patch Set 2 : Improve comments, fix cosmetic problems. #

Total comments: 34

Patch Set 3 : Address most comments from Chris and Primiano. #

Patch Set 4 : Improve comments a bit. #

Patch Set 5 : WIP: Push the size estimate function into AllocatorDispatch, rejig users and tests accordingly. #

Patch Set 6 : Add the get_size_estimate function to other default impls. #

Patch Set 7 : Fix a brain****, may even compile now. #

Total comments: 46

Patch Set 8 : Address Primiano's comments. #

Patch Set 9 : Implement initial mocked shim testing, still to come: variation in the size function. #

Patch Set 10 : Fix accounting semantics, fix testing, fix linkage in component builds, split tests into shim/integ… #

Patch Set 11 : Fix speling[sic], add override specifier, fix unsigned literal comparisons. #

Patch Set 12 : Make moar static to fix compilation error. #

Patch Set 13 : Add a missing malloc.h include, fix the shim unittest after semantic change. #

Patch Set 14 : Fix another @#$%&! literal signedness goof. #

Patch Set 15 : Merge ToT and change ASSERT->EXPECT. #

Total comments: 43

Patch Set 16 : Address comments, add tests for overhead bytes and for realloc. #

Patch Set 17 : Fix class static linkage problem. #

Patch Set 18 : Fix the non-null realloc(..., 0) case. #

Patch Set 19 : Add missing dispatch function and a test, pass right dispatch through to next level (sigh). #

Patch Set 20 : Change Init implementation to return a bool status. ::Init is now also tested when the shim is disa… #

Total comments: 4

Patch Set 21 : Prevent clever compilers from optimizing out malloc/free pair in test. General cleanup. #

Patch Set 22 : Change interface to Init/Enable/DisableForTesting, clean up tests. #

Patch Set 23 : Fix memory leak found by ASAN bot. #

Total comments: 11

Patch Set 24 : Address Primiano's comments. #

Patch Set 25 : Speling [sic] #

Patch Set 26 : Pull enabled variable out of the #defines to avoid unused variable errors. #

Patch Set 27 : Moar speling [sic]. #

Total comments: 6

Patch Set 28 : Address Nico's comments. #

Unified diffs Side-by-side diffs Delta from patch set Stats (+925 lines, -28 lines) Patch
M base/BUILD.gn View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 2 chunks +3 lines, -0 lines 0 comments Download
M base/allocator/allocator_shim.h View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 chunk +7 lines, -0 lines 0 comments Download
M base/allocator/allocator_shim_default_dispatch_to_glibc.cc View 1 2 3 4 5 6 7 8 9 10 11 12 2 chunks +15 lines, -6 lines 0 comments Download
M base/allocator/allocator_shim_default_dispatch_to_linker_wrapped_symbols.cc View 1 2 3 4 5 6 7 1 chunk +13 lines, -6 lines 0 comments Download
M base/allocator/allocator_shim_default_dispatch_to_tcmalloc.cc View 1 2 3 4 5 6 1 chunk +11 lines, -6 lines 0 comments Download
M base/allocator/allocator_shim_default_dispatch_to_winheap.cc View 1 2 3 4 5 1 chunk +12 lines, -3 lines 0 comments Download
M base/allocator/winheap_stubs_win.h View 1 2 3 4 1 chunk +5 lines, -1 line 0 comments Download
M base/allocator/winheap_stubs_win.cc View 1 2 3 4 2 chunks +23 lines, -0 lines 0 comments Download
A base/debug/scoped_thread_heap_usage.h View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 1 chunk +103 lines, -0 lines 0 comments Download
A base/debug/scoped_thread_heap_usage.cc View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 1 chunk +234 lines, -0 lines 0 comments Download
A base/debug/scoped_thread_heap_usage_unittest.cc View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 1 chunk +487 lines, -0 lines 0 comments Download
M base/trace_event/malloc_dump_provider.cc View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 1 chunk +12 lines, -6 lines 0 comments Download

Messages

Total messages: 129 (99 generated)
Sigurður Ásgeirsson
Hey guys, here's what I'm wanting to hook up to the heap shim. This in ...
4 years, 5 months ago (2016-07-20 18:52:22 UTC) #2
chrisha
https://codereview.chromium.org/2163783003/diff/20001/base/debug/scoped_heap_usage.cc File base/debug/scoped_heap_usage.cc (right): https://codereview.chromium.org/2163783003/diff/20001/base/debug/scoped_heap_usage.cc#newcode33 base/debug/scoped_heap_usage.cc:33: // instead allows querying the actual user size of ...
4 years, 5 months ago (2016-07-21 14:23:31 UTC) #3
Primiano Tucci (use gerrit)
Some initial thoughts. https://codereview.chromium.org/2163783003/diff/20001/base/debug/scoped_heap_usage.cc File base/debug/scoped_heap_usage.cc (right): https://codereview.chromium.org/2163783003/diff/20001/base/debug/scoped_heap_usage.cc#newcode34 base/debug/scoped_heap_usage.cc:34: // malloc_usable_size. I'm not sure how ...
4 years, 5 months ago (2016-07-21 15:59:20 UTC) #4
Sigurður Ásgeirsson
Hey guys, I've addressed most or all comments and pushed the "GetSizeEstimate" function up to ...
4 years, 4 months ago (2016-08-19 18:21:50 UTC) #5
Primiano Tucci (use gerrit)
Finally had time to look to this, sorry for the delay. Overall looks good an ...
4 years, 4 months ago (2016-08-24 14:11:46 UTC) #23
Primiano Tucci (use gerrit)
comments after our vc, see if it makes sense. https://codereview.chromium.org/2163783003/diff/200001/base/allocator/allocator_shim.h File base/allocator/allocator_shim.h (right): https://codereview.chromium.org/2163783003/diff/200001/base/allocator/allocator_shim.h#newcode63 base/allocator/allocator_shim.h:63: ...
4 years, 4 months ago (2016-08-24 15:28:47 UTC) #24
Sigurður Ásgeirsson
Chris - can I ask you to give this the once-over? I'm still trying to ...
4 years, 3 months ago (2016-09-01 15:18:19 UTC) #52
chrisha
https://codereview.chromium.org/2163783003/diff/460001/base/allocator/allocator_shim.h File base/allocator/allocator_shim.h (right): https://codereview.chromium.org/2163783003/diff/460001/base/allocator/allocator_shim.h#newcode62 base/allocator/allocator_shim.h:62: // allocation. What should implementations do when this isn't ...
4 years, 3 months ago (2016-09-01 20:29:18 UTC) #59
Primiano Tucci (use gerrit)
Proactive-LGTM to kill timezone latency. Overall looks good % remaining Chris comments. Can do another ...
4 years, 3 months ago (2016-09-02 17:31:20 UTC) #60
Sigurður Ásgeirsson
Thanks guys - I've addressed all comments, aside from the TLS initialization one. I think ...
4 years, 3 months ago (2016-09-06 14:58:54 UTC) #63
chrisha
https://codereview.chromium.org/2163783003/diff/460001/base/debug/scoped_thread_heap_usage.cc File base/debug/scoped_thread_heap_usage.cc (right): https://codereview.chromium.org/2163783003/diff/460001/base/debug/scoped_thread_heap_usage.cc#newcode124 base/debug/scoped_thread_heap_usage.cc:124: nullptr}; On 2016/09/06 14:58:53, Sigurður Ásgeirsson wrote: > On ...
4 years, 3 months ago (2016-09-06 15:51:43 UTC) #70
Sigurður Ásgeirsson
Thanks - now less incorrect and moar tested. https://codereview.chromium.org/2163783003/diff/460001/base/debug/scoped_thread_heap_usage.cc File base/debug/scoped_thread_heap_usage.cc (right): https://codereview.chromium.org/2163783003/diff/460001/base/debug/scoped_thread_heap_usage.cc#newcode124 base/debug/scoped_thread_heap_usage.cc:124: nullptr}; ...
4 years, 3 months ago (2016-09-06 16:25:23 UTC) #75
Sigurður Ásgeirsson
K, so I've changed my mind on the ::Init function once again. Here's what I'm ...
4 years, 3 months ago (2016-09-06 18:41:12 UTC) #80
Primiano Tucci (use gerrit)
> This function wants to take a "bool intercept_heap" and return a boolean result. Alternatively ...
4 years, 3 months ago (2016-09-06 19:33:12 UTC) #84
Sigurður Ásgeirsson
On 2016/09/06 19:33:12, Primiano Tucci wrote: > > This function wants to take a "bool ...
4 years, 3 months ago (2016-09-07 14:51:50 UTC) #87
Sigurður Ásgeirsson
OK guys, I think this is finally ready for submission - one last look? Thanks ...
4 years, 3 months ago (2016-09-07 15:49:26 UTC) #91
Primiano Tucci (use gerrit)
great. still LGTM, just some final comments about checks. https://codereview.chromium.org/2163783003/diff/620001/base/debug/scoped_thread_heap_usage.cc File base/debug/scoped_thread_heap_usage.cc (right): https://codereview.chromium.org/2163783003/diff/620001/base/debug/scoped_thread_heap_usage.cc#newcode18 base/debug/scoped_thread_heap_usage.cc:18: ...
4 years, 3 months ago (2016-09-07 17:53:38 UTC) #96
Sigurður Ásgeirsson
Thanks - comments addressed. Chris? Nico for owners pretty please? https://codereview.chromium.org/2163783003/diff/620001/base/debug/scoped_thread_heap_usage.cc File base/debug/scoped_thread_heap_usage.cc (right): https://codereview.chromium.org/2163783003/diff/620001/base/debug/scoped_thread_heap_usage.cc#newcode18 ...
4 years, 3 months ago (2016-09-07 18:35:35 UTC) #102
Primiano Tucci (use gerrit)
https://codereview.chromium.org/2163783003/diff/620001/base/debug/scoped_thread_heap_usage.cc File base/debug/scoped_thread_heap_usage.cc (right): https://codereview.chromium.org/2163783003/diff/620001/base/debug/scoped_thread_heap_usage.cc#newcode202 base/debug/scoped_thread_heap_usage.cc:202: } On 2016/09/07 18:35:35, Sigurður Ásgeirsson wrote: > On ...
4 years, 3 months ago (2016-09-07 18:57:33 UTC) #107
chrisha
Nothing more to add from me. lgtm! https://codereview.chromium.org/2163783003/diff/460001/base/debug/scoped_thread_heap_usage.cc File base/debug/scoped_thread_heap_usage.cc (right): https://codereview.chromium.org/2163783003/diff/460001/base/debug/scoped_thread_heap_usage.cc#newcode71 base/debug/scoped_thread_heap_usage.cc:71: size_t estimate ...
4 years, 3 months ago (2016-09-07 19:05:45 UTC) #108
brucedawson
I haven't looked at the code, but... I want a bit more detail in the ...
4 years, 3 months ago (2016-09-07 21:40:56 UTC) #111
Sigurður Ásgeirsson
Thanks, updated the issue title and body. The ScopedThreadHeapUsage class name was intended to be ...
4 years, 3 months ago (2016-09-07 22:02:21 UTC) #113
Sigurður Ásgeirsson
Nico; gentle nudge for owners please...
4 years, 3 months ago (2016-09-08 15:30:53 UTC) #118
Nico
lgtm I apologize for the bikeshed comment, feel free to ignore. https://codereview.chromium.org/2163783003/diff/700001/base/debug/scoped_thread_heap_usage.cc File base/debug/scoped_thread_heap_usage.cc (right): ...
4 years, 3 months ago (2016-09-09 14:40:33 UTC) #119
Primiano Tucci (use gerrit)
https://codereview.chromium.org/2163783003/diff/700001/base/debug/scoped_thread_heap_usage.cc File base/debug/scoped_thread_heap_usage.cc (right): https://codereview.chromium.org/2163783003/diff/700001/base/debug/scoped_thread_heap_usage.cc#newcode208 base/debug/scoped_thread_heap_usage.cc:208: CHECK_EQ(false, g_heap_tracking_enabled) << "No double-enabling."; On 2016/09/09 14:40:33, Nico ...
4 years, 3 months ago (2016-09-09 14:56:18 UTC) #120
Sigurður Ásgeirsson
Thanks, committing. https://codereview.chromium.org/2163783003/diff/700001/base/debug/scoped_thread_heap_usage.cc File base/debug/scoped_thread_heap_usage.cc (right): https://codereview.chromium.org/2163783003/diff/700001/base/debug/scoped_thread_heap_usage.cc#newcode208 base/debug/scoped_thread_heap_usage.cc:208: CHECK_EQ(false, g_heap_tracking_enabled) << "No double-enabling."; On 2016/09/09 ...
4 years, 3 months ago (2016-09-09 14:58:20 UTC) #121
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.org/2163783003/720001
4 years, 3 months ago (2016-09-09 14:59:04 UTC) #124
commit-bot: I haz the power
Committed patchset #28 (id:720001)
4 years, 3 months ago (2016-09-09 16:43:59 UTC) #126
commit-bot: I haz the power
Patchset 28 (id:??) landed as https://crrev.com/46e1b077586d5b91f9abb7a6a8f9eb6558a584bd Cr-Commit-Position: refs/heads/master@{#417601}
4 years, 3 months ago (2016-09-09 16:46:09 UTC) #128
Sébastien Marchand
4 years, 3 months ago (2016-09-11 03:52:33 UTC) #129
Message was sent while issue was closed.
On 2016/09/09 16:46:09, commit-bot: I haz the power wrote:
> Patchset 28 (id:??) landed as
> https://crrev.com/46e1b077586d5b91f9abb7a6a8f9eb6558a584bd
> Cr-Commit-Position: refs/heads/master@{#417601}

This is breaking the SyzyAsan builder
(http://build.chromium.org/p/chromium.lkgr/builders/Win%20SyzyASAN%20LKGR/buil...):

Writing """\
disable_precompiled_headers = true
is_debug = false
is_syzyasan = true
target_cpu = "x86"
""" to C:\b\c\b\Win_SyzyASAN_LKGR\src\out\Release\args.gn.

C:\b\c\b\Win_SyzyASAN_LKGR\src\buildtools\win\gn.exe gen //out/Release --check
  -> returned 1
ERROR at //base/allocator/winheap_stubs_win.cc:16:11: Include not allowed.
#include "base/bits.h"
          ^----------
It is not in any dependency of
  //base/allocator:allocator_shim
The include file is in the target(s):
  //base:base
which should somehow be reachable.
GN gen failed: 1
step returned non-zero exit code: 1
@@@STEP_FAILURE@@@

Powered by Google App Engine
This is Rietveld 408576698