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 <functional> | |
| 10 #include <memory> | |
| 9 #include <set> | 11 #include <set> |
| 10 #include <string> | 12 #include <string> |
| 11 #include <vector> | 13 #include <vector> |
| 12 | 14 |
| 15 #include "base/containers/linked_list.h" | |
| 13 #include "base/files/file.h" | 16 #include "base/files/file.h" |
| 14 #include "base/files/file_path.h" | 17 #include "base/files/file_path.h" |
| 18 #include "base/macros.h" | |
| 15 #include "base/metrics/histogram.h" | 19 #include "base/metrics/histogram.h" |
| 20 #include "leveldb/db.h" | |
| 16 #include "leveldb/env.h" | 21 #include "leveldb/env.h" |
| 17 #include "port/port_chromium.h" | 22 #include "port/port_chromium.h" |
| 18 #include "util/mutexlock.h" | 23 #include "util/mutexlock.h" |
| 19 | 24 |
| 20 namespace leveldb_env { | 25 namespace leveldb_env { |
| 21 | 26 |
| 22 // These entries map to values in tools/metrics/histograms/histograms.xml. New | 27 // These entries map to values in tools/metrics/histograms/histograms.xml. New |
| 23 // values should be appended at the end. | 28 // values should be appended at the end. |
| 24 enum MethodID { | 29 enum MethodID { |
| 25 kSequentialFileRead, | 30 kSequentialFileRead, |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 223 // Entry per Schedule() call | 228 // Entry per Schedule() call |
| 224 struct BGItem { | 229 struct BGItem { |
| 225 void* arg; | 230 void* arg; |
| 226 void (*function)(void*); | 231 void (*function)(void*); |
| 227 }; | 232 }; |
| 228 typedef std::deque<BGItem> BGQueue; | 233 typedef std::deque<BGItem> BGQueue; |
| 229 BGQueue queue_; | 234 BGQueue queue_; |
| 230 LockTable locks_; | 235 LockTable locks_; |
| 231 }; | 236 }; |
| 232 | 237 |
| 238 // Keeps track of live databases (opened via Open() method) and | |
|
pwnall
2017/06/26 23:37:14
"Tracks database open via .... " seems shorter.
I
DmitrySkiba
2017/06/28 20:35:28
As you mention in the next commend, GetMemoryDumpN
| |
| 239 // reports them to memory-infra. The class is thread safe. | |
| 240 class DBTracker { | |
| 241 public: | |
| 242 // Opens a database and starts tracking it. Until the database is closed | |
| 243 // (i.e. database object deleted) it's exposed to memory-infra and is | |
| 244 // enumerated by VisitDatabases() method. | |
| 245 static leveldb::Status Open(const leveldb::Options& options, | |
| 246 const std::string& name, | |
| 247 leveldb::DB** dbptr); | |
| 248 | |
| 249 // Returns name of memory-infra dump for |database|. Can be used to attach | |
| 250 // additional info to a database dump, or to attribute memory usage via | |
| 251 // ProcessMemoryDump::AddSuballocation(). | |
| 252 static std::string GetMemoryDumpName(leveldb::DB* db); | |
|
pwnall
2017/06/26 23:37:14
FWIW, this method makes DBTracker depend on memory
DmitrySkiba
2017/06/28 20:35:28
I'll move the method to the next CL, and we can de
| |
| 253 | |
| 254 // DBTracker singleton instance. | |
| 255 static DBTracker* GetInstance(); | |
| 256 | |
| 257 // DB wrapper that provides extra information about the database. | |
| 258 class DBWrapper : public leveldb::DB { | |
| 259 public: | |
| 260 // Name that OpenDatabase() was called with. | |
| 261 virtual const std::string& name() const = 0; | |
| 262 }; | |
| 263 | |
| 264 using DatabaseVisitor = std::function<void(DBWrapper*)>; | |
| 265 | |
| 266 // Calls |visitor| for each live database. Takes a lock, preventing | |
| 267 // any database from being created or destroyed (but doesn't lock the | |
| 268 // databases themselves). Note that visiting order is not specified. | |
|
pwnall
2017/06/26 23:37:14
"The databases may be visited in an arbitrary orde
DmitrySkiba
2017/06/28 20:35:28
Done.
| |
| 269 void VisitDatabases(const DatabaseVisitor& visitor); | |
| 270 | |
| 271 private: | |
| 272 class DBWrapperImpl; | |
| 273 class MemoryDumpProvider; | |
| 274 | |
| 275 DBTracker(); | |
| 276 ~DBTracker(); | |
| 277 | |
| 278 void DatabaseOpened(DBWrapperImpl* database); | |
| 279 void DatabaseClosed(DBWrapperImpl* database); | |
| 280 | |
| 281 std::unique_ptr<MemoryDumpProvider> mdp_; | |
| 282 | |
| 283 base::Lock databases_lock_; | |
| 284 base::LinkedList<DBWrapperImpl> databases_; | |
| 285 | |
| 286 DISALLOW_COPY_AND_ASSIGN(DBTracker); | |
| 287 }; | |
| 288 | |
| 233 } // namespace leveldb_env | 289 } // namespace leveldb_env |
| 234 | 290 |
| 235 #endif // THIRD_PARTY_LEVELDATABASE_ENV_CHROMIUM_H_ | 291 #endif // THIRD_PARTY_LEVELDATABASE_ENV_CHROMIUM_H_ |
| OLD | NEW |