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

Unified Diff: skia/ext/SkMemory_new_handler.cpp

Issue 1780053003: DO NOT COMMIT: Heap profiler for Skia (sk_malloc) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
« no previous file with comments | « no previous file | skia/ext/skia_memory_dump_provider.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: skia/ext/SkMemory_new_handler.cpp
diff --git a/skia/ext/SkMemory_new_handler.cpp b/skia/ext/SkMemory_new_handler.cpp
index 91adb34118f198f625e11d60d6ed7c122a0b6a6e..282a5d2be5ce1609bec024165a112ddba7b6a1ea 100644
--- a/skia/ext/SkMemory_new_handler.cpp
+++ b/skia/ext/SkMemory_new_handler.cpp
@@ -7,6 +7,7 @@
#include "base/process/memory.h"
#include "build/build_config.h"
+#include "skia_memory_dump_provider.h"
#include "third_party/skia/include/core/SkTypes.h"
// This implementation of sk_malloc_flags() and friends is similar to
@@ -33,12 +34,16 @@ void sk_out_of_memory(void) {
abort();
}
-void* sk_realloc_throw(void* addr, size_t size) {
- return throw_on_failure(size, realloc(addr, size));
+void* sk_realloc_throw(void* addr, size_t size, const char* typeName) {
+ skia::SkiaAllocHooks::FreeHookIfEnabled(addr);
+ void* new_address = realloc(addr, size);
+ skia::SkiaAllocHooks::AllocationHookIfEnabled(new_address, size, typeName);
+ return throw_on_failure(size, new_address);
}
void sk_free(void* p) {
if (p) {
+ skia::SkiaAllocHooks::FreeHookIfEnabled(p);
free(p);
}
}
@@ -54,11 +59,13 @@ static void* prevent_overcommit(int fill, size_t size, void* p) {
return p;
}
-void* sk_malloc_throw(size_t size) {
- return prevent_overcommit(0x42, size, throw_on_failure(size, malloc(size)));
+void* sk_malloc_throw(size_t size, const char* typeName) {
+ void* address = throw_on_failure(size, malloc(size));
+ skia::SkiaAllocHooks::AllocationHookIfEnabled(address, size, typeName);
+ return prevent_overcommit(0x42, size, address);
}
-static void* sk_malloc_nothrow(size_t size) {
+static void* sk_malloc_nothrow(size_t size, const char* typeName) {
// TODO(b.kelemen): we should always use UncheckedMalloc but currently it
// doesn't work as intended everywhere.
void* result;
@@ -71,21 +78,24 @@ static void* sk_malloc_nothrow(size_t size) {
if (result) {
prevent_overcommit(0x47, size, result);
}
+ skia::SkiaAllocHooks::AllocationHookIfEnabled(result, size, typeName);
return result;
}
-void* sk_malloc_flags(size_t size, unsigned flags) {
+void* sk_malloc_flags(size_t size, unsigned flags, const char* typeName) {
if (flags & SK_MALLOC_THROW) {
- return sk_malloc_throw(size);
+ return sk_malloc_throw(size, typeName);
}
- return sk_malloc_nothrow(size);
+ return sk_malloc_nothrow(size, typeName);
}
-void* sk_calloc_throw(size_t size) {
- return prevent_overcommit(0, size, throw_on_failure(size, calloc(size, 1)));
+void* sk_calloc_throw(size_t size, const char* typeName) {
+ void* address = calloc(size, 1);
+ skia::SkiaAllocHooks::AllocationHookIfEnabled(address, size, typeName);
+ return prevent_overcommit(0, size, throw_on_failure(size, address));
}
-void* sk_calloc(size_t size) {
+void* sk_calloc(size_t size, const char* typeName) {
// TODO(b.kelemen): we should always use UncheckedCalloc but currently it
// doesn't work as intended everywhere.
void* result;
@@ -98,5 +108,6 @@ void* sk_calloc(size_t size) {
if (result) {
prevent_overcommit(0, size, result);
}
+ skia::SkiaAllocHooks::AllocationHookIfEnabled(result, size, typeName);
return result;
}
« no previous file with comments | « no previous file | skia/ext/skia_memory_dump_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698