blob: 1df2c1bfbc4145dc5fb1d7c5f5d66b74295db274 [file] [log] [blame]
ssid3be5b1ec2016-01-13 14:21:571// 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
Victor Costancfbfa602018-08-01 23:24:465#ifndef SQL_DATABASE_MEMORY_DUMP_PROVIDER_H_
6#define SQL_DATABASE_MEMORY_DUMP_PROVIDER_H_
ssid3be5b1ec2016-01-13 14:21:577
8#include <string>
9
10#include "base/macros.h"
11#include "base/synchronization/lock.h"
12#include "base/trace_event/memory_dump_provider.h"
13
14struct sqlite3;
15
ssid1f4e5362016-12-08 20:41:3816namespace base {
17namespace trace_event {
18class ProcessMemoryDump;
19}
Victor Costancfbfa602018-08-01 23:24:4620} // namespace base
ssid1f4e5362016-12-08 20:41:3821
ssid3be5b1ec2016-01-13 14:21:5722namespace sql {
23
Victor Costancfbfa602018-08-01 23:24:4624class DatabaseMemoryDumpProvider
ssid3be5b1ec2016-01-13 14:21:5725 : public base::trace_event::MemoryDumpProvider {
26 public:
Victor Costancfbfa602018-08-01 23:24:4627 DatabaseMemoryDumpProvider(sqlite3* db, const std::string& name);
28 ~DatabaseMemoryDumpProvider() override;
ssid3be5b1ec2016-01-13 14:21:5729
30 void ResetDatabase();
31
32 // base::trace_event::MemoryDumpProvider implementation.
33 bool OnMemoryDump(
34 const base::trace_event::MemoryDumpArgs& args,
35 base::trace_event::ProcessMemoryDump* process_memory_dump) override;
36
ssid1f4e5362016-12-08 20:41:3837 // Reports memory usage into provided memory dump with the given |dump_name|.
Victor Costancfbfa602018-08-01 23:24:4638 // Called by sql::Database when its owner asks it to report memory usage.
ssid1f4e5362016-12-08 20:41:3839 bool ReportMemoryUsage(base::trace_event::ProcessMemoryDump* pmd,
40 const std::string& dump_name);
dskibab4199f82016-11-21 20:16:1341
ssid3be5b1ec2016-01-13 14:21:5742 private:
Victor Costancfbfa602018-08-01 23:24:4643 bool GetDbMemoryUsage(int* cache_size, int* schema_size, int* statement_size);
dskibab4199f82016-11-21 20:16:1344
45 std::string FormatDumpName() const;
46
ssid3be5b1ec2016-01-13 14:21:5747 sqlite3* db_; // not owned.
48 base::Lock lock_;
49 std::string connection_name_;
50
Victor Costancfbfa602018-08-01 23:24:4651 DISALLOW_COPY_AND_ASSIGN(DatabaseMemoryDumpProvider);
ssid3be5b1ec2016-01-13 14:21:5752};
53
54} // namespace sql
55
Victor Costancfbfa602018-08-01 23:24:4656#endif // SQL_DATABASE_MEMORY_DUMP_PROVIDER_H_