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

Side by Side Diff: base/memory/memory_pressure_monitor.cc

Issue 2434103003: Add Mac memory pressure statistic reporting and consolidate platform code (Closed)
Patch Set: Add radar ID Created 4 years, 1 month 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
« no previous file with comments | « base/memory/memory_pressure_monitor.h ('k') | base/memory/memory_pressure_monitor_chromeos.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/memory/memory_pressure_monitor.h" 5 #include "base/memory/memory_pressure_monitor.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/metrics/histogram_macros.h"
8 9
9 namespace base { 10 namespace base {
10 namespace { 11 namespace {
11 12
12 MemoryPressureMonitor* g_monitor = nullptr; 13 MemoryPressureMonitor* g_monitor = nullptr;
13 14
15 // Enumeration of UMA memory pressure levels. This needs to be kept in sync with
16 // histograms.xml and the memory pressure levels defined in
17 // MemoryPressureListener.
18 enum MemoryPressureLevelUMA {
19 UMA_MEMORY_PRESSURE_LEVEL_NONE = 0,
20 UMA_MEMORY_PRESSURE_LEVEL_MODERATE = 1,
21 UMA_MEMORY_PRESSURE_LEVEL_CRITICAL = 2,
22 // This must be the last value in the enum.
23 UMA_MEMORY_PRESSURE_LEVEL_COUNT,
24 };
25
26 // Converts a memory pressure level to an UMA enumeration value.
27 MemoryPressureLevelUMA MemoryPressureLevelToUmaEnumValue(
28 base::MemoryPressureListener::MemoryPressureLevel level) {
29 switch (level) {
30 case MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE:
31 return UMA_MEMORY_PRESSURE_LEVEL_NONE;
32 case MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE:
33 return UMA_MEMORY_PRESSURE_LEVEL_MODERATE;
34 case MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL:
35 return UMA_MEMORY_PRESSURE_LEVEL_CRITICAL;
36 }
37 NOTREACHED();
38 return UMA_MEMORY_PRESSURE_LEVEL_NONE;
39 }
40
14 } // namespace 41 } // namespace
15 42
16 MemoryPressureMonitor::MemoryPressureMonitor() { 43 MemoryPressureMonitor::MemoryPressureMonitor() {
17 DCHECK(!g_monitor); 44 DCHECK(!g_monitor);
18 g_monitor = this; 45 g_monitor = this;
19 } 46 }
20 47
21 MemoryPressureMonitor::~MemoryPressureMonitor() { 48 MemoryPressureMonitor::~MemoryPressureMonitor() {
22 DCHECK(g_monitor); 49 DCHECK(g_monitor);
23 g_monitor = nullptr; 50 g_monitor = nullptr;
24 } 51 }
25 52
26 // static 53 // static
27 MemoryPressureMonitor* MemoryPressureMonitor::Get() { 54 MemoryPressureMonitor* MemoryPressureMonitor::Get() {
28 return g_monitor; 55 return g_monitor;
29 } 56 }
57 void MemoryPressureMonitor::RecordMemoryPressure(
58 base::MemoryPressureListener::MemoryPressureLevel level,
59 int ticks) {
60 // Use the more primitive STATIC_HISTOGRAM_POINTER_BLOCK macro because the
61 // simple UMA_HISTOGRAM macros don't expose 'AddCount' functionality.
62 STATIC_HISTOGRAM_POINTER_BLOCK(
63 "Memory.PressureLevel",
64 AddCount(MemoryPressureLevelToUmaEnumValue(level), ticks),
65 base::LinearHistogram::FactoryGet(
66 "Memory.PressureLevel", 1, UMA_MEMORY_PRESSURE_LEVEL_COUNT,
67 UMA_MEMORY_PRESSURE_LEVEL_COUNT + 1,
68 base::HistogramBase::kUmaTargetedHistogramFlag));
69 }
30 70
31 } // namespace base 71 } // namespace base
OLDNEW
« no previous file with comments | « base/memory/memory_pressure_monitor.h ('k') | base/memory/memory_pressure_monitor_chromeos.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698