OLD | NEW |
---|---|
(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), name_(name) { | |
17 DCHECK(db_); | |
Primiano Tucci (use gerrit)
2016/01/11 19:27:42
this dcheck doesn't seem to be really needed as yo
ssid
2016/01/12 12:23:07
Done.
| |
18 } | |
19 | |
20 ConnectionMemoryDumpProvider::~ConnectionMemoryDumpProvider() {} | |
21 | |
22 bool ConnectionMemoryDumpProvider::OnMemoryDump( | |
23 const base::trace_event::MemoryDumpArgs& args, | |
24 base::trace_event::ProcessMemoryDump* pmd) { | |
25 if (args.level_of_detail == base::trace_event::MemoryDumpLevelOfDetail::LIGHT) | |
26 return true; | |
27 | |
28 base::AutoLock l(lock_); | |
Primiano Tucci (use gerrit)
2016/01/11 19:27:42
add a comment explaining why you need this lock he
ssid
2016/01/12 12:23:07
Done.
| |
29 if (!db_) { | |
30 return false; | |
31 } | |
32 | |
33 // The high water mark is not tracked for the following usages. | |
34 int cache_size, dummy_int; | |
35 int status; | |
36 status = sqlite3_db_status(db_, SQLITE_DBSTATUS_CACHE_USED, &cache_size, | |
37 &dummy_int, 0 /* resetFlag */); | |
38 DCHECK_EQ(SQLITE_OK, status); | |
39 int schema_size; | |
40 status = sqlite3_db_status(db_, SQLITE_DBSTATUS_SCHEMA_USED, &schema_size, | |
41 &dummy_int, 0 /* resetFlag */); | |
42 DCHECK_EQ(SQLITE_OK, status); | |
43 int statement_size; | |
44 status = sqlite3_db_status(db_, SQLITE_DBSTATUS_STMT_USED, &statement_size, | |
45 &dummy_int, 0 /* resetFlag */); | |
46 DCHECK_EQ(SQLITE_OK, status); | |
47 | |
48 std::string name = | |
49 base::StringPrintf("sqlite/%s_connection/%p", | |
50 name_.empty() ? "Unknown" : name_.c_str(), this); | |
51 base::trace_event::MemoryAllocatorDump* dump = pmd->CreateAllocatorDump(name); | |
52 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, | |
53 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | |
54 cache_size + schema_size + statement_size); | |
55 dump->AddScalar("cache_size", | |
56 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | |
57 cache_size); | |
58 dump->AddScalar("schema_size", | |
59 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | |
60 schema_size); | |
61 dump->AddScalar("statement_size", | |
62 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | |
63 statement_size); | |
64 return true; | |
65 } | |
66 | |
67 } // namespace sql | |
OLD | NEW |