ssid | 3be5b1ec | 2016-01-13 14:21:57 | [diff] [blame] | 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 | #ifndef SQL_CONNECTION_MEMORY_DUMP_PROVIDER_H |
| 6 | #define SQL_CONNECTION_MEMORY_DUMP_PROVIDER_H |
| 7 | |
| 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 | |
| 14 | struct sqlite3; |
| 15 | |
ssid | 1f4e536 | 2016-12-08 20:41:38 | [diff] [blame] | 16 | namespace base { |
| 17 | namespace trace_event { |
| 18 | class ProcessMemoryDump; |
| 19 | } |
| 20 | } |
| 21 | |
ssid | 3be5b1ec | 2016-01-13 14:21:57 | [diff] [blame] | 22 | namespace sql { |
| 23 | |
| 24 | class ConnectionMemoryDumpProvider |
| 25 | : public base::trace_event::MemoryDumpProvider { |
| 26 | public: |
| 27 | ConnectionMemoryDumpProvider(sqlite3* db, const std::string& name); |
| 28 | ~ConnectionMemoryDumpProvider() override; |
| 29 | |
| 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 | |
ssid | 1f4e536 | 2016-12-08 20:41:38 | [diff] [blame] | 37 | // Reports memory usage into provided memory dump with the given |dump_name|. |
dskiba | b4199f8 | 2016-11-21 20:16:13 | [diff] [blame] | 38 | // Called by sql::Connection when its owner asks it to report memory usage. |
ssid | 1f4e536 | 2016-12-08 20:41:38 | [diff] [blame] | 39 | bool ReportMemoryUsage(base::trace_event::ProcessMemoryDump* pmd, |
| 40 | const std::string& dump_name); |
dskiba | b4199f8 | 2016-11-21 20:16:13 | [diff] [blame] | 41 | |
ssid | 3be5b1ec | 2016-01-13 14:21:57 | [diff] [blame] | 42 | private: |
dskiba | b4199f8 | 2016-11-21 20:16:13 | [diff] [blame] | 43 | bool GetDbMemoryUsage(int* cache_size, |
| 44 | int* schema_size, |
| 45 | int* statement_size); |
| 46 | |
| 47 | std::string FormatDumpName() const; |
| 48 | |
ssid | 3be5b1ec | 2016-01-13 14:21:57 | [diff] [blame] | 49 | sqlite3* db_; // not owned. |
| 50 | base::Lock lock_; |
| 51 | std::string connection_name_; |
| 52 | |
| 53 | DISALLOW_COPY_AND_ASSIGN(ConnectionMemoryDumpProvider); |
| 54 | }; |
| 55 | |
| 56 | } // namespace sql |
| 57 | |
| 58 | #endif // SQL_CONNECTION_MEMORY_DUMP_PROVIDER_H |