Chromium Code Reviews| OLD | NEW |
|---|---|
| 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> |
| (...skipping 1175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1186 // 0x7FE70F2040A0 4.0 KiB /Users/.../data_reduction_proxy_leveldb | 1186 // 0x7FE70F2040A0 4.0 KiB /Users/.../data_reduction_proxy_leveldb |
| 1187 // 0x7FE70F530D80 188.4 KiB /Users/.../Sync Data/LevelDB | 1187 // 0x7FE70F530D80 188.4 KiB /Users/.../Sync Data/LevelDB |
| 1188 // 0x7FE71442F270 4.0 KiB /Users/.../Sync App Settings/... | 1188 // 0x7FE71442F270 4.0 KiB /Users/.../Sync App Settings/... |
| 1189 // 0x7FE71471EC50 8.0 KiB /Users/.../Extension State | 1189 // 0x7FE71471EC50 8.0 KiB /Users/.../Extension State |
| 1190 // | 1190 // |
| 1191 class DBTracker::MemoryDumpProvider | 1191 class DBTracker::MemoryDumpProvider |
| 1192 : public base::trace_event::MemoryDumpProvider { | 1192 : public base::trace_event::MemoryDumpProvider { |
| 1193 public: | 1193 public: |
| 1194 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, | 1194 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, |
| 1195 base::trace_event::ProcessMemoryDump* pmd) override { | 1195 base::trace_event::ProcessMemoryDump* pmd) override { |
| 1196 // Don't dump in background mode ("from the field") until whitelisted. | |
| 1197 if (args.level_of_detail == | |
| 1198 base::trace_event::MemoryDumpLevelOfDetail::BACKGROUND) { | |
| 1199 return true; | |
| 1200 } | |
| 1201 | |
| 1196 auto db_visitor = [](const base::trace_event::MemoryDumpArgs& args, | 1202 auto db_visitor = [](const base::trace_event::MemoryDumpArgs& args, |
| 1197 base::trace_event::ProcessMemoryDump* pmd, | 1203 base::trace_event::ProcessMemoryDump* pmd, |
| 1198 TrackedDB* db) { | 1204 TrackedDB* db) { |
| 1199 std::string db_dump_name = base::StringPrintf( | 1205 std::string db_dump_name = DBTracker::GetMemoryDumpName(db); |
| 1200 "leveldatabase/0x%" PRIXPTR, reinterpret_cast<uintptr_t>(db)); | |
| 1201 auto* db_dump = pmd->CreateAllocatorDump(db_dump_name.c_str()); | 1206 auto* db_dump = pmd->CreateAllocatorDump(db_dump_name.c_str()); |
| 1202 | 1207 |
| 1203 uint64_t db_memory_usage = 0; | 1208 uint64_t db_memory_usage = 0; |
| 1204 { | 1209 { |
| 1205 std::string usage_string; | 1210 std::string usage_string; |
| 1206 bool success = db->GetProperty("leveldb.approximate-memory-usage", | 1211 bool success = db->GetProperty("leveldb.approximate-memory-usage", |
| 1207 &usage_string) && | 1212 &usage_string) && |
| 1208 base::StringToUint64(usage_string, &db_memory_usage); | 1213 base::StringToUint64(usage_string, &db_memory_usage); |
| 1209 DCHECK(success); | 1214 DCHECK(success); |
| 1210 } | 1215 } |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 1238 | 1243 |
| 1239 DBTracker::~DBTracker() { | 1244 DBTracker::~DBTracker() { |
| 1240 NOTREACHED(); // DBTracker is a singleton | 1245 NOTREACHED(); // DBTracker is a singleton |
| 1241 } | 1246 } |
| 1242 | 1247 |
| 1243 DBTracker* DBTracker::GetInstance() { | 1248 DBTracker* DBTracker::GetInstance() { |
| 1244 static DBTracker* instance = new DBTracker(); | 1249 static DBTracker* instance = new DBTracker(); |
| 1245 return instance; | 1250 return instance; |
| 1246 } | 1251 } |
| 1247 | 1252 |
| 1253 std::string DBTracker::GetMemoryDumpName(leveldb::DB* tracked_db) { | |
| 1254 return base::StringPrintf("leveldatabase/0x%" PRIXPTR, | |
|
pwnall
2017/07/07 22:30:29
nit: I'd prefer that GetMemoryDumpName() DCHECKs t
DmitrySkiba
2017/07/17 22:09:25
I can see value in that DCHECK, but I'm not sure w
| |
| 1255 reinterpret_cast<uintptr_t>(tracked_db)); | |
| 1256 } | |
| 1257 | |
| 1248 leveldb::Status DBTracker::OpenDatabase(const leveldb::Options& options, | 1258 leveldb::Status DBTracker::OpenDatabase(const leveldb::Options& options, |
| 1249 const std::string& name, | 1259 const std::string& name, |
| 1250 TrackedDB** dbptr) { | 1260 TrackedDB** dbptr) { |
| 1251 leveldb::DB* db = nullptr; | 1261 leveldb::DB* db = nullptr; |
| 1252 auto status = leveldb::DB::Open(options, name, &db); | 1262 auto status = leveldb::DB::Open(options, name, &db); |
| 1263 CHECK((status.ok() && db) || (!status.ok() && !db)); | |
| 1253 if (status.ok()) { | 1264 if (status.ok()) { |
| 1254 // TrackedDBImpl ctor adds the instance to the tracker. | 1265 // TrackedDBImpl ctor adds the instance to the tracker. |
| 1255 *dbptr = new TrackedDBImpl(GetInstance(), name, db); | 1266 *dbptr = new TrackedDBImpl(GetInstance(), name, db); |
| 1256 } | 1267 } |
| 1257 return status; | 1268 return status; |
| 1258 } | 1269 } |
| 1259 | 1270 |
| 1260 void DBTracker::VisitDatabases(const DatabaseVisitor& visitor) { | 1271 void DBTracker::VisitDatabases(const DatabaseVisitor& visitor) { |
| 1261 base::AutoLock lock(databases_lock_); | 1272 base::AutoLock lock(databases_lock_); |
| 1262 for (auto* i = databases_.head(); i != databases_.end(); i = i->next()) { | 1273 for (auto* i = databases_.head(); i != databases_.end(); i = i->next()) { |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 1288 | 1299 |
| 1289 } // namespace leveldb_env | 1300 } // namespace leveldb_env |
| 1290 | 1301 |
| 1291 namespace leveldb { | 1302 namespace leveldb { |
| 1292 | 1303 |
| 1293 Env* Env::Default() { | 1304 Env* Env::Default() { |
| 1294 return leveldb_env::default_env.Pointer(); | 1305 return leveldb_env::default_env.Pointer(); |
| 1295 } | 1306 } |
| 1296 | 1307 |
| 1297 } // namespace leveldb | 1308 } // namespace leveldb |
| OLD | NEW |