| 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. |
| 262 // This function is an implementation detail of leveldb_env::OpenDB(), and |
| 263 // has similar guarantees regarding |dbptr| argument. |
| 255 leveldb::Status OpenDatabase(const leveldb::Options& options, | 264 leveldb::Status OpenDatabase(const leveldb::Options& options, |
| 256 const std::string& name, | 265 const std::string& name, |
| 257 TrackedDB** dbptr); | 266 TrackedDB** dbptr); |
| 258 | 267 |
| 259 using DatabaseVisitor = base::RepeatingCallback<void(TrackedDB*)>; | 268 using DatabaseVisitor = base::RepeatingCallback<void(TrackedDB*)>; |
| 260 | 269 |
| 261 // Calls |visitor| for each live database. The database is live from the | 270 // 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 | 271 // point it was returned from OpenDatabase() and up until its instance is |
| 263 // destroyed. | 272 // destroyed. |
| 264 // The databases may be visited in an arbitrary order. | 273 // The databases may be visited in an arbitrary order. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 278 | 287 |
| 279 std::unique_ptr<MemoryDumpProvider> mdp_; | 288 std::unique_ptr<MemoryDumpProvider> mdp_; |
| 280 | 289 |
| 281 base::Lock databases_lock_; | 290 base::Lock databases_lock_; |
| 282 base::LinkedList<TrackedDBImpl> databases_; | 291 base::LinkedList<TrackedDBImpl> databases_; |
| 283 | 292 |
| 284 DISALLOW_COPY_AND_ASSIGN(DBTracker); | 293 DISALLOW_COPY_AND_ASSIGN(DBTracker); |
| 285 }; | 294 }; |
| 286 | 295 |
| 287 // Opens a database and exposes it to Chrome's tracing (see DBTracker for | 296 // Opens a database and exposes it to Chrome's tracing (see DBTracker for |
| 288 // details). Note that |dbptr| is touched only when function succeeds. | 297 // details). The function guarantees that: |
| 298 // 1. |dbptr| is not touched on failure |
| 299 // 2. |dbptr| is not NULL on success |
| 289 leveldb::Status OpenDB(const leveldb::Options& options, | 300 leveldb::Status OpenDB(const leveldb::Options& options, |
| 290 const std::string& name, | 301 const std::string& name, |
| 291 std::unique_ptr<leveldb::DB>* dbptr); | 302 std::unique_ptr<leveldb::DB>* dbptr); |
| 292 | 303 |
| 293 } // namespace leveldb_env | 304 } // namespace leveldb_env |
| 294 | 305 |
| 295 #endif // THIRD_PARTY_LEVELDATABASE_ENV_CHROMIUM_H_ | 306 #endif // THIRD_PARTY_LEVELDATABASE_ENV_CHROMIUM_H_ |
| OLD | NEW |