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

Side by Side Diff: third_party/leveldatabase/env_chromium.cc

Issue 2964793002: leveldb: Use base::RepeatingCallback in DBTracker. (Closed)
Patch Set: Created 3 years, 5 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
1 // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 1 // Copyright (c) 2011 The LevelDB 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. See the AUTHORS file for names of contributors. 3 // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 4
5 #include "third_party/leveldatabase/env_chromium.h" 5 #include "third_party/leveldatabase/env_chromium.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #if defined(OS_POSIX) 9 #if defined(OS_POSIX)
10 #include <dirent.h> 10 #include <dirent.h>
11 #include <sys/types.h> 11 #include <sys/types.h>
12 #endif 12 #endif
13 13
14 #include "base/bind.h"
14 #include "base/files/file_enumerator.h" 15 #include "base/files/file_enumerator.h"
15 #include "base/files/file_util.h" 16 #include "base/files/file_util.h"
16 #include "base/format_macros.h" 17 #include "base/format_macros.h"
17 #include "base/lazy_instance.h" 18 #include "base/lazy_instance.h"
18 #include "base/logging.h" 19 #include "base/logging.h"
19 #include "base/macros.h" 20 #include "base/macros.h"
20 #include "base/metrics/histogram_functions.h" 21 #include "base/metrics/histogram_functions.h"
21 #include "base/process/process_metrics.h" 22 #include "base/process/process_metrics.h"
22 #include "base/stl_util.h" 23 #include "base/stl_util.h"
23 #include "base/strings/string_number_conversions.h" 24 #include "base/strings/string_number_conversions.h"
(...skipping 1161 matching lines...) Expand 10 before | Expand all | Expand 10 after
1185 // 0x7FE70F2040A0 4.0 KiB /Users/.../data_reduction_proxy_leveldb 1186 // 0x7FE70F2040A0 4.0 KiB /Users/.../data_reduction_proxy_leveldb
1186 // 0x7FE70F530D80 188.4 KiB /Users/.../Sync Data/LevelDB 1187 // 0x7FE70F530D80 188.4 KiB /Users/.../Sync Data/LevelDB
1187 // 0x7FE71442F270 4.0 KiB /Users/.../Sync App Settings/... 1188 // 0x7FE71442F270 4.0 KiB /Users/.../Sync App Settings/...
1188 // 0x7FE71471EC50 8.0 KiB /Users/.../Extension State 1189 // 0x7FE71471EC50 8.0 KiB /Users/.../Extension State
1189 // 1190 //
1190 class DBTracker::MemoryDumpProvider 1191 class DBTracker::MemoryDumpProvider
1191 : public base::trace_event::MemoryDumpProvider { 1192 : public base::trace_event::MemoryDumpProvider {
1192 public: 1193 public:
1193 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, 1194 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args,
1194 base::trace_event::ProcessMemoryDump* pmd) override { 1195 base::trace_event::ProcessMemoryDump* pmd) override {
1195 auto db_visitor = [&](TrackedDB* db) { 1196 auto db_visitor = [](const base::trace_event::MemoryDumpArgs& args,
1197 base::trace_event::ProcessMemoryDump* pmd,
1198 TrackedDB* db) {
1196 std::string db_dump_name = base::StringPrintf( 1199 std::string db_dump_name = base::StringPrintf(
1197 "leveldatabase/0x%" PRIXPTR, reinterpret_cast<uintptr_t>(db)); 1200 "leveldatabase/0x%" PRIXPTR, reinterpret_cast<uintptr_t>(db));
1198 auto* db_dump = pmd->CreateAllocatorDump(db_dump_name.c_str()); 1201 auto* db_dump = pmd->CreateAllocatorDump(db_dump_name.c_str());
1199 1202
1200 uint64_t db_memory_usage = 0; 1203 uint64_t db_memory_usage = 0;
1201 { 1204 {
1202 std::string usage_string; 1205 std::string usage_string;
1203 bool success = db->GetProperty("leveldb.approximate-memory-usage", 1206 bool success = db->GetProperty("leveldb.approximate-memory-usage",
1204 &usage_string) && 1207 &usage_string) &&
1205 base::StringToUint64(usage_string, &db_memory_usage); 1208 base::StringToUint64(usage_string, &db_memory_usage);
1206 DCHECK(success); 1209 DCHECK(success);
1207 } 1210 }
1208 db_dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, 1211 db_dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
1209 base::trace_event::MemoryAllocatorDump::kUnitsBytes, 1212 base::trace_event::MemoryAllocatorDump::kUnitsBytes,
1210 db_memory_usage); 1213 db_memory_usage);
1211 1214
1212 if (args.level_of_detail != 1215 if (args.level_of_detail !=
1213 base::trace_event::MemoryDumpLevelOfDetail::BACKGROUND) { 1216 base::trace_event::MemoryDumpLevelOfDetail::BACKGROUND) {
1214 db_dump->AddString("name", "", db->name()); 1217 db_dump->AddString("name", "", db->name());
1215 } 1218 }
1216 1219
1217 const char* system_allocator_name = 1220 const char* system_allocator_name =
1218 base::trace_event::MemoryDumpManager::GetInstance() 1221 base::trace_event::MemoryDumpManager::GetInstance()
1219 ->system_allocator_pool_name(); 1222 ->system_allocator_pool_name();
1220 if (system_allocator_name) { 1223 if (system_allocator_name) {
1221 pmd->AddSuballocation(db_dump->guid(), system_allocator_name); 1224 pmd->AddSuballocation(db_dump->guid(), system_allocator_name);
1222 } 1225 }
1223 }; 1226 };
1224 1227
1225 DBTracker::GetInstance()->VisitDatabases(db_visitor); 1228 DBTracker::GetInstance()->VisitDatabases(
1229 base::BindRepeating(db_visitor, args, base::Unretained(pmd)));
1226 return true; 1230 return true;
1227 } 1231 }
1228 }; 1232 };
1229 1233
1230 DBTracker::DBTracker() : mdp_(new MemoryDumpProvider()) { 1234 DBTracker::DBTracker() : mdp_(new MemoryDumpProvider()) {
1231 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( 1235 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider(
1232 mdp_.get(), "LevelDB", nullptr); 1236 mdp_.get(), "LevelDB", nullptr);
1233 } 1237 }
1234 1238
1235 DBTracker::~DBTracker() { 1239 DBTracker::~DBTracker() {
(...skipping 13 matching lines...) Expand all
1249 if (status.ok()) { 1253 if (status.ok()) {
1250 // TrackedDBImpl ctor adds the instance to the tracker. 1254 // TrackedDBImpl ctor adds the instance to the tracker.
1251 *dbptr = new TrackedDBImpl(GetInstance(), name, db); 1255 *dbptr = new TrackedDBImpl(GetInstance(), name, db);
1252 } 1256 }
1253 return status; 1257 return status;
1254 } 1258 }
1255 1259
1256 void DBTracker::VisitDatabases(const DatabaseVisitor& visitor) { 1260 void DBTracker::VisitDatabases(const DatabaseVisitor& visitor) {
1257 base::AutoLock lock(databases_lock_); 1261 base::AutoLock lock(databases_lock_);
1258 for (auto* i = databases_.head(); i != databases_.end(); i = i->next()) { 1262 for (auto* i = databases_.head(); i != databases_.end(); i = i->next()) {
1259 visitor(i->value()); 1263 visitor.Run(i->value());
1260 } 1264 }
1261 } 1265 }
1262 1266
1263 void DBTracker::DatabaseOpened(TrackedDBImpl* database) { 1267 void DBTracker::DatabaseOpened(TrackedDBImpl* database) {
1264 base::AutoLock lock(databases_lock_); 1268 base::AutoLock lock(databases_lock_);
1265 databases_.Append(database); 1269 databases_.Append(database);
1266 } 1270 }
1267 1271
1268 void DBTracker::DatabaseDestroyed(TrackedDBImpl* database) { 1272 void DBTracker::DatabaseDestroyed(TrackedDBImpl* database) {
1269 base::AutoLock lock(databases_lock_); 1273 base::AutoLock lock(databases_lock_);
(...skipping 14 matching lines...) Expand all
1284 1288
1285 } // namespace leveldb_env 1289 } // namespace leveldb_env
1286 1290
1287 namespace leveldb { 1291 namespace leveldb {
1288 1292
1289 Env* Env::Default() { 1293 Env* Env::Default() {
1290 return leveldb_env::default_env.Pointer(); 1294 return leveldb_env::default_env.Pointer();
1291 } 1295 }
1292 1296
1293 } // namespace leveldb 1297 } // namespace leveldb
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698