Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The LevelDB Authors. All rights reserved. | 1 // Copyright (c) 2013 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 #ifndef THIRD_PARTY_LEVELDATABASE_ENV_CHROMIUM_H_ | 5 #ifndef THIRD_PARTY_LEVELDATABASE_ENV_CHROMIUM_H_ |
| 6 #define THIRD_PARTY_LEVELDATABASE_ENV_CHROMIUM_H_ | 6 #define THIRD_PARTY_LEVELDATABASE_ENV_CHROMIUM_H_ |
| 7 | 7 |
| 8 #include <deque> | 8 #include <deque> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 235 LockTable locks_; | 235 LockTable locks_; |
| 236 }; | 236 }; |
| 237 | 237 |
| 238 // Tracks databases open via OpenDatabase() method and exposes them to | 238 // Tracks databases open via OpenDatabase() method and exposes them to |
| 239 // memory-infra. The class is thread safe. | 239 // memory-infra. The class is thread safe. |
| 240 class DBTracker { | 240 class DBTracker { |
| 241 public: | 241 public: |
| 242 // DBTracker singleton instance. | 242 // DBTracker singleton instance. |
| 243 static DBTracker* GetInstance(); | 243 static DBTracker* GetInstance(); |
| 244 | 244 |
| 245 // Returns name of memory-infra dump for |tracked_db|. Can be used to attach | |
| 246 // additional info to the database dump, or to properly attribute memory | |
| 247 // usage in memory dump providers that also dump |tracked_db|. | |
| 248 // Note that |tracked_db| should be a live database instance produced by | |
| 249 // OpenDatabase() method or leveldb_env::OpenDB() function. | |
| 250 static std::string GetMemoryDumpName(leveldb::DB* tracked_db); | |
| 251 | |
| 245 // Provides extra information about a tracked database. | 252 // Provides extra information about a tracked database. |
| 246 class TrackedDB : public leveldb::DB { | 253 class TrackedDB : public leveldb::DB { |
| 247 public: | 254 public: |
| 248 // Name that OpenDatabase() was called with. | 255 // Name that OpenDatabase() was called with. |
| 249 virtual const std::string& name() const = 0; | 256 virtual const std::string& name() const = 0; |
| 250 }; | 257 }; |
| 251 | 258 |
| 252 // Opens a database and starts tracking it. As long as the opened database | 259 // Opens a database and starts tracking it. As long as the opened database |
| 253 // is alive (i.e. its instance is not destroyed) the database is exposed to | 260 // is alive (i.e. its instance is not destroyed) the database is exposed to |
| 254 // memory-infra and is enumerated by VisitDatabases() method. | 261 // memory-infra and is enumerated by VisitDatabases() method. |
|
pwnall
2017/07/07 22:30:29
nit 1: Can you please add a statement that this i
| |
| 262 // The function guarantees that: | |
|
pwnall
2017/07/07 22:30:29
nit 2: You could say that the function has the sam
DmitrySkiba
2017/07/17 22:09:25
Done.
| |
| 263 // 1. |dbptr| is not touched on failure | |
| 264 // 2. |dbptr| is not NULL on success | |
| 255 leveldb::Status OpenDatabase(const leveldb::Options& options, | 265 leveldb::Status OpenDatabase(const leveldb::Options& options, |
| 256 const std::string& name, | 266 const std::string& name, |
| 257 TrackedDB** dbptr); | 267 TrackedDB** dbptr); |
| 258 | 268 |
| 259 using DatabaseVisitor = base::RepeatingCallback<void(TrackedDB*)>; | 269 using DatabaseVisitor = base::RepeatingCallback<void(TrackedDB*)>; |
| 260 | 270 |
| 261 // Calls |visitor| for each live database. The database is live from the | 271 // Calls |visitor| for each live database. The database is live from the |
| 262 // point it was returned from OpenDatabase() and up until its instance is | 272 // point it was returned from OpenDatabase() and up until its instance is |
| 263 // destroyed. | 273 // destroyed. |
| 264 // The databases may be visited in an arbitrary order. | 274 // The databases may be visited in an arbitrary order. |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 278 | 288 |
| 279 std::unique_ptr<MemoryDumpProvider> mdp_; | 289 std::unique_ptr<MemoryDumpProvider> mdp_; |
| 280 | 290 |
| 281 base::Lock databases_lock_; | 291 base::Lock databases_lock_; |
| 282 base::LinkedList<TrackedDBImpl> databases_; | 292 base::LinkedList<TrackedDBImpl> databases_; |
| 283 | 293 |
| 284 DISALLOW_COPY_AND_ASSIGN(DBTracker); | 294 DISALLOW_COPY_AND_ASSIGN(DBTracker); |
| 285 }; | 295 }; |
| 286 | 296 |
| 287 // Opens a database and exposes it to Chrome's tracing (see DBTracker for | 297 // Opens a database and exposes it to Chrome's tracing (see DBTracker for |
| 288 // details). Note that |dbptr| is touched only when function succeeds. | 298 // details). The function guarantees that: |
| 299 // 1. |dbptr| is not touched on failure | |
| 300 // 2. |dbptr| is not NULL on success | |
| 289 leveldb::Status OpenDB(const leveldb::Options& options, | 301 leveldb::Status OpenDB(const leveldb::Options& options, |
| 290 const std::string& name, | 302 const std::string& name, |
| 291 std::unique_ptr<leveldb::DB>* dbptr); | 303 std::unique_ptr<leveldb::DB>* dbptr); |
| 292 | 304 |
| 293 } // namespace leveldb_env | 305 } // namespace leveldb_env |
| 294 | 306 |
| 295 #endif // THIRD_PARTY_LEVELDATABASE_ENV_CHROMIUM_H_ | 307 #endif // THIRD_PARTY_LEVELDATABASE_ENV_CHROMIUM_H_ |
| OLD | NEW |