summaryrefslogtreecommitdiffstats
path: root/sql/connection.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/connection.cc')
-rw-r--r--sql/connection.cc44
1 files changed, 44 insertions, 0 deletions
diff --git a/sql/connection.cc b/sql/connection.cc
index 20f0f07..61aebbe 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,
+ 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();
}