diff options
author | gspencer@chromium.org <gspencer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-03 20:30:43 +0000 |
---|---|---|
committer | gspencer@chromium.org <gspencer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-03 20:30:43 +0000 |
commit | 232ed4691df490e376c74ecf04f2f6092f03427f (patch) | |
tree | 3dd09707acccf9eb175e592b4f0fbade06a5015b /chrome/browser | |
parent | 9a4fd693db2ee9e383f7a826d50bc63bc5bf7db0 (diff) | |
download | chromium_src-232ed4691df490e376c74ecf04f2f6092f03427f.zip chromium_src-232ed4691df490e376c74ecf04f2f6092f03427f.tar.gz chromium_src-232ed4691df490e376c74ecf04f2f6092f03427f.tar.bz2 |
This creates a field trial to determine the best level for low memory
notification.
It creates a field trial with 7 groups: default (kernel default
value), turning notification off (relying on OOM killer only), 0MB, 25MB, 50MB
margin, 100MB margin, and 200MB margin.
Also, in order to set parameters for the trial, this CL creates
an API for setting the low memory margin.
BUG=chromium-os:20080
TEST=Ran on device several times, checked that the memory margin was
set correctly when the session started, and that different trial groups
were selected.
Review URL: http://codereview.chromium.org/10206029
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@135205 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/chromeos/chrome_browser_main_chromeos.cc | 56 | ||||
-rw-r--r-- | chrome/browser/chromeos/chrome_browser_main_chromeos.h | 4 | ||||
-rw-r--r-- | chrome/browser/low_memory_observer.cc | 10 | ||||
-rw-r--r-- | chrome/browser/low_memory_observer.h | 5 | ||||
-rw-r--r-- | chrome/browser/oom_priority_manager.cc | 45 | ||||
-rw-r--r-- | chrome/browser/ui/views/sad_tab_view.cc | 43 |
6 files changed, 134 insertions, 29 deletions
diff --git a/chrome/browser/chromeos/chrome_browser_main_chromeos.cc b/chrome/browser/chromeos/chrome_browser_main_chromeos.cc index ea86e8f..5563502 100644 --- a/chrome/browser/chromeos/chrome_browser_main_chromeos.cc +++ b/chrome/browser/chromeos/chrome_browser_main_chromeos.cc @@ -49,6 +49,7 @@ #include "chrome/browser/chromeos/web_socket_proxy_controller.h" #include "chrome/browser/chromeos/xinput_hierarchy_changed_event_listener.h" #include "chrome/browser/defaults.h" +#include "chrome/browser/low_memory_observer.h" #include "chrome/browser/metrics/metrics_service.h" #include "chrome/browser/oom_priority_manager.h" #include "chrome/browser/policy/browser_policy_connector.h" @@ -59,6 +60,7 @@ #include "chrome/browser/ui/views/browser_dialogs.h" #include "chrome/common/chrome_notification_types.h" #include "chrome/common/chrome_switches.h" +#include "chrome/common/chrome_version_info.h" #include "chrome/common/logging_chrome.h" #include "chrome/common/pref_names.h" #include "chromeos/dbus/dbus_thread_manager.h" @@ -285,6 +287,13 @@ void ChromeBrowserMainPartsChromeos::PostMainMessageLoopStart() { ChromeBrowserMainPartsLinux::PostMainMessageLoopStart(); } +int ChromeBrowserMainPartsChromeos::PreCreateThreads() { + // Set up field trial for low memory headroom settings. + SetupLowMemoryHeadroomFieldTrial(); + + return ChromeBrowserMainPartsLinux::PreCreateThreads(); +} + // Threads are initialized MainMessageLoopStart and MainMessageLoopRun. void ChromeBrowserMainPartsChromeos::PreMainMessageLoopRun() { @@ -495,3 +504,50 @@ void ChromeBrowserMainPartsChromeos::PostMainMessageLoopRun() { ChromeBrowserMainPartsLinux::PostMainMessageLoopRun(); } + +void ChromeBrowserMainPartsChromeos::SetupLowMemoryHeadroomFieldTrial() { + chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); + // Only enable this experiment on Canary and Dev, since it's possible + // that this will make the machine unstable. + // Note that to have this code execute in a developer build, + // then chrome::VersionInfo::CHANNEL_UNKNOWN needs to be added here. + if (channel == chrome::VersionInfo::CHANNEL_CANARY || + channel == chrome::VersionInfo::CHANNEL_DEV) { + const base::FieldTrial::Probability kDivisor = 7; + // 1 in 7 probability of being in each group. If the default value for the + // kernel matches one of the experiment groups, then they will have + // identical results. + const base::FieldTrial::Probability kEnableProbability = 1; + scoped_refptr<base::FieldTrial> trial = + base::FieldTrialList::FactoryGetFieldTrial( + "LowMemoryMargin", kDivisor, "default", 2012, 6, 30, NULL); + int disable = trial->AppendGroup("off", kEnableProbability); + int margin_0mb = trial->AppendGroup("0mb", kEnableProbability); + int margin_25mb = trial->AppendGroup("25mb", kEnableProbability); + int margin_50mb = trial->AppendGroup("50mb", kEnableProbability); + int margin_100mb = trial->AppendGroup("100mb", kEnableProbability); + int margin_200mb = trial->AppendGroup("200mb", kEnableProbability); + if (trial->group() == disable) { + LOG(WARNING) << "low_mem: Part of 'off' experiment"; + browser::LowMemoryObserver::SetLowMemoryMargin(0); + } else if (trial->group() == margin_0mb) { + LOG(WARNING) << "low_mem: Part of '0MB' experiment"; + browser::LowMemoryObserver::SetLowMemoryMargin(50); + } else if (trial->group() == margin_25mb) { + LOG(WARNING) << "low_mem: Part of '25MB' experiment"; + browser::LowMemoryObserver::SetLowMemoryMargin(50); + } else if (trial->group() == margin_50mb) { + LOG(WARNING) << "low_mem: Part of '50MB' experiment"; + browser::LowMemoryObserver::SetLowMemoryMargin(50); + } else if (trial->group() == margin_100mb) { + LOG(WARNING) << "low_mem: Part of '100MB' experiment"; + browser::LowMemoryObserver::SetLowMemoryMargin(100); + } else if (trial->group() == margin_200mb) { + LOG(WARNING) << "low_mem: Part of '200MB' experiment"; + browser::LowMemoryObserver::SetLowMemoryMargin(200); + } else { + LOG(WARNING) << "low_mem: Part of 'default' experiment"; + } + } +} + diff --git a/chrome/browser/chromeos/chrome_browser_main_chromeos.h b/chrome/browser/chromeos/chrome_browser_main_chromeos.h index a001ea1..4cc2a61 100644 --- a/chrome/browser/chromeos/chrome_browser_main_chromeos.h +++ b/chrome/browser/chromeos/chrome_browser_main_chromeos.h @@ -30,6 +30,7 @@ class ChromeBrowserMainPartsChromeos : public ChromeBrowserMainPartsLinux { virtual void PreEarlyInitialization() OVERRIDE; virtual void PreMainMessageLoopStart() OVERRIDE; virtual void PostMainMessageLoopStart() OVERRIDE; + virtual int PreCreateThreads() OVERRIDE; virtual void PreMainMessageLoopRun() OVERRIDE; // Stages called from PreMainMessageLoopRun. @@ -40,6 +41,9 @@ class ChromeBrowserMainPartsChromeos : public ChromeBrowserMainPartsLinux { virtual void PostMainMessageLoopRun() OVERRIDE; + // Set up field trial for low memory headroom settings. + void SetupLowMemoryHeadroomFieldTrial(); + private: scoped_ptr<chromeos::BrightnessObserver> brightness_observer_; scoped_ptr<chromeos::ResumeObserver> resume_observer_; diff --git a/chrome/browser/low_memory_observer.cc b/chrome/browser/low_memory_observer.cc index 8788f03..5396696 100644 --- a/chrome/browser/low_memory_observer.cc +++ b/chrome/browser/low_memory_observer.cc @@ -15,6 +15,11 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/oom_priority_manager.h" #include "content/public/browser/browser_thread.h" +#include "content/public/browser/zygote_host_linux.h" + +#if !defined(OS_CHROMEOS) +#error This file only meant to be compiled on ChromeOS +#endif using content::BrowserThread; @@ -180,4 +185,9 @@ void LowMemoryObserver::Stop() { observer_.get())); } +// static +void LowMemoryObserver::SetLowMemoryMargin(int64 margin_mb) { + content::ZygoteHost::GetInstance()->AdjustLowMemoryMargin(margin_mb); +} + } // namespace browser diff --git a/chrome/browser/low_memory_observer.h b/chrome/browser/low_memory_observer.h index 088a74c..1caad25 100644 --- a/chrome/browser/low_memory_observer.h +++ b/chrome/browser/low_memory_observer.h @@ -34,6 +34,11 @@ class LowMemoryObserver { void Start(); void Stop(); + + // Sets the threshold level of the low memory notifier in megabytes. Setting + // to -1 will turn off the low memory notifier. + static void SetLowMemoryMargin(int64 margin_mb); + private: scoped_refptr<LowMemoryObserverImpl> observer_; diff --git a/chrome/browser/oom_priority_manager.cc b/chrome/browser/oom_priority_manager.cc index 0d87d4c..60fa186 100644 --- a/chrome/browser/oom_priority_manager.cc +++ b/chrome/browser/oom_priority_manager.cc @@ -10,6 +10,7 @@ #include "base/bind.h" #include "base/bind_helpers.h" #include "base/command_line.h" +#include "base/metrics/field_trial.h" #include "base/metrics/histogram.h" #include "base/process.h" #include "base/process_util.h" @@ -51,14 +52,25 @@ namespace browser { namespace { +// Name of the experiment to run. +const char kExperiment[] = "LowMemoryMargin"; + +#define EXPERIMENT_CUSTOM_COUNTS(name, sample, min, max, buckets) \ + UMA_HISTOGRAM_CUSTOM_COUNTS(name, sample, min, max, buckets); \ + if (base::FieldTrialList::TrialExists(kExperiment)) \ + UMA_HISTOGRAM_CUSTOM_COUNTS( \ + base::FieldTrial::MakeName(name, kExperiment), \ + sample, min, max, buckets); + // Record a time in seconds, over a potential interval of about a day. Must be a // macro and not a function because the histograms system requires a unique // static variable at the site of each call. -#define UMA_HISTOGRAM_SECONDS(name, sample) UMA_HISTOGRAM_CUSTOM_COUNTS( \ - name, sample, 1, 10000, 50) +#define EXPERIMENT_HISTOGRAM_SECONDS(name, sample) \ + EXPERIMENT_CUSTOM_COUNTS(name, sample, 1, 10000, 50) + // Record a size in megabytes, over a potential interval up to 32 GB. -#define UMA_HISTOGRAM_MEGABYTES(name, sample) UMA_HISTOGRAM_CUSTOM_COUNTS( \ - name, sample, 1, 32768, 50) +#define EXPERIMENT_HISTOGRAM_MEGABYTES(name, sample) \ + EXPERIMENT_CUSTOM_COUNTS(name, sample, 1, 32768, 50) // The default interval in seconds after which to adjust the oom_score_adj // value. @@ -241,11 +253,11 @@ bool OomPriorityManager::DiscardTabById(int64 target_web_contents_id) { void OomPriorityManager::RecordDiscardStatistics() { // Record a raw count so we can compare to discard reloads. discard_count_++; - UMA_HISTOGRAM_CUSTOM_COUNTS( - "Tabs.Discard.DiscardCount", discard_count_, 1, 1000, 50); + EXPERIMENT_CUSTOM_COUNTS("Tabs.Discard.DiscardCount", + discard_count_, 1, 1000, 50); // TODO(jamescook): Maybe incorporate extension count? - UMA_HISTOGRAM_COUNTS_100("Tabs.Discard.TabCount", GetTabCount()); + EXPERIMENT_CUSTOM_COUNTS("Tabs.Discard.TabCount", GetTabCount(), 1, 100, 50); // TODO(jamescook): If the time stats prove too noisy, then divide up users // based on how heavily they use Chrome using tab count as a proxy. @@ -254,23 +266,24 @@ void OomPriorityManager::RecordDiscardStatistics() { // This is the first discard this session. TimeDelta interval = TimeTicks::Now() - start_time_; int interval_seconds = static_cast<int>(interval.InSeconds()); - UMA_HISTOGRAM_SECONDS("Tabs.Discard.InitialTime", interval_seconds); + EXPERIMENT_HISTOGRAM_SECONDS("Tabs.Discard.InitialTime", interval_seconds); } else { // Not the first discard, so compute time since last discard. TimeDelta interval = TimeTicks::Now() - last_discard_time_; int interval_seconds = static_cast<int>(interval.InSeconds()); - UMA_HISTOGRAM_SECONDS("Tabs.Discard.IntervalTime", interval_seconds); + EXPERIMENT_HISTOGRAM_SECONDS("Tabs.Discard.IntervalTime", interval_seconds); } // Record Chrome's concept of system memory usage at the time of the discard. base::SystemMemoryInfoKB memory; if (base::GetSystemMemoryInfo(&memory)) { - int mem_anonymous_kb = memory.active_anon + memory.inactive_anon; - UMA_HISTOGRAM_MEGABYTES("Tabs.Discard.MemAnonymousMB", - mem_anonymous_kb / 1024); - int mem_available_kb = - memory.active_file + memory.inactive_file + memory.free; - UMA_HISTOGRAM_MEGABYTES("Tabs.Discard.MemAvailableMB", - mem_available_kb / 1024); + int mem_anonymous_mb = (memory.active_anon + memory.inactive_anon) / 1024; + EXPERIMENT_HISTOGRAM_MEGABYTES("Tabs.Discard.MemAnonymousMB", + mem_anonymous_mb); + + int mem_available_mb = + (memory.active_file + memory.inactive_file + memory.free) / 1024; + EXPERIMENT_HISTOGRAM_MEGABYTES("Tabs.Discard.MemAvailableMB", + mem_available_mb); } // Set up to record the next interval. last_discard_time_ = TimeTicks::Now(); diff --git a/chrome/browser/ui/views/sad_tab_view.cc b/chrome/browser/ui/views/sad_tab_view.cc index d64b2ac..566cf9b 100644 --- a/chrome/browser/ui/views/sad_tab_view.cc +++ b/chrome/browser/ui/views/sad_tab_view.cc @@ -6,6 +6,7 @@ #include <string> +#include "base/metrics/field_trial.h" #include "base/metrics/histogram.h" #include "base/utf_string_conversions.h" #include "chrome/browser/feedback/feedback_util.h" @@ -28,23 +29,37 @@ using content::OpenURLParams; using content::WebContents; -static const int kPadding = 20; -static const float kMessageSize = 0.65f; -static const SkColor kTextColor = SK_ColorWHITE; -static const SkColor kCrashColor = SkColorSetRGB(35, 48, 64); -static const SkColor kKillColor = SkColorSetRGB(57, 48, 88); +namespace { + +const int kPadding = 20; +const float kMessageSize = 0.65f; +const SkColor kTextColor = SK_ColorWHITE; +const SkColor kCrashColor = SkColorSetRGB(35, 48, 64); +const SkColor kKillColor = SkColorSetRGB(57, 48, 88); const char kCategoryTagCrash[] = "Crash"; // Font size correction. #if defined(CROS_FONTS_USING_BCI) -static const int kTitleFontSizeDelta = 1; -static const int kMessageFontSizeDelta = 0; +const int kTitleFontSizeDelta = 1; +const int kMessageFontSizeDelta = 0; #else -static const int kTitleFontSizeDelta = 2; -static const int kMessageFontSizeDelta = 1; +const int kTitleFontSizeDelta = 2; +const int kMessageFontSizeDelta = 1; #endif +// Name of the experiment to run. +const char kExperiment[] = "LowMemoryMargin"; + +#define EXPERIMENT_CUSTOM_COUNTS(name, sample, min, max, buckets) \ + UMA_HISTOGRAM_CUSTOM_COUNTS(name, sample, min, max, buckets); \ + if (base::FieldTrialList::TrialExists(kExperiment)) \ + UMA_HISTOGRAM_CUSTOM_COUNTS( \ + base::FieldTrial::MakeName(name, kExperiment), \ + sample, min, max, buckets); + +} // namespace + SadTabView::SadTabView(WebContents* web_contents, Kind kind) : web_contents_(web_contents), kind_(kind), @@ -70,14 +85,16 @@ SadTabView::SadTabView(WebContents* web_contents, Kind kind) switch (kind_) { case CRASHED: { static int crashed = 0; - UMA_HISTOGRAM_CUSTOM_COUNTS( - "Tabs.SadTab.CrashCreated", ++crashed, 1, 1000, 50); + crashed++; + EXPERIMENT_CUSTOM_COUNTS( + "Tabs.SadTab.CrashCreated", crashed, 1, 1000, 50); break; } case KILLED: { static int killed = 0; - UMA_HISTOGRAM_CUSTOM_COUNTS( - "Tabs.SadTab.KillCreated", ++killed, 1, 1000, 50); + killed++; + EXPERIMENT_CUSTOM_COUNTS( + "Tabs.SadTab.KillCreated", killed, 1, 1000, 50); break; } default: |