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

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

Issue 792163002: Add ExitFunnel to prepare for instrumenting browser exits. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Address Erik's comments. Created 6 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
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"
11 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
12 #include "base/test/histogram_tester.h" 12 #include "base/test/histogram_tester.h"
13 #include "base/test/test_reg_util_win.h" 13 #include "base/test/test_reg_util_win.h"
14 #include "base/win/registry.h" 14 #include "base/win/registry.h"
15 #include "components/browser_watcher/exit_funnel_win.h"
15 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
16 17
17 namespace browser_watcher { 18 namespace browser_watcher {
18 19
19 namespace { 20 namespace {
20 21
21 const wchar_t kRegistryPath[] = L"Software\\WatcherMetricsProviderWinTest"; 22 const wchar_t kRegistryPath[] = L"Software\\WatcherMetricsProviderWinTest";
22 23
23 class WatcherMetricsProviderWinTest : public testing::Test { 24 class WatcherMetricsProviderWinTest : public testing::Test {
24 public: 25 public:
(...skipping 24 matching lines...) Expand all
49 // Write the exit code to registry. 50 // Write the exit code to registry.
50 ULONG result = key.WriteValue(key_name.c_str(), exit_code); 51 ULONG result = key.WriteValue(key_name.c_str(), exit_code);
51 ASSERT_EQ(result, ERROR_SUCCESS); 52 ASSERT_EQ(result, ERROR_SUCCESS);
52 } 53 }
53 54
54 size_t ExitCodeRegistryPathValueCount() { 55 size_t ExitCodeRegistryPathValueCount() {
55 base::win::RegKey key(HKEY_CURRENT_USER, kRegistryPath, KEY_READ); 56 base::win::RegKey key(HKEY_CURRENT_USER, kRegistryPath, KEY_READ);
56 return key.GetValueCount(); 57 return key.GetValueCount();
57 } 58 }
58 59
60 void AddExitFunnelEvent(int pid, const base::char16* name, int64 value) {
61 base::string16 key_name =
62 base::StringPrintf(L"%ls\\%d-%d", kRegistryPath, pid, pid);
63
64 base::win::RegKey key(HKEY_CURRENT_USER, key_name.c_str(), KEY_WRITE);
65 ASSERT_EQ(key.WriteValue(name, &value, sizeof(value), REG_QWORD),
66 ERROR_SUCCESS);
67 }
68
59 protected: 69 protected:
60 registry_util::RegistryOverrideManager override_manager_; 70 registry_util::RegistryOverrideManager override_manager_;
61 base::HistogramTester histogram_tester_; 71 base::HistogramTester histogram_tester_;
62 }; 72 };
63 73
64 } // namespace 74 } // namespace
65 75
66 TEST_F(WatcherMetricsProviderWinTest, RecordsStabilityHistogram) { 76 TEST_F(WatcherMetricsProviderWinTest, RecordsStabilityHistogram) {
67 // Record multiple success exits. 77 // Record multiple success exits.
68 for (size_t i = 0; i < 11; ++i) 78 for (size_t i = 0; i < 11; ++i)
(...skipping 27 matching lines...) Expand all
96 WatcherMetricsProviderWin provider(kRegistryPath); 106 WatcherMetricsProviderWin provider(kRegistryPath);
97 107
98 provider.ProvideStabilityMetrics(NULL); 108 provider.ProvideStabilityMetrics(NULL);
99 histogram_tester_.ExpectUniqueSample( 109 histogram_tester_.ExpectUniqueSample(
100 WatcherMetricsProviderWin::kBrowserExitCodeHistogramName, 0, 11); 110 WatcherMetricsProviderWin::kBrowserExitCodeHistogramName, 0, 11);
101 111
102 // Verify that the reported values are gone. 112 // Verify that the reported values are gone.
103 EXPECT_EQ(ExitCodeRegistryPathValueCount(), 1); 113 EXPECT_EQ(ExitCodeRegistryPathValueCount(), 1);
104 } 114 }
105 115
116 TEST_F(WatcherMetricsProviderWinTest, RecordsOrderedExitFunnelEvents) {
117 // Record an exit funnel with a given set of timings and check that the
118 // ordering is correct on the reported histograms.
119 // Note the recorded times are in microseconds, but the reporting is in
120 // milliseconds, hence the times 1000.
121 AddExitFunnelEvent(100, L"One", 1000 * 1000);
122 AddExitFunnelEvent(100, L"Two", 1010 * 1000);
123 AddExitFunnelEvent(100, L"Three", 990 * 1000);
124
125 WatcherMetricsProviderWin provider(kRegistryPath);
126
127 provider.ProvideStabilityMetrics(NULL);
128 histogram_tester_.ExpectUniqueSample("Stability.ExitFunnel.Three", 0, 1);
129 histogram_tester_.ExpectUniqueSample("Stability.ExitFunnel.One", 10, 1);
130 histogram_tester_.ExpectUniqueSample("Stability.ExitFunnel.Two", 20, 1);
131
132 // Make sure the subkey is deleted on reporting.
133 base::win::RegistryKeyIterator it(HKEY_CURRENT_USER, kRegistryPath);
134 ASSERT_EQ(it.SubkeyCount(), 0);
135 }
136
137 TEST_F(WatcherMetricsProviderWinTest, ReadsExitFunnelWrites) {
138 // Test that the metrics provider picks up the writes from
139 ExitFunnel funnel;
140
141 ASSERT_TRUE(funnel.Init(kRegistryPath, base::GetCurrentProcessHandle()));
142
143 // Each named event can only exist in a single copy.
144 ASSERT_TRUE(funnel.RecordEvent(L"One"));
145 ASSERT_TRUE(funnel.RecordEvent(L"One"));
146 ASSERT_TRUE(funnel.RecordEvent(L"One"));
147 ASSERT_TRUE(funnel.RecordEvent(L"Two"));
148 ASSERT_TRUE(funnel.RecordEvent(L"Three"));
149
150 WatcherMetricsProviderWin provider(kRegistryPath);
151
152 provider.ProvideStabilityMetrics(NULL);
153 histogram_tester_.ExpectTotalCount("Stability.ExitFunnel.One", 1);
154 histogram_tester_.ExpectTotalCount("Stability.ExitFunnel.Two", 1);
155 histogram_tester_.ExpectTotalCount("Stability.ExitFunnel.Three", 1);
156
157 // Make sure the subkey has been deleted on reporting.
158 base::win::RegistryKeyIterator it(HKEY_CURRENT_USER, kRegistryPath);
159 ASSERT_EQ(it.SubkeyCount(), 0);
160 }
161
106 } // namespace browser_watcher 162 } // namespace browser_watcher
OLDNEW
« no previous file with comments | « components/browser_watcher/watcher_metrics_provider_win.cc ('k') | components/components_tests.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698