| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "sql/connection.h" | 5 #include "sql/connection.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 void RecordSqliteMemoryHour() { | 121 void RecordSqliteMemoryHour() { |
| 122 const int64 used = sqlite3_memory_used(); | 122 const int64 used = sqlite3_memory_used(); |
| 123 UMA_HISTOGRAM_COUNTS("Sqlite.MemoryKB.OneHour", used / 1024); | 123 UMA_HISTOGRAM_COUNTS("Sqlite.MemoryKB.OneHour", used / 1024); |
| 124 } | 124 } |
| 125 | 125 |
| 126 void RecordSqliteMemoryDay() { | 126 void RecordSqliteMemoryDay() { |
| 127 const int64 used = sqlite3_memory_used(); | 127 const int64 used = sqlite3_memory_used(); |
| 128 UMA_HISTOGRAM_COUNTS("Sqlite.MemoryKB.OneDay", used / 1024); | 128 UMA_HISTOGRAM_COUNTS("Sqlite.MemoryKB.OneDay", used / 1024); |
| 129 } | 129 } |
| 130 | 130 |
| 131 void RecordSqliteMemoryWeek() { |
| 132 const int64 used = sqlite3_memory_used(); |
| 133 UMA_HISTOGRAM_COUNTS("Sqlite.MemoryKB.OneWeek", used / 1024); |
| 134 } |
| 135 |
| 131 // SQLite automatically calls sqlite3_initialize() lazily, but | 136 // SQLite automatically calls sqlite3_initialize() lazily, but |
| 132 // sqlite3_initialize() uses double-checked locking and thus can have | 137 // sqlite3_initialize() uses double-checked locking and thus can have |
| 133 // data races. | 138 // data races. |
| 134 // | 139 // |
| 135 // TODO(shess): Another alternative would be to have | 140 // TODO(shess): Another alternative would be to have |
| 136 // sqlite3_initialize() called as part of process bring-up. If this | 141 // sqlite3_initialize() called as part of process bring-up. If this |
| 137 // is changed, remove the dynamic_annotations dependency in sql.gyp. | 142 // is changed, remove the dynamic_annotations dependency in sql.gyp. |
| 138 base::LazyInstance<base::Lock>::Leaky | 143 base::LazyInstance<base::Lock>::Leaky |
| 139 g_sqlite_init_lock = LAZY_INSTANCE_INITIALIZER; | 144 g_sqlite_init_lock = LAZY_INSTANCE_INITIALIZER; |
| 140 void InitializeSqlite() { | 145 void InitializeSqlite() { |
| 141 base::AutoLock lock(g_sqlite_init_lock.Get()); | 146 base::AutoLock lock(g_sqlite_init_lock.Get()); |
| 142 static bool first_call = true; | 147 static bool first_call = true; |
| 143 if (first_call) { | 148 if (first_call) { |
| 144 sqlite3_initialize(); | 149 sqlite3_initialize(); |
| 145 | 150 |
| 146 // Schedule callback to record memory footprint histograms at 10m, 1h, and | 151 // Schedule callback to record memory footprint histograms at 10m, 1h, and |
| 147 // 1d. There may not be a message loop in tests. | 152 // 1d. There may not be a message loop in tests. |
| 148 if (base::MessageLoop::current()) { | 153 if (base::MessageLoop::current()) { |
| 149 base::MessageLoop::current()->PostDelayedTask( | 154 base::MessageLoop::current()->PostDelayedTask( |
| 150 FROM_HERE, base::Bind(&RecordSqliteMemory10Min), | 155 FROM_HERE, base::Bind(&RecordSqliteMemory10Min), |
| 151 base::TimeDelta::FromMinutes(10)); | 156 base::TimeDelta::FromMinutes(10)); |
| 152 base::MessageLoop::current()->PostDelayedTask( | 157 base::MessageLoop::current()->PostDelayedTask( |
| 153 FROM_HERE, base::Bind(&RecordSqliteMemoryHour), | 158 FROM_HERE, base::Bind(&RecordSqliteMemoryHour), |
| 154 base::TimeDelta::FromHours(1)); | 159 base::TimeDelta::FromHours(1)); |
| 155 base::MessageLoop::current()->PostDelayedTask( | 160 base::MessageLoop::current()->PostDelayedTask( |
| 156 FROM_HERE, base::Bind(&RecordSqliteMemoryDay), | 161 FROM_HERE, base::Bind(&RecordSqliteMemoryDay), |
| 157 base::TimeDelta::FromDays(1)); | 162 base::TimeDelta::FromDays(1)); |
| 163 base::MessageLoop::current()->PostDelayedTask( |
| 164 FROM_HERE, base::Bind(&RecordSqliteMemoryWeek), |
| 165 base::TimeDelta::FromDays(7)); |
| 158 } | 166 } |
| 159 | 167 |
| 160 first_call = false; | 168 first_call = false; |
| 161 } | 169 } |
| 162 } | 170 } |
| 163 | 171 |
| 164 // Helper to get the sqlite3_file* associated with the "main" database. | 172 // Helper to get the sqlite3_file* associated with the "main" database. |
| 165 int GetSqlite3File(sqlite3* db, sqlite3_file** file) { | 173 int GetSqlite3File(sqlite3* db, sqlite3_file** file) { |
| 166 *file = NULL; | 174 *file = NULL; |
| 167 int rc = sqlite3_file_control(db, NULL, SQLITE_FCNTL_FILE_POINTER, file); | 175 int rc = sqlite3_file_control(db, NULL, SQLITE_FCNTL_FILE_POINTER, file); |
| (...skipping 1206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1374 ignore_result(Execute(kNoWritableSchema)); | 1382 ignore_result(Execute(kNoWritableSchema)); |
| 1375 | 1383 |
| 1376 return ret; | 1384 return ret; |
| 1377 } | 1385 } |
| 1378 | 1386 |
| 1379 base::TimeTicks TimeSource::Now() { | 1387 base::TimeTicks TimeSource::Now() { |
| 1380 return base::TimeTicks::Now(); | 1388 return base::TimeTicks::Now(); |
| 1381 } | 1389 } |
| 1382 | 1390 |
| 1383 } // namespace sql | 1391 } // namespace sql |
| OLD | NEW |