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

Side by Side Diff: net/disk_cache/simple/simple_experiment.cc

Issue 2918893002: evict larger entries first (Closed)
Patch Set: -SortHelper Created 3 years, 5 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/disk_cache/simple/simple_experiment.h" 5 #include "net/disk_cache/simple/simple_experiment.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 9
10 #include "base/metrics/field_trial.h" 10 #include "base/metrics/field_trial.h"
11 #include "base/metrics/field_trial_param_associator.h" 11 #include "base/metrics/field_trial_param_associator.h"
12 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
13 13
14 namespace disk_cache { 14 namespace disk_cache {
15 15
16 const base::Feature kSimpleSizeExperiment = {"SimpleSizeExperiment", 16 const base::Feature kSimpleSizeExperiment = {"SimpleSizeExperiment",
17 base::FEATURE_DISABLED_BY_DEFAULT}; 17 base::FEATURE_DISABLED_BY_DEFAULT};
18 const base::Feature kSimpleCacheEvictionWithSizeExperiment = {
19 "SimpleCacheEvictionWithSizeExperiment", base::FEATURE_DISABLED_BY_DEFAULT};
20
18 const char kSizeMultiplierParam[] = "SizeMultiplier"; 21 const char kSizeMultiplierParam[] = "SizeMultiplier";
22 const char kSizeEvictionParam[] = "SizeEviction";
19 23
20 namespace { 24 namespace {
21 25
22 // Returns true if the experiment is found and properly defined. 26 struct ExperimentDescription {
23 bool CheckForSimpleSizeExperiment(disk_cache::SimpleExperiment* experiment) { 27 disk_cache::SimpleExperimentType experiment_type;
24 DCHECK_EQ(disk_cache::SimpleExperimentType::NONE, experiment->type); 28 const base::Feature* feature;
25 DCHECK_EQ(0u, experiment->param); 29 const char* param_name;
30 };
26 31
27 if (!base::FeatureList::IsEnabled(kSimpleSizeExperiment)) 32 // List of experimens to be checked for.
28 return false; 33 const ExperimentDescription experiments[] = {
29 34 {disk_cache::SimpleExperimentType::SIZE, &kSimpleSizeExperiment,
30 base::FieldTrial* trial = 35 kSizeMultiplierParam},
31 base::FeatureList::GetFieldTrial(kSimpleSizeExperiment); 36 {disk_cache::SimpleExperimentType::EVICT_WITH_SIZE,
32 if (!trial) 37 &kSimpleCacheEvictionWithSizeExperiment, kSizeEvictionParam},
33 return false; 38 };
34
35 std::map<std::string, std::string> params;
36 base::FieldTrialParamAssociator::GetInstance()->GetFieldTrialParams(
37 trial->trial_name(), &params);
38 auto iter = params.find(kSizeMultiplierParam);
39 if (iter == params.end())
40 return false;
41
42 uint32_t param;
43 if (!base::StringToUint(iter->second, &param))
44 return false;
45
46 experiment->type = disk_cache::SimpleExperimentType::SIZE;
47 experiment->param = param;
48 return true;
49 }
50 39
51 } // namespace 40 } // namespace
52 41
53 // Returns the experiment for the given |cache_type|. 42 // Returns the experiment for the given |cache_type|.
54 SimpleExperiment GetSimpleExperiment(net::CacheType cache_type) { 43 SimpleExperiment GetSimpleExperiment(net::CacheType cache_type) {
55 SimpleExperiment experiment; 44 SimpleExperiment experiment;
56
57 if (cache_type != net::DISK_CACHE) 45 if (cache_type != net::DISK_CACHE)
58 return experiment; 46 return experiment;
59 47
60 CheckForSimpleSizeExperiment(&experiment); 48 for (size_t i = 0; i < arraysize(experiments); i++) {
49 if (!base::FeatureList::IsEnabled(*experiments[i].feature))
50 continue;
51
52 base::FieldTrial* trial =
53 base::FeatureList::GetFieldTrial(*experiments[i].feature);
54 if (!trial)
55 continue;
56
57 std::map<std::string, std::string> params;
58 base::FieldTrialParamAssociator::GetInstance()->GetFieldTrialParams(
59 trial->trial_name(), &params);
60 auto iter = params.find(experiments[i].param_name);
61 if (iter == params.end())
62 continue;
63
64 uint32_t param;
65 if (!base::StringToUint(iter->second, &param))
66 continue;
67
68 experiment.type = experiments[i].experiment_type;
69 experiment.param = param;
70 return experiment;
71 }
72
61 return experiment; 73 return experiment;
62 } 74 }
63 75
64 } // namespace disk_cache 76 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/disk_cache/simple/simple_experiment.h ('k') | net/disk_cache/simple/simple_experiment_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698