OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef SKIA_EXT_SKIA_MEMORY_DUMP_PROVIDER_H_ | 5 #ifndef SKIA_EXT_SKIA_MEMORY_DUMP_PROVIDER_H_ |
6 #define SKIA_EXT_SKIA_MEMORY_DUMP_PROVIDER_H_ | 6 #define SKIA_EXT_SKIA_MEMORY_DUMP_PROVIDER_H_ |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/memory/singleton.h" | 9 #include "base/memory/singleton.h" |
| 10 #include "base/trace_event/heap_profiler_allocation_register.h" |
10 #include "base/trace_event/memory_dump_provider.h" | 11 #include "base/trace_event/memory_dump_provider.h" |
11 #include "third_party/skia/include/core/SkTypes.h" | 12 #include "third_party/skia/include/core/SkTypes.h" |
12 | 13 |
13 namespace skia { | 14 namespace skia { |
14 | 15 |
| 16 class SkiaAllocHooks { |
| 17 public: |
| 18 typedef void AllocationHook(void* address, size_t size, |
| 19 const char* type_name); |
| 20 typedef void FreeHook(void* address); |
| 21 static void SetAllocationHook(AllocationHook* hook) { |
| 22 allocation_hook_ = hook; |
| 23 } |
| 24 static void SetFreeHook(FreeHook* hook) { |
| 25 free_hook_ = hook; |
| 26 } |
| 27 static void AllocationHookIfEnabled(void* address, size_t size, |
| 28 const char* type_name) { |
| 29 AllocationHook* allocation_hook = allocation_hook_; |
| 30 if (UNLIKELY(allocation_hook != nullptr)) { |
| 31 allocation_hook(address, size, type_name); |
| 32 } |
| 33 } |
| 34 static void FreeHookIfEnabled(void* address) { |
| 35 FreeHook* free_hook = free_hook_; |
| 36 if (UNLIKELY(free_hook != nullptr)) { |
| 37 free_hook(address); |
| 38 } |
| 39 } |
| 40 |
| 41 private: |
| 42 static AllocationHook* allocation_hook_; |
| 43 static FreeHook* free_hook_; |
| 44 }; |
| 45 |
15 class SK_API SkiaMemoryDumpProvider | 46 class SK_API SkiaMemoryDumpProvider |
16 : public base::trace_event::MemoryDumpProvider { | 47 : public base::trace_event::MemoryDumpProvider { |
17 public: | 48 public: |
18 static SkiaMemoryDumpProvider* GetInstance(); | 49 static SkiaMemoryDumpProvider* GetInstance(); |
19 | 50 |
20 // base::trace_event::MemoryDumpProvider implementation: | 51 // base::trace_event::MemoryDumpProvider implementation: |
21 bool OnMemoryDump( | 52 bool OnMemoryDump( |
22 const base::trace_event::MemoryDumpArgs& args, | 53 const base::trace_event::MemoryDumpArgs& args, |
23 base::trace_event::ProcessMemoryDump* process_memory_dump) override; | 54 base::trace_event::ProcessMemoryDump* process_memory_dump) override; |
| 55 void OnHeapProfilingEnabled(bool enabled) override; |
| 56 |
| 57 void Insert(void* address, size_t size, const char* type_name); |
| 58 void Remove(void* address); |
24 | 59 |
25 private: | 60 private: |
26 friend struct base::DefaultSingletonTraits<SkiaMemoryDumpProvider>; | 61 friend struct base::DefaultSingletonTraits<SkiaMemoryDumpProvider>; |
27 | 62 |
28 SkiaMemoryDumpProvider(); | 63 SkiaMemoryDumpProvider(); |
29 ~SkiaMemoryDumpProvider() override; | 64 ~SkiaMemoryDumpProvider() override; |
30 | 65 |
| 66 base::Lock lock_; |
| 67 scoped_ptr<base::trace_event::AllocationRegister> allocation_register_; |
| 68 bool is_heap_profiling_enabled_; |
| 69 |
31 DISALLOW_COPY_AND_ASSIGN(SkiaMemoryDumpProvider); | 70 DISALLOW_COPY_AND_ASSIGN(SkiaMemoryDumpProvider); |
32 }; | 71 }; |
33 | 72 |
34 } // namespace skia | 73 } // namespace skia |
35 | 74 |
36 #endif // SKIA_EXT_SKIA_MEMORY_DUMP_PROVIDER_H_ | 75 #endif // SKIA_EXT_SKIA_MEMORY_DUMP_PROVIDER_H_ |
OLD | NEW |