Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(111)

Side by Side Diff: sql/connection.cc

Issue 1327063002: [tracing] Add sqlite memory statistics to tracing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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,
michaeln 2015/10/15 23:03:28 what prevents this method from being called after
Scott Hess - ex-Googler 2015/10/15 23:50:29 ~Connection unregisters, and the !db_ test below s
Primiano Tucci (use gerrit) 2015/10/16 08:37:44 As long as the dtor happens on the same thread of
223 base::trace_event::ProcessMemoryDump* pmd) {
224 if (args.level_of_detail ==
225 base::trace_event::MemoryDumpLevelOfDetail::LIGHT ||
226 !db_) {
227 return true;
228 }
229
230 // The high water mark is not tracked for the following usages.
231 int cache_size, dummy_int;
232 sqlite3_db_status(db_, SQLITE_DBSTATUS_CACHE_USED, &cache_size, &dummy_int,
233 0 /* resetFlag */);
234 int schema_size;
235 sqlite3_db_status(db_, SQLITE_DBSTATUS_SCHEMA_USED, &schema_size, &dummy_int,
236 0 /* resetFlag */);
237 int statement_size;
238 sqlite3_db_status(db_, SQLITE_DBSTATUS_STMT_USED, &statement_size, &dummy_int,
239 0 /* resetFlag */);
240
241 std::string name = base::StringPrintf(
242 "sqlite/%s_connection/%p",
243 histogram_tag_.empty() ? "Unknown" : histogram_tag_.c_str(), this);
244 base::trace_event::MemoryAllocatorDump* dump = pmd->CreateAllocatorDump(name);
245 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
246 base::trace_event::MemoryAllocatorDump::kUnitsBytes,
247 cache_size + schema_size + statement_size);
248 dump->AddScalar("cache_size",
249 base::trace_event::MemoryAllocatorDump::kUnitsBytes,
250 cache_size);
251 dump->AddScalar("schema_size",
252 base::trace_event::MemoryAllocatorDump::kUnitsBytes,
253 schema_size);
254 dump->AddScalar("statement_size",
255 base::trace_event::MemoryAllocatorDump::kUnitsBytes,
256 statement_size);
257 return true;
258 }
259
220 // static 260 // static
221 void Connection::SetErrorIgnorer(Connection::ErrorIgnorerCallback* cb) { 261 void Connection::SetErrorIgnorer(Connection::ErrorIgnorerCallback* cb) {
222 CHECK(current_ignorer_cb_ == NULL); 262 CHECK(current_ignorer_cb_ == NULL);
223 current_ignorer_cb_ = cb; 263 current_ignorer_cb_ = cb;
224 } 264 }
225 265
226 // static 266 // static
227 void Connection::ResetErrorIgnorer() { 267 void Connection::ResetErrorIgnorer() {
228 CHECK(current_ignorer_cb_); 268 CHECK(current_ignorer_cb_);
229 current_ignorer_cb_ = NULL; 269 current_ignorer_cb_ = NULL;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 poisoned_(false), 324 poisoned_(false),
285 mmap_disabled_(false), 325 mmap_disabled_(false),
286 mmap_enabled_(false), 326 mmap_enabled_(false),
287 total_changes_at_last_release_(0), 327 total_changes_at_last_release_(0),
288 stats_histogram_(NULL), 328 stats_histogram_(NULL),
289 commit_time_histogram_(NULL), 329 commit_time_histogram_(NULL),
290 autocommit_time_histogram_(NULL), 330 autocommit_time_histogram_(NULL),
291 update_time_histogram_(NULL), 331 update_time_histogram_(NULL),
292 query_time_histogram_(NULL), 332 query_time_histogram_(NULL),
293 clock_(new TimeSource()) { 333 clock_(new TimeSource()) {
334 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider(
335 this);
294 } 336 }
295 337
296 Connection::~Connection() { 338 Connection::~Connection() {
339 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider(
340 this);
297 Close(); 341 Close();
298 } 342 }
299 343
300 void Connection::RecordEvent(Events event, size_t count) { 344 void Connection::RecordEvent(Events event, size_t count) {
301 for (size_t i = 0; i < count; ++i) { 345 for (size_t i = 0; i < count; ++i) {
302 UMA_HISTOGRAM_ENUMERATION("Sqlite.Stats", event, EVENT_MAX_VALUE); 346 UMA_HISTOGRAM_ENUMERATION("Sqlite.Stats", event, EVENT_MAX_VALUE);
303 } 347 }
304 348
305 if (stats_histogram_) { 349 if (stats_histogram_) {
306 for (size_t i = 0; i < count; ++i) { 350 for (size_t i = 0; i < count; ++i) {
(...skipping 1176 matching lines...) Expand 10 before | Expand all | Expand 10 after
1483 ignore_result(Execute(kNoWritableSchema)); 1527 ignore_result(Execute(kNoWritableSchema));
1484 1528
1485 return ret; 1529 return ret;
1486 } 1530 }
1487 1531
1488 base::TimeTicks TimeSource::Now() { 1532 base::TimeTicks TimeSource::Now() {
1489 return base::TimeTicks::Now(); 1533 return base::TimeTicks::Now();
1490 } 1534 }
1491 1535
1492 } // namespace sql 1536 } // namespace sql
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698