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

Side by Side Diff: sql/connection_memory_dump_provider.cc

Issue 2452713003: [Sync] Implement MemoryDumpProvider. (Closed)
Patch Set: Fix presumit; fix Windows; git cl format Created 4 years, 1 month 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
« no previous file with comments | « sql/connection_memory_dump_provider.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 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_memory_dump_provider.h" 5 #include "sql/connection_memory_dump_provider.h"
6 6
7 #include <inttypes.h> 7 #include <inttypes.h>
8 8
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "base/trace_event/process_memory_dump.h" 10 #include "base/trace_event/process_memory_dump.h"
(...skipping 15 matching lines...) Expand all
26 26
27 bool ConnectionMemoryDumpProvider::OnMemoryDump( 27 bool ConnectionMemoryDumpProvider::OnMemoryDump(
28 const base::trace_event::MemoryDumpArgs& args, 28 const base::trace_event::MemoryDumpArgs& args,
29 base::trace_event::ProcessMemoryDump* pmd) { 29 base::trace_event::ProcessMemoryDump* pmd) {
30 if (args.level_of_detail == base::trace_event::MemoryDumpLevelOfDetail::LIGHT) 30 if (args.level_of_detail == base::trace_event::MemoryDumpLevelOfDetail::LIGHT)
31 return true; 31 return true;
32 32
33 int cache_size = 0; 33 int cache_size = 0;
34 int schema_size = 0; 34 int schema_size = 0;
35 int statement_size = 0; 35 int statement_size = 0;
36 { 36 if (!GetDbMemoryUsage(&cache_size, &schema_size, &statement_size)) {
37 // Lock is acquired here so that db_ is not reset in ResetDatabase when 37 return false;
38 // collecting stats.
39 base::AutoLock lock(lock_);
40 if (!db_) {
41 return false;
42 }
43
44 // The high water mark is not tracked for the following usages.
45 int dummy_int;
46 int status = sqlite3_db_status(db_, SQLITE_DBSTATUS_CACHE_USED, &cache_size,
47 &dummy_int, 0 /* resetFlag */);
48 DCHECK_EQ(SQLITE_OK, status);
49 status = sqlite3_db_status(db_, SQLITE_DBSTATUS_SCHEMA_USED, &schema_size,
50 &dummy_int, 0 /* resetFlag */);
51 DCHECK_EQ(SQLITE_OK, status);
52 status = sqlite3_db_status(db_, SQLITE_DBSTATUS_STMT_USED, &statement_size,
53 &dummy_int, 0 /* resetFlag */);
54 DCHECK_EQ(SQLITE_OK, status);
55 } 38 }
56 39
57 std::string name = base::StringPrintf( 40 base::trace_event::MemoryAllocatorDump* dump =
58 "sqlite/%s_connection/0x%" PRIXPTR, 41 pmd->CreateAllocatorDump(FormatDumpName());
59 connection_name_.empty() ? "Unknown" : connection_name_.c_str(),
60 reinterpret_cast<uintptr_t>(this));
61 base::trace_event::MemoryAllocatorDump* dump = pmd->CreateAllocatorDump(name);
62 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, 42 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
63 base::trace_event::MemoryAllocatorDump::kUnitsBytes, 43 base::trace_event::MemoryAllocatorDump::kUnitsBytes,
64 cache_size + schema_size + statement_size); 44 cache_size + schema_size + statement_size);
65 dump->AddScalar("cache_size", 45 dump->AddScalar("cache_size",
66 base::trace_event::MemoryAllocatorDump::kUnitsBytes, 46 base::trace_event::MemoryAllocatorDump::kUnitsBytes,
67 cache_size); 47 cache_size);
68 dump->AddScalar("schema_size", 48 dump->AddScalar("schema_size",
69 base::trace_event::MemoryAllocatorDump::kUnitsBytes, 49 base::trace_event::MemoryAllocatorDump::kUnitsBytes,
70 schema_size); 50 schema_size);
71 dump->AddScalar("statement_size", 51 dump->AddScalar("statement_size",
72 base::trace_event::MemoryAllocatorDump::kUnitsBytes, 52 base::trace_event::MemoryAllocatorDump::kUnitsBytes,
73 statement_size); 53 statement_size);
74 return true; 54 return true;
75 } 55 }
76 56
57 bool ConnectionMemoryDumpProvider::ReportMemoryUsage(
58 base::trace_event::MemoryAllocatorDump* mad) {
59 int cache_size = 0;
60 int schema_size = 0;
61 int statement_size = 0;
62 if (!GetDbMemoryUsage(&cache_size, &schema_size, &statement_size)) {
63 return false;
64 }
65
66 mad->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
67 base::trace_event::MemoryAllocatorDump::kUnitsBytes,
68 cache_size + schema_size + statement_size);
69 mad->process_memory_dump()->AddSuballocation(mad->guid(), FormatDumpName());
70
71 return true;
72 }
73
74 bool ConnectionMemoryDumpProvider::GetDbMemoryUsage(int* cache_size,
75 int* schema_size,
76 int* statement_size) {
77 // Lock is acquired here so that db_ is not reset in ResetDatabase when
78 // collecting stats.
79 base::AutoLock lock(lock_);
80 if (!db_) {
81 return false;
82 }
83
84 // The high water mark is not tracked for the following usages.
85 int dummy_int;
86 int status = sqlite3_db_status(db_, SQLITE_DBSTATUS_CACHE_USED, cache_size,
87 &dummy_int, 0 /* resetFlag */);
88 DCHECK_EQ(SQLITE_OK, status);
89 status = sqlite3_db_status(db_, SQLITE_DBSTATUS_SCHEMA_USED, schema_size,
90 &dummy_int, 0 /* resetFlag */);
91 DCHECK_EQ(SQLITE_OK, status);
92 status = sqlite3_db_status(db_, SQLITE_DBSTATUS_STMT_USED, statement_size,
93 &dummy_int, 0 /* resetFlag */);
94 DCHECK_EQ(SQLITE_OK, status);
95
96 return true;
97 }
98
99 std::string ConnectionMemoryDumpProvider::FormatDumpName() const {
100 return base::StringPrintf(
101 "sqlite/%s_connection/0x%" PRIXPTR,
102 connection_name_.empty() ? "Unknown" : connection_name_.c_str(),
103 reinterpret_cast<uintptr_t>(this));
104 }
105
77 } // namespace sql 106 } // namespace sql
OLDNEW
« no previous file with comments | « sql/connection_memory_dump_provider.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698