[sql] Record memory usage at various periods after startup.
This will be used to track improvements occuring from enabling memory-mapped I/O. BUG=489784 Review URL: https://codereview.chromium.org/1283033004 Cr-Commit-Position: refs/heads/master@{#343100}
This commit is contained in:
@ -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.MemoryKB.TenMinutes", used / 1024);
|
||||
}
|
||||
|
||||
void RecordSqliteMemoryHour() {
|
||||
const int64 used = sqlite3_memory_used();
|
||||
UMA_HISTOGRAM_COUNTS("Sqlite.MemoryKB.OneHour", used / 1024);
|
||||
}
|
||||
|
||||
void RecordSqliteMemoryDay() {
|
||||
const int64 used = sqlite3_memory_used();
|
||||
UMA_HISTOGRAM_COUNTS("Sqlite.MemoryKB.OneDay", 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.
|
||||
|
@ -42942,6 +42942,30 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries.
|
||||
<summary>Error codes returned by sqlite for the history db.</summary>
|
||||
</histogram>
|
||||
|
||||
<histogram name="Sqlite.MemoryKB.OneDay" units="KB">
|
||||
<owner>shess@chromium.org</owner>
|
||||
<summary>
|
||||
SQLite memory footprint from sqlite3_memory_used() recorded 1 day after
|
||||
first database is opened by sql::Connection.
|
||||
</summary>
|
||||
</histogram>
|
||||
|
||||
<histogram name="Sqlite.MemoryKB.OneHour" units="KB">
|
||||
<owner>shess@chromium.org</owner>
|
||||
<summary>
|
||||
SQLite memory footprint from sqlite3_memory_used() recorded 1 hour after
|
||||
first database is opened by sql::Connection.
|
||||
</summary>
|
||||
</histogram>
|
||||
|
||||
<histogram name="Sqlite.MemoryKB.TenMinutes" units="KB">
|
||||
<owner>shess@chromium.org</owner>
|
||||
<summary>
|
||||
SQLite memory footprint from sqlite3_memory_used() recorded 10 minutes after
|
||||
first database is opened by sql::Connection.
|
||||
</summary>
|
||||
</histogram>
|
||||
|
||||
<histogram name="Sqlite.Migration.History" units="milliseconds">
|
||||
<owner>shess@chromium.org</owner>
|
||||
<summary>
|
||||
|
Reference in New Issue
Block a user