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

Side by Side Diff: chrome/browser/memory/memory_kills_monitor_unittest.cc

Issue 2721553004: Remove auto raw pointer deduction from non-linux specific code. (Closed)
Patch Set: rebase Created 3 years, 9 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 "chrome/browser/memory/memory_kills_monitor.h" 5 #include "chrome/browser/memory/memory_kills_monitor.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/metrics/histogram_base.h" 8 #include "base/metrics/histogram_base.h"
9 #include "base/metrics/histogram_samples.h" 9 #include "base/metrics/histogram_samples.h"
10 #include "base/metrics/statistics_recorder.h" 10 #include "base/metrics/statistics_recorder.h"
11 #include "base/time/time.h" 11 #include "base/time/time.h"
12 #include "chrome/browser/memory/memory_kills_histogram.h" 12 #include "chrome/browser/memory/memory_kills_histogram.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 namespace memory { 15 namespace memory {
16 16
17 using MemoryKillsMonitorTest = testing::Test; 17 using MemoryKillsMonitorTest = testing::Test;
18 18
19 TEST_F(MemoryKillsMonitorTest, LogLowMemoryKill) { 19 TEST_F(MemoryKillsMonitorTest, LogLowMemoryKill) {
20 MemoryKillsMonitor::LogLowMemoryKill("APP", 123); 20 MemoryKillsMonitor::LogLowMemoryKill("APP", 123);
21 MemoryKillsMonitor::LogLowMemoryKill("APP", 100); 21 MemoryKillsMonitor::LogLowMemoryKill("APP", 100);
22 MemoryKillsMonitor::LogLowMemoryKill("TAB", 10000); 22 MemoryKillsMonitor::LogLowMemoryKill("TAB", 10000);
23 23
24 auto histogram_count = 24 auto* histogram_count =
25 base::StatisticsRecorder::FindHistogram("Arc.LowMemoryKiller.Count"); 25 base::StatisticsRecorder::FindHistogram("Arc.LowMemoryKiller.Count");
26 ASSERT_TRUE(histogram_count); 26 ASSERT_TRUE(histogram_count);
27 auto count_samples = histogram_count->SnapshotSamples(); 27 auto count_samples = histogram_count->SnapshotSamples();
28 EXPECT_EQ(3, count_samples->TotalCount()); 28 EXPECT_EQ(3, count_samples->TotalCount());
29 EXPECT_EQ(1, count_samples->GetCount(1)); 29 EXPECT_EQ(1, count_samples->GetCount(1));
30 EXPECT_EQ(1, count_samples->GetCount(2)); 30 EXPECT_EQ(1, count_samples->GetCount(2));
31 EXPECT_EQ(1, count_samples->GetCount(3)); 31 EXPECT_EQ(1, count_samples->GetCount(3));
32 32
33 auto histogram_freed_size = 33 auto* histogram_freed_size =
34 base::StatisticsRecorder::FindHistogram("Arc.LowMemoryKiller.FreedSize"); 34 base::StatisticsRecorder::FindHistogram("Arc.LowMemoryKiller.FreedSize");
35 ASSERT_TRUE(histogram_freed_size); 35 ASSERT_TRUE(histogram_freed_size);
36 auto freed_size_samples = histogram_freed_size->SnapshotSamples(); 36 auto freed_size_samples = histogram_freed_size->SnapshotSamples();
37 EXPECT_EQ(3, freed_size_samples->TotalCount()); 37 EXPECT_EQ(3, freed_size_samples->TotalCount());
38 // 123 and 100 are in the same bucket. 38 // 123 and 100 are in the same bucket.
39 EXPECT_EQ(2, freed_size_samples->GetCount(123)); 39 EXPECT_EQ(2, freed_size_samples->GetCount(123));
40 EXPECT_EQ(2, freed_size_samples->GetCount(100)); 40 EXPECT_EQ(2, freed_size_samples->GetCount(100));
41 EXPECT_EQ(1, freed_size_samples->GetCount(10000)); 41 EXPECT_EQ(1, freed_size_samples->GetCount(10000));
42 42
43 auto histogram_time_delta = 43 auto* histogram_time_delta =
44 base::StatisticsRecorder::FindHistogram("Arc.LowMemoryKiller.TimeDelta"); 44 base::StatisticsRecorder::FindHistogram("Arc.LowMemoryKiller.TimeDelta");
45 ASSERT_TRUE(histogram_time_delta); 45 ASSERT_TRUE(histogram_time_delta);
46 auto time_delta_samples = histogram_time_delta->SnapshotSamples(); 46 auto time_delta_samples = histogram_time_delta->SnapshotSamples();
47 EXPECT_EQ(3, time_delta_samples->TotalCount()); 47 EXPECT_EQ(3, time_delta_samples->TotalCount());
48 // First time delta is set to kMaxMemoryKillTimeDelta. 48 // First time delta is set to kMaxMemoryKillTimeDelta.
49 EXPECT_EQ(1, time_delta_samples->GetCount( 49 EXPECT_EQ(1, time_delta_samples->GetCount(
50 kMaxMemoryKillTimeDelta.InMilliseconds())); 50 kMaxMemoryKillTimeDelta.InMilliseconds()));
51 // Time delta for the other 2 events depends on Now() so we skip testing it 51 // Time delta for the other 2 events depends on Now() so we skip testing it
52 // here. 52 // here.
53 } 53 }
54 54
55 TEST_F(MemoryKillsMonitorTest, TryMatchOomKillLine) { 55 TEST_F(MemoryKillsMonitorTest, TryMatchOomKillLine) {
56 const char* sample_lines[] = { 56 const char* sample_lines[] = {
57 "3,3429,812967386,-;Out of memory: Kill process 8291 (handle-watcher-) " 57 "3,3429,812967386,-;Out of memory: Kill process 8291 (handle-watcher-) "
58 "score 674 or sacrifice child", 58 "score 674 or sacrifice child",
59 "3,3431,812981331,-;Out of memory: Kill process 8271 (.gms.persistent) " 59 "3,3431,812981331,-;Out of memory: Kill process 8271 (.gms.persistent) "
60 "score 652 or sacrifice child", 60 "score 652 or sacrifice child",
61 "3,3433,812993014,-;Out of memory: Kill process 9210 (lowpool[11]) " 61 "3,3433,812993014,-;Out of memory: Kill process 9210 (lowpool[11]) "
62 "score 653 or sacrifice child" 62 "score 653 or sacrifice child"
63 }; 63 };
64 64
65 for (unsigned long i = 0; i < arraysize(sample_lines); ++i) { 65 for (unsigned long i = 0; i < arraysize(sample_lines); ++i) {
66 MemoryKillsMonitor::TryMatchOomKillLine(sample_lines[i]); 66 MemoryKillsMonitor::TryMatchOomKillLine(sample_lines[i]);
67 } 67 }
68 68
69 auto histogram_count = 69 auto* histogram_count =
70 base::StatisticsRecorder::FindHistogram("Arc.OOMKills.Count"); 70 base::StatisticsRecorder::FindHistogram("Arc.OOMKills.Count");
71 ASSERT_TRUE(histogram_count); 71 ASSERT_TRUE(histogram_count);
72 auto count_samples = histogram_count->SnapshotSamples(); 72 auto count_samples = histogram_count->SnapshotSamples();
73 EXPECT_EQ(3, count_samples->TotalCount()); 73 EXPECT_EQ(3, count_samples->TotalCount());
74 EXPECT_EQ(1, count_samples->GetCount(1)); 74 EXPECT_EQ(1, count_samples->GetCount(1));
75 EXPECT_EQ(1, count_samples->GetCount(2)); 75 EXPECT_EQ(1, count_samples->GetCount(2));
76 EXPECT_EQ(1, count_samples->GetCount(3)); 76 EXPECT_EQ(1, count_samples->GetCount(3));
77 77
78 auto histogram_score = 78 auto* histogram_score =
79 base::StatisticsRecorder::FindHistogram("Arc.OOMKills.Score"); 79 base::StatisticsRecorder::FindHistogram("Arc.OOMKills.Score");
80 ASSERT_TRUE(histogram_score); 80 ASSERT_TRUE(histogram_score);
81 auto score_samples = histogram_score->SnapshotSamples(); 81 auto score_samples = histogram_score->SnapshotSamples();
82 EXPECT_EQ(3, score_samples->TotalCount()); 82 EXPECT_EQ(3, score_samples->TotalCount());
83 EXPECT_EQ(1, score_samples->GetCount(674)); 83 EXPECT_EQ(1, score_samples->GetCount(674));
84 EXPECT_EQ(1, score_samples->GetCount(652)); 84 EXPECT_EQ(1, score_samples->GetCount(652));
85 EXPECT_EQ(1, score_samples->GetCount(653)); 85 EXPECT_EQ(1, score_samples->GetCount(653));
86 86
87 auto histogram_time_delta = 87 auto* histogram_time_delta =
88 base::StatisticsRecorder::FindHistogram("Arc.OOMKills.TimeDelta"); 88 base::StatisticsRecorder::FindHistogram("Arc.OOMKills.TimeDelta");
89 ASSERT_TRUE(histogram_time_delta); 89 ASSERT_TRUE(histogram_time_delta);
90 auto time_delta_samples = histogram_time_delta->SnapshotSamples(); 90 auto time_delta_samples = histogram_time_delta->SnapshotSamples();
91 EXPECT_EQ(3, time_delta_samples->TotalCount()); 91 EXPECT_EQ(3, time_delta_samples->TotalCount());
92 // First time delta is set to kMaxMemoryKillTimeDelta. 92 // First time delta is set to kMaxMemoryKillTimeDelta.
93 EXPECT_EQ(1, time_delta_samples->GetCount( 93 EXPECT_EQ(1, time_delta_samples->GetCount(
94 kMaxMemoryKillTimeDelta.InMilliseconds())); 94 kMaxMemoryKillTimeDelta.InMilliseconds()));
95 EXPECT_EQ(1, time_delta_samples->GetCount(11)); 95 EXPECT_EQ(1, time_delta_samples->GetCount(11));
96 EXPECT_EQ(1, time_delta_samples->GetCount(13)); 96 EXPECT_EQ(1, time_delta_samples->GetCount(13));
97 } 97 }
98 98
99 } // namespace memory 99 } // namespace memory
OLDNEW
« no previous file with comments | « chrome/browser/mac/exception_processor.mm ('k') | chrome/browser/password_manager/password_store_mac.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698