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

Unified Diff: chrome/browser/chromeos/chrome_browser_main_chromeos.cc

Issue 11744024: Add zram field trial (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix compilation again, sigh Created 7 years, 11 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/chrome_browser_main_chromeos.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/chrome_browser_main_chromeos.cc
diff --git a/chrome/browser/chromeos/chrome_browser_main_chromeos.cc b/chrome/browser/chromeos/chrome_browser_main_chromeos.cc
index 5b947a9e19b4326db91819aa26438e4bca14b706..cb8018cda1d91677d6120294d33e791592539b38 100644
--- a/chrome/browser/chromeos/chrome_browser_main_chromeos.cc
+++ b/chrome/browser/chromeos/chrome_browser_main_chromeos.cc
@@ -12,6 +12,7 @@
#include "base/callback.h"
#include "base/chromeos/chromeos_version.h"
#include "base/command_line.h"
+#include "base/file_util.h"
#include "base/lazy_instance.h"
#include "base/linux_util.h"
#include "base/message_loop.h"
@@ -717,6 +718,7 @@ void ChromeBrowserMainPartsChromeos::PostMainMessageLoopRun() {
void ChromeBrowserMainPartsChromeos::SetupPlatformFieldTrials() {
SetupLowMemoryHeadroomFieldTrial();
+ SetupZramFieldTrial();
}
void ChromeBrowserMainPartsChromeos::SetupLowMemoryHeadroomFieldTrial() {
@@ -765,4 +767,40 @@ void ChromeBrowserMainPartsChromeos::SetupLowMemoryHeadroomFieldTrial() {
}
}
+
+void ChromeBrowserMainPartsChromeos::SetupZramFieldTrial() {
+ // The dice for this experiment have been thrown at boot. The selected group
+ // number is stored in a file.
+ const FilePath kZramGroupPath("/home/chronos/.swap_exp_enrolled");
+ std::string zram_file_content;
+ // If the file does not exist, the experiment has not started.
+ if (!file_util::ReadFileToString(kZramGroupPath, &zram_file_content))
+ return;
+ // The file contains a single significant character, possibly followed by
+ // newline. "x" means the user has opted out. "0" through "8" are the valid
+ // group names. (See src/platform/init/swap-exp.conf in chromiumos repo for
+ // group meanings.)
+ std::string zram_group = zram_file_content.substr(0, 1);
+ if (zram_group.compare("x") == 0)
+ return;
+ const base::FieldTrial::Probability kDivisor = 1; // on/off only
+ scoped_refptr<base::FieldTrial> trial =
+ base::FieldTrialList::FactoryGetFieldTrial(
+ "ZRAM", kDivisor, "default", 2013, 12, 31, NULL);
+ // Assign probability of 1 to the group Chrome OS has picked. Assign 0 to
+ // all other choices.
+ const char* const kGroups[] = { "0", "1", "2", "3", "4", "5", "6", "7", "8" };
+ bool matched = false;
+ for (size_t i = 0; i < arraysize(kGroups); ++i) {
+ bool match = zram_group.compare(kGroups[i]) == 0;
+ trial->AppendGroup(kGroups[i], match ? 1 : 0);
+ if (match) {
+ matched = true;
+ LOG(WARNING) << "zram field trial: group " << kGroups[i];
+ }
+ }
+ if (!matched)
+ LOG(WARNING) << "zram field trial: invalid group \"" << zram_group << "\"";
+}
+
} // namespace chromeos
« no previous file with comments | « chrome/browser/chromeos/chrome_browser_main_chromeos.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698