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

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

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

Powered by Google App Engine
This is Rietveld 408576698