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 "components/metrics/profiler/profiler_metrics_provider.h" | 5 #include "components/metrics/profiler/profiler_metrics_provider.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/metrics/metrics_hashes.h" |
10 #include "base/tracked_objects.h" | 11 #include "base/tracked_objects.h" |
11 #include "components/metrics/metrics_hashes.h" | |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 | 13 |
14 using tracked_objects::ProcessDataPhaseSnapshot; | 14 using tracked_objects::ProcessDataPhaseSnapshot; |
15 using tracked_objects::TaskSnapshot; | 15 using tracked_objects::TaskSnapshot; |
16 | 16 |
17 namespace metrics { | 17 namespace metrics { |
18 | 18 |
19 TEST(ProfilerMetricsProviderTest, RecordData) { | 19 TEST(ProfilerMetricsProviderTest, RecordData) { |
20 // WARNING: If you broke the below check, you've modified how | 20 // WARNING: If you broke the below check, you've modified how |
21 // HashMetricName works. Please also modify all server-side code that | 21 // HashMetricName works. Please also modify all server-side code that |
22 // relies on the existing way of hashing. | 22 // relies on the existing way of hashing. |
23 EXPECT_EQ(UINT64_C(1518842999910132863), HashMetricName("birth_thread*")); | 23 EXPECT_EQ(UINT64_C(1518842999910132863), |
| 24 base::HashMetricName("birth_thread*")); |
24 | 25 |
25 ProfilerMetricsProvider profiler_metrics_provider; | 26 ProfilerMetricsProvider profiler_metrics_provider; |
26 | 27 |
27 { | 28 { |
28 // Add data from the browser process. | 29 // Add data from the browser process. |
29 ProcessDataPhaseSnapshot process_data_phase; | 30 ProcessDataPhaseSnapshot process_data_phase; |
30 process_data_phase.tasks.push_back(TaskSnapshot()); | 31 process_data_phase.tasks.push_back(TaskSnapshot()); |
31 process_data_phase.tasks.back().birth.location.file_name = "a/b/file.h"; | 32 process_data_phase.tasks.back().birth.location.file_name = "a/b/file.h"; |
32 process_data_phase.tasks.back().birth.location.function_name = "function"; | 33 process_data_phase.tasks.back().birth.location.function_name = "function"; |
33 process_data_phase.tasks.back().birth.location.line_number = 1337; | 34 process_data_phase.tasks.back().birth.location.line_number = 1337; |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 uma_proto.profiler_event(0).profile_version()); | 145 uma_proto.profiler_event(0).profile_version()); |
145 EXPECT_EQ(ProfilerEventProto::WALL_CLOCK_TIME, | 146 EXPECT_EQ(ProfilerEventProto::WALL_CLOCK_TIME, |
146 uma_proto.profiler_event(0).time_source()); | 147 uma_proto.profiler_event(0).time_source()); |
147 ASSERT_EQ(0, uma_proto.profiler_event(0).past_session_event_size()); | 148 ASSERT_EQ(0, uma_proto.profiler_event(0).past_session_event_size()); |
148 ASSERT_EQ(60000, uma_proto.profiler_event(0).profiling_start_ms()); | 149 ASSERT_EQ(60000, uma_proto.profiler_event(0).profiling_start_ms()); |
149 ASSERT_EQ(120000, uma_proto.profiler_event(0).profiling_finish_ms()); | 150 ASSERT_EQ(120000, uma_proto.profiler_event(0).profiling_finish_ms()); |
150 ASSERT_EQ(4, uma_proto.profiler_event(0).tracked_object_size()); | 151 ASSERT_EQ(4, uma_proto.profiler_event(0).tracked_object_size()); |
151 | 152 |
152 const ProfilerEventProto::TrackedObject* tracked_object = | 153 const ProfilerEventProto::TrackedObject* tracked_object = |
153 &uma_proto.profiler_event(0).tracked_object(0); | 154 &uma_proto.profiler_event(0).tracked_object(0); |
154 EXPECT_EQ(HashMetricName("file.h"), tracked_object->source_file_name_hash()); | 155 EXPECT_EQ(base::HashMetricName("file.h"), |
155 EXPECT_EQ(HashMetricName("function"), | 156 tracked_object->source_file_name_hash()); |
| 157 EXPECT_EQ(base::HashMetricName("function"), |
156 tracked_object->source_function_name_hash()); | 158 tracked_object->source_function_name_hash()); |
157 EXPECT_EQ(1337, tracked_object->source_line_number()); | 159 EXPECT_EQ(1337, tracked_object->source_line_number()); |
158 EXPECT_EQ(HashMetricName("birth_thread"), | 160 EXPECT_EQ(base::HashMetricName("birth_thread"), |
159 tracked_object->birth_thread_name_hash()); | 161 tracked_object->birth_thread_name_hash()); |
160 EXPECT_EQ(37, tracked_object->exec_count()); | 162 EXPECT_EQ(37, tracked_object->exec_count()); |
161 EXPECT_EQ(31, tracked_object->exec_time_total()); | 163 EXPECT_EQ(31, tracked_object->exec_time_total()); |
162 EXPECT_EQ(13, tracked_object->exec_time_sampled()); | 164 EXPECT_EQ(13, tracked_object->exec_time_sampled()); |
163 EXPECT_EQ(8, tracked_object->queue_time_total()); | 165 EXPECT_EQ(8, tracked_object->queue_time_total()); |
164 EXPECT_EQ(3, tracked_object->queue_time_sampled()); | 166 EXPECT_EQ(3, tracked_object->queue_time_sampled()); |
165 EXPECT_EQ(HashMetricName("Still_Alive"), | 167 EXPECT_EQ(base::HashMetricName("Still_Alive"), |
166 tracked_object->exec_thread_name_hash()); | 168 tracked_object->exec_thread_name_hash()); |
167 EXPECT_EQ(177U, tracked_object->process_id()); | 169 EXPECT_EQ(177U, tracked_object->process_id()); |
168 EXPECT_EQ(ProfilerEventProto::TrackedObject::BROWSER, | 170 EXPECT_EQ(ProfilerEventProto::TrackedObject::BROWSER, |
169 tracked_object->process_type()); | 171 tracked_object->process_type()); |
170 | 172 |
171 tracked_object = &uma_proto.profiler_event(0).tracked_object(1); | 173 tracked_object = &uma_proto.profiler_event(0).tracked_object(1); |
172 EXPECT_EQ(HashMetricName("file2"), tracked_object->source_file_name_hash()); | 174 EXPECT_EQ(base::HashMetricName("file2"), |
173 EXPECT_EQ(HashMetricName("function2"), | 175 tracked_object->source_file_name_hash()); |
| 176 EXPECT_EQ(base::HashMetricName("function2"), |
174 tracked_object->source_function_name_hash()); | 177 tracked_object->source_function_name_hash()); |
175 EXPECT_EQ(1773, tracked_object->source_line_number()); | 178 EXPECT_EQ(1773, tracked_object->source_line_number()); |
176 EXPECT_EQ(HashMetricName("birth_thread*"), | 179 EXPECT_EQ(base::HashMetricName("birth_thread*"), |
177 tracked_object->birth_thread_name_hash()); | 180 tracked_object->birth_thread_name_hash()); |
178 EXPECT_EQ(19, tracked_object->exec_count()); | 181 EXPECT_EQ(19, tracked_object->exec_count()); |
179 EXPECT_EQ(23, tracked_object->exec_time_total()); | 182 EXPECT_EQ(23, tracked_object->exec_time_total()); |
180 EXPECT_EQ(7, tracked_object->exec_time_sampled()); | 183 EXPECT_EQ(7, tracked_object->exec_time_sampled()); |
181 EXPECT_EQ(0, tracked_object->queue_time_total()); | 184 EXPECT_EQ(0, tracked_object->queue_time_total()); |
182 EXPECT_EQ(0, tracked_object->queue_time_sampled()); | 185 EXPECT_EQ(0, tracked_object->queue_time_sampled()); |
183 EXPECT_EQ(HashMetricName("death_thread"), | 186 EXPECT_EQ(base::HashMetricName("death_thread"), |
184 tracked_object->exec_thread_name_hash()); | 187 tracked_object->exec_thread_name_hash()); |
185 EXPECT_EQ(177U, tracked_object->process_id()); | 188 EXPECT_EQ(177U, tracked_object->process_id()); |
186 EXPECT_EQ(ProfilerEventProto::TrackedObject::BROWSER, | 189 EXPECT_EQ(ProfilerEventProto::TrackedObject::BROWSER, |
187 tracked_object->process_type()); | 190 tracked_object->process_type()); |
188 | 191 |
189 tracked_object = &uma_proto.profiler_event(0).tracked_object(2); | 192 tracked_object = &uma_proto.profiler_event(0).tracked_object(2); |
190 EXPECT_EQ(HashMetricName("file3"), tracked_object->source_file_name_hash()); | 193 EXPECT_EQ(base::HashMetricName("file3"), |
191 EXPECT_EQ(HashMetricName("function3"), | 194 tracked_object->source_file_name_hash()); |
| 195 EXPECT_EQ(base::HashMetricName("function3"), |
192 tracked_object->source_function_name_hash()); | 196 tracked_object->source_function_name_hash()); |
193 EXPECT_EQ(7331, tracked_object->source_line_number()); | 197 EXPECT_EQ(7331, tracked_object->source_line_number()); |
194 EXPECT_EQ(HashMetricName("birth_thread*"), | 198 EXPECT_EQ(base::HashMetricName("birth_thread*"), |
195 tracked_object->birth_thread_name_hash()); | 199 tracked_object->birth_thread_name_hash()); |
196 EXPECT_EQ(137, tracked_object->exec_count()); | 200 EXPECT_EQ(137, tracked_object->exec_count()); |
197 EXPECT_EQ(131, tracked_object->exec_time_total()); | 201 EXPECT_EQ(131, tracked_object->exec_time_total()); |
198 EXPECT_EQ(113, tracked_object->exec_time_sampled()); | 202 EXPECT_EQ(113, tracked_object->exec_time_sampled()); |
199 EXPECT_EQ(108, tracked_object->queue_time_total()); | 203 EXPECT_EQ(108, tracked_object->queue_time_total()); |
200 EXPECT_EQ(103, tracked_object->queue_time_sampled()); | 204 EXPECT_EQ(103, tracked_object->queue_time_sampled()); |
201 EXPECT_EQ(HashMetricName("death_thread*"), | 205 EXPECT_EQ(base::HashMetricName("death_thread*"), |
202 tracked_object->exec_thread_name_hash()); | 206 tracked_object->exec_thread_name_hash()); |
203 EXPECT_EQ(1177U, tracked_object->process_id()); | 207 EXPECT_EQ(1177U, tracked_object->process_id()); |
204 EXPECT_EQ(ProfilerEventProto::TrackedObject::RENDERER, | 208 EXPECT_EQ(ProfilerEventProto::TrackedObject::RENDERER, |
205 tracked_object->process_type()); | 209 tracked_object->process_type()); |
206 | 210 |
207 tracked_object = &uma_proto.profiler_event(0).tracked_object(3); | 211 tracked_object = &uma_proto.profiler_event(0).tracked_object(3); |
208 EXPECT_EQ(HashMetricName(""), tracked_object->source_file_name_hash()); | 212 EXPECT_EQ(base::HashMetricName(""), tracked_object->source_file_name_hash()); |
209 EXPECT_EQ(HashMetricName(""), tracked_object->source_function_name_hash()); | 213 EXPECT_EQ(base::HashMetricName(""), |
| 214 tracked_object->source_function_name_hash()); |
210 EXPECT_EQ(7332, tracked_object->source_line_number()); | 215 EXPECT_EQ(7332, tracked_object->source_line_number()); |
211 EXPECT_EQ(HashMetricName(""), tracked_object->birth_thread_name_hash()); | 216 EXPECT_EQ(base::HashMetricName(""), tracked_object->birth_thread_name_hash()); |
212 EXPECT_EQ(138, tracked_object->exec_count()); | 217 EXPECT_EQ(138, tracked_object->exec_count()); |
213 EXPECT_EQ(132, tracked_object->exec_time_total()); | 218 EXPECT_EQ(132, tracked_object->exec_time_total()); |
214 EXPECT_EQ(114, tracked_object->exec_time_sampled()); | 219 EXPECT_EQ(114, tracked_object->exec_time_sampled()); |
215 EXPECT_EQ(109, tracked_object->queue_time_total()); | 220 EXPECT_EQ(109, tracked_object->queue_time_total()); |
216 EXPECT_EQ(104, tracked_object->queue_time_sampled()); | 221 EXPECT_EQ(104, tracked_object->queue_time_sampled()); |
217 EXPECT_EQ(HashMetricName(""), tracked_object->exec_thread_name_hash()); | 222 EXPECT_EQ(base::HashMetricName(""), tracked_object->exec_thread_name_hash()); |
218 EXPECT_EQ(ProfilerEventProto::TrackedObject::RENDERER, | 223 EXPECT_EQ(ProfilerEventProto::TrackedObject::RENDERER, |
219 tracked_object->process_type()); | 224 tracked_object->process_type()); |
220 | 225 |
221 // Phase 1 | 226 // Phase 1 |
222 EXPECT_EQ(ProfilerEventProto::VERSION_SPLIT_PROFILE, | 227 EXPECT_EQ(ProfilerEventProto::VERSION_SPLIT_PROFILE, |
223 uma_proto.profiler_event(1).profile_version()); | 228 uma_proto.profiler_event(1).profile_version()); |
224 EXPECT_EQ(ProfilerEventProto::WALL_CLOCK_TIME, | 229 EXPECT_EQ(ProfilerEventProto::WALL_CLOCK_TIME, |
225 uma_proto.profiler_event(1).time_source()); | 230 uma_proto.profiler_event(1).time_source()); |
226 ASSERT_EQ(1, uma_proto.profiler_event(1).past_session_event_size()); | 231 ASSERT_EQ(1, uma_proto.profiler_event(1).past_session_event_size()); |
227 ASSERT_EQ(ProfilerEventProto::EVENT_FIRST_NONEMPTY_PAINT, | 232 ASSERT_EQ(ProfilerEventProto::EVENT_FIRST_NONEMPTY_PAINT, |
228 uma_proto.profiler_event(1).past_session_event(0)); | 233 uma_proto.profiler_event(1).past_session_event(0)); |
229 ASSERT_EQ(600000, uma_proto.profiler_event(1).profiling_start_ms()); | 234 ASSERT_EQ(600000, uma_proto.profiler_event(1).profiling_start_ms()); |
230 ASSERT_EQ(1200000, uma_proto.profiler_event(1).profiling_finish_ms()); | 235 ASSERT_EQ(1200000, uma_proto.profiler_event(1).profiling_finish_ms()); |
231 ASSERT_EQ(2, uma_proto.profiler_event(1).tracked_object_size()); | 236 ASSERT_EQ(2, uma_proto.profiler_event(1).tracked_object_size()); |
232 | 237 |
233 tracked_object = &uma_proto.profiler_event(1).tracked_object(0); | 238 tracked_object = &uma_proto.profiler_event(1).tracked_object(0); |
234 EXPECT_EQ(HashMetricName("file10.h"), | 239 EXPECT_EQ(base::HashMetricName("file10.h"), |
235 tracked_object->source_file_name_hash()); | 240 tracked_object->source_file_name_hash()); |
236 EXPECT_EQ(HashMetricName("function10"), | 241 EXPECT_EQ(base::HashMetricName("function10"), |
237 tracked_object->source_function_name_hash()); | 242 tracked_object->source_function_name_hash()); |
238 EXPECT_EQ(101337, tracked_object->source_line_number()); | 243 EXPECT_EQ(101337, tracked_object->source_line_number()); |
239 EXPECT_EQ(HashMetricName("birth_thread_ten"), | 244 EXPECT_EQ(base::HashMetricName("birth_thread_ten"), |
240 tracked_object->birth_thread_name_hash()); | 245 tracked_object->birth_thread_name_hash()); |
241 EXPECT_EQ(1037, tracked_object->exec_count()); | 246 EXPECT_EQ(1037, tracked_object->exec_count()); |
242 EXPECT_EQ(1031, tracked_object->exec_time_total()); | 247 EXPECT_EQ(1031, tracked_object->exec_time_total()); |
243 EXPECT_EQ(1013, tracked_object->exec_time_sampled()); | 248 EXPECT_EQ(1013, tracked_object->exec_time_sampled()); |
244 EXPECT_EQ(108, tracked_object->queue_time_total()); | 249 EXPECT_EQ(108, tracked_object->queue_time_total()); |
245 EXPECT_EQ(103, tracked_object->queue_time_sampled()); | 250 EXPECT_EQ(103, tracked_object->queue_time_sampled()); |
246 EXPECT_EQ(HashMetricName("Already_Dead"), | 251 EXPECT_EQ(base::HashMetricName("Already_Dead"), |
247 tracked_object->exec_thread_name_hash()); | 252 tracked_object->exec_thread_name_hash()); |
248 EXPECT_EQ(177U, tracked_object->process_id()); | 253 EXPECT_EQ(177U, tracked_object->process_id()); |
249 EXPECT_EQ(ProfilerEventProto::TrackedObject::BROWSER, | 254 EXPECT_EQ(ProfilerEventProto::TrackedObject::BROWSER, |
250 tracked_object->process_type()); | 255 tracked_object->process_type()); |
251 | 256 |
252 tracked_object = &uma_proto.profiler_event(1).tracked_object(1); | 257 tracked_object = &uma_proto.profiler_event(1).tracked_object(1); |
253 EXPECT_EQ(HashMetricName("file210"), tracked_object->source_file_name_hash()); | 258 EXPECT_EQ(base::HashMetricName("file210"), |
254 EXPECT_EQ(HashMetricName("function210"), | 259 tracked_object->source_file_name_hash()); |
| 260 EXPECT_EQ(base::HashMetricName("function210"), |
255 tracked_object->source_function_name_hash()); | 261 tracked_object->source_function_name_hash()); |
256 EXPECT_EQ(101773, tracked_object->source_line_number()); | 262 EXPECT_EQ(101773, tracked_object->source_line_number()); |
257 EXPECT_EQ(HashMetricName("birth_thread_ten*"), | 263 EXPECT_EQ(base::HashMetricName("birth_thread_ten*"), |
258 tracked_object->birth_thread_name_hash()); | 264 tracked_object->birth_thread_name_hash()); |
259 EXPECT_EQ(1019, tracked_object->exec_count()); | 265 EXPECT_EQ(1019, tracked_object->exec_count()); |
260 EXPECT_EQ(1023, tracked_object->exec_time_total()); | 266 EXPECT_EQ(1023, tracked_object->exec_time_total()); |
261 EXPECT_EQ(107, tracked_object->exec_time_sampled()); | 267 EXPECT_EQ(107, tracked_object->exec_time_sampled()); |
262 EXPECT_EQ(100, tracked_object->queue_time_total()); | 268 EXPECT_EQ(100, tracked_object->queue_time_total()); |
263 EXPECT_EQ(100, tracked_object->queue_time_sampled()); | 269 EXPECT_EQ(100, tracked_object->queue_time_sampled()); |
264 EXPECT_EQ(HashMetricName("death_thread_ten"), | 270 EXPECT_EQ(base::HashMetricName("death_thread_ten"), |
265 tracked_object->exec_thread_name_hash()); | 271 tracked_object->exec_thread_name_hash()); |
266 EXPECT_EQ(177U, tracked_object->process_id()); | 272 EXPECT_EQ(177U, tracked_object->process_id()); |
267 EXPECT_EQ(ProfilerEventProto::TrackedObject::BROWSER, | 273 EXPECT_EQ(ProfilerEventProto::TrackedObject::BROWSER, |
268 tracked_object->process_type()); | 274 tracked_object->process_type()); |
269 } | 275 } |
270 | 276 |
271 } // namespace metrics | 277 } // namespace metrics |
OLD | NEW |