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

Side by Side Diff: base/chromeos/memory_pressure_observer_chromeos.cc

Issue 874483008: Add UMA stats to get the quality of service of memory pressure handling scheme in ChromeOS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address the code review comment. Created 5 years, 10 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "base/chromeos/memory_pressure_observer_chromeos.h" 5 #include "base/chromeos/memory_pressure_observer_chromeos.h"
6 6
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/metrics/histogram_macros.h"
8 #include "base/process/process_metrics.h" 9 #include "base/process/process_metrics.h"
9 #include "base/time/time.h" 10 #include "base/time/time.h"
10 11
11 namespace base { 12 namespace base {
12 13
13 namespace { 14 namespace {
14 15
15 // The time between memory pressure checks. While under critical pressure, this 16 // The time between memory pressure checks. While under critical pressure, this
16 // is also the timer to repeat cleanup attempts. 17 // is also the timer to repeat cleanup attempts.
17 const int kMemoryPressureIntervalMs = 1000; 18 const int kMemoryPressureIntervalMs = 1000;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 68
68 MemoryPressureObserverChromeOS::MemoryPressureObserverChromeOS( 69 MemoryPressureObserverChromeOS::MemoryPressureObserverChromeOS(
69 MemoryPressureThresholds thresholds) 70 MemoryPressureThresholds thresholds)
70 : current_memory_pressure_level_( 71 : current_memory_pressure_level_(
71 MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE), 72 MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE),
72 moderate_pressure_repeat_count_(0), 73 moderate_pressure_repeat_count_(0),
73 moderate_pressure_threshold_percent_( 74 moderate_pressure_threshold_percent_(
74 GetModerateMemoryThresholdInPercent(thresholds)), 75 GetModerateMemoryThresholdInPercent(thresholds)),
75 critical_pressure_threshold_percent_( 76 critical_pressure_threshold_percent_(
76 GetCriticalMemoryThresholdInPercent(thresholds)), 77 GetCriticalMemoryThresholdInPercent(thresholds)),
78 non_critical_start_time_(TimeTicks::Now()),
79 critical_start_time_(TimeTicks::Now()),
77 weak_ptr_factory_(this) { 80 weak_ptr_factory_(this) {
78 StartObserving(); 81 StartObserving();
79 } 82 }
80 83
81 MemoryPressureObserverChromeOS::~MemoryPressureObserverChromeOS() { 84 MemoryPressureObserverChromeOS::~MemoryPressureObserverChromeOS() {
85 // Record the percentage for the last time.
86 if (GetMemoryPressureLevelFromFillLevel(
87 GetUsedMemoryInPercent(), moderate_pressure_threshold_percent_,
88 critical_pressure_threshold_percent_) ==
89 MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) {
90 non_critical_delta_ = critical_start_time_ - non_critical_start_time_;
91 critical_delta_ = TimeTicks::Now() - critical_start_time_;
92 int percentage = (100 * non_critical_delta_.InMilliseconds()) /
93 ((non_critical_delta_ + critical_delta_).InMilliseconds());
Mr4D (OOO till 08-26) 2015/01/29 08:17:53 For line 90 - 93 I would create a function which c
xdai1 2015/01/31 00:01:39 Why should the function that writes the UMA stat b
94 UMA_HISTOGRAM_PERCENTAGE(
95 "ChromeOS.MemoryPressureHandleQuality.NonCriticalRatio", percentage);
96 } else {
97 UMA_HISTOGRAM_PERCENTAGE(
98 "ChromeOS.MemoryPressureHandleQuality.NonCriticalRatio", 100);
99 }
100
82 StopObserving(); 101 StopObserving();
83 } 102 }
84 103
85 void MemoryPressureObserverChromeOS::ScheduleEarlyCheck() { 104 void MemoryPressureObserverChromeOS::ScheduleEarlyCheck() {
86 MessageLoop::current()->PostTask( 105 MessageLoop::current()->PostTask(
87 FROM_HERE, 106 FROM_HERE,
88 Bind(&MemoryPressureObserverChromeOS::CheckMemoryPressure, 107 Bind(&MemoryPressureObserverChromeOS::CheckMemoryPressure,
89 weak_ptr_factory_.GetWeakPtr())); 108 weak_ptr_factory_.GetWeakPtr()));
90 } 109 }
91 110
92 void MemoryPressureObserverChromeOS::StartObserving() { 111 void MemoryPressureObserverChromeOS::StartObserving() {
93 timer_.Start(FROM_HERE, 112 timer_.Start(FROM_HERE,
94 TimeDelta::FromMilliseconds(kMemoryPressureIntervalMs), 113 TimeDelta::FromMilliseconds(kMemoryPressureIntervalMs),
95 Bind(&MemoryPressureObserverChromeOS::CheckMemoryPressure, 114 Bind(&MemoryPressureObserverChromeOS::CheckMemoryPressure,
96 weak_ptr_factory_.GetWeakPtr())); 115 weak_ptr_factory_.GetWeakPtr()));
97 } 116 }
98 117
99 void MemoryPressureObserverChromeOS::StopObserving() { 118 void MemoryPressureObserverChromeOS::StopObserving() {
100 // If StartObserving failed, StopObserving will still get called. 119 // If StartObserving failed, StopObserving will still get called.
101 timer_.Stop(); 120 timer_.Stop();
102 } 121 }
103 122
104 void MemoryPressureObserverChromeOS::CheckMemoryPressure() { 123 void MemoryPressureObserverChromeOS::CheckMemoryPressure() {
105 MemoryPressureListener::MemoryPressureLevel old_pressure = 124 MemoryPressureListener::MemoryPressureLevel old_pressure =
106 current_memory_pressure_level_; 125 current_memory_pressure_level_;
107 current_memory_pressure_level_ = 126 current_memory_pressure_level_ =
108 GetMemoryPressureLevelFromFillLevel(GetUsedMemoryInPercent(), 127 GetMemoryPressureLevelFromFillLevel(GetUsedMemoryInPercent(),
109 moderate_pressure_threshold_percent_, 128 moderate_pressure_threshold_percent_,
110 critical_pressure_threshold_percent_); 129 critical_pressure_threshold_percent_);
130
131 // Record quality of service of memory pressure handling scheme in ChromeOS.
Mr4D (OOO till 08-26) 2015/01/29 08:17:53 Maybe: // Record the quality of service for memor
xdai1 2015/01/31 00:01:39 Done.
132 if (old_pressure != current_memory_pressure_level_) {
133 if (old_pressure ==
134 MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) {
135 critical_delta_ = TimeTicks::Now() - critical_start_time_;
Mr4D (OOO till 08-26) 2015/01/29 08:17:53 Note: As stated in the header file we do not need
xdai1 2015/01/31 00:01:39 Done.
136 non_critical_start_time_ = TimeTicks::Now();
137
Mr4D (OOO till 08-26) 2015/01/29 08:17:53 What about: When leaving the critical memory pre
xdai1 2015/01/31 00:01:39 Done.
138 // We compute the percentage of the system stayed in non-critical memory
139 // pressure state each time when the system left the critical memory
140 // pressure state. The larger the percentage is, the better the memory
141 // pressure handling scheme is.
142 int percentage =
143 (100 * non_critical_delta_.InMilliseconds()) /
144 ((non_critical_delta_ + critical_delta_).InMilliseconds());
145 UMA_HISTOGRAM_PERCENTAGE(
146 "ChromeOS.MemoryPressureHandleQuality.NonCriticalRatio", percentage);
147
148 } else if (current_memory_pressure_level_ ==
149 MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) {
150 non_critical_delta_ = TimeTicks::Now() - non_critical_start_time_;
151 critical_start_time_ = TimeTicks::Now();
152 }
153 }
154
111 // In case there is no memory pressure we do not notify. 155 // In case there is no memory pressure we do not notify.
112 if (current_memory_pressure_level_ == 156 if (current_memory_pressure_level_ ==
113 MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE) { 157 MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE) {
114 return; 158 return;
115 } 159 }
116 if (old_pressure == current_memory_pressure_level_) { 160 if (old_pressure == current_memory_pressure_level_) {
117 // If the memory pressure is still at the same level, we notify again for a 161 // If the memory pressure is still at the same level, we notify again for a
118 // critical level. In case of a moderate level repeat however, we only send 162 // critical level. In case of a moderate level repeat however, we only send
119 // a notification after a certain time has passed. 163 // a notification after a certain time has passed.
120 if (current_memory_pressure_level_ == 164 if (current_memory_pressure_level_ ==
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 // Available memory is the sum of free, swap and easy reclaimable memory. 212 // Available memory is the sum of free, swap and easy reclaimable memory.
169 int available_memory = 213 int available_memory =
170 info.free + info.swap_free / kSwapWeight + file_memory; 214 info.free + info.swap_free / kSwapWeight + file_memory;
171 215
172 DCHECK(available_memory < total_memory); 216 DCHECK(available_memory < total_memory);
173 int percentage = ((total_memory - available_memory) * 100) / total_memory; 217 int percentage = ((total_memory - available_memory) * 100) / total_memory;
174 return percentage; 218 return percentage;
175 } 219 }
176 220
177 } // namespace base 221 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698