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

Side by Side Diff: content/browser/indexed_db/leveldb/leveldb_database.cc

Issue 1420193003: [tracing] Add IndexDB database memory usages to tracing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@leveldb
Patch Set: Nit. Created 4 years, 9 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
« no previous file with comments | « content/browser/indexed_db/leveldb/leveldb_database.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium 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. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/indexed_db/leveldb/leveldb_database.h" 5 #include "content/browser/indexed_db/leveldb/leveldb_database.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <cerrno> 8 #include <cerrno>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/files/file.h" 11 #include "base/files/file.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/metrics/histogram.h" 15 #include "base/metrics/histogram.h"
16 #include "base/strings/string16.h" 16 #include "base/strings/string16.h"
17 #include "base/strings/string_number_conversions.h"
17 #include "base/strings/string_piece.h" 18 #include "base/strings/string_piece.h"
18 #include "base/strings/stringprintf.h" 19 #include "base/strings/stringprintf.h"
19 #include "base/strings/utf_string_conversions.h" 20 #include "base/strings/utf_string_conversions.h"
20 #include "base/sys_info.h" 21 #include "base/sys_info.h"
22 #include "base/trace_event/memory_dump_manager.h"
23 #include "base/trace_event/process_memory_dump.h"
21 #include "build/build_config.h" 24 #include "build/build_config.h"
22 #include "content/browser/indexed_db/indexed_db_class_factory.h" 25 #include "content/browser/indexed_db/indexed_db_class_factory.h"
23 #include "content/browser/indexed_db/indexed_db_tracing.h" 26 #include "content/browser/indexed_db/indexed_db_tracing.h"
24 #include "content/browser/indexed_db/leveldb/leveldb_comparator.h" 27 #include "content/browser/indexed_db/leveldb/leveldb_comparator.h"
25 #include "content/browser/indexed_db/leveldb/leveldb_env.h" 28 #include "content/browser/indexed_db/leveldb/leveldb_env.h"
26 #include "content/browser/indexed_db/leveldb/leveldb_iterator_impl.h" 29 #include "content/browser/indexed_db/leveldb/leveldb_iterator_impl.h"
27 #include "content/browser/indexed_db/leveldb/leveldb_write_batch.h" 30 #include "content/browser/indexed_db/leveldb/leveldb_write_batch.h"
28 #include "third_party/leveldatabase/env_chromium.h" 31 #include "third_party/leveldatabase/env_chromium.h"
29 #include "third_party/leveldatabase/src/helpers/memenv/memenv.h" 32 #include "third_party/leveldatabase/src/helpers/memenv/memenv.h"
30 #include "third_party/leveldatabase/src/include/leveldb/db.h" 33 #include "third_party/leveldatabase/src/include/leveldb/db.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 std::string* key) const {} 85 std::string* key) const {}
83 86
84 LevelDBSnapshot::LevelDBSnapshot(LevelDBDatabase* db) 87 LevelDBSnapshot::LevelDBSnapshot(LevelDBDatabase* db)
85 : db_(db->db_.get()), snapshot_(db_->GetSnapshot()) {} 88 : db_(db->db_.get()), snapshot_(db_->GetSnapshot()) {}
86 89
87 LevelDBSnapshot::~LevelDBSnapshot() { db_->ReleaseSnapshot(snapshot_); } 90 LevelDBSnapshot::~LevelDBSnapshot() { db_->ReleaseSnapshot(snapshot_); }
88 91
89 LevelDBDatabase::LevelDBDatabase() {} 92 LevelDBDatabase::LevelDBDatabase() {}
90 93
91 LevelDBDatabase::~LevelDBDatabase() { 94 LevelDBDatabase::~LevelDBDatabase() {
95 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider(
96 this);
92 // db_'s destructor uses comparator_adapter_; order of deletion is important. 97 // db_'s destructor uses comparator_adapter_; order of deletion is important.
93 CloseDatabase(); 98 CloseDatabase();
94 comparator_adapter_.reset(); 99 comparator_adapter_.reset();
95 env_.reset(); 100 env_.reset();
96 } 101 }
97 102
98 void LevelDBDatabase::CloseDatabase() { 103 void LevelDBDatabase::CloseDatabase() {
99 if (db_) { 104 if (db_) {
100 base::TimeTicks begin_time = base::TimeTicks::Now(); 105 base::TimeTicks begin_time = base::TimeTicks::Now();
101 db_.reset(); 106 db_.reset();
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 UMA_HISTOGRAM_MEDIUM_TIMES("WebCore.IndexedDB.LevelDB.OpenTime", 309 UMA_HISTOGRAM_MEDIUM_TIMES("WebCore.IndexedDB.LevelDB.OpenTime",
305 base::TimeTicks::Now() - begin_time); 310 base::TimeTicks::Now() - begin_time);
306 311
307 CheckFreeSpace("Success", file_name); 312 CheckFreeSpace("Success", file_name);
308 313
309 (*result).reset(new LevelDBDatabase); 314 (*result).reset(new LevelDBDatabase);
310 (*result)->db_ = make_scoped_ptr(db); 315 (*result)->db_ = make_scoped_ptr(db);
311 (*result)->comparator_adapter_ = std::move(comparator_adapter); 316 (*result)->comparator_adapter_ = std::move(comparator_adapter);
312 (*result)->comparator_ = comparator; 317 (*result)->comparator_ = comparator;
313 (*result)->filter_policy_ = std::move(filter_policy); 318 (*result)->filter_policy_ = std::move(filter_policy);
319 (*result)->file_name_for_tracing = file_name.BaseName().AsUTF8Unsafe();
314 320
315 return s; 321 return s;
316 } 322 }
317 323
318 scoped_ptr<LevelDBDatabase> LevelDBDatabase::OpenInMemory( 324 scoped_ptr<LevelDBDatabase> LevelDBDatabase::OpenInMemory(
319 const LevelDBComparator* comparator) { 325 const LevelDBComparator* comparator) {
320 scoped_ptr<ComparatorAdapter> comparator_adapter( 326 scoped_ptr<ComparatorAdapter> comparator_adapter(
321 new ComparatorAdapter(comparator)); 327 new ComparatorAdapter(comparator));
322 scoped_ptr<leveldb::Env> in_memory_env(leveldb::NewMemEnv(LevelDBEnv::Get())); 328 scoped_ptr<leveldb::Env> in_memory_env(leveldb::NewMemEnv(LevelDBEnv::Get()));
323 329
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 IDB_TRACE("LevelDBDatabase::Compact"); 437 IDB_TRACE("LevelDBDatabase::Compact");
432 const leveldb::Slice start_slice = MakeSlice(start); 438 const leveldb::Slice start_slice = MakeSlice(start);
433 const leveldb::Slice stop_slice = MakeSlice(stop); 439 const leveldb::Slice stop_slice = MakeSlice(stop);
434 // NULL batch means just wait for earlier writes to be done 440 // NULL batch means just wait for earlier writes to be done
435 db_->Write(leveldb::WriteOptions(), NULL); 441 db_->Write(leveldb::WriteOptions(), NULL);
436 db_->CompactRange(&start_slice, &stop_slice); 442 db_->CompactRange(&start_slice, &stop_slice);
437 } 443 }
438 444
439 void LevelDBDatabase::CompactAll() { db_->CompactRange(NULL, NULL); } 445 void LevelDBDatabase::CompactAll() { db_->CompactRange(NULL, NULL); }
440 446
447 bool LevelDBDatabase::OnMemoryDump(
448 const base::trace_event::MemoryDumpArgs& args,
449 base::trace_event::ProcessMemoryDump* pmd) {
450 if (!db_)
451 return false;
452
453 std::string value;
454 size_t size;
455 bool res = db_->GetProperty("leveldb.approximate-memory-usage", &value);
456 DCHECK(res);
457 base::StringToUint64(value, &size);
458
459 DCHECK(!file_name_for_tracing.empty());
460 auto dump =
461 pmd->CreateAllocatorDump("leveldb/index_db/" + file_name_for_tracing);
jsbell 2016/02/29 20:18:54 Sanity check: the filename here is going to be a s
ssid 2016/02/29 23:23:30 True. I did not think about this case. made the st
462 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
463 base::trace_event::MemoryAllocatorDump::kUnitsBytes, size);
464
465 // Memory is allocated from system allocator (malloc).
466 pmd->AddSuballocation(dump->guid(),
467 base::trace_event::MemoryDumpManager::GetInstance()
468 ->system_allocator_pool_name());
469 return true;
470 }
471
441 } // namespace content 472 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/indexed_db/leveldb/leveldb_database.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698