| Index: sql/connection.cc
|
| diff --git a/sql/connection.cc b/sql/connection.cc
|
| index d07d425eb1721ac5b1da4c78198caac030fd4744..809e19de04f2e4dfe29d06ed60bc38f43a1ac4e1 100644
|
| --- a/sql/connection.cc
|
| +++ b/sql/connection.cc
|
| @@ -6,10 +6,12 @@
|
|
|
| #include <string.h>
|
|
|
| +#include "base/bind.h"
|
| #include "base/files/file_path.h"
|
| #include "base/files/file_util.h"
|
| #include "base/lazy_instance.h"
|
| #include "base/logging.h"
|
| +#include "base/message_loop/message_loop.h"
|
| #include "base/metrics/histogram.h"
|
| #include "base/metrics/sparse_histogram.h"
|
| #include "base/strings/string_split.h"
|
| @@ -111,6 +113,21 @@ bool ValidAttachmentPoint(const char* attachment_point) {
|
| return true;
|
| }
|
|
|
| +void RecordSqliteMemory10Min() {
|
| + const int64 used = sqlite3_memory_used();
|
| + UMA_HISTOGRAM_COUNTS("Sqlite.MemoryKBTenMinutes", used / 1024);
|
| +}
|
| +
|
| +void RecordSqliteMemoryHour() {
|
| + const int64 used = sqlite3_memory_used();
|
| + UMA_HISTOGRAM_COUNTS("Sqlite.MemoryKBOneHour", used / 1024);
|
| +}
|
| +
|
| +void RecordSqliteMemoryDay() {
|
| + const int64 used = sqlite3_memory_used();
|
| + UMA_HISTOGRAM_COUNTS("Sqlite.MemoryKBOneDay", used / 1024);
|
| +}
|
| +
|
| // SQLite automatically calls sqlite3_initialize() lazily, but
|
| // sqlite3_initialize() uses double-checked locking and thus can have
|
| // data races.
|
| @@ -122,7 +139,26 @@ base::LazyInstance<base::Lock>::Leaky
|
| g_sqlite_init_lock = LAZY_INSTANCE_INITIALIZER;
|
| void InitializeSqlite() {
|
| base::AutoLock lock(g_sqlite_init_lock.Get());
|
| - sqlite3_initialize();
|
| + static bool first_call = true;
|
| + if (first_call) {
|
| + sqlite3_initialize();
|
| +
|
| + // Schedule callback to record memory footprint histograms at 10m, 1h, and
|
| + // 1d. There may not be a message loop in tests.
|
| + if (base::MessageLoop::current()) {
|
| + base::MessageLoop::current()->PostDelayedTask(
|
| + FROM_HERE, base::Bind(&RecordSqliteMemory10Min),
|
| + base::TimeDelta::FromMinutes(10));
|
| + base::MessageLoop::current()->PostDelayedTask(
|
| + FROM_HERE, base::Bind(&RecordSqliteMemoryHour),
|
| + base::TimeDelta::FromHours(1));
|
| + base::MessageLoop::current()->PostDelayedTask(
|
| + FROM_HERE, base::Bind(&RecordSqliteMemoryDay),
|
| + base::TimeDelta::FromDays(1));
|
| + }
|
| +
|
| + first_call = false;
|
| + }
|
| }
|
|
|
| // Helper to get the sqlite3_file* associated with the "main" database.
|
|
|