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

Side by Side Diff: components/browser_watcher/watcher_metrics_provider_win_unittest.cc

Issue 868163002: Only report exit funnels for canary and dev channels. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address Alexei's comments. Created 5 years, 11 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
« no previous file with comments | « components/browser_watcher/watcher_metrics_provider_win.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "components/browser_watcher/watcher_metrics_provider_win.h" 5 #include "components/browser_watcher/watcher_metrics_provider_win.h"
6 6
7 #include <cstdlib> 7 #include <cstdlib>
8 8
9 #include "base/process/process_handle.h" 9 #include "base/process/process_handle.h"
10 #include "base/strings/string16.h" 10 #include "base/strings/string16.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 } // namespace 74 } // namespace
75 75
76 TEST_F(WatcherMetricsProviderWinTest, RecordsStabilityHistogram) { 76 TEST_F(WatcherMetricsProviderWinTest, RecordsStabilityHistogram) {
77 // Record multiple success exits. 77 // Record multiple success exits.
78 for (size_t i = 0; i < 11; ++i) 78 for (size_t i = 0; i < 11; ++i)
79 AddProcessExitCode(false, 0); 79 AddProcessExitCode(false, 0);
80 80
81 // Record a single failure. 81 // Record a single failure.
82 AddProcessExitCode(false, 100); 82 AddProcessExitCode(false, 100);
83 83
84 WatcherMetricsProviderWin provider(kRegistryPath); 84 WatcherMetricsProviderWin provider(kRegistryPath, true);
85 85
86 provider.ProvideStabilityMetrics(NULL); 86 provider.ProvideStabilityMetrics(NULL);
87 histogram_tester_.ExpectBucketCount( 87 histogram_tester_.ExpectBucketCount(
88 WatcherMetricsProviderWin::kBrowserExitCodeHistogramName, 0, 11); 88 WatcherMetricsProviderWin::kBrowserExitCodeHistogramName, 0, 11);
89 histogram_tester_.ExpectBucketCount( 89 histogram_tester_.ExpectBucketCount(
90 WatcherMetricsProviderWin::kBrowserExitCodeHistogramName, 100, 1); 90 WatcherMetricsProviderWin::kBrowserExitCodeHistogramName, 100, 1);
91 histogram_tester_.ExpectTotalCount( 91 histogram_tester_.ExpectTotalCount(
92 WatcherMetricsProviderWin::kBrowserExitCodeHistogramName, 12); 92 WatcherMetricsProviderWin::kBrowserExitCodeHistogramName, 12);
93 93
94 // Verify that the reported values are gone. 94 // Verify that the reported values are gone.
95 EXPECT_EQ(ExitCodeRegistryPathValueCount(), 0); 95 EXPECT_EQ(ExitCodeRegistryPathValueCount(), 0);
96 } 96 }
97 97
98 TEST_F(WatcherMetricsProviderWinTest, DoesNotReportOwnProcessId) { 98 TEST_F(WatcherMetricsProviderWinTest, DoesNotReportOwnProcessId) {
99 // Record multiple success exits. 99 // Record multiple success exits.
100 for (size_t i = 0; i < 11; ++i) 100 for (size_t i = 0; i < 11; ++i)
101 AddProcessExitCode(i, 0); 101 AddProcessExitCode(i, 0);
102 102
103 // Record own process as STILL_ACTIVE. 103 // Record own process as STILL_ACTIVE.
104 AddProcessExitCode(true, STILL_ACTIVE); 104 AddProcessExitCode(true, STILL_ACTIVE);
105 105
106 WatcherMetricsProviderWin provider(kRegistryPath); 106 WatcherMetricsProviderWin provider(kRegistryPath, true);
107 107
108 provider.ProvideStabilityMetrics(NULL); 108 provider.ProvideStabilityMetrics(NULL);
109 histogram_tester_.ExpectUniqueSample( 109 histogram_tester_.ExpectUniqueSample(
110 WatcherMetricsProviderWin::kBrowserExitCodeHistogramName, 0, 11); 110 WatcherMetricsProviderWin::kBrowserExitCodeHistogramName, 0, 11);
111 111
112 // Verify that the reported values are gone. 112 // Verify that the reported values are gone.
113 EXPECT_EQ(ExitCodeRegistryPathValueCount(), 1); 113 EXPECT_EQ(ExitCodeRegistryPathValueCount(), 1);
114 } 114 }
115 115
116 TEST_F(WatcherMetricsProviderWinTest, RecordsOrderedExitFunnelEvents) { 116 TEST_F(WatcherMetricsProviderWinTest, RecordsOrderedExitFunnelEvents) {
117 // Record an exit funnel with a given set of timings and check that the 117 // Record an exit funnel with a given set of timings and check that the
118 // ordering is correct on the reported histograms. 118 // ordering is correct on the reported histograms.
119 // Note the recorded times are in microseconds, but the reporting is in 119 // Note the recorded times are in microseconds, but the reporting is in
120 // milliseconds, hence the times 1000. 120 // milliseconds, hence the times 1000.
121 AddExitFunnelEvent(100, L"One", 1000 * 1000); 121 AddExitFunnelEvent(100, L"One", 1000 * 1000);
122 AddExitFunnelEvent(100, L"Two", 1010 * 1000); 122 AddExitFunnelEvent(100, L"Two", 1010 * 1000);
123 AddExitFunnelEvent(100, L"Three", 990 * 1000); 123 AddExitFunnelEvent(100, L"Three", 990 * 1000);
124 124
125 WatcherMetricsProviderWin provider(kRegistryPath); 125 WatcherMetricsProviderWin provider(kRegistryPath, true);
126 126
127 provider.ProvideStabilityMetrics(NULL); 127 provider.ProvideStabilityMetrics(NULL);
128 histogram_tester_.ExpectUniqueSample("Stability.ExitFunnel.Three", 0, 1); 128 histogram_tester_.ExpectUniqueSample("Stability.ExitFunnel.Three", 0, 1);
129 histogram_tester_.ExpectUniqueSample("Stability.ExitFunnel.One", 10, 1); 129 histogram_tester_.ExpectUniqueSample("Stability.ExitFunnel.One", 10, 1);
130 histogram_tester_.ExpectUniqueSample("Stability.ExitFunnel.Two", 20, 1); 130 histogram_tester_.ExpectUniqueSample("Stability.ExitFunnel.Two", 20, 1);
131 131
132 // Make sure the subkey is deleted on reporting. 132 // Make sure the subkey is deleted on reporting.
133 base::win::RegistryKeyIterator it(HKEY_CURRENT_USER, kRegistryPath); 133 base::win::RegistryKeyIterator it(HKEY_CURRENT_USER, kRegistryPath);
134 ASSERT_EQ(it.SubkeyCount(), 0); 134 ASSERT_EQ(it.SubkeyCount(), 0);
135 } 135 }
136 136
137 TEST_F(WatcherMetricsProviderWinTest, ReadsExitFunnelWrites) { 137 TEST_F(WatcherMetricsProviderWinTest, ReadsExitFunnelWrites) {
138 // Test that the metrics provider picks up the writes from 138 // Test that the metrics provider picks up the writes from the funnel.
139 ExitFunnel funnel; 139 ExitFunnel funnel;
140 140
141 // Events against our own process should not get reported. 141 // Events against our own process should not get reported.
142 ASSERT_TRUE(funnel.Init(kRegistryPath, base::GetCurrentProcessHandle())); 142 ASSERT_TRUE(funnel.Init(kRegistryPath, base::GetCurrentProcessHandle()));
143 ASSERT_TRUE(funnel.RecordEvent(L"Forgetaboutit")); 143 ASSERT_TRUE(funnel.RecordEvent(L"Forgetaboutit"));
144 144
145 // Reset the funnel to a pseudo process. The PID 4 is the system process, 145 // Reset the funnel to a pseudo process. The PID 4 is the system process,
146 // which tests can hopefully never open. 146 // which tests can hopefully never open.
147 ASSERT_TRUE(funnel.InitImpl(kRegistryPath, 4, base::Time::Now())); 147 ASSERT_TRUE(funnel.InitImpl(kRegistryPath, 4, base::Time::Now()));
148 148
149 // Each named event can only exist in a single copy. 149 // Each named event can only exist in a single copy.
150 ASSERT_TRUE(funnel.RecordEvent(L"One")); 150 ASSERT_TRUE(funnel.RecordEvent(L"One"));
151 ASSERT_TRUE(funnel.RecordEvent(L"One")); 151 ASSERT_TRUE(funnel.RecordEvent(L"One"));
152 ASSERT_TRUE(funnel.RecordEvent(L"One")); 152 ASSERT_TRUE(funnel.RecordEvent(L"One"));
153 ASSERT_TRUE(funnel.RecordEvent(L"Two")); 153 ASSERT_TRUE(funnel.RecordEvent(L"Two"));
154 ASSERT_TRUE(funnel.RecordEvent(L"Three")); 154 ASSERT_TRUE(funnel.RecordEvent(L"Three"));
155 155
156 WatcherMetricsProviderWin provider(kRegistryPath); 156 WatcherMetricsProviderWin provider(kRegistryPath, true);
157 157
158 provider.ProvideStabilityMetrics(NULL); 158 provider.ProvideStabilityMetrics(NULL);
159 histogram_tester_.ExpectTotalCount("Stability.ExitFunnel.One", 1); 159 histogram_tester_.ExpectTotalCount("Stability.ExitFunnel.One", 1);
160 histogram_tester_.ExpectTotalCount("Stability.ExitFunnel.Two", 1); 160 histogram_tester_.ExpectTotalCount("Stability.ExitFunnel.Two", 1);
161 histogram_tester_.ExpectTotalCount("Stability.ExitFunnel.Three", 1); 161 histogram_tester_.ExpectTotalCount("Stability.ExitFunnel.Three", 1);
162 162
163 // Make sure the subkey for the pseudo process has been deleted on reporting. 163 // Make sure the subkey for the pseudo process has been deleted on reporting.
164 base::win::RegistryKeyIterator it(HKEY_CURRENT_USER, kRegistryPath); 164 base::win::RegistryKeyIterator it(HKEY_CURRENT_USER, kRegistryPath);
165 ASSERT_EQ(it.SubkeyCount(), 1); 165 ASSERT_EQ(it.SubkeyCount(), 1);
166 } 166 }
167 167
168 TEST_F(WatcherMetricsProviderWinTest, ClearsExitFunnelWriteWhenNotReporting) {
169 // Tests that the metrics provider cleans up, but doesn't report exit funnels
170 // when funnel reporting is quenched.
171 ExitFunnel funnel;
172
173 // Events against our own process should not get reported.
174 ASSERT_TRUE(funnel.Init(kRegistryPath, base::GetCurrentProcessHandle()));
175 ASSERT_TRUE(funnel.RecordEvent(L"Forgetaboutit"));
176
177 // Reset the funnel to a pseudo process. The PID 4 is the system process,
178 // which tests can hopefully never open.
179 ASSERT_TRUE(funnel.InitImpl(kRegistryPath, 4, base::Time::Now()));
180
181 // Each named event can only exist in a single copy.
182 ASSERT_TRUE(funnel.RecordEvent(L"One"));
183 ASSERT_TRUE(funnel.RecordEvent(L"One"));
184 ASSERT_TRUE(funnel.RecordEvent(L"One"));
185 ASSERT_TRUE(funnel.RecordEvent(L"Two"));
186 ASSERT_TRUE(funnel.RecordEvent(L"Three"));
187
188 // Turn off exit funnel reporting.
189 WatcherMetricsProviderWin provider(kRegistryPath, false);
190
191 provider.ProvideStabilityMetrics(NULL);
192 histogram_tester_.ExpectTotalCount("Stability.ExitFunnel.One", 0);
193 histogram_tester_.ExpectTotalCount("Stability.ExitFunnel.Two", 0);
194 histogram_tester_.ExpectTotalCount("Stability.ExitFunnel.Three", 0);
195
196 // Make sure the subkey for the pseudo process has been deleted on reporting.
197 base::win::RegistryKeyIterator it(HKEY_CURRENT_USER, kRegistryPath);
198 ASSERT_EQ(it.SubkeyCount(), 1);
199 }
200
168 } // namespace browser_watcher 201 } // namespace browser_watcher
OLDNEW
« no previous file with comments | « components/browser_watcher/watcher_metrics_provider_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698