Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Unified Diff: third_party/leveldatabase/env_chromium.h

Issue 2855953002: leveldb: Add DBTracker for exposing databases to Chrome's memory-infra. (Closed)
Patch Set: OpenDB and friends Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | third_party/leveldatabase/env_chromium.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/leveldatabase/env_chromium.h
diff --git a/third_party/leveldatabase/env_chromium.h b/third_party/leveldatabase/env_chromium.h
index d4335810b24496abaf1835a01ada393d9bdbbc43..edbb419a92a23a2bc81402a668ef132e40d5e6fd 100644
--- a/third_party/leveldatabase/env_chromium.h
+++ b/third_party/leveldatabase/env_chromium.h
@@ -6,13 +6,18 @@
#define THIRD_PARTY_LEVELDATABASE_ENV_CHROMIUM_H_
#include <deque>
+#include <functional>
+#include <memory>
#include <set>
#include <string>
#include <vector>
+#include "base/containers/linked_list.h"
#include "base/files/file.h"
#include "base/files/file_path.h"
+#include "base/macros.h"
#include "base/metrics/histogram.h"
+#include "leveldb/db.h"
#include "leveldb/env.h"
#include "port/port_chromium.h"
#include "util/mutexlock.h"
@@ -230,6 +235,60 @@ class ChromiumEnv : public leveldb::Env,
LockTable locks_;
};
+// Tracks databases open via OpenDatabase() method and exposes them to
+// memory-infra. The class is thread safe.
+class DBTracker {
+ public:
+ // DBTracker singleton instance.
+ static DBTracker* GetInstance();
+
+ // Provides extra information about a tracked database.
+ class TrackedDB : public leveldb::DB {
+ public:
+ // Name that OpenDatabase() was called with.
+ virtual const std::string& name() const = 0;
+ };
+
+ // Opens a database and starts tracking it. As long as opened database
pwnall 2017/06/28 22:52:55 nit: the opened database is alive
+ // is alive (i.e. its instance is not destroyed) the database is exposed
+ // to memory-infra and is enumerated by VisitDatabases() method.
+ leveldb::Status OpenDatabase(const leveldb::Options& options,
+ const std::string& name,
+ TrackedDB** dbptr);
+
+ using DatabaseVisitor = std::function<void(TrackedDB*)>;
+
+ // Calls |visitor| for each live database. Database is live from the point it
pwnall 2017/06/28 22:52:55 Nit: The database is live
+ // was returned from OpenDatabase() and up until its instance is destroyed.
+ // The databases may be visited in an arbitrary order.
+ // This function takes a lock, preventing any database from being opened or
+ // destroyed (but doesn't lock the databases themselves).
+ void VisitDatabases(const DatabaseVisitor& visitor);
+
+ private:
+ class TrackedDBImpl;
+ class MemoryDumpProvider;
+
+ DBTracker();
+ ~DBTracker();
+
+ void DatabaseOpened(TrackedDBImpl* database);
+ void DatabaseDestroyed(TrackedDBImpl* database);
+
+ std::unique_ptr<MemoryDumpProvider> mdp_;
+
+ base::Lock databases_lock_;
+ base::LinkedList<TrackedDBImpl> databases_;
+
+ DISALLOW_COPY_AND_ASSIGN(DBTracker);
+};
+
+// Opens a database and exposes it to Chrome's tracing (see DBTracker for
+// details). Note that |dbptr| is touched only when function succeeds.
+leveldb::Status OpenDB(const leveldb::Options& options,
+ const std::string& name,
+ std::unique_ptr<leveldb::DB>* dbptr);
+
} // namespace leveldb_env
#endif // THIRD_PARTY_LEVELDATABASE_ENV_CHROMIUM_H_
« no previous file with comments | « no previous file | third_party/leveldatabase/env_chromium.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698