Chromium Code Reviews| Index: sql/connection.cc |
| diff --git a/sql/connection.cc b/sql/connection.cc |
| index 20f0f075cbafb0dd6c09f4afe5f4a021f5522b36..61aebbe0c94f8640904875d1a7d86a5627906181 100644 |
| --- a/sql/connection.cc |
| +++ b/sql/connection.cc |
| @@ -19,6 +19,8 @@ |
| #include "base/strings/stringprintf.h" |
| #include "base/strings/utf_string_conversions.h" |
| #include "base/synchronization/lock.h" |
| +#include "base/trace_event/memory_dump_manager.h" |
| +#include "base/trace_event/process_memory_dump.h" |
| #include "sql/statement.h" |
| #include "third_party/sqlite/sqlite3.h" |
| @@ -217,6 +219,44 @@ bool Connection::ShouldIgnoreSqliteError(int error) { |
| return current_ignorer_cb_->Run(error); |
| } |
| +bool Connection::OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, |
|
michaeln
2015/10/15 23:03:28
what prevents this method from being called after
Scott Hess - ex-Googler
2015/10/15 23:50:29
~Connection unregisters, and the !db_ test below s
Primiano Tucci (use gerrit)
2015/10/16 08:37:44
As long as the dtor happens on the same thread of
|
| + base::trace_event::ProcessMemoryDump* pmd) { |
| + if (args.level_of_detail == |
| + base::trace_event::MemoryDumpLevelOfDetail::LIGHT || |
| + !db_) { |
| + return true; |
| + } |
| + |
| + // The high water mark is not tracked for the following usages. |
| + int cache_size, dummy_int; |
| + sqlite3_db_status(db_, SQLITE_DBSTATUS_CACHE_USED, &cache_size, &dummy_int, |
| + 0 /* resetFlag */); |
| + int schema_size; |
| + sqlite3_db_status(db_, SQLITE_DBSTATUS_SCHEMA_USED, &schema_size, &dummy_int, |
| + 0 /* resetFlag */); |
| + int statement_size; |
| + sqlite3_db_status(db_, SQLITE_DBSTATUS_STMT_USED, &statement_size, &dummy_int, |
| + 0 /* resetFlag */); |
| + |
| + std::string name = base::StringPrintf( |
| + "sqlite/%s_connection/%p", |
| + histogram_tag_.empty() ? "Unknown" : histogram_tag_.c_str(), this); |
| + base::trace_event::MemoryAllocatorDump* dump = pmd->CreateAllocatorDump(name); |
| + dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, |
| + base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
| + cache_size + schema_size + statement_size); |
| + dump->AddScalar("cache_size", |
| + base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
| + cache_size); |
| + dump->AddScalar("schema_size", |
| + base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
| + schema_size); |
| + dump->AddScalar("statement_size", |
| + base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
| + statement_size); |
| + return true; |
| +} |
| + |
| // static |
| void Connection::SetErrorIgnorer(Connection::ErrorIgnorerCallback* cb) { |
| CHECK(current_ignorer_cb_ == NULL); |
| @@ -291,9 +331,13 @@ Connection::Connection() |
| update_time_histogram_(NULL), |
| query_time_histogram_(NULL), |
| clock_(new TimeSource()) { |
| + base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( |
| + this); |
| } |
| Connection::~Connection() { |
| + base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( |
| + this); |
| Close(); |
| } |