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

Unified Diff: content/browser/indexed_db/leveldb/leveldb_transaction.cc

Issue 2904603003: [IndexedDB] Adding txn, value, and key size metrics (Closed)
Patch Set: made sure size is 0'd out Created 3 years, 7 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
Index: content/browser/indexed_db/leveldb/leveldb_transaction.cc
diff --git a/content/browser/indexed_db/leveldb/leveldb_transaction.cc b/content/browser/indexed_db/leveldb/leveldb_transaction.cc
index 252059f0ad415929d31a8be204790fa22564e216..b2e83c42b239c65832571d1eb3a3ba95596baff4 100644
--- a/content/browser/indexed_db/leveldb/leveldb_transaction.cc
+++ b/content/browser/indexed_db/leveldb/leveldb_transaction.cc
@@ -26,7 +26,6 @@ bool IsKeyBeforeEndOfRange(const content::LevelDBComparator* comparator,
return (open ? comparator->Compare(key, end) < 0
: comparator->Compare(key, end) <= 0);
}
-
} // namespace
namespace content {
@@ -51,6 +50,7 @@ void LevelDBTransaction::Set(const StringPiece& key,
if (it == data_.end()) {
std::unique_ptr<Record> record = base::MakeUnique<Record>();
+ size_ += SizeOfRecordInMap(key.size()) + value->size();
record->key.assign(key.begin(), key.end() - key.begin());
record->value.swap(*value);
record->deleted = deleted;
@@ -58,7 +58,9 @@ void LevelDBTransaction::Set(const StringPiece& key,
NotifyIterators();
return;
}
+ size_ += value->size();
it->second->value.swap(*value);
+ size_ -= value->size();
it->second->deleted = deleted;
}
@@ -163,6 +165,10 @@ LevelDBTransaction::DataIterator::Create(LevelDBTransaction* transaction) {
return base::WrapUnique(new DataIterator(transaction));
}
+constexpr uint64_t LevelDBTransaction::SizeOfRecordInMap(size_t key_size) {
+ return sizeof(Record) + key_size * 2;
+}
+
bool LevelDBTransaction::DataIterator::IsValid() const {
return iterator_ != data_->end();
}
@@ -374,11 +380,14 @@ void LevelDBTransaction::TransactionIterator::DataChanged() {
void LevelDBTransaction::TransactionIterator::Delete() {
DCHECK(IsValid());
if (current_ == data_iterator_.get()) {
+ transaction_->size_ -= data_iterator_->Value().size();
data_iterator_->Delete();
} else {
std::unique_ptr<Record> record = base::MakeUnique<Record>();
record->key = Key().as_string();
record->deleted = true;
+ transaction_->size_ +=
+ LevelDBTransaction::SizeOfRecordInMap(record->key.size());
transaction_->data_[record->key] = std::move(record);
}
}

Powered by Google App Engine
This is Rietveld 408576698