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" |
11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
16 #include "base/metrics/sparse_histogram.h" | 16 #include "base/metrics/sparse_histogram.h" |
17 #include "base/strings/string_split.h" | 17 #include "base/strings/string_split.h" |
18 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
19 #include "base/strings/stringprintf.h" | 19 #include "base/strings/stringprintf.h" |
20 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
21 #include "base/synchronization/lock.h" | 21 #include "base/synchronization/lock.h" |
22 #include "base/trace_event/memory_dump_manager.h" | |
23 #include "base/trace_event/process_memory_dump.h" | |
22 #include "sql/statement.h" | 24 #include "sql/statement.h" |
23 #include "third_party/sqlite/sqlite3.h" | 25 #include "third_party/sqlite/sqlite3.h" |
24 | 26 |
25 #if defined(OS_IOS) && defined(USE_SYSTEM_SQLITE) | 27 #if defined(OS_IOS) && defined(USE_SYSTEM_SQLITE) |
26 #include "third_party/sqlite/src/ext/icu/sqliteicu.h" | 28 #include "third_party/sqlite/src/ext/icu/sqliteicu.h" |
27 #endif | 29 #endif |
28 | 30 |
29 namespace { | 31 namespace { |
30 | 32 |
31 // Spin for up to a second waiting for the lock to clear when setting | 33 // Spin for up to a second waiting for the lock to clear when setting |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
210 // static | 212 // static |
211 Connection::ErrorIgnorerCallback* Connection::current_ignorer_cb_ = NULL; | 213 Connection::ErrorIgnorerCallback* Connection::current_ignorer_cb_ = NULL; |
212 | 214 |
213 // static | 215 // static |
214 bool Connection::ShouldIgnoreSqliteError(int error) { | 216 bool Connection::ShouldIgnoreSqliteError(int error) { |
215 if (!current_ignorer_cb_) | 217 if (!current_ignorer_cb_) |
216 return false; | 218 return false; |
217 return current_ignorer_cb_->Run(error); | 219 return current_ignorer_cb_->Run(error); |
218 } | 220 } |
219 | 221 |
222 bool Connection::OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, | |
223 base::trace_event::ProcessMemoryDump* pmd) { | |
224 if (args.level_of_detail == base::trace_event::MemoryDumpLevelOfDetail::LIGHT) | |
225 return true; | |
226 | |
227 // The high water mark is not tracked for the following usages. | |
228 int cache_size, dummy_int; | |
229 sqlite3_db_status(db_, SQLITE_DBSTATUS_CACHE_USED, &cache_size, &dummy_int, | |
230 0 /* resetFlag */); | |
231 int schema_size; | |
232 sqlite3_db_status(db_, SQLITE_DBSTATUS_SCHEMA_USED, &schema_size, &dummy_int, | |
233 0 /* resetFlag */); | |
234 int statement_size; | |
235 sqlite3_db_status(db_, SQLITE_DBSTATUS_STMT_USED, &statement_size, &dummy_int, | |
236 0 /* resetFlag */); | |
237 | |
238 base::trace_event::MemoryAllocatorDump* dump = pmd->CreateAllocatorDump( | |
239 base::StringPrintf("sqlite/connection_%p", this)); | |
Scott Hess - ex-Googler
2015/10/07 23:08:57
You might consider injecting histogram_tag_, if no
ssid
2015/10/08 16:53:59
Done thanks.
| |
240 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, | |
241 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | |
242 cache_size + schema_size + statement_size); | |
243 dump->AddScalar("cache_size", | |
244 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | |
245 cache_size); | |
246 dump->AddScalar("schema_size", | |
247 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | |
248 schema_size); | |
249 dump->AddScalar("statement_size", | |
250 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | |
251 statement_size); | |
252 return true; | |
253 } | |
254 | |
220 // static | 255 // static |
221 void Connection::SetErrorIgnorer(Connection::ErrorIgnorerCallback* cb) { | 256 void Connection::SetErrorIgnorer(Connection::ErrorIgnorerCallback* cb) { |
222 CHECK(current_ignorer_cb_ == NULL); | 257 CHECK(current_ignorer_cb_ == NULL); |
223 current_ignorer_cb_ = cb; | 258 current_ignorer_cb_ = cb; |
224 } | 259 } |
225 | 260 |
226 // static | 261 // static |
227 void Connection::ResetErrorIgnorer() { | 262 void Connection::ResetErrorIgnorer() { |
228 CHECK(current_ignorer_cb_); | 263 CHECK(current_ignorer_cb_); |
229 current_ignorer_cb_ = NULL; | 264 current_ignorer_cb_ = NULL; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
281 transaction_nesting_(0), | 316 transaction_nesting_(0), |
282 needs_rollback_(false), | 317 needs_rollback_(false), |
283 in_memory_(false), | 318 in_memory_(false), |
284 poisoned_(false), | 319 poisoned_(false), |
285 stats_histogram_(NULL), | 320 stats_histogram_(NULL), |
286 commit_time_histogram_(NULL), | 321 commit_time_histogram_(NULL), |
287 autocommit_time_histogram_(NULL), | 322 autocommit_time_histogram_(NULL), |
288 update_time_histogram_(NULL), | 323 update_time_histogram_(NULL), |
289 query_time_histogram_(NULL), | 324 query_time_histogram_(NULL), |
290 clock_(new TimeSource()) { | 325 clock_(new TimeSource()) { |
326 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( | |
327 this); | |
291 } | 328 } |
292 | 329 |
293 Connection::~Connection() { | 330 Connection::~Connection() { |
331 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( | |
332 this); | |
294 Close(); | 333 Close(); |
295 } | 334 } |
296 | 335 |
297 void Connection::RecordEvent(Events event, size_t count) { | 336 void Connection::RecordEvent(Events event, size_t count) { |
298 for (size_t i = 0; i < count; ++i) { | 337 for (size_t i = 0; i < count; ++i) { |
299 UMA_HISTOGRAM_ENUMERATION("Sqlite.Stats", event, EVENT_MAX_VALUE); | 338 UMA_HISTOGRAM_ENUMERATION("Sqlite.Stats", event, EVENT_MAX_VALUE); |
300 } | 339 } |
301 | 340 |
302 if (stats_histogram_) { | 341 if (stats_histogram_) { |
303 for (size_t i = 0; i < count; ++i) { | 342 for (size_t i = 0; i < count; ++i) { |
(...skipping 1081 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1385 ignore_result(Execute(kNoWritableSchema)); | 1424 ignore_result(Execute(kNoWritableSchema)); |
1386 | 1425 |
1387 return ret; | 1426 return ret; |
1388 } | 1427 } |
1389 | 1428 |
1390 base::TimeTicks TimeSource::Now() { | 1429 base::TimeTicks TimeSource::Now() { |
1391 return base::TimeTicks::Now(); | 1430 return base::TimeTicks::Now(); |
1392 } | 1431 } |
1393 | 1432 |
1394 } // namespace sql | 1433 } // namespace sql |
OLD | NEW |