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

Unified Diff: src/base/accounting-allocator.cc

Issue 2050173002: [DoNotSubmit] Added peak_memory_size to accounting-allocator. Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 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 | « src/base/accounting-allocator.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/base/accounting-allocator.cc
diff --git a/src/base/accounting-allocator.cc b/src/base/accounting-allocator.cc
index 2269c60680c0e1d13b542ebbc9a56451382560b5..72a9deeb6553f4b0cd6705128b334422e4d8f795 100644
--- a/src/base/accounting-allocator.cc
+++ b/src/base/accounting-allocator.cc
@@ -15,18 +15,31 @@ namespace base {
void* AccountingAllocator::Allocate(size_t bytes) {
void* memory = malloc(bytes);
- if (memory) NoBarrier_AtomicIncrement(&current_memory_usage_, bytes);
+ if (memory) {
+ LockGuard<Mutex> guard(&mutex_);
+ current_memory_usage_ += bytes;
+ if (peak_memory_usage_ < current_memory_usage_)
+ peak_memory_usage_ = current_memory_usage_;
+ }
return memory;
}
void AccountingAllocator::Free(void* memory, size_t bytes) {
free(memory);
- NoBarrier_AtomicIncrement(&current_memory_usage_,
- -static_cast<AtomicWord>(bytes));
+ {
+ LockGuard<Mutex> guard(&mutex_);
+ current_memory_usage_ -= bytes;
+ }
}
size_t AccountingAllocator::GetCurrentMemoryUsage() const {
- return NoBarrier_Load(&current_memory_usage_);
+ LockGuard<Mutex> guard(const_cast<Mutex*>(&mutex_));
+ return current_memory_usage_;
+}
+
+size_t AccountingAllocator::GetPeakMemoryUsage() const {
+ LockGuard<Mutex> guard(const_cast<Mutex*>(&mutex_));
+ return peak_memory_usage_;
}
} // namespace base
« no previous file with comments | « src/base/accounting-allocator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698