OLD | NEW |
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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 dump->AddScalar("schema_size", | 48 dump->AddScalar("schema_size", |
49 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | 49 base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
50 schema_size); | 50 schema_size); |
51 dump->AddScalar("statement_size", | 51 dump->AddScalar("statement_size", |
52 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | 52 base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
53 statement_size); | 53 statement_size); |
54 return true; | 54 return true; |
55 } | 55 } |
56 | 56 |
57 bool ConnectionMemoryDumpProvider::ReportMemoryUsage( | 57 bool ConnectionMemoryDumpProvider::ReportMemoryUsage( |
58 base::trace_event::MemoryAllocatorDump* mad) { | 58 base::trace_event::ProcessMemoryDump* pmd, |
| 59 const std::string& dump_name) { |
59 int cache_size = 0; | 60 int cache_size = 0; |
60 int schema_size = 0; | 61 int schema_size = 0; |
61 int statement_size = 0; | 62 int statement_size = 0; |
62 if (!GetDbMemoryUsage(&cache_size, &schema_size, &statement_size)) { | 63 if (!GetDbMemoryUsage(&cache_size, &schema_size, &statement_size)) |
63 return false; | 64 return false; |
64 } | |
65 | 65 |
| 66 auto* mad = pmd->CreateAllocatorDump(dump_name); |
66 mad->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, | 67 mad->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, |
67 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | 68 base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
68 cache_size + schema_size + statement_size); | 69 cache_size + schema_size + statement_size); |
69 mad->process_memory_dump()->AddSuballocation(mad->guid(), FormatDumpName()); | 70 pmd->AddSuballocation(mad->guid(), FormatDumpName()); |
70 | 71 |
71 return true; | 72 return true; |
72 } | 73 } |
73 | 74 |
74 bool ConnectionMemoryDumpProvider::GetDbMemoryUsage(int* cache_size, | 75 bool ConnectionMemoryDumpProvider::GetDbMemoryUsage(int* cache_size, |
75 int* schema_size, | 76 int* schema_size, |
76 int* statement_size) { | 77 int* statement_size) { |
77 // Lock is acquired here so that db_ is not reset in ResetDatabase when | 78 // Lock is acquired here so that db_ is not reset in ResetDatabase when |
78 // collecting stats. | 79 // collecting stats. |
79 base::AutoLock lock(lock_); | 80 base::AutoLock lock(lock_); |
(...skipping 17 matching lines...) Expand all Loading... |
97 } | 98 } |
98 | 99 |
99 std::string ConnectionMemoryDumpProvider::FormatDumpName() const { | 100 std::string ConnectionMemoryDumpProvider::FormatDumpName() const { |
100 return base::StringPrintf( | 101 return base::StringPrintf( |
101 "sqlite/%s_connection/0x%" PRIXPTR, | 102 "sqlite/%s_connection/0x%" PRIXPTR, |
102 connection_name_.empty() ? "Unknown" : connection_name_.c_str(), | 103 connection_name_.empty() ? "Unknown" : connection_name_.c_str(), |
103 reinterpret_cast<uintptr_t>(this)); | 104 reinterpret_cast<uintptr_t>(this)); |
104 } | 105 } |
105 | 106 |
106 } // namespace sql | 107 } // namespace sql |
OLD | NEW |