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

Unified Diff: chrome/browser/memory/tab_manager.cc

Issue 2350423003: [Tentaive patch for discussion] Add Purge+Suspend metrics as UMA.
Patch Set: Add UMA to tab_manager Created 4 years, 3 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: chrome/browser/memory/tab_manager.cc
diff --git a/chrome/browser/memory/tab_manager.cc b/chrome/browser/memory/tab_manager.cc
index 582b2e667099f6fa0085f6721c4b9c69a37709c8..1daa6acd181f7a7756b7fd967fabdf041948d5d1 100644
--- a/chrome/browser/memory/tab_manager.cc
+++ b/chrome/browser/memory/tab_manager.cc
@@ -20,6 +20,7 @@
#include "base/metrics/histogram_macros.h"
#include "base/observer_list.h"
#include "base/process/process.h"
+#include "base/process/process_metrics.h"
#include "base/strings/string16.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
@@ -670,6 +671,45 @@ void TabManager::UpdateTimerCallback() {
PurgeAndSuspendBackgroundedTabs();
}
+bool TabManager::CanPurgeAndSuspendBackgroundedTab(
+ int64_t target_web_contents_id) const {
+ TabStripModel* model;
+ int idx = FindTabStripModelById(target_web_contents_id, &model);
+
+ if (idx == -1)
+ return false;
+
+ WebContents* web_contents = model->GetWebContentsAt(idx);
+
+ // Do not suspend tabs that are playing either playing audio or accessing the
+ // microphone or camera as it's too distruptive to the user experience.
+ if (IsMediaTab(web_contents))
+ return false;
+
+ if (web_contents->GetContentsMimeType() == "application/pdf")
+ return false;
+
+ // Do not purge and suspend a tab that was explicitly disallowed to.
+ // Note: reused tab discarding logic.
+ if (!IsTabAutoDiscardable(web_contents))
+ return false;
+
+ return true;
+}
+
+void TabManager::RecordPurgeAndSuspendMetrics(
+ const base::ProcessHandle& handle) {
+ std::unique_ptr<base::ProcessMetrics> process_metrics(
+ base::ProcessMetrics::CreateProcessMetrics(handle));
+ size_t private_bytes, shared_bytes;
+ if (process_metrics->GetMemoryBytes(&private_bytes, &shared_bytes)) {
+ UMA_HISTOGRAM_MEMORY_KB("Memory.PurgeAndSuspend.PrivateBytesKB",
+ private_bytes);
+ UMA_HISTOGRAM_MEMORY_KB("Memory.PurgeAndSuspend.SharedBytesKB",
+ shared_bytes);
+ }
+}
+
void TabManager::PurgeAndSuspendBackgroundedTabs() {
const base::CommandLine& command_line =
*base::CommandLine::ForCurrentProcess();
@@ -695,7 +735,26 @@ void TabManager::PurgeAndSuspendBackgroundedTabs() {
// timers if we want necessary and sufficient signals.
if (tab.last_active > purge_and_suspend_time_threshold)
continue;
- tab.render_process_host->PurgeAndSuspend();
+
+ if (CanPurgeAndSuspendBackgroundedTab(tab.tab_contents_id))
+ continue;
+
+ if (tab.render_process_host->GetLastPurgeAndSuspendTime() <
+ tab.last_active) {
+ // If purge_and_suspend is disabled, PurgeAndSuspend() just updates
+ // LastPurgeAndSuspendTime. So we can avoid invoking
+ // RecordPurgeAndSuspendMetrics twice.
+ tab.render_process_host->PurgeAndSuspend();
+
+ if (!task_runner_.get())
+ task_runner_ = base::ThreadTaskRunnerHandle::Get();
+ task_runner_->PostDelayedTask(
+ FROM_HERE,
+ base::Bind(&TabManager::RecordPurgeAndSuspendMetrics,
+ base::Unretained(this),
+ base::ConstRef(tab.render_process_host->GetHandle())),
+ base::TimeDelta::FromSeconds(15));
+ }
}
}

Powered by Google App Engine
This is Rietveld 408576698