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

Side by Side Diff: sql/connection_memory_dump_provider.cc

Issue 1434993002: [tracing] Add separate dump provider for sql connection (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@web_cache2_base
Patch Set: Fixes. Created 4 years, 11 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
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "sql/connection_memory_dump_provider.h"
6
7 #include "base/strings/stringprintf.h"
8 #include "base/trace_event/process_memory_dump.h"
9 #include "third_party/sqlite/sqlite3.h"
10
11 namespace sql {
12
13 ConnectionMemoryDumpProvider::ConnectionMemoryDumpProvider(
14 sqlite3* db,
15 const std::string& name)
16 : db_(db), connection_name_(name) {}
17
18 ConnectionMemoryDumpProvider::~ConnectionMemoryDumpProvider() {}
19
20 void ConnectionMemoryDumpProvider::ResetDatabase() {
21 base::AutoLock lock(lock_);
22 db_ = nullptr;
23 }
24
25 bool ConnectionMemoryDumpProvider::OnMemoryDump(
26 const base::trace_event::MemoryDumpArgs& args,
27 base::trace_event::ProcessMemoryDump* pmd) {
28 if (args.level_of_detail == base::trace_event::MemoryDumpLevelOfDetail::LIGHT)
29 return true;
30
31 int cache_size = 0;
32 int schema_size = 0;
33 int statement_size = 0;
34 {
35 // Lock is acquired here so that db_ is not reset in ResetDatabase when
36 // collecting stats.
37 base::AutoLock lock(lock_);
38 if (!db_) {
39 return false;
40 }
41
42 // The high water mark is not tracked for the following usages.
43 int dummy_int;
44 int status = sqlite3_db_status(db_, SQLITE_DBSTATUS_CACHE_USED, &cache_size,
michaeln 2016/01/14 01:37:40 maybe a comment or check of some kind about SQLITE
Scott Hess - ex-Googler 2016/01/21 20:30:07 SQLITE_THREADSAFE is out of reach, here, but sqlit
45 &dummy_int, 0 /* resetFlag */);
46 DCHECK_EQ(SQLITE_OK, status);
47 status = sqlite3_db_status(db_, SQLITE_DBSTATUS_SCHEMA_USED, &schema_size,
48 &dummy_int, 0 /* resetFlag */);
49 DCHECK_EQ(SQLITE_OK, status);
50 status = sqlite3_db_status(db_, SQLITE_DBSTATUS_STMT_USED, &statement_size,
51 &dummy_int, 0 /* resetFlag */);
52 DCHECK_EQ(SQLITE_OK, status);
53 }
54
55 std::string name = base::StringPrintf(
56 "sqlite/%s_connection/%p",
57 connection_name_.empty() ? "Unknown" : connection_name_.c_str(), this);
58 base::trace_event::MemoryAllocatorDump* dump = pmd->CreateAllocatorDump(name);
59 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
60 base::trace_event::MemoryAllocatorDump::kUnitsBytes,
61 cache_size + schema_size + statement_size);
62 dump->AddScalar("cache_size",
63 base::trace_event::MemoryAllocatorDump::kUnitsBytes,
64 cache_size);
65 dump->AddScalar("schema_size",
66 base::trace_event::MemoryAllocatorDump::kUnitsBytes,
67 schema_size);
68 dump->AddScalar("statement_size",
69 base::trace_event::MemoryAllocatorDump::kUnitsBytes,
70 statement_size);
71 return true;
72 }
73
74 } // namespace sql
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698