OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/call_stack_profile_metrics_provider.h" | 5 #include "components/metrics/call_stack_profile_metrics_provider.h" |
6 | 6 |
7 #include "base/metrics/field_trial.h" | 7 #include "base/metrics/field_trial.h" |
8 #include "base/profiler/stack_sampling_profiler.h" | 8 #include "base/profiler/stack_sampling_profiler.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 | 58 |
59 // Checks that all properties from multiple profiles are filled as expected. | 59 // Checks that all properties from multiple profiles are filled as expected. |
60 TEST_F(CallStackProfileMetricsProviderTest, MultipleProfiles) { | 60 TEST_F(CallStackProfileMetricsProviderTest, MultipleProfiles) { |
61 const uintptr_t module1_base_address = 0x1000; | 61 const uintptr_t module1_base_address = 0x1000; |
62 const uintptr_t module2_base_address = 0x2000; | 62 const uintptr_t module2_base_address = 0x2000; |
63 const uintptr_t module3_base_address = 0x3000; | 63 const uintptr_t module3_base_address = 0x3000; |
64 | 64 |
65 const Module profile_modules[][2] = { | 65 const Module profile_modules[][2] = { |
66 { | 66 { |
67 Module( | 67 Module( |
68 reinterpret_cast<const void*>(module1_base_address), | 68 module1_base_address, |
69 "ABCD", | 69 "ABCD", |
70 #if defined(OS_WIN) | 70 #if defined(OS_WIN) |
71 base::FilePath(L"c:\\some\\path\\to\\chrome.exe") | 71 base::FilePath(L"c:\\some\\path\\to\\chrome.exe") |
72 #else | 72 #else |
73 base::FilePath("/some/path/to/chrome") | 73 base::FilePath("/some/path/to/chrome") |
74 #endif | 74 #endif |
75 ), | 75 ), |
76 Module( | 76 Module( |
77 reinterpret_cast<const void*>(module2_base_address), | 77 module2_base_address, |
78 "EFGH", | 78 "EFGH", |
79 #if defined(OS_WIN) | 79 #if defined(OS_WIN) |
80 base::FilePath(L"c:\\some\\path\\to\\third_party.dll") | 80 base::FilePath(L"c:\\some\\path\\to\\third_party.dll") |
81 #else | 81 #else |
82 base::FilePath("/some/path/to/third_party.so") | 82 base::FilePath("/some/path/to/third_party.so") |
83 #endif | 83 #endif |
84 ), | 84 ), |
85 }, | 85 }, |
86 { | 86 { |
87 Module( | 87 Module( |
88 reinterpret_cast<const void*>(module3_base_address), | 88 module3_base_address, |
89 "MNOP", | 89 "MNOP", |
90 #if defined(OS_WIN) | 90 #if defined(OS_WIN) |
91 base::FilePath(L"c:\\some\\path\\to\\third_party2.dll") | 91 base::FilePath(L"c:\\some\\path\\to\\third_party2.dll") |
92 #else | 92 #else |
93 base::FilePath("/some/path/to/third_party2.so") | 93 base::FilePath("/some/path/to/third_party2.so") |
94 #endif | 94 #endif |
95 ), | 95 ), |
96 Module( // Repeated from the first profile. | 96 Module( // Repeated from the first profile. |
97 reinterpret_cast<const void*>(module1_base_address), | 97 module1_base_address, |
98 "ABCD", | 98 "ABCD", |
99 #if defined(OS_WIN) | 99 #if defined(OS_WIN) |
100 base::FilePath(L"c:\\some\\path\\to\\chrome.exe") | 100 base::FilePath(L"c:\\some\\path\\to\\chrome.exe") |
101 #else | 101 #else |
102 base::FilePath("/some/path/to/chrome") | 102 base::FilePath("/some/path/to/chrome") |
103 #endif | 103 #endif |
104 ) | 104 ) |
105 } | 105 } |
106 }; | 106 }; |
107 | 107 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 // module index corresponding to the module for the profile in | 140 // module index corresponding to the module for the profile in |
141 // profile_modules. | 141 // profile_modules. |
142 // | 142 // |
143 // So, the first stack sample below has its top frame in module 0 at an offset | 143 // So, the first stack sample below has its top frame in module 0 at an offset |
144 // of 0x10 from the module's base address, the next-to-top frame in module 1 | 144 // of 0x10 from the module's base address, the next-to-top frame in module 1 |
145 // at an offset of 0x20 from the module's base address, and the bottom frame | 145 // at an offset of 0x20 from the module's base address, and the bottom frame |
146 // in module 0 at an offset of 0x30 from the module's base address | 146 // in module 0 at an offset of 0x30 from the module's base address |
147 const Frame profile_sample_frames[][2][3] = { | 147 const Frame profile_sample_frames[][2][3] = { |
148 { | 148 { |
149 { | 149 { |
150 Frame(reinterpret_cast<const void*>(module1_base_address + 0x10), 0), | 150 Frame(module1_base_address + 0x10, 0), |
151 Frame(reinterpret_cast<const void*>(module2_base_address + 0x20), 1), | 151 Frame(module2_base_address + 0x20, 1), |
152 Frame(reinterpret_cast<const void*>(module1_base_address + 0x30), 0) | 152 Frame(module1_base_address + 0x30, 0) |
153 }, | 153 }, |
154 { | 154 { |
155 Frame(reinterpret_cast<const void*>(module2_base_address + 0x10), 1), | 155 Frame(module2_base_address + 0x10, 1), |
156 Frame(reinterpret_cast<const void*>(module1_base_address + 0x20), 0), | 156 Frame(module1_base_address + 0x20, 0), |
157 Frame(reinterpret_cast<const void*>(module2_base_address + 0x30), 1) | 157 Frame(module2_base_address + 0x30, 1) |
158 } | 158 } |
159 }, | 159 }, |
160 { | 160 { |
161 { | 161 { |
162 Frame(reinterpret_cast<const void*>(module3_base_address + 0x10), 0), | 162 Frame(module3_base_address + 0x10, 0), |
163 Frame(reinterpret_cast<const void*>(module1_base_address + 0x20), 1), | 163 Frame(module1_base_address + 0x20, 1), |
164 Frame(reinterpret_cast<const void*>(module3_base_address + 0x30), 0) | 164 Frame(module3_base_address + 0x30, 0) |
165 }, | 165 }, |
166 { | 166 { |
167 Frame(reinterpret_cast<const void*>(module1_base_address + 0x10), 1), | 167 Frame(module1_base_address + 0x10, 1), |
168 Frame(reinterpret_cast<const void*>(module3_base_address + 0x20), 0), | 168 Frame(module3_base_address + 0x20, 0), |
169 Frame(reinterpret_cast<const void*>(module1_base_address + 0x30), 1) | 169 Frame(module1_base_address + 0x30, 1) |
170 } | 170 } |
171 } | 171 } |
172 }; | 172 }; |
173 | 173 |
174 base::TimeDelta profile_durations[2] = { | 174 base::TimeDelta profile_durations[2] = { |
175 base::TimeDelta::FromMilliseconds(100), | 175 base::TimeDelta::FromMilliseconds(100), |
176 base::TimeDelta::FromMilliseconds(200) | 176 base::TimeDelta::FromMilliseconds(200) |
177 }; | 177 }; |
178 | 178 |
179 base::TimeDelta profile_sampling_periods[2] = { | 179 base::TimeDelta profile_sampling_periods[2] = { |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 } | 270 } |
271 } | 271 } |
272 | 272 |
273 // Checks that all duplicate samples are collapsed with | 273 // Checks that all duplicate samples are collapsed with |
274 // preserve_sample_ordering = false. | 274 // preserve_sample_ordering = false. |
275 TEST_F(CallStackProfileMetricsProviderTest, RepeatedStacksUnordered) { | 275 TEST_F(CallStackProfileMetricsProviderTest, RepeatedStacksUnordered) { |
276 const uintptr_t module_base_address = 0x1000; | 276 const uintptr_t module_base_address = 0x1000; |
277 | 277 |
278 const Module modules[] = { | 278 const Module modules[] = { |
279 Module( | 279 Module( |
280 reinterpret_cast<const void*>(module_base_address), | 280 module_base_address, |
281 "ABCD", | 281 "ABCD", |
282 #if defined(OS_WIN) | 282 #if defined(OS_WIN) |
283 base::FilePath(L"c:\\some\\path\\to\\chrome.exe") | 283 base::FilePath(L"c:\\some\\path\\to\\chrome.exe") |
284 #else | 284 #else |
285 base::FilePath("/some/path/to/chrome") | 285 base::FilePath("/some/path/to/chrome") |
286 #endif | 286 #endif |
287 ) | 287 ) |
288 }; | 288 }; |
289 | 289 |
290 // Duplicate samples in slots 0, 2, and 3. | 290 // Duplicate samples in slots 0, 2, and 3. |
291 const Frame sample_frames[][1] = { | 291 const Frame sample_frames[][1] = { |
292 { Frame(reinterpret_cast<const void*>(module_base_address + 0x10), 0), }, | 292 { Frame(module_base_address + 0x10, 0), }, |
293 { Frame(reinterpret_cast<const void*>(module_base_address + 0x20), 0), }, | 293 { Frame(module_base_address + 0x20, 0), }, |
294 { Frame(reinterpret_cast<const void*>(module_base_address + 0x10), 0), }, | 294 { Frame(module_base_address + 0x10, 0), }, |
295 { Frame(reinterpret_cast<const void*>(module_base_address + 0x10), 0) } | 295 { Frame(module_base_address + 0x10, 0) } |
296 }; | 296 }; |
297 | 297 |
298 Profile profile; | 298 Profile profile; |
299 profile.modules.insert(profile.modules.end(), &modules[0], | 299 profile.modules.insert(profile.modules.end(), &modules[0], |
300 &modules[0] + arraysize(modules)); | 300 &modules[0] + arraysize(modules)); |
301 | 301 |
302 for (size_t i = 0; i < arraysize(sample_frames); ++i) { | 302 for (size_t i = 0; i < arraysize(sample_frames); ++i) { |
303 profile.samples.push_back(Sample()); | 303 profile.samples.push_back(Sample()); |
304 Sample& sample = profile.samples.back(); | 304 Sample& sample = profile.samples.back(); |
305 sample.insert(sample.end(), &sample_frames[i][0], | 305 sample.insert(sample.end(), &sample_frames[i][0], |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 } | 349 } |
350 } | 350 } |
351 | 351 |
352 // Checks that only contiguous duplicate samples are collapsed with | 352 // Checks that only contiguous duplicate samples are collapsed with |
353 // preserve_sample_ordering = true. | 353 // preserve_sample_ordering = true. |
354 TEST_F(CallStackProfileMetricsProviderTest, RepeatedStacksOrdered) { | 354 TEST_F(CallStackProfileMetricsProviderTest, RepeatedStacksOrdered) { |
355 const uintptr_t module_base_address = 0x1000; | 355 const uintptr_t module_base_address = 0x1000; |
356 | 356 |
357 const Module modules[] = { | 357 const Module modules[] = { |
358 Module( | 358 Module( |
359 reinterpret_cast<const void*>(module_base_address), | 359 module_base_address, |
360 "ABCD", | 360 "ABCD", |
361 #if defined(OS_WIN) | 361 #if defined(OS_WIN) |
362 base::FilePath(L"c:\\some\\path\\to\\chrome.exe") | 362 base::FilePath(L"c:\\some\\path\\to\\chrome.exe") |
363 #else | 363 #else |
364 base::FilePath("/some/path/to/chrome") | 364 base::FilePath("/some/path/to/chrome") |
365 #endif | 365 #endif |
366 ) | 366 ) |
367 }; | 367 }; |
368 | 368 |
369 // Duplicate samples in slots 0, 2, and 3. | 369 // Duplicate samples in slots 0, 2, and 3. |
370 const Frame sample_frames[][1] = { | 370 const Frame sample_frames[][1] = { |
371 { Frame(reinterpret_cast<const void*>(module_base_address + 0x10), 0), }, | 371 { Frame(module_base_address + 0x10, 0), }, |
372 { Frame(reinterpret_cast<const void*>(module_base_address + 0x20), 0), }, | 372 { Frame(module_base_address + 0x20, 0), }, |
373 { Frame(reinterpret_cast<const void*>(module_base_address + 0x10), 0), }, | 373 { Frame(module_base_address + 0x10, 0), }, |
374 { Frame(reinterpret_cast<const void*>(module_base_address + 0x10), 0) } | 374 { Frame(module_base_address + 0x10, 0) } |
375 }; | 375 }; |
376 | 376 |
377 Profile profile; | 377 Profile profile; |
378 profile.modules.insert(profile.modules.end(), &modules[0], | 378 profile.modules.insert(profile.modules.end(), &modules[0], |
379 &modules[0] + arraysize(modules)); | 379 &modules[0] + arraysize(modules)); |
380 | 380 |
381 for (size_t i = 0; i < arraysize(sample_frames); ++i) { | 381 for (size_t i = 0; i < arraysize(sample_frames); ++i) { |
382 profile.samples.push_back(Sample()); | 382 profile.samples.push_back(Sample()); |
383 Sample& sample = profile.samples.back(); | 383 Sample& sample = profile.samples.back(); |
384 sample.insert(sample.end(), &sample_frames[i][0], | 384 sample.insert(sample.end(), &sample_frames[i][0], |
385 &sample_frames[i][0] + arraysize(sample_frames[i])); | 385 &sample_frames[i][0] + arraysize(sample_frames[i])); |
386 } | 386 } |
387 | 387 |
388 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); | 388 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); |
389 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); | 389 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); |
390 | 390 |
391 CallStackProfileMetricsProvider provider; | 391 CallStackProfileMetricsProvider provider; |
392 provider.OnRecordingEnabled(); | 392 provider.OnRecordingEnabled(); |
393 AppendProfiles( | 393 AppendProfiles(Params(CallStackProfileMetricsProvider::PROCESS_STARTUP, true), |
394 Params(CallStackProfileMetricsProvider::PROCESS_STARTUP, true), | 394 std::vector<Profile>(1, profile)); |
395 std::vector<Profile>(1, profile)); | |
396 ChromeUserMetricsExtension uma_proto; | 395 ChromeUserMetricsExtension uma_proto; |
397 provider.ProvideGeneralMetrics(&uma_proto); | 396 provider.ProvideGeneralMetrics(&uma_proto); |
398 | 397 |
399 ASSERT_EQ(1, uma_proto.sampled_profile().size()); | 398 ASSERT_EQ(1, uma_proto.sampled_profile().size()); |
400 const SampledProfile& sampled_profile = uma_proto.sampled_profile().Get(0); | 399 const SampledProfile& sampled_profile = uma_proto.sampled_profile().Get(0); |
401 ASSERT_TRUE(sampled_profile.has_call_stack_profile()); | 400 ASSERT_TRUE(sampled_profile.has_call_stack_profile()); |
402 const CallStackProfile& call_stack_profile = | 401 const CallStackProfile& call_stack_profile = |
403 sampled_profile.call_stack_profile(); | 402 sampled_profile.call_stack_profile(); |
404 | 403 |
405 ASSERT_EQ(3, call_stack_profile.sample().size()); | 404 ASSERT_EQ(3, call_stack_profile.sample().size()); |
(...skipping 17 matching lines...) Expand all Loading... |
423 entry.address()); | 422 entry.address()); |
424 ASSERT_TRUE(entry.has_module_id_index()); | 423 ASSERT_TRUE(entry.has_module_id_index()); |
425 EXPECT_EQ(sample_frames[i][j].module_index, | 424 EXPECT_EQ(sample_frames[i][j].module_index, |
426 static_cast<size_t>(entry.module_id_index())); | 425 static_cast<size_t>(entry.module_id_index())); |
427 } | 426 } |
428 } | 427 } |
429 } | 428 } |
430 | 429 |
431 // Checks that unknown modules produce an empty Entry. | 430 // Checks that unknown modules produce an empty Entry. |
432 TEST_F(CallStackProfileMetricsProviderTest, UnknownModule) { | 431 TEST_F(CallStackProfileMetricsProviderTest, UnknownModule) { |
433 const Frame frame(reinterpret_cast<const void*>(0x1000), | 432 const Frame frame(0x1000, Frame::kUnknownModuleIndex); |
434 Frame::kUnknownModuleIndex); | |
435 | 433 |
436 Profile profile; | 434 Profile profile; |
437 | 435 |
438 profile.samples.push_back(Sample(1, frame)); | 436 profile.samples.push_back(Sample(1, frame)); |
439 | 437 |
440 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); | 438 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); |
441 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); | 439 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); |
442 | 440 |
443 CallStackProfileMetricsProvider provider; | 441 CallStackProfileMetricsProvider provider; |
444 provider.OnRecordingEnabled(); | 442 provider.OnRecordingEnabled(); |
(...skipping 19 matching lines...) Expand all Loading... |
464 EXPECT_FALSE(entry.has_address()); | 462 EXPECT_FALSE(entry.has_address()); |
465 EXPECT_FALSE(entry.has_module_id_index()); | 463 EXPECT_FALSE(entry.has_module_id_index()); |
466 } | 464 } |
467 | 465 |
468 // Checks that pending profiles are only passed back to ProvideGeneralMetrics | 466 // Checks that pending profiles are only passed back to ProvideGeneralMetrics |
469 // once. | 467 // once. |
470 TEST_F(CallStackProfileMetricsProviderTest, ProfilesProvidedOnlyOnce) { | 468 TEST_F(CallStackProfileMetricsProviderTest, ProfilesProvidedOnlyOnce) { |
471 CallStackProfileMetricsProvider provider; | 469 CallStackProfileMetricsProvider provider; |
472 for (int i = 0; i < 2; ++i) { | 470 for (int i = 0; i < 2; ++i) { |
473 Profile profile; | 471 Profile profile; |
474 profile.samples.push_back(Sample(1, Frame( | 472 profile.samples.push_back( |
475 reinterpret_cast<const void*>(0x1000), Frame::kUnknownModuleIndex))); | 473 Sample(1, Frame(0x1000, Frame::kUnknownModuleIndex))); |
476 | 474 |
477 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); | 475 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); |
478 // Use the sampling period to distinguish the two profiles. | 476 // Use the sampling period to distinguish the two profiles. |
479 profile.sampling_period = base::TimeDelta::FromMilliseconds(i); | 477 profile.sampling_period = base::TimeDelta::FromMilliseconds(i); |
480 | 478 |
481 provider.OnRecordingEnabled(); | 479 provider.OnRecordingEnabled(); |
482 AppendProfiles( | 480 AppendProfiles( |
483 Params(CallStackProfileMetricsProvider::PROCESS_STARTUP, false), | 481 Params(CallStackProfileMetricsProvider::PROCESS_STARTUP, false), |
484 std::vector<Profile>(1, profile)); | 482 std::vector<Profile>(1, profile)); |
485 ChromeUserMetricsExtension uma_proto; | 483 ChromeUserMetricsExtension uma_proto; |
486 provider.ProvideGeneralMetrics(&uma_proto); | 484 provider.ProvideGeneralMetrics(&uma_proto); |
487 | 485 |
488 ASSERT_EQ(1, uma_proto.sampled_profile().size()); | 486 ASSERT_EQ(1, uma_proto.sampled_profile().size()); |
489 const SampledProfile& sampled_profile = uma_proto.sampled_profile().Get(0); | 487 const SampledProfile& sampled_profile = uma_proto.sampled_profile().Get(0); |
490 ASSERT_TRUE(sampled_profile.has_call_stack_profile()); | 488 ASSERT_TRUE(sampled_profile.has_call_stack_profile()); |
491 const CallStackProfile& call_stack_profile = | 489 const CallStackProfile& call_stack_profile = |
492 sampled_profile.call_stack_profile(); | 490 sampled_profile.call_stack_profile(); |
493 ASSERT_TRUE(call_stack_profile.has_sampling_period_ms()); | 491 ASSERT_TRUE(call_stack_profile.has_sampling_period_ms()); |
494 EXPECT_EQ(i, call_stack_profile.sampling_period_ms()); | 492 EXPECT_EQ(i, call_stack_profile.sampling_period_ms()); |
495 } | 493 } |
496 } | 494 } |
497 | 495 |
498 // Checks that pending profiles are provided to ProvideGeneralMetrics | 496 // Checks that pending profiles are provided to ProvideGeneralMetrics |
499 // when collected before CallStackProfileMetricsProvider is instantiated. | 497 // when collected before CallStackProfileMetricsProvider is instantiated. |
500 TEST_F(CallStackProfileMetricsProviderTest, | 498 TEST_F(CallStackProfileMetricsProviderTest, |
501 ProfilesProvidedWhenCollectedBeforeInstantiation) { | 499 ProfilesProvidedWhenCollectedBeforeInstantiation) { |
502 Profile profile; | 500 Profile profile; |
503 profile.samples.push_back(Sample(1, Frame( | 501 profile.samples.push_back( |
504 reinterpret_cast<const void*>(0x1000), Frame::kUnknownModuleIndex))); | 502 Sample(1, Frame(0x1000, Frame::kUnknownModuleIndex))); |
505 | 503 |
506 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); | 504 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); |
507 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); | 505 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); |
508 | 506 |
509 AppendProfiles( | 507 AppendProfiles( |
510 Params(CallStackProfileMetricsProvider::PROCESS_STARTUP, false), | 508 Params(CallStackProfileMetricsProvider::PROCESS_STARTUP, false), |
511 std::vector<Profile>(1, profile)); | 509 std::vector<Profile>(1, profile)); |
512 | 510 |
513 CallStackProfileMetricsProvider provider; | 511 CallStackProfileMetricsProvider provider; |
514 provider.OnRecordingEnabled(); | 512 provider.OnRecordingEnabled(); |
515 ChromeUserMetricsExtension uma_proto; | 513 ChromeUserMetricsExtension uma_proto; |
516 provider.ProvideGeneralMetrics(&uma_proto); | 514 provider.ProvideGeneralMetrics(&uma_proto); |
517 | 515 |
518 EXPECT_EQ(1, uma_proto.sampled_profile_size()); | 516 EXPECT_EQ(1, uma_proto.sampled_profile_size()); |
519 } | 517 } |
520 | 518 |
521 // Checks that pending profiles are not provided to ProvideGeneralMetrics | 519 // Checks that pending profiles are not provided to ProvideGeneralMetrics |
522 // while recording is disabled. | 520 // while recording is disabled. |
523 TEST_F(CallStackProfileMetricsProviderTest, ProfilesNotProvidedWhileDisabled) { | 521 TEST_F(CallStackProfileMetricsProviderTest, ProfilesNotProvidedWhileDisabled) { |
524 Profile profile; | 522 Profile profile; |
525 profile.samples.push_back(Sample(1, Frame( | 523 profile.samples.push_back( |
526 reinterpret_cast<const void*>(0x1000), Frame::kUnknownModuleIndex))); | 524 Sample(1, Frame(0x1000, Frame::kUnknownModuleIndex))); |
527 | 525 |
528 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); | 526 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); |
529 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); | 527 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); |
530 | 528 |
531 CallStackProfileMetricsProvider provider; | 529 CallStackProfileMetricsProvider provider; |
532 provider.OnRecordingDisabled(); | 530 provider.OnRecordingDisabled(); |
533 AppendProfiles( | 531 AppendProfiles( |
534 Params(CallStackProfileMetricsProvider::PROCESS_STARTUP, false), | 532 Params(CallStackProfileMetricsProvider::PROCESS_STARTUP, false), |
535 std::vector<Profile>(1, profile)); | 533 std::vector<Profile>(1, profile)); |
536 ChromeUserMetricsExtension uma_proto; | 534 ChromeUserMetricsExtension uma_proto; |
537 provider.ProvideGeneralMetrics(&uma_proto); | 535 provider.ProvideGeneralMetrics(&uma_proto); |
538 | 536 |
539 EXPECT_EQ(0, uma_proto.sampled_profile_size()); | 537 EXPECT_EQ(0, uma_proto.sampled_profile_size()); |
540 } | 538 } |
541 | 539 |
542 // Checks that pending profiles are not provided to ProvideGeneralMetrics | 540 // Checks that pending profiles are not provided to ProvideGeneralMetrics |
543 // if recording is disabled while profiling. | 541 // if recording is disabled while profiling. |
544 TEST_F(CallStackProfileMetricsProviderTest, | 542 TEST_F(CallStackProfileMetricsProviderTest, |
545 ProfilesNotProvidedAfterChangeToDisabled) { | 543 ProfilesNotProvidedAfterChangeToDisabled) { |
546 Profile profile; | 544 Profile profile; |
547 profile.samples.push_back(Sample(1, Frame( | 545 profile.samples.push_back( |
548 reinterpret_cast<const void*>(0x1000), Frame::kUnknownModuleIndex))); | 546 Sample(1, Frame(0x1000, Frame::kUnknownModuleIndex))); |
549 | 547 |
550 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); | 548 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); |
551 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); | 549 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); |
552 | 550 |
553 CallStackProfileMetricsProvider provider; | 551 CallStackProfileMetricsProvider provider; |
554 provider.OnRecordingEnabled(); | 552 provider.OnRecordingEnabled(); |
555 base::StackSamplingProfiler::CompletedCallback callback = | 553 base::StackSamplingProfiler::CompletedCallback callback = |
556 CallStackProfileMetricsProvider::GetProfilerCallback( | 554 CallStackProfileMetricsProvider::GetProfilerCallback( |
557 Params(CallStackProfileMetricsProvider::PROCESS_STARTUP, false)); | 555 Params(CallStackProfileMetricsProvider::PROCESS_STARTUP, false)); |
558 | 556 |
559 provider.OnRecordingDisabled(); | 557 provider.OnRecordingDisabled(); |
560 callback.Run(std::vector<Profile>(1, profile)); | 558 callback.Run(std::vector<Profile>(1, profile)); |
561 ChromeUserMetricsExtension uma_proto; | 559 ChromeUserMetricsExtension uma_proto; |
562 provider.ProvideGeneralMetrics(&uma_proto); | 560 provider.ProvideGeneralMetrics(&uma_proto); |
563 | 561 |
564 EXPECT_EQ(0, uma_proto.sampled_profile_size()); | 562 EXPECT_EQ(0, uma_proto.sampled_profile_size()); |
565 } | 563 } |
566 | 564 |
567 // Checks that pending profiles are not provided to ProvideGeneralMetrics if | 565 // Checks that pending profiles are not provided to ProvideGeneralMetrics if |
568 // recording is enabled, but then disabled and reenabled while profiling. | 566 // recording is enabled, but then disabled and reenabled while profiling. |
569 TEST_F(CallStackProfileMetricsProviderTest, | 567 TEST_F(CallStackProfileMetricsProviderTest, |
570 ProfilesNotProvidedAfterChangeToDisabledThenEnabled) { | 568 ProfilesNotProvidedAfterChangeToDisabledThenEnabled) { |
571 Profile profile; | 569 Profile profile; |
572 profile.samples.push_back(Sample(1, Frame( | 570 profile.samples.push_back( |
573 reinterpret_cast<const void*>(0x1000), Frame::kUnknownModuleIndex))); | 571 Sample(1, Frame(0x1000, Frame::kUnknownModuleIndex))); |
574 | 572 |
575 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); | 573 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); |
576 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); | 574 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); |
577 | 575 |
578 CallStackProfileMetricsProvider provider; | 576 CallStackProfileMetricsProvider provider; |
579 provider.OnRecordingEnabled(); | 577 provider.OnRecordingEnabled(); |
580 base::StackSamplingProfiler::CompletedCallback callback = | 578 base::StackSamplingProfiler::CompletedCallback callback = |
581 CallStackProfileMetricsProvider::GetProfilerCallback( | 579 CallStackProfileMetricsProvider::GetProfilerCallback( |
582 Params(CallStackProfileMetricsProvider::PROCESS_STARTUP, false)); | 580 Params(CallStackProfileMetricsProvider::PROCESS_STARTUP, false)); |
583 | 581 |
584 provider.OnRecordingDisabled(); | 582 provider.OnRecordingDisabled(); |
585 provider.OnRecordingEnabled(); | 583 provider.OnRecordingEnabled(); |
586 callback.Run(std::vector<Profile>(1, profile)); | 584 callback.Run(std::vector<Profile>(1, profile)); |
587 ChromeUserMetricsExtension uma_proto; | 585 ChromeUserMetricsExtension uma_proto; |
588 provider.ProvideGeneralMetrics(&uma_proto); | 586 provider.ProvideGeneralMetrics(&uma_proto); |
589 | 587 |
590 EXPECT_EQ(0, uma_proto.sampled_profile_size()); | 588 EXPECT_EQ(0, uma_proto.sampled_profile_size()); |
591 } | 589 } |
592 | 590 |
593 // Checks that pending profiles are not provided to ProvideGeneralMetrics | 591 // Checks that pending profiles are not provided to ProvideGeneralMetrics |
594 // if recording is disabled, but then enabled while profiling. | 592 // if recording is disabled, but then enabled while profiling. |
595 TEST_F(CallStackProfileMetricsProviderTest, | 593 TEST_F(CallStackProfileMetricsProviderTest, |
596 ProfilesNotProvidedAfterChangeFromDisabled) { | 594 ProfilesNotProvidedAfterChangeFromDisabled) { |
597 Profile profile; | 595 Profile profile; |
598 profile.samples.push_back(Sample(1, Frame( | 596 profile.samples.push_back( |
599 reinterpret_cast<const void*>(0x1000), Frame::kUnknownModuleIndex))); | 597 Sample(1, Frame(0x1000, Frame::kUnknownModuleIndex))); |
600 | 598 |
601 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); | 599 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); |
602 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); | 600 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); |
603 | 601 |
604 CallStackProfileMetricsProvider provider; | 602 CallStackProfileMetricsProvider provider; |
605 provider.OnRecordingDisabled(); | 603 provider.OnRecordingDisabled(); |
606 base::StackSamplingProfiler::CompletedCallback callback = | 604 base::StackSamplingProfiler::CompletedCallback callback = |
607 CallStackProfileMetricsProvider::GetProfilerCallback( | 605 CallStackProfileMetricsProvider::GetProfilerCallback( |
608 Params(CallStackProfileMetricsProvider::PROCESS_STARTUP, false)); | 606 Params(CallStackProfileMetricsProvider::PROCESS_STARTUP, false)); |
609 | 607 |
610 provider.OnRecordingEnabled(); | 608 provider.OnRecordingEnabled(); |
611 callback.Run(std::vector<Profile>(1, profile)); | 609 callback.Run(std::vector<Profile>(1, profile)); |
612 ChromeUserMetricsExtension uma_proto; | 610 ChromeUserMetricsExtension uma_proto; |
613 provider.ProvideGeneralMetrics(&uma_proto); | 611 provider.ProvideGeneralMetrics(&uma_proto); |
614 | 612 |
615 EXPECT_EQ(0, uma_proto.sampled_profile_size()); | 613 EXPECT_EQ(0, uma_proto.sampled_profile_size()); |
616 } | 614 } |
617 | 615 |
618 } // namespace metrics | 616 } // namespace metrics |
OLD | NEW |