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

Unified Diff: chrome/browser/chromeos/status/memory_menu_button.cc

Issue 7607035: CrOS - Memory debug widget shows anonymous memory and renderer kills. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressing review comments Created 9 years, 4 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 | « chrome/browser/chromeos/status/memory_menu_button.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/status/memory_menu_button.cc
diff --git a/chrome/browser/chromeos/status/memory_menu_button.cc b/chrome/browser/chromeos/status/memory_menu_button.cc
index 606ebc16ebc5732c9b2efafd743668ac88466510..634c985098427726eaeb711aae38370010a42ed3 100644
--- a/chrome/browser/chromeos/status/memory_menu_button.cc
+++ b/chrome/browser/chromeos/status/memory_menu_button.cc
@@ -8,6 +8,8 @@
#include "base/stringprintf.h"
#include "chrome/browser/chromeos/status/status_area_host.h"
#include "chrome/browser/memory_purger.h"
+#include "content/browser/renderer_host/render_process_host.h"
+#include "content/common/notification_service.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
#include "views/widget/widget.h"
@@ -33,11 +35,12 @@ const int kUpdateIntervalSeconds = 5;
MemoryMenuButton::MemoryMenuButton(StatusAreaHost* host)
: StatusAreaButton(host, this),
- mem_total_(0),
- shmem_(0),
- mem_free_(0),
- mem_buffers_(0),
- mem_cache_(0) {
+ meminfo_(new base::SystemMemoryInfoKB()),
+ renderer_kills_(0) {
+ // Track renderer kills, as the kernel OOM killer will start to kill our
+ // renderers as we run out of memory.
+ registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED,
+ NotificationService::AllSources());
UpdateTextAndSetNextTimer();
}
@@ -52,17 +55,20 @@ void MemoryMenuButton::UpdateTextAndSetNextTimer() {
}
void MemoryMenuButton::UpdateText() {
- base::GetSystemMemoryInfo(&mem_total_, &mem_free_, &mem_buffers_, &mem_cache_,
- &shmem_);
- std::wstring label = base::StringPrintf(L"%d MB", mem_free_ / 1024);
+ base::GetSystemMemoryInfo(meminfo_.get());
+ // "Anonymous" memory, meaning not mapped to a file (which has a name),
+ // represents memory that has been dynamically allocated to a process.
+ // It thus approximates heap memory usage across all processes.
+ int anon_kb = meminfo_->active_anon + meminfo_->inactive_anon;
+ std::wstring label = base::StringPrintf(L"%d MB (%d)",
+ anon_kb / 1024,
+ renderer_kills_);
SetText(label);
std::wstring tooltip = base::StringPrintf(
- L"%d MB total\n%d MB free\n%d MB buffers\n%d MB cache\n%d MB shmem",
- mem_total_ / 1024,
- mem_free_ / 1024,
- mem_buffers_ / 1024,
- mem_cache_ / 1024,
- shmem_ / 1024);
+ L"%d MB allocated (anonymous)\n"
+ L"%d renderer kill(s)",
+ anon_kb / 1024,
+ renderer_kills_);
SetTooltipText(tooltip);
SchedulePaint();
}
@@ -71,15 +77,15 @@ void MemoryMenuButton::UpdateText() {
std::wstring MemoryMenuButton::GetLabel(int id) const {
switch (id) {
case MEM_TOTAL_ITEM:
- return StringPrintf(L"%d MB total", mem_total_ / 1024);
+ return StringPrintf(L"%d MB total", meminfo_->total / 1024);
case MEM_FREE_ITEM:
- return StringPrintf(L"%d MB free", mem_free_ / 1024);
+ return StringPrintf(L"%d MB free", meminfo_->free / 1024);
case MEM_BUFFERS_ITEM:
- return StringPrintf(L"%d MB buffers", mem_buffers_ / 1024);
+ return StringPrintf(L"%d MB buffers", meminfo_->buffers / 1024);
case MEM_CACHE_ITEM:
- return StringPrintf(L"%d MB cache", mem_cache_ / 1024);
+ return StringPrintf(L"%d MB cache", meminfo_->cached / 1024);
case SHMEM_ITEM:
- return StringPrintf(L"%d MB shmem", shmem_ / 1024);
+ return StringPrintf(L"%d MB shmem", meminfo_->shmem / 1024);
case PURGE_MEMORY_ITEM:
return L"Purge memory";
default:
@@ -146,4 +152,28 @@ void MemoryMenuButton::EnsureMenu() {
menu_->AppendDelegateMenuItem(PURGE_MEMORY_ITEM);
}
+/////////////////////////////////////////////////////////////////////////////
+// NotificationObserver overrides.
+
+void MemoryMenuButton::Observe(int type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ switch (type) {
+ case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: {
+ RenderProcessHost::RendererClosedDetails* process_details =
+ Details<RenderProcessHost::RendererClosedDetails>(details).ptr();
+ if (process_details->status ==
+ base::TERMINATION_STATUS_PROCESS_WAS_KILLED) {
+ renderer_kills_++;
+ // A kill is a very interesting event, so repaint immediately.
+ UpdateText();
+ }
+ break;
+ }
+ default:
+ NOTREACHED() << L"Received unexpected notification";
+ break;
+ }
+}
+
} // namespace chromeos
« no previous file with comments | « chrome/browser/chromeos/status/memory_menu_button.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698