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

Side by Side Diff: third_party/leveldatabase/env_chromium.h

Issue 2855953002: leveldb: Add DBTracker for exposing databases to Chrome's memory-infra. (Closed)
Patch Set: Address comments 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 unified diff | Download patch
OLDNEW
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
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 // Database registry. Keeps track of all live databases and reports them to
239 // memory-infra. This class is thread safe.
240 class DBRegistry {
pwnall 2017/06/22 02:50:22 I'd prefer that Open() and VisitOpenDatabases() be
DmitrySkiba 2017/06/26 20:45:18 Renaming: done. I'm not sure about free-standing
pwnall 2017/06/26 23:37:13 This comment (that I agree with) suggests that lev
DmitrySkiba 2017/06/28 20:35:28 Done.
241 public:
242 // Opens a database. Internally calls leveldb::DB::Open(options, name)
pwnall 2017/06/22 02:50:22 Can you please write the docs from the perspective
DmitrySkiba 2017/06/26 20:45:19 Done.
243 // and wraps the result in |DBWrapper| instance (see below).
244 static leveldb::Status Open(const leveldb::Options& options,
245 const std::string& name,
246 leveldb::DB** dbptr);
247
248 static DBRegistry* GetInstance();
249
250 // DB wrapper that provides extra information about the database.
251 class DBWrapper : public leveldb::DB {
252 public:
253 // DB name that Open() was called with.
254 virtual const std::string& name() const = 0;
pwnall 2017/06/22 02:50:22 Do you envision adding more functionality here, su
DmitrySkiba 2017/06/26 20:45:19 Yes, more stuff is planned: visiting iterators, ex
pwnall 2017/06/26 23:37:13 How about TrackedDB instead of DB for the name, th
DmitrySkiba 2017/06/28 20:35:28 Done.
255 };
256
257 using DatabaseVisitor = std::function<void(DBWrapper*)>;
pwnall 2017/06/22 02:50:22 Visitor?
DmitrySkiba 2017/06/26 20:45:18 I think that if method is called VisitDatabases(),
pwnall 2017/06/26 23:37:13 I thought Visitor is acceptable if this is the onl
DmitrySkiba 2017/06/28 20:35:28 Acknowledged.
258
259 // Calls |visitor| for each live database. Takes a lock, preventing
260 // any database from being created or destroyed (but doesn't lock the
261 // databases themselves).
262 void VisitDatabases(const DatabaseVisitor& visitor);
pwnall 2017/06/22 02:50:22 VisitOpenDatabases?
DmitrySkiba 2017/06/26 20:45:19 I feel that 'Open' is redundant, since it's the on
pwnall 2017/06/26 23:37:13 It is, once you've thought things through. However
DmitrySkiba 2017/06/28 20:35:28 I think this is job for comments, so I updated the
263
264 private:
265 class DBWrapperImpl;
266 class MDP;
pwnall 2017/06/22 02:50:22 Can you please use the full name MemoryDumpProvide
DmitrySkiba 2017/06/26 20:45:19 Done.
267
268 DBRegistry();
269 ~DBRegistry();
270
271 void RegisterDatabase(DBWrapperImpl* database);
272 void UnregisterDatabase(DBWrapperImpl* database);
273
274 std::unique_ptr<MDP> mdp_;
275
276 base::Lock databases_lock_;
277 base::LinkedList<DBWrapperImpl> databases_;
278
279 DISALLOW_COPY_AND_ASSIGN(DBRegistry);
280 };
281
233 } // namespace leveldb_env 282 } // namespace leveldb_env
234 283
235 #endif // THIRD_PARTY_LEVELDATABASE_ENV_CHROMIUM_H_ 284 #endif // THIRD_PARTY_LEVELDATABASE_ENV_CHROMIUM_H_
OLDNEW
« no previous file with comments | « no previous file | third_party/leveldatabase/env_chromium.cc » ('j') | third_party/leveldatabase/env_chromium.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698