1 // Copyright 2015 The Chromium Authors
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 "sql/sqlite_result_code.h"
10 #include "sql/sqlite_result_code_values.h"
11 #include "third_party/sqlite/sqlite3.h"
16 SqlMemoryDumpProvider* SqlMemoryDumpProvider::GetInstance() {
17 return base::Singleton<
18 SqlMemoryDumpProvider,
19 base::LeakySingletonTraits<SqlMemoryDumpProvider>>::get();
22 SqlMemoryDumpProvider::SqlMemoryDumpProvider() = default;
24 SqlMemoryDumpProvider::~SqlMemoryDumpProvider() = default;
26 bool SqlMemoryDumpProvider::OnMemoryDump(
27 const base::trace_event::MemoryDumpArgs& args,
28 base::trace_event::ProcessMemoryDump* pmd) {
29 sqlite3_int64 memory_used = 0;
30 sqlite3_int64 memory_high_water = 0;
31 auto sqlite_result_code = ToSqliteResultCode(sqlite3_status64(
32 SQLITE_STATUS_MEMORY_USED, &memory_used, &memory_high_water,
34 DCHECK_EQ(sqlite_result_code, SqliteResultCode::kOk)
35 << "sqlite3_status64(SQLITE_STATUS_MEMORY_USED) failed";
37 base::trace_event::MemoryAllocatorDump* dump =
38 pmd->CreateAllocatorDump("sqlite");
39 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
40 base::trace_event::MemoryAllocatorDump::kUnitsBytes,
42 dump->AddScalar("malloc_high_wmark_size",
43 base::trace_event::MemoryAllocatorDump::kUnitsBytes,
46 sqlite3_int64 dummy_high_water = -1;
47 sqlite3_int64 malloc_count = -1;
48 sqlite_result_code = ToSqliteResultCode(sqlite3_status64(
49 SQLITE_STATUS_MALLOC_COUNT, &malloc_count, &dummy_high_water,
51 DCHECK_EQ(sqlite_result_code, SqliteResultCode::kOk)
52 << "sqlite3_status64(SQLITE_STATUS_MALLOC_COUNT) failed";
53 dump->AddScalar("malloc_count",
54 base::trace_event::MemoryAllocatorDump::kUnitsObjects,
57 const char* system_allocator_name =
58 base::trace_event::MemoryDumpManager::GetInstance()
59 ->system_allocator_pool_name();
60 if (system_allocator_name) {
61 pmd->AddSuballocation(dump->guid(), system_allocator_name);