OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "chrome/browser/metrics/profiler_metrics_provider.h" | 5 #include "components/metrics/profiler/profiler_metrics_provider.h" |
6 | 6 |
7 #include "base/tracked_objects.h" | 7 #include "base/tracked_objects.h" |
8 #include "components/metrics/metrics_hashes.h" | 8 #include "components/metrics/metrics_hashes.h" |
9 #include "content/public/common/process_type.h" | 9 #include "content/public/common/process_type.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 | 11 |
12 using metrics::ProfilerEventProto; | |
13 using tracked_objects::ProcessDataSnapshot; | 12 using tracked_objects::ProcessDataSnapshot; |
14 using tracked_objects::TaskSnapshot; | 13 using tracked_objects::TaskSnapshot; |
15 | 14 |
| 15 namespace metrics { |
| 16 |
16 TEST(ProfilerMetricsProviderTest, RecordData) { | 17 TEST(ProfilerMetricsProviderTest, RecordData) { |
17 // WARNING: If you broke the below check, you've modified how | 18 // WARNING: If you broke the below check, you've modified how |
18 // metrics::HashMetricName works. Please also modify all server-side code that | 19 // HashMetricName works. Please also modify all server-side code that |
19 // relies on the existing way of hashing. | 20 // relies on the existing way of hashing. |
20 EXPECT_EQ(GG_UINT64_C(1518842999910132863), | 21 EXPECT_EQ(GG_UINT64_C(1518842999910132863), HashMetricName("birth_thread*")); |
21 metrics::HashMetricName("birth_thread*")); | |
22 | 22 |
23 ProfilerMetricsProvider profiler_metrics_provider; | 23 ProfilerMetricsProvider profiler_metrics_provider; |
24 | 24 |
25 { | 25 { |
26 // Add data from the browser process. | 26 // Add data from the browser process. |
27 ProcessDataSnapshot process_data; | 27 ProcessDataSnapshot process_data; |
28 process_data.process_id = 177; | 28 process_data.process_id = 177; |
29 process_data.tasks.push_back(TaskSnapshot()); | 29 process_data.tasks.push_back(TaskSnapshot()); |
30 process_data.tasks.back().birth.location.file_name = "a/b/file.h"; | 30 process_data.tasks.back().birth.location.file_name = "a/b/file.h"; |
31 process_data.tasks.back().birth.location.function_name = "function"; | 31 process_data.tasks.back().birth.location.function_name = "function"; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 process_data.tasks.back().death_data.run_duration_sample = 114; | 85 process_data.tasks.back().death_data.run_duration_sample = 114; |
86 process_data.tasks.back().death_data.queue_duration_sum = 109; | 86 process_data.tasks.back().death_data.queue_duration_sum = 109; |
87 process_data.tasks.back().death_data.queue_duration_max = 106; | 87 process_data.tasks.back().death_data.queue_duration_max = 106; |
88 process_data.tasks.back().death_data.queue_duration_sample = 104; | 88 process_data.tasks.back().death_data.queue_duration_sample = 104; |
89 process_data.tasks.back().death_thread_name = ""; | 89 process_data.tasks.back().death_thread_name = ""; |
90 | 90 |
91 profiler_metrics_provider.RecordProfilerData( | 91 profiler_metrics_provider.RecordProfilerData( |
92 process_data, content::PROCESS_TYPE_RENDERER); | 92 process_data, content::PROCESS_TYPE_RENDERER); |
93 | 93 |
94 // Capture the data and verify that it is as expected. | 94 // Capture the data and verify that it is as expected. |
95 metrics::ChromeUserMetricsExtension uma_proto; | 95 ChromeUserMetricsExtension uma_proto; |
96 profiler_metrics_provider.ProvideGeneralMetrics(&uma_proto); | 96 profiler_metrics_provider.ProvideGeneralMetrics(&uma_proto); |
97 | 97 |
98 ASSERT_EQ(1, uma_proto.profiler_event_size()); | 98 ASSERT_EQ(1, uma_proto.profiler_event_size()); |
99 EXPECT_EQ(ProfilerEventProto::STARTUP_PROFILE, | 99 EXPECT_EQ(ProfilerEventProto::STARTUP_PROFILE, |
100 uma_proto.profiler_event(0).profile_type()); | 100 uma_proto.profiler_event(0).profile_type()); |
101 EXPECT_EQ(ProfilerEventProto::WALL_CLOCK_TIME, | 101 EXPECT_EQ(ProfilerEventProto::WALL_CLOCK_TIME, |
102 uma_proto.profiler_event(0).time_source()); | 102 uma_proto.profiler_event(0).time_source()); |
103 ASSERT_EQ(4, uma_proto.profiler_event(0).tracked_object_size()); | 103 ASSERT_EQ(4, uma_proto.profiler_event(0).tracked_object_size()); |
104 | 104 |
105 const ProfilerEventProto::TrackedObject* tracked_object = | 105 const ProfilerEventProto::TrackedObject* tracked_object = |
106 &uma_proto.profiler_event(0).tracked_object(0); | 106 &uma_proto.profiler_event(0).tracked_object(0); |
107 EXPECT_EQ(metrics::HashMetricName("file.h"), | 107 EXPECT_EQ(HashMetricName("file.h"), |
108 tracked_object->source_file_name_hash()); | 108 tracked_object->source_file_name_hash()); |
109 EXPECT_EQ(metrics::HashMetricName("function"), | 109 EXPECT_EQ(HashMetricName("function"), |
110 tracked_object->source_function_name_hash()); | 110 tracked_object->source_function_name_hash()); |
111 EXPECT_EQ(1337, tracked_object->source_line_number()); | 111 EXPECT_EQ(1337, tracked_object->source_line_number()); |
112 EXPECT_EQ(metrics::HashMetricName("birth_thread"), | 112 EXPECT_EQ(HashMetricName("birth_thread"), |
113 tracked_object->birth_thread_name_hash()); | 113 tracked_object->birth_thread_name_hash()); |
114 EXPECT_EQ(37, tracked_object->exec_count()); | 114 EXPECT_EQ(37, tracked_object->exec_count()); |
115 EXPECT_EQ(31, tracked_object->exec_time_total()); | 115 EXPECT_EQ(31, tracked_object->exec_time_total()); |
116 EXPECT_EQ(13, tracked_object->exec_time_sampled()); | 116 EXPECT_EQ(13, tracked_object->exec_time_sampled()); |
117 EXPECT_EQ(8, tracked_object->queue_time_total()); | 117 EXPECT_EQ(8, tracked_object->queue_time_total()); |
118 EXPECT_EQ(3, tracked_object->queue_time_sampled()); | 118 EXPECT_EQ(3, tracked_object->queue_time_sampled()); |
119 EXPECT_EQ(metrics::HashMetricName("Still_Alive"), | 119 EXPECT_EQ(HashMetricName("Still_Alive"), |
120 tracked_object->exec_thread_name_hash()); | 120 tracked_object->exec_thread_name_hash()); |
121 EXPECT_EQ(177U, tracked_object->process_id()); | 121 EXPECT_EQ(177U, tracked_object->process_id()); |
122 EXPECT_EQ(ProfilerEventProto::TrackedObject::BROWSER, | 122 EXPECT_EQ(ProfilerEventProto::TrackedObject::BROWSER, |
123 tracked_object->process_type()); | 123 tracked_object->process_type()); |
124 | 124 |
125 tracked_object = &uma_proto.profiler_event(0).tracked_object(1); | 125 tracked_object = &uma_proto.profiler_event(0).tracked_object(1); |
126 EXPECT_EQ(metrics::HashMetricName("file2"), | 126 EXPECT_EQ(HashMetricName("file2"), |
127 tracked_object->source_file_name_hash()); | 127 tracked_object->source_file_name_hash()); |
128 EXPECT_EQ(metrics::HashMetricName("function2"), | 128 EXPECT_EQ(HashMetricName("function2"), |
129 tracked_object->source_function_name_hash()); | 129 tracked_object->source_function_name_hash()); |
130 EXPECT_EQ(1773, tracked_object->source_line_number()); | 130 EXPECT_EQ(1773, tracked_object->source_line_number()); |
131 EXPECT_EQ(metrics::HashMetricName("birth_thread*"), | 131 EXPECT_EQ(HashMetricName("birth_thread*"), |
132 tracked_object->birth_thread_name_hash()); | 132 tracked_object->birth_thread_name_hash()); |
133 EXPECT_EQ(19, tracked_object->exec_count()); | 133 EXPECT_EQ(19, tracked_object->exec_count()); |
134 EXPECT_EQ(23, tracked_object->exec_time_total()); | 134 EXPECT_EQ(23, tracked_object->exec_time_total()); |
135 EXPECT_EQ(7, tracked_object->exec_time_sampled()); | 135 EXPECT_EQ(7, tracked_object->exec_time_sampled()); |
136 EXPECT_EQ(0, tracked_object->queue_time_total()); | 136 EXPECT_EQ(0, tracked_object->queue_time_total()); |
137 EXPECT_EQ(0, tracked_object->queue_time_sampled()); | 137 EXPECT_EQ(0, tracked_object->queue_time_sampled()); |
138 EXPECT_EQ(metrics::HashMetricName("death_thread"), | 138 EXPECT_EQ(HashMetricName("death_thread"), |
139 tracked_object->exec_thread_name_hash()); | 139 tracked_object->exec_thread_name_hash()); |
140 EXPECT_EQ(177U, tracked_object->process_id()); | 140 EXPECT_EQ(177U, tracked_object->process_id()); |
141 EXPECT_EQ(ProfilerEventProto::TrackedObject::BROWSER, | 141 EXPECT_EQ(ProfilerEventProto::TrackedObject::BROWSER, |
142 tracked_object->process_type()); | 142 tracked_object->process_type()); |
143 | 143 |
144 tracked_object = &uma_proto.profiler_event(0).tracked_object(2); | 144 tracked_object = &uma_proto.profiler_event(0).tracked_object(2); |
145 EXPECT_EQ(metrics::HashMetricName("file3"), | 145 EXPECT_EQ(HashMetricName("file3"), |
146 tracked_object->source_file_name_hash()); | 146 tracked_object->source_file_name_hash()); |
147 EXPECT_EQ(metrics::HashMetricName("function3"), | 147 EXPECT_EQ(HashMetricName("function3"), |
148 tracked_object->source_function_name_hash()); | 148 tracked_object->source_function_name_hash()); |
149 EXPECT_EQ(7331, tracked_object->source_line_number()); | 149 EXPECT_EQ(7331, tracked_object->source_line_number()); |
150 EXPECT_EQ(metrics::HashMetricName("birth_thread*"), | 150 EXPECT_EQ(HashMetricName("birth_thread*"), |
151 tracked_object->birth_thread_name_hash()); | 151 tracked_object->birth_thread_name_hash()); |
152 EXPECT_EQ(137, tracked_object->exec_count()); | 152 EXPECT_EQ(137, tracked_object->exec_count()); |
153 EXPECT_EQ(131, tracked_object->exec_time_total()); | 153 EXPECT_EQ(131, tracked_object->exec_time_total()); |
154 EXPECT_EQ(113, tracked_object->exec_time_sampled()); | 154 EXPECT_EQ(113, tracked_object->exec_time_sampled()); |
155 EXPECT_EQ(108, tracked_object->queue_time_total()); | 155 EXPECT_EQ(108, tracked_object->queue_time_total()); |
156 EXPECT_EQ(103, tracked_object->queue_time_sampled()); | 156 EXPECT_EQ(103, tracked_object->queue_time_sampled()); |
157 EXPECT_EQ(metrics::HashMetricName("death_thread*"), | 157 EXPECT_EQ(HashMetricName("death_thread*"), |
158 tracked_object->exec_thread_name_hash()); | 158 tracked_object->exec_thread_name_hash()); |
159 EXPECT_EQ(1177U, tracked_object->process_id()); | 159 EXPECT_EQ(1177U, tracked_object->process_id()); |
160 EXPECT_EQ(ProfilerEventProto::TrackedObject::RENDERER, | 160 EXPECT_EQ(ProfilerEventProto::TrackedObject::RENDERER, |
161 tracked_object->process_type()); | 161 tracked_object->process_type()); |
162 | 162 |
163 tracked_object = &uma_proto.profiler_event(0).tracked_object(3); | 163 tracked_object = &uma_proto.profiler_event(0).tracked_object(3); |
164 EXPECT_EQ(metrics::HashMetricName(""), | 164 EXPECT_EQ(HashMetricName(""), |
165 tracked_object->source_file_name_hash()); | 165 tracked_object->source_file_name_hash()); |
166 EXPECT_EQ(metrics::HashMetricName(""), | 166 EXPECT_EQ(HashMetricName(""), |
167 tracked_object->source_function_name_hash()); | 167 tracked_object->source_function_name_hash()); |
168 EXPECT_EQ(7332, tracked_object->source_line_number()); | 168 EXPECT_EQ(7332, tracked_object->source_line_number()); |
169 EXPECT_EQ(metrics::HashMetricName(""), | 169 EXPECT_EQ(HashMetricName(""), |
170 tracked_object->birth_thread_name_hash()); | 170 tracked_object->birth_thread_name_hash()); |
171 EXPECT_EQ(138, tracked_object->exec_count()); | 171 EXPECT_EQ(138, tracked_object->exec_count()); |
172 EXPECT_EQ(132, tracked_object->exec_time_total()); | 172 EXPECT_EQ(132, tracked_object->exec_time_total()); |
173 EXPECT_EQ(114, tracked_object->exec_time_sampled()); | 173 EXPECT_EQ(114, tracked_object->exec_time_sampled()); |
174 EXPECT_EQ(109, tracked_object->queue_time_total()); | 174 EXPECT_EQ(109, tracked_object->queue_time_total()); |
175 EXPECT_EQ(104, tracked_object->queue_time_sampled()); | 175 EXPECT_EQ(104, tracked_object->queue_time_sampled()); |
176 EXPECT_EQ(metrics::HashMetricName(""), | 176 EXPECT_EQ(HashMetricName(""), |
177 tracked_object->exec_thread_name_hash()); | 177 tracked_object->exec_thread_name_hash()); |
178 EXPECT_EQ(ProfilerEventProto::TrackedObject::RENDERER, | 178 EXPECT_EQ(ProfilerEventProto::TrackedObject::RENDERER, |
179 tracked_object->process_type()); | 179 tracked_object->process_type()); |
180 } | 180 } |
181 } | 181 } |
| 182 |
| 183 } // namespace metrics |
OLD | NEW |