OLD | NEW |
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/metrics/leak_detector_controller.h" | 5 #include "chrome/browser/metrics/leak_detector_controller.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 EXPECT_EQ(4U, proto.max_stack_depth()); | 62 EXPECT_EQ(4U, proto.max_stack_depth()); |
63 EXPECT_EQ(32U * 1024 * 1024, proto.analysis_interval_bytes()); | 63 EXPECT_EQ(32U * 1024 * 1024, proto.analysis_interval_bytes()); |
64 EXPECT_EQ(4U, proto.size_suspicion_threshold()); | 64 EXPECT_EQ(4U, proto.size_suspicion_threshold()); |
65 EXPECT_EQ(4U, proto.call_stack_suspicion_threshold()); | 65 EXPECT_EQ(4U, proto.call_stack_suspicion_threshold()); |
66 | 66 |
67 // No more reports. | 67 // No more reports. |
68 controller->GetLeakReports(&stored_reports); | 68 controller->GetLeakReports(&stored_reports); |
69 ASSERT_EQ(0U, stored_reports.size()); | 69 ASSERT_EQ(0U, stored_reports.size()); |
70 } | 70 } |
71 | 71 |
| 72 TEST(LeakDetectorControllerTest, SingleReportHistory) { |
| 73 LeakReport report; |
| 74 report.alloc_breakdown_history.resize(3); |
| 75 report.alloc_breakdown_history[0].counts_by_size = {100, 200, 300}; |
| 76 report.alloc_breakdown_history[0].count_for_call_stack = 15; |
| 77 report.alloc_breakdown_history[1].counts_by_size = {150, 250, 350, 650}; |
| 78 report.alloc_breakdown_history[1].count_for_call_stack = 30; |
| 79 report.alloc_breakdown_history[2].counts_by_size = {200, 300, 400, 700, 800}; |
| 80 report.alloc_breakdown_history[2].count_for_call_stack = 45; |
| 81 |
| 82 TestLeakDetectorController* controller = &g_instance.Get(); |
| 83 controller->OnLeakFound(report); |
| 84 |
| 85 std::vector<MemoryLeakReportProto> stored_reports; |
| 86 controller->GetLeakReports(&stored_reports); |
| 87 ASSERT_EQ(1U, stored_reports.size()); |
| 88 |
| 89 const auto& history = stored_reports[0].alloc_breakdown_history(); |
| 90 ASSERT_EQ(3, history.size()); |
| 91 |
| 92 ASSERT_EQ(3, history.Get(0).counts_by_size().size()); |
| 93 EXPECT_EQ(100U, history.Get(0).counts_by_size(0)); |
| 94 EXPECT_EQ(200U, history.Get(0).counts_by_size(1)); |
| 95 EXPECT_EQ(300U, history.Get(0).counts_by_size(2)); |
| 96 EXPECT_EQ(15U, history.Get(0).count_for_call_stack()); |
| 97 |
| 98 ASSERT_EQ(4, history.Get(1).counts_by_size_size()); |
| 99 EXPECT_EQ(150U, history.Get(1).counts_by_size(0)); |
| 100 EXPECT_EQ(250U, history.Get(1).counts_by_size(1)); |
| 101 EXPECT_EQ(350U, history.Get(1).counts_by_size(2)); |
| 102 EXPECT_EQ(650U, history.Get(1).counts_by_size(3)); |
| 103 EXPECT_EQ(30U, history.Get(1).count_for_call_stack()); |
| 104 |
| 105 ASSERT_EQ(5, history.Get(2).counts_by_size_size()); |
| 106 EXPECT_EQ(200U, history.Get(2).counts_by_size(0)); |
| 107 EXPECT_EQ(300U, history.Get(2).counts_by_size(1)); |
| 108 EXPECT_EQ(400U, history.Get(2).counts_by_size(2)); |
| 109 EXPECT_EQ(700U, history.Get(2).counts_by_size(3)); |
| 110 EXPECT_EQ(800U, history.Get(2).counts_by_size(4)); |
| 111 EXPECT_EQ(45U, history.Get(2).count_for_call_stack()); |
| 112 |
| 113 // No more reports. |
| 114 controller->GetLeakReports(&stored_reports); |
| 115 ASSERT_EQ(0U, stored_reports.size()); |
| 116 } |
| 117 |
72 TEST(LeakDetectorControllerTest, MultipleReportsSeparately) { | 118 TEST(LeakDetectorControllerTest, MultipleReportsSeparately) { |
73 TestLeakDetectorController* controller = &g_instance.Get(); | 119 TestLeakDetectorController* controller = &g_instance.Get(); |
74 std::vector<MemoryLeakReportProto> stored_reports; | 120 std::vector<MemoryLeakReportProto> stored_reports; |
75 | 121 |
76 // Pass in first report. | 122 // Pass in first report. |
77 LeakReport report; | 123 LeakReport report; |
78 report.alloc_size_bytes = 8; | 124 report.alloc_size_bytes = 8; |
79 report.call_stack = {1, 2, 3, 4}; | 125 report.call_stack = {1, 2, 3, 4}; |
80 | 126 |
81 controller->OnLeakFound(report); | 127 controller->OnLeakFound(report); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 EXPECT_EQ(13U, stored_reports[2].call_stack().Get(4)); | 225 EXPECT_EQ(13U, stored_reports[2].call_stack().Get(4)); |
180 EXPECT_EQ(14U, stored_reports[2].call_stack().Get(5)); | 226 EXPECT_EQ(14U, stored_reports[2].call_stack().Get(5)); |
181 EXPECT_EQ(15U, stored_reports[2].call_stack().Get(6)); | 227 EXPECT_EQ(15U, stored_reports[2].call_stack().Get(6)); |
182 EXPECT_EQ(16U, stored_reports[2].call_stack().Get(7)); | 228 EXPECT_EQ(16U, stored_reports[2].call_stack().Get(7)); |
183 | 229 |
184 controller->GetLeakReports(&stored_reports); | 230 controller->GetLeakReports(&stored_reports); |
185 ASSERT_EQ(0U, stored_reports.size()); | 231 ASSERT_EQ(0U, stored_reports.size()); |
186 } | 232 } |
187 | 233 |
188 } // namespace metrics | 234 } // namespace metrics |
OLD | NEW |