| 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 1179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1190 // 0x7FE70F2040A0 4.0 KiB /Users/.../data_reduction_proxy_leveldb | 1190 // 0x7FE70F2040A0 4.0 KiB /Users/.../data_reduction_proxy_leveldb |
| 1191 // 0x7FE70F530D80 188.4 KiB /Users/.../Sync Data/LevelDB | 1191 // 0x7FE70F530D80 188.4 KiB /Users/.../Sync Data/LevelDB |
| 1192 // 0x7FE71442F270 4.0 KiB /Users/.../Sync App Settings/... | 1192 // 0x7FE71442F270 4.0 KiB /Users/.../Sync App Settings/... |
| 1193 // 0x7FE71471EC50 8.0 KiB /Users/.../Extension State | 1193 // 0x7FE71471EC50 8.0 KiB /Users/.../Extension State |
| 1194 // | 1194 // |
| 1195 class DBTracker::MemoryDumpProvider | 1195 class DBTracker::MemoryDumpProvider |
| 1196 : public base::trace_event::MemoryDumpProvider { | 1196 : public base::trace_event::MemoryDumpProvider { |
| 1197 public: | 1197 public: |
| 1198 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, | 1198 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, |
| 1199 base::trace_event::ProcessMemoryDump* pmd) override { | 1199 base::trace_event::ProcessMemoryDump* pmd) override { |
| 1200 // Don't dump in background mode ("from the field") until whitelisted. |
| 1201 if (args.level_of_detail == |
| 1202 base::trace_event::MemoryDumpLevelOfDetail::BACKGROUND) { |
| 1203 return true; |
| 1204 } |
| 1205 |
| 1200 auto db_visitor = [](const base::trace_event::MemoryDumpArgs& args, | 1206 auto db_visitor = [](const base::trace_event::MemoryDumpArgs& args, |
| 1201 base::trace_event::ProcessMemoryDump* pmd, | 1207 base::trace_event::ProcessMemoryDump* pmd, |
| 1202 TrackedDB* db) { | 1208 TrackedDB* db) { |
| 1203 std::string db_dump_name = base::StringPrintf( | 1209 std::string db_dump_name = DBTracker::GetMemoryDumpName(db); |
| 1204 "leveldatabase/0x%" PRIXPTR, reinterpret_cast<uintptr_t>(db)); | |
| 1205 auto* db_dump = pmd->CreateAllocatorDump(db_dump_name.c_str()); | 1210 auto* db_dump = pmd->CreateAllocatorDump(db_dump_name.c_str()); |
| 1206 | 1211 |
| 1207 uint64_t db_memory_usage = 0; | 1212 uint64_t db_memory_usage = 0; |
| 1208 { | 1213 { |
| 1209 std::string usage_string; | 1214 std::string usage_string; |
| 1210 bool success = db->GetProperty("leveldb.approximate-memory-usage", | 1215 bool success = db->GetProperty("leveldb.approximate-memory-usage", |
| 1211 &usage_string) && | 1216 &usage_string) && |
| 1212 base::StringToUint64(usage_string, &db_memory_usage); | 1217 base::StringToUint64(usage_string, &db_memory_usage); |
| 1213 DCHECK(success); | 1218 DCHECK(success); |
| 1214 } | 1219 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1242 | 1247 |
| 1243 DBTracker::~DBTracker() { | 1248 DBTracker::~DBTracker() { |
| 1244 NOTREACHED(); // DBTracker is a singleton | 1249 NOTREACHED(); // DBTracker is a singleton |
| 1245 } | 1250 } |
| 1246 | 1251 |
| 1247 DBTracker* DBTracker::GetInstance() { | 1252 DBTracker* DBTracker::GetInstance() { |
| 1248 static DBTracker* instance = new DBTracker(); | 1253 static DBTracker* instance = new DBTracker(); |
| 1249 return instance; | 1254 return instance; |
| 1250 } | 1255 } |
| 1251 | 1256 |
| 1257 std::string DBTracker::GetMemoryDumpName(leveldb::DB* tracked_db) { |
| 1258 return base::StringPrintf("leveldatabase/0x%" PRIXPTR, |
| 1259 reinterpret_cast<uintptr_t>(tracked_db)); |
| 1260 } |
| 1261 |
| 1252 leveldb::Status DBTracker::OpenDatabase(const leveldb::Options& options, | 1262 leveldb::Status DBTracker::OpenDatabase(const leveldb::Options& options, |
| 1253 const std::string& name, | 1263 const std::string& name, |
| 1254 TrackedDB** dbptr) { | 1264 TrackedDB** dbptr) { |
| 1255 leveldb::DB* db = nullptr; | 1265 leveldb::DB* db = nullptr; |
| 1256 auto status = leveldb::DB::Open(options, name, &db); | 1266 auto status = leveldb::DB::Open(options, name, &db); |
| 1267 // Enforce expectations: either we succeed, and get a valid object in |db|, |
| 1268 // or we fail, and |db| is still NULL. |
| 1269 CHECK((status.ok() && db) || (!status.ok() && !db)); |
| 1257 if (status.ok()) { | 1270 if (status.ok()) { |
| 1258 // TrackedDBImpl ctor adds the instance to the tracker. | 1271 // TrackedDBImpl ctor adds the instance to the tracker. |
| 1259 *dbptr = new TrackedDBImpl(GetInstance(), name, db); | 1272 *dbptr = new TrackedDBImpl(GetInstance(), name, db); |
| 1260 } | 1273 } |
| 1261 return status; | 1274 return status; |
| 1262 } | 1275 } |
| 1263 | 1276 |
| 1264 void DBTracker::VisitDatabases(const DatabaseVisitor& visitor) { | 1277 void DBTracker::VisitDatabases(const DatabaseVisitor& visitor) { |
| 1265 base::AutoLock lock(databases_lock_); | 1278 base::AutoLock lock(databases_lock_); |
| 1266 for (auto* i = databases_.head(); i != databases_.end(); i = i->next()) { | 1279 for (auto* i = databases_.head(); i != databases_.end(); i = i->next()) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1292 | 1305 |
| 1293 } // namespace leveldb_env | 1306 } // namespace leveldb_env |
| 1294 | 1307 |
| 1295 namespace leveldb { | 1308 namespace leveldb { |
| 1296 | 1309 |
| 1297 Env* Env::Default() { | 1310 Env* Env::Default() { |
| 1298 return leveldb_env::default_env.Pointer(); | 1311 return leveldb_env::default_env.Pointer(); |
| 1299 } | 1312 } |
| 1300 | 1313 |
| 1301 } // namespace leveldb | 1314 } // namespace leveldb |
| OLD | NEW |