blob: f59f811aee339d02cb6a267ac2a17172a36f33e8 [file] [log] [blame]
ssid9f8022f2015-10-12 17:49:031// 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
11namespace sql {
12
13// static
14SqlMemoryDumpProvider* SqlMemoryDumpProvider::GetInstance() {
15 return base::Singleton<
16 SqlMemoryDumpProvider,
17 base::LeakySingletonTraits<SqlMemoryDumpProvider>>::get();
18}
19
Chris Watkinscf6172552017-11-27 03:25:1820SqlMemoryDumpProvider::SqlMemoryDumpProvider() = default;
ssid9f8022f2015-10-12 17:49:0321
Chris Watkinscf6172552017-11-27 03:25:1822SqlMemoryDumpProvider::~SqlMemoryDumpProvider() = default;
ssid9f8022f2015-10-12 17:49:0323
24bool SqlMemoryDumpProvider::OnMemoryDump(
25 const base::trace_event::MemoryDumpArgs& args,
26 base::trace_event::ProcessMemoryDump* pmd) {
Victor Costanccc764722018-07-23 21:15:0927 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);
ssid9f8022f2015-10-12 17:49:0331 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
Victor Costanccc764722018-07-23 21:15:0943 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);
ssid9f8022f2015-10-12 17:49:0347 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