OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "sql/sql_memory_dump_provider.h" |
| 6 |
| 7 #include "base/trace_event/memory_dump_manager.h" |
| 8 #include "base/trace_event/process_memory_dump.h" |
| 9 #include "third_party/sqlite/sqlite3.h" |
| 10 |
| 11 namespace sql { |
| 12 |
| 13 // static |
| 14 SqlMemoryDumpProvider* SqlMemoryDumpProvider::GetInstance() { |
| 15 return base::Singleton< |
| 16 SqlMemoryDumpProvider, |
| 17 base::LeakySingletonTraits<SqlMemoryDumpProvider>>::get(); |
| 18 } |
| 19 |
| 20 SqlMemoryDumpProvider::SqlMemoryDumpProvider() {} |
| 21 |
| 22 SqlMemoryDumpProvider::~SqlMemoryDumpProvider() {} |
| 23 |
| 24 bool SqlMemoryDumpProvider::OnMemoryDump( |
| 25 const base::trace_event::MemoryDumpArgs& args, |
| 26 base::trace_event::ProcessMemoryDump* pmd) { |
| 27 int memory_used = 0; |
| 28 int memory_high_water = 0; |
| 29 int status = sqlite3_status(SQLITE_STATUS_MEMORY_USED, &memory_used, |
| 30 &memory_high_water, 1 /*resetFlag */); |
| 31 if (status != SQLITE_OK) |
| 32 return false; |
| 33 |
| 34 base::trace_event::MemoryAllocatorDump* dump = |
| 35 pmd->CreateAllocatorDump("sqlite"); |
| 36 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, |
| 37 base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
| 38 memory_used); |
| 39 dump->AddScalar("malloc_high_wmark_size", |
| 40 base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
| 41 memory_high_water); |
| 42 |
| 43 int dummy_high_water = -1; |
| 44 int malloc_count = -1; |
| 45 status = sqlite3_status(SQLITE_STATUS_MALLOC_COUNT, &malloc_count, |
| 46 &dummy_high_water, 0 /* resetFlag */); |
| 47 if (status == SQLITE_OK) { |
| 48 dump->AddScalar("malloc_count", |
| 49 base::trace_event::MemoryAllocatorDump::kUnitsObjects, |
| 50 malloc_count); |
| 51 } |
| 52 |
| 53 const char* system_allocator_name = |
| 54 base::trace_event::MemoryDumpManager::GetInstance() |
| 55 ->system_allocator_pool_name(); |
| 56 if (system_allocator_name) { |
| 57 pmd->AddSuballocation(dump->guid(), system_allocator_name); |
| 58 } |
| 59 return true; |
| 60 } |
| 61 |
| 62 } // namespace sql |
OLD | NEW |