Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(738)

Unified Diff: sql/connection_memory_dump_provider.cc

Issue 2452713003: [Sync] Implement MemoryDumpProvider. (Closed)
Patch Set: Fix presumit; fix Windows; git cl format Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sql/connection_memory_dump_provider.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sql/connection_memory_dump_provider.cc
diff --git a/sql/connection_memory_dump_provider.cc b/sql/connection_memory_dump_provider.cc
index eaee9b43e3bb8a7601aa32194d09f4cd504d7fcb..23a90450eba44d53c7bbaa8a6032d51677134385 100644
--- a/sql/connection_memory_dump_provider.cc
+++ b/sql/connection_memory_dump_provider.cc
@@ -33,32 +33,12 @@ bool ConnectionMemoryDumpProvider::OnMemoryDump(
int cache_size = 0;
int schema_size = 0;
int statement_size = 0;
- {
- // Lock is acquired here so that db_ is not reset in ResetDatabase when
- // collecting stats.
- base::AutoLock lock(lock_);
- if (!db_) {
- return false;
- }
-
- // The high water mark is not tracked for the following usages.
- int dummy_int;
- int status = sqlite3_db_status(db_, SQLITE_DBSTATUS_CACHE_USED, &cache_size,
- &dummy_int, 0 /* resetFlag */);
- DCHECK_EQ(SQLITE_OK, status);
- status = sqlite3_db_status(db_, SQLITE_DBSTATUS_SCHEMA_USED, &schema_size,
- &dummy_int, 0 /* resetFlag */);
- DCHECK_EQ(SQLITE_OK, status);
- status = sqlite3_db_status(db_, SQLITE_DBSTATUS_STMT_USED, &statement_size,
- &dummy_int, 0 /* resetFlag */);
- DCHECK_EQ(SQLITE_OK, status);
+ if (!GetDbMemoryUsage(&cache_size, &schema_size, &statement_size)) {
+ return false;
}
- std::string name = base::StringPrintf(
- "sqlite/%s_connection/0x%" PRIXPTR,
- connection_name_.empty() ? "Unknown" : connection_name_.c_str(),
- reinterpret_cast<uintptr_t>(this));
- base::trace_event::MemoryAllocatorDump* dump = pmd->CreateAllocatorDump(name);
+ base::trace_event::MemoryAllocatorDump* dump =
+ pmd->CreateAllocatorDump(FormatDumpName());
dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
base::trace_event::MemoryAllocatorDump::kUnitsBytes,
cache_size + schema_size + statement_size);
@@ -74,4 +54,53 @@ bool ConnectionMemoryDumpProvider::OnMemoryDump(
return true;
}
+bool ConnectionMemoryDumpProvider::ReportMemoryUsage(
+ base::trace_event::MemoryAllocatorDump* mad) {
+ int cache_size = 0;
+ int schema_size = 0;
+ int statement_size = 0;
+ if (!GetDbMemoryUsage(&cache_size, &schema_size, &statement_size)) {
+ return false;
+ }
+
+ mad->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
+ base::trace_event::MemoryAllocatorDump::kUnitsBytes,
+ cache_size + schema_size + statement_size);
+ mad->process_memory_dump()->AddSuballocation(mad->guid(), FormatDumpName());
+
+ return true;
+}
+
+bool ConnectionMemoryDumpProvider::GetDbMemoryUsage(int* cache_size,
+ int* schema_size,
+ int* statement_size) {
+ // Lock is acquired here so that db_ is not reset in ResetDatabase when
+ // collecting stats.
+ base::AutoLock lock(lock_);
+ if (!db_) {
+ return false;
+ }
+
+ // The high water mark is not tracked for the following usages.
+ int dummy_int;
+ int status = sqlite3_db_status(db_, SQLITE_DBSTATUS_CACHE_USED, cache_size,
+ &dummy_int, 0 /* resetFlag */);
+ DCHECK_EQ(SQLITE_OK, status);
+ status = sqlite3_db_status(db_, SQLITE_DBSTATUS_SCHEMA_USED, schema_size,
+ &dummy_int, 0 /* resetFlag */);
+ DCHECK_EQ(SQLITE_OK, status);
+ status = sqlite3_db_status(db_, SQLITE_DBSTATUS_STMT_USED, statement_size,
+ &dummy_int, 0 /* resetFlag */);
+ DCHECK_EQ(SQLITE_OK, status);
+
+ return true;
+}
+
+std::string ConnectionMemoryDumpProvider::FormatDumpName() const {
+ return base::StringPrintf(
+ "sqlite/%s_connection/0x%" PRIXPTR,
+ connection_name_.empty() ? "Unknown" : connection_name_.c_str(),
+ reinterpret_cast<uintptr_t>(this));
+}
+
} // namespace sql
« no previous file with comments | « sql/connection_memory_dump_provider.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698