| 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/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 10 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
| 11 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
| 12 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/message_loop/message_loop.h" |
| 13 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
| 14 #include "base/metrics/sparse_histogram.h" | 16 #include "base/metrics/sparse_histogram.h" |
| 15 #include "base/strings/string_split.h" | 17 #include "base/strings/string_split.h" |
| 16 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
| 17 #include "base/strings/stringprintf.h" | 19 #include "base/strings/stringprintf.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
| 19 #include "base/synchronization/lock.h" | 21 #include "base/synchronization/lock.h" |
| 20 #include "sql/statement.h" | 22 #include "sql/statement.h" |
| 21 #include "third_party/sqlite/sqlite3.h" | 23 #include "third_party/sqlite/sqlite3.h" |
| 22 | 24 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 if (!((attachment_point[i] >= '0' && attachment_point[i] <= '9') || | 106 if (!((attachment_point[i] >= '0' && attachment_point[i] <= '9') || |
| 105 (attachment_point[i] >= 'a' && attachment_point[i] <= 'z') || | 107 (attachment_point[i] >= 'a' && attachment_point[i] <= 'z') || |
| 106 (attachment_point[i] >= 'A' && attachment_point[i] <= 'Z') || | 108 (attachment_point[i] >= 'A' && attachment_point[i] <= 'Z') || |
| 107 attachment_point[i] == '_')) { | 109 attachment_point[i] == '_')) { |
| 108 return false; | 110 return false; |
| 109 } | 111 } |
| 110 } | 112 } |
| 111 return true; | 113 return true; |
| 112 } | 114 } |
| 113 | 115 |
| 116 void RecordSqliteMemory10Min() { |
| 117 const int64 used = sqlite3_memory_used(); |
| 118 UMA_HISTOGRAM_COUNTS("Sqlite.MemoryKB.TenMinutes", used / 1024); |
| 119 } |
| 120 |
| 121 void RecordSqliteMemoryHour() { |
| 122 const int64 used = sqlite3_memory_used(); |
| 123 UMA_HISTOGRAM_COUNTS("Sqlite.MemoryKB.OneHour", used / 1024); |
| 124 } |
| 125 |
| 126 void RecordSqliteMemoryDay() { |
| 127 const int64 used = sqlite3_memory_used(); |
| 128 UMA_HISTOGRAM_COUNTS("Sqlite.MemoryKB.OneDay", used / 1024); |
| 129 } |
| 130 |
| 114 // SQLite automatically calls sqlite3_initialize() lazily, but | 131 // SQLite automatically calls sqlite3_initialize() lazily, but |
| 115 // sqlite3_initialize() uses double-checked locking and thus can have | 132 // sqlite3_initialize() uses double-checked locking and thus can have |
| 116 // data races. | 133 // data races. |
| 117 // | 134 // |
| 118 // TODO(shess): Another alternative would be to have | 135 // TODO(shess): Another alternative would be to have |
| 119 // sqlite3_initialize() called as part of process bring-up. If this | 136 // sqlite3_initialize() called as part of process bring-up. If this |
| 120 // is changed, remove the dynamic_annotations dependency in sql.gyp. | 137 // is changed, remove the dynamic_annotations dependency in sql.gyp. |
| 121 base::LazyInstance<base::Lock>::Leaky | 138 base::LazyInstance<base::Lock>::Leaky |
| 122 g_sqlite_init_lock = LAZY_INSTANCE_INITIALIZER; | 139 g_sqlite_init_lock = LAZY_INSTANCE_INITIALIZER; |
| 123 void InitializeSqlite() { | 140 void InitializeSqlite() { |
| 124 base::AutoLock lock(g_sqlite_init_lock.Get()); | 141 base::AutoLock lock(g_sqlite_init_lock.Get()); |
| 125 sqlite3_initialize(); | 142 static bool first_call = true; |
| 143 if (first_call) { |
| 144 sqlite3_initialize(); |
| 145 |
| 146 // Schedule callback to record memory footprint histograms at 10m, 1h, and |
| 147 // 1d. There may not be a message loop in tests. |
| 148 if (base::MessageLoop::current()) { |
| 149 base::MessageLoop::current()->PostDelayedTask( |
| 150 FROM_HERE, base::Bind(&RecordSqliteMemory10Min), |
| 151 base::TimeDelta::FromMinutes(10)); |
| 152 base::MessageLoop::current()->PostDelayedTask( |
| 153 FROM_HERE, base::Bind(&RecordSqliteMemoryHour), |
| 154 base::TimeDelta::FromHours(1)); |
| 155 base::MessageLoop::current()->PostDelayedTask( |
| 156 FROM_HERE, base::Bind(&RecordSqliteMemoryDay), |
| 157 base::TimeDelta::FromDays(1)); |
| 158 } |
| 159 |
| 160 first_call = false; |
| 161 } |
| 126 } | 162 } |
| 127 | 163 |
| 128 // Helper to get the sqlite3_file* associated with the "main" database. | 164 // Helper to get the sqlite3_file* associated with the "main" database. |
| 129 int GetSqlite3File(sqlite3* db, sqlite3_file** file) { | 165 int GetSqlite3File(sqlite3* db, sqlite3_file** file) { |
| 130 *file = NULL; | 166 *file = NULL; |
| 131 int rc = sqlite3_file_control(db, NULL, SQLITE_FCNTL_FILE_POINTER, file); | 167 int rc = sqlite3_file_control(db, NULL, SQLITE_FCNTL_FILE_POINTER, file); |
| 132 if (rc != SQLITE_OK) | 168 if (rc != SQLITE_OK) |
| 133 return rc; | 169 return rc; |
| 134 | 170 |
| 135 // TODO(shess): NULL in file->pMethods has been observed on android_dbg | 171 // TODO(shess): NULL in file->pMethods has been observed on android_dbg |
| (...skipping 1201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1337 ignore_result(Execute(kNoWritableSchema)); | 1373 ignore_result(Execute(kNoWritableSchema)); |
| 1338 | 1374 |
| 1339 return ret; | 1375 return ret; |
| 1340 } | 1376 } |
| 1341 | 1377 |
| 1342 base::TimeTicks TimeSource::Now() { | 1378 base::TimeTicks TimeSource::Now() { |
| 1343 return base::TimeTicks::Now(); | 1379 return base::TimeTicks::Now(); |
| 1344 } | 1380 } |
| 1345 | 1381 |
| 1346 } // namespace sql | 1382 } // namespace sql |
| OLD | NEW |