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

Unified Diff: content/child/child_discardable_shared_memory_manager.cc

Issue 952273005: content: Update crash key and discardable memory usage counter in child process. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: make sure crash key and trace counter is updated if needed in dtor Created 5 years, 10 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/child/child_discardable_shared_memory_manager.cc
diff --git a/content/child/child_discardable_shared_memory_manager.cc b/content/child/child_discardable_shared_memory_manager.cc
index b1a6b8098267b189dd218c6e196a80fea27c810b..bd62a93b6dfebdfc185131b3f6cc5d5f57fba703 100644
--- a/content/child/child_discardable_shared_memory_manager.cc
+++ b/content/child/child_discardable_shared_memory_manager.cc
@@ -4,8 +4,11 @@
#include "content/child/child_discardable_shared_memory_manager.h"
+#include "base/debug/crash_logging.h"
#include "base/memory/discardable_shared_memory.h"
#include "base/process/process_metrics.h"
+#include "base/strings/string_number_conversions.h"
+#include "base/trace_event/trace_event.h"
#include "content/common/child_process_messages.h"
namespace content {
@@ -43,10 +46,12 @@ class DiscardableMemoryShmemChunkImpl
ChildDiscardableSharedMemoryManager::ChildDiscardableSharedMemoryManager(
ThreadSafeSender* sender)
- : heap_(base::GetPageSize()), sender_(sender) {
+ : heap_(base::GetPageSize()), sender_(sender), bytes_allocated_(0) {
}
ChildDiscardableSharedMemoryManager::~ChildDiscardableSharedMemoryManager() {
+ if (bytes_allocated_)
+ BytesAllocatedChanged(0);
}
scoped_ptr<base::DiscardableMemoryShmemChunk>
@@ -75,7 +80,11 @@ ChildDiscardableSharedMemoryManager::AllocateLockedDiscardableMemory(
base::DiscardableSharedMemory::FAILED) {
DCHECK(!free_span->shared_memory()->IsMemoryResident());
// We have to release free memory before |free_span| can be destroyed.
- heap_.ReleaseFreeMemory();
+ size_t bytes_released = heap_.ReleaseFreeMemory();
+ DCHECK_NE(bytes_released, 0u);
+ DCHECK_LE(bytes_released, bytes_allocated_);
+ bytes_allocated_ -= bytes_released;
+ BytesAllocatedChanged(bytes_allocated_);
DCHECK(!free_span->shared_memory());
continue;
}
@@ -86,7 +95,12 @@ ChildDiscardableSharedMemoryManager::AllocateLockedDiscardableMemory(
// Release free memory and free up the address space. Failing to do this
// can result in the child process running out of address space.
- heap_.ReleaseFreeMemory();
+ size_t bytes_released = heap_.ReleaseFreeMemory();
+ if (bytes_released) {
+ DCHECK_LE(bytes_released, bytes_allocated_);
+ bytes_allocated_ -= bytes_released;
+ BytesAllocatedChanged(bytes_allocated_);
+ }
size_t pages_to_allocate =
std::max(kAllocationSize / base::GetPageSize(), pages);
@@ -96,6 +110,11 @@ ChildDiscardableSharedMemoryManager::AllocateLockedDiscardableMemory(
scoped_ptr<base::DiscardableSharedMemory> shared_memory(
AllocateLockedDiscardableSharedMemory(allocation_size_in_bytes));
+ // Note: use mapped size rather than |allocation_size_in_bytes| as
+ // the later only represent the amount of memory available for usage.
Avi (use Gerrit) 2015/02/26 16:21:15 ... the latter only represents ...
reveman 2015/02/26 16:55:44 Done.
+ bytes_allocated_ += shared_memory->mapped_size();
+ BytesAllocatedChanged(bytes_allocated_);
+
// Create span for allocated memory.
scoped_ptr<DiscardableSharedMemoryHeap::Span> new_span(
heap_.Grow(shared_memory.Pass(), allocation_size_in_bytes));
@@ -118,7 +137,12 @@ ChildDiscardableSharedMemoryManager::AllocateLockedDiscardableMemory(
void ChildDiscardableSharedMemoryManager::ReleaseFreeMemory() {
base::AutoLock lock(lock_);
- heap_.ReleaseFreeMemory();
+ size_t bytes_released = heap_.ReleaseFreeMemory();
+ if (bytes_released) {
+ DCHECK_LE(bytes_released, bytes_allocated_);
+ bytes_allocated_ -= bytes_released;
+ BytesAllocatedChanged(bytes_allocated_);
+ }
}
bool ChildDiscardableSharedMemoryManager::LockSpan(
@@ -194,4 +218,14 @@ ChildDiscardableSharedMemoryManager::AllocateLockedDiscardableSharedMemory(
return memory.Pass();
}
+void ChildDiscardableSharedMemoryManager::BytesAllocatedChanged(
+ size_t new_bytes_allocated) const {
+ TRACE_COUNTER_ID1("renderer", "DiscardableMemoryUsage", this,
+ new_bytes_allocated);
+
+ static const char kDiscardableMemoryUsageKey[] = "dm-usage";
+ base::debug::SetCrashKeyValue(kDiscardableMemoryUsageKey,
+ base::Uint64ToString(new_bytes_allocated));
+}
+
} // namespace content
« no previous file with comments | « content/child/child_discardable_shared_memory_manager.h ('k') | content/common/discardable_shared_memory_heap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698