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.
5 #include "sql/sql_memory_dump_provider.h"
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"
14 SqlMemoryDumpProvider* SqlMemoryDumpProvider::GetInstance() {
15 return base::Singleton<
16 SqlMemoryDumpProvider,
17 base::LeakySingletonTraits<SqlMemoryDumpProvider>>::get();
20 SqlMemoryDumpProvider::SqlMemoryDumpProvider() = default;
22 SqlMemoryDumpProvider::~SqlMemoryDumpProvider() = default;
24 bool SqlMemoryDumpProvider::OnMemoryDump(
25 const base::trace_event::MemoryDumpArgs& args,
26 base::trace_event::ProcessMemoryDump* pmd) {
27 sqlite3_int64 memory_used = 0;
28 sqlite3_int64 memory_high_water = 0;
29 int status = sqlite3_status64(SQLITE_STATUS_MEMORY_USED, &memory_used,
30 &memory_high_water, /* resetFlag= */ 1);
31 if (status != SQLITE_OK)
34 base::trace_event::MemoryAllocatorDump* dump =
35 pmd->CreateAllocatorDump("sqlite");
36 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
37 base::trace_event::MemoryAllocatorDump::kUnitsBytes,
39 dump->AddScalar("malloc_high_wmark_size",
40 base::trace_event::MemoryAllocatorDump::kUnitsBytes,
43 sqlite3_int64 dummy_high_water = -1;
44 sqlite3_int64 malloc_count = -1;
45 status = sqlite3_status64(SQLITE_STATUS_MALLOC_COUNT, &malloc_count,
46 &dummy_high_water, /* resetFlag= */ 0);
47 if (status == SQLITE_OK) {
48 dump->AddScalar("malloc_count",
49 base::trace_event::MemoryAllocatorDump::kUnitsObjects,
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);