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

Unified Diff: base/allocator/winheap_stubs_win.cc

Issue 2163783003: Implement a ScopedThreadHeapUsage class to allow profiling per-thread heap usage. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@shim-default
Patch Set: Fix a brain****, may even compile now. Created 4 years, 4 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: base/allocator/winheap_stubs_win.cc
diff --git a/base/allocator/winheap_stubs_win.cc b/base/allocator/winheap_stubs_win.cc
index 3cbbfaf038d99c3c852d6cc857e0916257fef10f..42f40dc8ad4cd48aa9ceb75d8a46b98981300fab 100644
--- a/base/allocator/winheap_stubs_win.cc
+++ b/base/allocator/winheap_stubs_win.cc
@@ -13,6 +13,8 @@
#include <new.h>
#include <windows.h>
+#include "base/bits.h"
+
namespace base {
namespace allocator {
@@ -51,6 +53,27 @@ void* WinHeapRealloc(void* ptr, size_t size) {
return nullptr;
}
+size_t WinHeapGetSizeEstimate(void* ptr) {
+ if (!ptr)
+ return 0;
+
+ // Get the user size of the allocation.
+ size_t size = HeapSize(get_heap_handle(), 0, ptr);
+
+ // Account for the 8-byte HEAP_HEADER preceding the block.
+ size += 8;
+
+// Round up to the nearest allocation granularity, which is 8 for
+// 32 bit machines, and 16 for 64 bit machines.
+#if defined(ARCH_CPU_64_BITS)
+ const size_t kAllocationGranularity = 16;
+#else
+ const size_t kAllocationGranularity = 8;
+#endif
+
+ return base::bits::Align(size, kAllocationGranularity);
+}
+
// Call the new handler, if one has been set.
// Returns true on successfully calling the handler, false otherwise.
bool WinCallNewHandler(size_t size) {

Powered by Google App Engine
This is Rietveld 408576698