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

Side by Side Diff: components/leveldb_proto/leveldb_database.cc

Issue 2340983002: [tracing] Memory dump provider for leveldb_proto (Closed)
Patch Set: Created 4 years, 3 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
« no previous file with comments | « components/leveldb_proto/leveldb_database.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/leveldb_proto/leveldb_database.h" 5 #include "components/leveldb_proto/leveldb_database.h"
6 6
7 #include <inttypes.h>
8
7 #include <string> 9 #include <string>
8 #include <vector> 10 #include <vector>
9 11
10 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
11 #include "base/files/file_util.h" 13 #include "base/files/file_util.h"
12 #include "base/metrics/histogram.h" 14 #include "base/metrics/histogram.h"
15 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/string_split.h" 16 #include "base/strings/string_split.h"
17 #include "base/strings/stringprintf.h"
18 #include "base/threading/sequenced_task_runner_handle.h"
14 #include "base/threading/thread_checker.h" 19 #include "base/threading/thread_checker.h"
20 #include "base/trace_event/memory_dump_manager.h"
21 #include "base/trace_event/process_memory_dump.h"
15 #include "third_party/leveldatabase/env_chromium.h" 22 #include "third_party/leveldatabase/env_chromium.h"
16 #include "third_party/leveldatabase/src/helpers/memenv/memenv.h" 23 #include "third_party/leveldatabase/src/helpers/memenv/memenv.h"
17 #include "third_party/leveldatabase/src/include/leveldb/db.h" 24 #include "third_party/leveldatabase/src/include/leveldb/db.h"
18 #include "third_party/leveldatabase/src/include/leveldb/env.h" 25 #include "third_party/leveldatabase/src/include/leveldb/env.h"
19 #include "third_party/leveldatabase/src/include/leveldb/iterator.h" 26 #include "third_party/leveldatabase/src/include/leveldb/iterator.h"
20 #include "third_party/leveldatabase/src/include/leveldb/options.h" 27 #include "third_party/leveldatabase/src/include/leveldb/options.h"
21 #include "third_party/leveldatabase/src/include/leveldb/slice.h" 28 #include "third_party/leveldatabase/src/include/leveldb/slice.h"
22 #include "third_party/leveldatabase/src/include/leveldb/status.h" 29 #include "third_party/leveldatabase/src/include/leveldb/status.h"
23 #include "third_party/leveldatabase/src/include/leveldb/write_batch.h" 30 #include "third_party/leveldatabase/src/include/leveldb/write_batch.h"
24 31
(...skipping 10 matching lines...) Expand all
35 // Used in lieu of UMA_HISTOGRAM_ENUMERATION because the histogram name is 42 // Used in lieu of UMA_HISTOGRAM_ENUMERATION because the histogram name is
36 // not a constant. 43 // not a constant.
37 open_histogram_ = base::LinearHistogram::FactoryGet( 44 open_histogram_ = base::LinearHistogram::FactoryGet(
38 std::string("LevelDB.Open.") + client_name, 1, 45 std::string("LevelDB.Open.") + client_name, 1,
39 leveldb_env::LEVELDB_STATUS_MAX, leveldb_env::LEVELDB_STATUS_MAX + 1, 46 leveldb_env::LEVELDB_STATUS_MAX, leveldb_env::LEVELDB_STATUS_MAX + 1,
40 base::Histogram::kUmaTargetedHistogramFlag); 47 base::Histogram::kUmaTargetedHistogramFlag);
41 } 48 }
42 49
43 LevelDB::~LevelDB() { 50 LevelDB::~LevelDB() {
44 DFAKE_SCOPED_LOCK(thread_checker_); 51 DFAKE_SCOPED_LOCK(thread_checker_);
52 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider(
53 this);
45 } 54 }
46 55
47 bool LevelDB::InitWithOptions(const base::FilePath& database_dir, 56 bool LevelDB::InitWithOptions(const base::FilePath& database_dir,
48 const leveldb::Options& options) { 57 const leveldb::Options& options) {
49 DFAKE_SCOPED_LOCK(thread_checker_); 58 DFAKE_SCOPED_LOCK(thread_checker_);
50 59
51 std::string path = database_dir.AsUTF8Unsafe(); 60 std::string path = database_dir.AsUTF8Unsafe();
52 61
53 leveldb::DB* db = NULL; 62 leveldb::DB* db = NULL;
54 leveldb::Status status = leveldb::DB::Open(options, path, &db); 63 leveldb::Status status = leveldb::DB::Open(options, path, &db);
55 if (open_histogram_) 64 if (open_histogram_)
56 open_histogram_->Add(leveldb_env::GetLevelDBStatusUMAValue(status)); 65 open_histogram_->Add(leveldb_env::GetLevelDBStatusUMAValue(status));
57 if (status.IsCorruption()) { 66 if (status.IsCorruption()) {
58 base::DeleteFile(database_dir, true); 67 base::DeleteFile(database_dir, true);
59 status = leveldb::DB::Open(options, path, &db); 68 status = leveldb::DB::Open(options, path, &db);
60 } 69 }
61 70
62 if (status.ok()) { 71 if (status.ok()) {
63 CHECK(db); 72 CHECK(db);
64 db_.reset(db); 73 db_.reset(db);
74
75 base::trace_event::MemoryDumpManager::GetInstance()
76 ->RegisterDumpProviderWithSequencedTaskRunner(
77 this, "LevelDB", base::SequencedTaskRunnerHandle::Get(),
78 base::trace_event::MemoryDumpProvider::Options());
65 return true; 79 return true;
66 } 80 }
67 81
68 LOG(WARNING) << "Unable to open " << database_dir.value() << ": " 82 LOG(WARNING) << "Unable to open " << database_dir.value() << ": "
69 << status.ToString(); 83 << status.ToString();
70 return false; 84 return false;
71 } 85 }
72 86
73 bool LevelDB::Init(const base::FilePath& database_dir) { 87 bool LevelDB::Init(const base::FilePath& database_dir) {
74 leveldb::Options options; 88 leveldb::Options options;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 if (status.IsNotFound()) { 151 if (status.IsNotFound()) {
138 *found = false; 152 *found = false;
139 return true; 153 return true;
140 } 154 }
141 155
142 DLOG(WARNING) << "Failed loading leveldb_proto entry with key \"" << key 156 DLOG(WARNING) << "Failed loading leveldb_proto entry with key \"" << key
143 << "\": " << status.ToString(); 157 << "\": " << status.ToString();
144 return false; 158 return false;
145 } 159 }
146 160
161 bool LevelDB::OnMemoryDump(const base::trace_event::MemoryDumpArgs& dump_args,
162 base::trace_event::ProcessMemoryDump* pmd) {
163 DFAKE_SCOPED_LOCK(thread_checker_);
164 if (!db_)
165 return false;
166 std::string value;
167 uint64_t size;
168 bool res = db_->GetProperty("leveldb.approximate-memory-usage", &value);
169 DCHECK(res);
170 base::StringToUint64(value, &size);
171
172 auto* dump = pmd->CreateAllocatorDump(
173 base::StringPrintf("leveldb/leveldb_proto/0x%" PRIXPTR,
174 reinterpret_cast<uintptr_t>(db_.get())));
175 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
176 base::trace_event::MemoryAllocatorDump::kUnitsBytes, size);
177 if (open_histogram_ &&
178 dump_args.level_of_detail !=
179 base::trace_event::MemoryDumpLevelOfDetail::BACKGROUND) {
180 dump->AddString("name", "", open_histogram_->histogram_name());
DmitrySkiba 2016/09/15 17:15:59 This causes name to have "LevelDB.Open." prefix, f
ssid 2016/09/15 18:13:41 Done.
181 }
182
183 // Memory is allocated from system allocator (malloc).
184 pmd->AddSuballocation(dump->guid(),
185 base::trace_event::MemoryDumpManager::GetInstance()
186 ->system_allocator_pool_name());
187 return true;
188 }
189
147 } // namespace leveldb_proto 190 } // namespace leveldb_proto
OLDNEW
« no previous file with comments | « components/leveldb_proto/leveldb_database.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698