Commit 37b6dbdc authored by Sebastien Marchand's avatar Sebastien Marchand Committed by Commit Bot

Put the RAM limit to classify a device as LowEnd behind a feature flag

Having this feature will make it easier to measure the various impact of
changing this value.

Bug: 896687
Change-Id: I4f976a41dc402c1b1b49625c4105cee3814a12fe
Reviewed-on: https://chromium-review.googlesource.com/c/1288892Reviewed-by: default avatarErik Chen <erikchen@chromium.org>
Reviewed-by: default avatarFrançois Doray <fdoray@chromium.org>
Commit-Queue: Sébastien Marchand <sebmarchand@chromium.org>
Cr-Commit-Position: refs/heads/master@{#601038}
parent 035f4f55
...@@ -10,9 +10,11 @@ ...@@ -10,9 +10,11 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/callback.h" #include "base/callback.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/feature_list.h"
#include "base/lazy_instance.h" #include "base/lazy_instance.h"
#include "base/location.h" #include "base/location.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/metrics/field_trial_params.h"
#include "base/sys_info_internal.h" #include "base/sys_info_internal.h"
#include "base/task/post_task.h" #include "base/task/post_task.h"
#include "base/task/task_traits.h" #include "base/task/task_traits.h"
...@@ -22,14 +24,28 @@ ...@@ -22,14 +24,28 @@
namespace base { namespace base {
namespace { namespace {
static const int kLowMemoryDeviceThresholdMB = 512;
// Feature used to control the heuristics used to categorize a device as low
// end.
const base::Feature kLowEndDeviceDetectionFeature{
"LowEndDeviceDetection", base::FEATURE_DISABLED_BY_DEFAULT};
static const int kLowMemoryDeviceThresholdMBDefault = 512;
int GetLowMemoryDeviceThresholdMB() {
static constexpr base::FeatureParam<int> kLowEndDeviceMemoryThresholdMB{
&kLowEndDeviceDetectionFeature, "LowEndDeviceMemoryThresholdMB",
kLowMemoryDeviceThresholdMBDefault};
// If the feature is disabled then |Get| will return the default value.
return kLowEndDeviceMemoryThresholdMB.Get();
}
} }
// static // static
int64_t SysInfo::AmountOfPhysicalMemory() { int64_t SysInfo::AmountOfPhysicalMemory() {
if (base::CommandLine::ForCurrentProcess()->HasSwitch( if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableLowEndDeviceMode)) { switches::kEnableLowEndDeviceMode)) {
return kLowMemoryDeviceThresholdMB * 1024 * 1024; return GetLowMemoryDeviceThresholdMB() * 1024 * 1024;
} }
return AmountOfPhysicalMemoryImpl(); return AmountOfPhysicalMemoryImpl();
...@@ -40,10 +56,10 @@ int64_t SysInfo::AmountOfAvailablePhysicalMemory() { ...@@ -40,10 +56,10 @@ int64_t SysInfo::AmountOfAvailablePhysicalMemory() {
if (base::CommandLine::ForCurrentProcess()->HasSwitch( if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableLowEndDeviceMode)) { switches::kEnableLowEndDeviceMode)) {
// Estimate the available memory by subtracting our memory used estimate // Estimate the available memory by subtracting our memory used estimate
// from the fake |kLowMemoryDeviceThresholdMB| limit. // from the fake |GetLowMemoryDeviceThresholdMB()| limit.
size_t memory_used = size_t memory_used =
AmountOfPhysicalMemoryImpl() - AmountOfAvailablePhysicalMemoryImpl(); AmountOfPhysicalMemoryImpl() - AmountOfAvailablePhysicalMemoryImpl();
size_t memory_limit = kLowMemoryDeviceThresholdMB * 1024 * 1024; size_t memory_limit = GetLowMemoryDeviceThresholdMB() * 1024 * 1024;
// std::min ensures no underflow, as |memory_used| can be > |memory_limit|. // std::min ensures no underflow, as |memory_used| can be > |memory_limit|.
return memory_limit - std::min(memory_used, memory_limit); return memory_limit - std::min(memory_used, memory_limit);
} }
...@@ -70,7 +86,7 @@ bool DetectLowEndDevice() { ...@@ -70,7 +86,7 @@ bool DetectLowEndDevice() {
return false; return false;
int ram_size_mb = SysInfo::AmountOfPhysicalMemoryMB(); int ram_size_mb = SysInfo::AmountOfPhysicalMemoryMB();
return (ram_size_mb > 0 && ram_size_mb <= kLowMemoryDeviceThresholdMB); return (ram_size_mb > 0 && ram_size_mb <= GetLowMemoryDeviceThresholdMB());
} }
static LazyInstance< static LazyInstance<
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment