| 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/call_stack_profile_params.h" |
| 7 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
| 8 #include "base/profiler/stack_sampling_profiler.h" | 9 #include "base/profiler/stack_sampling_profiler.h" |
| 9 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| 10 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 11 #include "components/metrics/proto/chrome_user_metrics_extension.pb.h" | 12 #include "components/metrics/proto/chrome_user_metrics_extension.pb.h" |
| 12 #include "components/variations/entropy_provider.h" | 13 #include "components/variations/entropy_provider.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 15 |
| 15 using base::StackSamplingProfiler; | 16 using base::StackSamplingProfiler; |
| 16 using Frame = StackSamplingProfiler::Frame; | 17 using Frame = StackSamplingProfiler::Frame; |
| 17 using Module = StackSamplingProfiler::Module; | 18 using Module = StackSamplingProfiler::Module; |
| 18 using Profile = StackSamplingProfiler::CallStackProfile; | 19 using Profile = StackSamplingProfiler::CallStackProfile; |
| 19 using Profiles = StackSamplingProfiler::CallStackProfiles; | 20 using Profiles = StackSamplingProfiler::CallStackProfiles; |
| 20 using Sample = StackSamplingProfiler::Sample; | 21 using Sample = StackSamplingProfiler::Sample; |
| 21 | 22 |
| 22 namespace metrics { | 23 namespace metrics { |
| 23 | 24 |
| 24 using Params = CallStackProfileMetricsProvider::Params; | 25 using Params = base::CallStackProfileParams; |
| 25 | 26 |
| 26 // This test fixture enables the field trial that | 27 // This test fixture enables the field trial that |
| 27 // CallStackProfileMetricsProvider depends on to report profiles. | 28 // CallStackProfileMetricsProvider depends on to report profiles. |
| 28 class CallStackProfileMetricsProviderTest : public testing::Test { | 29 class CallStackProfileMetricsProviderTest : public testing::Test { |
| 29 public: | 30 public: |
| 30 CallStackProfileMetricsProviderTest() | 31 CallStackProfileMetricsProviderTest() |
| 31 : field_trial_list_(nullptr) { | 32 : field_trial_list_(nullptr) { |
| 32 base::FieldTrialList::CreateFieldTrial( | 33 base::FieldTrialList::CreateFieldTrial( |
| 33 TestState::kFieldTrialName, | 34 TestState::kFieldTrialName, |
| 34 TestState::kReportProfilesGroupName); | 35 TestState::kReportProfilesGroupName); |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 } | 198 } |
| 198 | 199 |
| 199 profile.profile_duration = profile_durations[i]; | 200 profile.profile_duration = profile_durations[i]; |
| 200 profile.sampling_period = profile_sampling_periods[i]; | 201 profile.sampling_period = profile_sampling_periods[i]; |
| 201 | 202 |
| 202 profiles.push_back(profile); | 203 profiles.push_back(profile); |
| 203 } | 204 } |
| 204 | 205 |
| 205 CallStackProfileMetricsProvider provider; | 206 CallStackProfileMetricsProvider provider; |
| 206 provider.OnRecordingEnabled(); | 207 provider.OnRecordingEnabled(); |
| 207 AppendProfiles( | 208 AppendProfiles(Params(Params::PROCESS_STARTUP, false), profiles); |
| 208 Params(CallStackProfileMetricsProvider::PROCESS_STARTUP, false), | |
| 209 profiles); | |
| 210 ChromeUserMetricsExtension uma_proto; | 209 ChromeUserMetricsExtension uma_proto; |
| 211 provider.ProvideGeneralMetrics(&uma_proto); | 210 provider.ProvideGeneralMetrics(&uma_proto); |
| 212 | 211 |
| 213 ASSERT_EQ(static_cast<int>(arraysize(profile_sample_frames)), | 212 ASSERT_EQ(static_cast<int>(arraysize(profile_sample_frames)), |
| 214 uma_proto.sampled_profile().size()); | 213 uma_proto.sampled_profile().size()); |
| 215 for (size_t i = 0; i < arraysize(profile_sample_frames); ++i) { | 214 for (size_t i = 0; i < arraysize(profile_sample_frames); ++i) { |
| 216 SCOPED_TRACE("profile " + base::IntToString(i)); | 215 SCOPED_TRACE("profile " + base::IntToString(i)); |
| 217 const SampledProfile& sampled_profile = uma_proto.sampled_profile().Get(i); | 216 const SampledProfile& sampled_profile = uma_proto.sampled_profile().Get(i); |
| 218 ASSERT_TRUE(sampled_profile.has_call_stack_profile()); | 217 ASSERT_TRUE(sampled_profile.has_call_stack_profile()); |
| 219 const CallStackProfile& call_stack_profile = | 218 const CallStackProfile& call_stack_profile = |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 Sample& sample = profile.samples.back(); | 303 Sample& sample = profile.samples.back(); |
| 305 sample.insert(sample.end(), &sample_frames[i][0], | 304 sample.insert(sample.end(), &sample_frames[i][0], |
| 306 &sample_frames[i][0] + arraysize(sample_frames[i])); | 305 &sample_frames[i][0] + arraysize(sample_frames[i])); |
| 307 } | 306 } |
| 308 | 307 |
| 309 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); | 308 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); |
| 310 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); | 309 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); |
| 311 | 310 |
| 312 CallStackProfileMetricsProvider provider; | 311 CallStackProfileMetricsProvider provider; |
| 313 provider.OnRecordingEnabled(); | 312 provider.OnRecordingEnabled(); |
| 314 AppendProfiles( | 313 AppendProfiles(Params(Params::PROCESS_STARTUP, false), |
| 315 Params(CallStackProfileMetricsProvider::PROCESS_STARTUP, false), | 314 std::vector<Profile>(1, profile)); |
| 316 std::vector<Profile>(1, profile)); | |
| 317 ChromeUserMetricsExtension uma_proto; | 315 ChromeUserMetricsExtension uma_proto; |
| 318 provider.ProvideGeneralMetrics(&uma_proto); | 316 provider.ProvideGeneralMetrics(&uma_proto); |
| 319 | 317 |
| 320 ASSERT_EQ(1, uma_proto.sampled_profile().size()); | 318 ASSERT_EQ(1, uma_proto.sampled_profile().size()); |
| 321 const SampledProfile& sampled_profile = uma_proto.sampled_profile().Get(0); | 319 const SampledProfile& sampled_profile = uma_proto.sampled_profile().Get(0); |
| 322 ASSERT_TRUE(sampled_profile.has_call_stack_profile()); | 320 ASSERT_TRUE(sampled_profile.has_call_stack_profile()); |
| 323 const CallStackProfile& call_stack_profile = | 321 const CallStackProfile& call_stack_profile = |
| 324 sampled_profile.call_stack_profile(); | 322 sampled_profile.call_stack_profile(); |
| 325 | 323 |
| 326 ASSERT_EQ(2, call_stack_profile.sample().size()); | 324 ASSERT_EQ(2, call_stack_profile.sample().size()); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 Sample& sample = profile.samples.back(); | 381 Sample& sample = profile.samples.back(); |
| 384 sample.insert(sample.end(), &sample_frames[i][0], | 382 sample.insert(sample.end(), &sample_frames[i][0], |
| 385 &sample_frames[i][0] + arraysize(sample_frames[i])); | 383 &sample_frames[i][0] + arraysize(sample_frames[i])); |
| 386 } | 384 } |
| 387 | 385 |
| 388 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); | 386 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); |
| 389 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); | 387 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); |
| 390 | 388 |
| 391 CallStackProfileMetricsProvider provider; | 389 CallStackProfileMetricsProvider provider; |
| 392 provider.OnRecordingEnabled(); | 390 provider.OnRecordingEnabled(); |
| 393 AppendProfiles( | 391 AppendProfiles(Params(Params::PROCESS_STARTUP, true), |
| 394 Params(CallStackProfileMetricsProvider::PROCESS_STARTUP, true), | 392 std::vector<Profile>(1, profile)); |
| 395 std::vector<Profile>(1, profile)); | |
| 396 ChromeUserMetricsExtension uma_proto; | 393 ChromeUserMetricsExtension uma_proto; |
| 397 provider.ProvideGeneralMetrics(&uma_proto); | 394 provider.ProvideGeneralMetrics(&uma_proto); |
| 398 | 395 |
| 399 ASSERT_EQ(1, uma_proto.sampled_profile().size()); | 396 ASSERT_EQ(1, uma_proto.sampled_profile().size()); |
| 400 const SampledProfile& sampled_profile = uma_proto.sampled_profile().Get(0); | 397 const SampledProfile& sampled_profile = uma_proto.sampled_profile().Get(0); |
| 401 ASSERT_TRUE(sampled_profile.has_call_stack_profile()); | 398 ASSERT_TRUE(sampled_profile.has_call_stack_profile()); |
| 402 const CallStackProfile& call_stack_profile = | 399 const CallStackProfile& call_stack_profile = |
| 403 sampled_profile.call_stack_profile(); | 400 sampled_profile.call_stack_profile(); |
| 404 | 401 |
| 405 ASSERT_EQ(3, call_stack_profile.sample().size()); | 402 ASSERT_EQ(3, call_stack_profile.sample().size()); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 435 | 432 |
| 436 Profile profile; | 433 Profile profile; |
| 437 | 434 |
| 438 profile.samples.push_back(Sample(1, frame)); | 435 profile.samples.push_back(Sample(1, frame)); |
| 439 | 436 |
| 440 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); | 437 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); |
| 441 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); | 438 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); |
| 442 | 439 |
| 443 CallStackProfileMetricsProvider provider; | 440 CallStackProfileMetricsProvider provider; |
| 444 provider.OnRecordingEnabled(); | 441 provider.OnRecordingEnabled(); |
| 445 AppendProfiles( | 442 AppendProfiles(Params(Params::PROCESS_STARTUP, false), |
| 446 Params(CallStackProfileMetricsProvider::PROCESS_STARTUP, false), | 443 std::vector<Profile>(1, profile)); |
| 447 std::vector<Profile>(1, profile)); | |
| 448 ChromeUserMetricsExtension uma_proto; | 444 ChromeUserMetricsExtension uma_proto; |
| 449 provider.ProvideGeneralMetrics(&uma_proto); | 445 provider.ProvideGeneralMetrics(&uma_proto); |
| 450 | 446 |
| 451 ASSERT_EQ(1, uma_proto.sampled_profile().size()); | 447 ASSERT_EQ(1, uma_proto.sampled_profile().size()); |
| 452 const SampledProfile& sampled_profile = uma_proto.sampled_profile().Get(0); | 448 const SampledProfile& sampled_profile = uma_proto.sampled_profile().Get(0); |
| 453 ASSERT_TRUE(sampled_profile.has_call_stack_profile()); | 449 ASSERT_TRUE(sampled_profile.has_call_stack_profile()); |
| 454 const CallStackProfile& call_stack_profile = | 450 const CallStackProfile& call_stack_profile = |
| 455 sampled_profile.call_stack_profile(); | 451 sampled_profile.call_stack_profile(); |
| 456 | 452 |
| 457 ASSERT_EQ(1, call_stack_profile.sample().size()); | 453 ASSERT_EQ(1, call_stack_profile.sample().size()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 472 for (int i = 0; i < 2; ++i) { | 468 for (int i = 0; i < 2; ++i) { |
| 473 Profile profile; | 469 Profile profile; |
| 474 profile.samples.push_back(Sample(1, Frame( | 470 profile.samples.push_back(Sample(1, Frame( |
| 475 reinterpret_cast<const void*>(0x1000), Frame::kUnknownModuleIndex))); | 471 reinterpret_cast<const void*>(0x1000), Frame::kUnknownModuleIndex))); |
| 476 | 472 |
| 477 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); | 473 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); |
| 478 // Use the sampling period to distinguish the two profiles. | 474 // Use the sampling period to distinguish the two profiles. |
| 479 profile.sampling_period = base::TimeDelta::FromMilliseconds(i); | 475 profile.sampling_period = base::TimeDelta::FromMilliseconds(i); |
| 480 | 476 |
| 481 provider.OnRecordingEnabled(); | 477 provider.OnRecordingEnabled(); |
| 482 AppendProfiles( | 478 AppendProfiles(Params(Params::PROCESS_STARTUP, false), |
| 483 Params(CallStackProfileMetricsProvider::PROCESS_STARTUP, false), | 479 std::vector<Profile>(1, profile)); |
| 484 std::vector<Profile>(1, profile)); | |
| 485 ChromeUserMetricsExtension uma_proto; | 480 ChromeUserMetricsExtension uma_proto; |
| 486 provider.ProvideGeneralMetrics(&uma_proto); | 481 provider.ProvideGeneralMetrics(&uma_proto); |
| 487 | 482 |
| 488 ASSERT_EQ(1, uma_proto.sampled_profile().size()); | 483 ASSERT_EQ(1, uma_proto.sampled_profile().size()); |
| 489 const SampledProfile& sampled_profile = uma_proto.sampled_profile().Get(0); | 484 const SampledProfile& sampled_profile = uma_proto.sampled_profile().Get(0); |
| 490 ASSERT_TRUE(sampled_profile.has_call_stack_profile()); | 485 ASSERT_TRUE(sampled_profile.has_call_stack_profile()); |
| 491 const CallStackProfile& call_stack_profile = | 486 const CallStackProfile& call_stack_profile = |
| 492 sampled_profile.call_stack_profile(); | 487 sampled_profile.call_stack_profile(); |
| 493 ASSERT_TRUE(call_stack_profile.has_sampling_period_ms()); | 488 ASSERT_TRUE(call_stack_profile.has_sampling_period_ms()); |
| 494 EXPECT_EQ(i, call_stack_profile.sampling_period_ms()); | 489 EXPECT_EQ(i, call_stack_profile.sampling_period_ms()); |
| 495 } | 490 } |
| 496 } | 491 } |
| 497 | 492 |
| 498 // Checks that pending profiles are provided to ProvideGeneralMetrics | 493 // Checks that pending profiles are provided to ProvideGeneralMetrics |
| 499 // when collected before CallStackProfileMetricsProvider is instantiated. | 494 // when collected before CallStackProfileMetricsProvider is instantiated. |
| 500 TEST_F(CallStackProfileMetricsProviderTest, | 495 TEST_F(CallStackProfileMetricsProviderTest, |
| 501 ProfilesProvidedWhenCollectedBeforeInstantiation) { | 496 ProfilesProvidedWhenCollectedBeforeInstantiation) { |
| 502 Profile profile; | 497 Profile profile; |
| 503 profile.samples.push_back(Sample(1, Frame( | 498 profile.samples.push_back(Sample(1, Frame( |
| 504 reinterpret_cast<const void*>(0x1000), Frame::kUnknownModuleIndex))); | 499 reinterpret_cast<const void*>(0x1000), Frame::kUnknownModuleIndex))); |
| 505 | 500 |
| 506 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); | 501 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); |
| 507 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); | 502 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); |
| 508 | 503 |
| 509 AppendProfiles( | 504 AppendProfiles(Params(Params::PROCESS_STARTUP, false), |
| 510 Params(CallStackProfileMetricsProvider::PROCESS_STARTUP, false), | 505 std::vector<Profile>(1, profile)); |
| 511 std::vector<Profile>(1, profile)); | |
| 512 | 506 |
| 513 CallStackProfileMetricsProvider provider; | 507 CallStackProfileMetricsProvider provider; |
| 514 provider.OnRecordingEnabled(); | 508 provider.OnRecordingEnabled(); |
| 515 ChromeUserMetricsExtension uma_proto; | 509 ChromeUserMetricsExtension uma_proto; |
| 516 provider.ProvideGeneralMetrics(&uma_proto); | 510 provider.ProvideGeneralMetrics(&uma_proto); |
| 517 | 511 |
| 518 EXPECT_EQ(1, uma_proto.sampled_profile_size()); | 512 EXPECT_EQ(1, uma_proto.sampled_profile_size()); |
| 519 } | 513 } |
| 520 | 514 |
| 521 // Checks that pending profiles are not provided to ProvideGeneralMetrics | 515 // Checks that pending profiles are not provided to ProvideGeneralMetrics |
| 522 // while recording is disabled. | 516 // while recording is disabled. |
| 523 TEST_F(CallStackProfileMetricsProviderTest, ProfilesNotProvidedWhileDisabled) { | 517 TEST_F(CallStackProfileMetricsProviderTest, ProfilesNotProvidedWhileDisabled) { |
| 524 Profile profile; | 518 Profile profile; |
| 525 profile.samples.push_back(Sample(1, Frame( | 519 profile.samples.push_back(Sample(1, Frame( |
| 526 reinterpret_cast<const void*>(0x1000), Frame::kUnknownModuleIndex))); | 520 reinterpret_cast<const void*>(0x1000), Frame::kUnknownModuleIndex))); |
| 527 | 521 |
| 528 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); | 522 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); |
| 529 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); | 523 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); |
| 530 | 524 |
| 531 CallStackProfileMetricsProvider provider; | 525 CallStackProfileMetricsProvider provider; |
| 532 provider.OnRecordingDisabled(); | 526 provider.OnRecordingDisabled(); |
| 533 AppendProfiles( | 527 AppendProfiles(Params(Params::PROCESS_STARTUP, false), |
| 534 Params(CallStackProfileMetricsProvider::PROCESS_STARTUP, false), | 528 std::vector<Profile>(1, profile)); |
| 535 std::vector<Profile>(1, profile)); | |
| 536 ChromeUserMetricsExtension uma_proto; | 529 ChromeUserMetricsExtension uma_proto; |
| 537 provider.ProvideGeneralMetrics(&uma_proto); | 530 provider.ProvideGeneralMetrics(&uma_proto); |
| 538 | 531 |
| 539 EXPECT_EQ(0, uma_proto.sampled_profile_size()); | 532 EXPECT_EQ(0, uma_proto.sampled_profile_size()); |
| 540 } | 533 } |
| 541 | 534 |
| 542 // Checks that pending profiles are not provided to ProvideGeneralMetrics | 535 // Checks that pending profiles are not provided to ProvideGeneralMetrics |
| 543 // if recording is disabled while profiling. | 536 // if recording is disabled while profiling. |
| 544 TEST_F(CallStackProfileMetricsProviderTest, | 537 TEST_F(CallStackProfileMetricsProviderTest, |
| 545 ProfilesNotProvidedAfterChangeToDisabled) { | 538 ProfilesNotProvidedAfterChangeToDisabled) { |
| 546 Profile profile; | 539 Profile profile; |
| 547 profile.samples.push_back(Sample(1, Frame( | 540 profile.samples.push_back(Sample(1, Frame( |
| 548 reinterpret_cast<const void*>(0x1000), Frame::kUnknownModuleIndex))); | 541 reinterpret_cast<const void*>(0x1000), Frame::kUnknownModuleIndex))); |
| 549 | 542 |
| 550 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); | 543 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); |
| 551 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); | 544 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); |
| 552 | 545 |
| 553 CallStackProfileMetricsProvider provider; | 546 CallStackProfileMetricsProvider provider; |
| 554 provider.OnRecordingEnabled(); | 547 provider.OnRecordingEnabled(); |
| 555 base::StackSamplingProfiler::CompletedCallback callback = | 548 base::StackSamplingProfiler::CompletedCallback callback = |
| 556 CallStackProfileMetricsProvider::GetProfilerCallback( | 549 CallStackProfileMetricsProvider::GetProfilerCallback( |
| 557 Params(CallStackProfileMetricsProvider::PROCESS_STARTUP, false)); | 550 Params(Params::PROCESS_STARTUP, false)); |
| 558 | 551 |
| 559 provider.OnRecordingDisabled(); | 552 provider.OnRecordingDisabled(); |
| 560 callback.Run(std::vector<Profile>(1, profile)); | 553 callback.Run(std::vector<Profile>(1, profile)); |
| 561 ChromeUserMetricsExtension uma_proto; | 554 ChromeUserMetricsExtension uma_proto; |
| 562 provider.ProvideGeneralMetrics(&uma_proto); | 555 provider.ProvideGeneralMetrics(&uma_proto); |
| 563 | 556 |
| 564 EXPECT_EQ(0, uma_proto.sampled_profile_size()); | 557 EXPECT_EQ(0, uma_proto.sampled_profile_size()); |
| 565 } | 558 } |
| 566 | 559 |
| 567 // Checks that pending profiles are not provided to ProvideGeneralMetrics if | 560 // Checks that pending profiles are not provided to ProvideGeneralMetrics if |
| 568 // recording is enabled, but then disabled and reenabled while profiling. | 561 // recording is enabled, but then disabled and reenabled while profiling. |
| 569 TEST_F(CallStackProfileMetricsProviderTest, | 562 TEST_F(CallStackProfileMetricsProviderTest, |
| 570 ProfilesNotProvidedAfterChangeToDisabledThenEnabled) { | 563 ProfilesNotProvidedAfterChangeToDisabledThenEnabled) { |
| 571 Profile profile; | 564 Profile profile; |
| 572 profile.samples.push_back(Sample(1, Frame( | 565 profile.samples.push_back(Sample(1, Frame( |
| 573 reinterpret_cast<const void*>(0x1000), Frame::kUnknownModuleIndex))); | 566 reinterpret_cast<const void*>(0x1000), Frame::kUnknownModuleIndex))); |
| 574 | 567 |
| 575 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); | 568 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); |
| 576 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); | 569 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); |
| 577 | 570 |
| 578 CallStackProfileMetricsProvider provider; | 571 CallStackProfileMetricsProvider provider; |
| 579 provider.OnRecordingEnabled(); | 572 provider.OnRecordingEnabled(); |
| 580 base::StackSamplingProfiler::CompletedCallback callback = | 573 base::StackSamplingProfiler::CompletedCallback callback = |
| 581 CallStackProfileMetricsProvider::GetProfilerCallback( | 574 CallStackProfileMetricsProvider::GetProfilerCallback( |
| 582 Params(CallStackProfileMetricsProvider::PROCESS_STARTUP, false)); | 575 Params(Params::PROCESS_STARTUP, false)); |
| 583 | 576 |
| 584 provider.OnRecordingDisabled(); | 577 provider.OnRecordingDisabled(); |
| 585 provider.OnRecordingEnabled(); | 578 provider.OnRecordingEnabled(); |
| 586 callback.Run(std::vector<Profile>(1, profile)); | 579 callback.Run(std::vector<Profile>(1, profile)); |
| 587 ChromeUserMetricsExtension uma_proto; | 580 ChromeUserMetricsExtension uma_proto; |
| 588 provider.ProvideGeneralMetrics(&uma_proto); | 581 provider.ProvideGeneralMetrics(&uma_proto); |
| 589 | 582 |
| 590 EXPECT_EQ(0, uma_proto.sampled_profile_size()); | 583 EXPECT_EQ(0, uma_proto.sampled_profile_size()); |
| 591 } | 584 } |
| 592 | 585 |
| 593 // Checks that pending profiles are not provided to ProvideGeneralMetrics | 586 // Checks that pending profiles are not provided to ProvideGeneralMetrics |
| 594 // if recording is disabled, but then enabled while profiling. | 587 // if recording is disabled, but then enabled while profiling. |
| 595 TEST_F(CallStackProfileMetricsProviderTest, | 588 TEST_F(CallStackProfileMetricsProviderTest, |
| 596 ProfilesNotProvidedAfterChangeFromDisabled) { | 589 ProfilesNotProvidedAfterChangeFromDisabled) { |
| 597 Profile profile; | 590 Profile profile; |
| 598 profile.samples.push_back(Sample(1, Frame( | 591 profile.samples.push_back(Sample(1, Frame( |
| 599 reinterpret_cast<const void*>(0x1000), Frame::kUnknownModuleIndex))); | 592 reinterpret_cast<const void*>(0x1000), Frame::kUnknownModuleIndex))); |
| 600 | 593 |
| 601 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); | 594 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); |
| 602 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); | 595 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); |
| 603 | 596 |
| 604 CallStackProfileMetricsProvider provider; | 597 CallStackProfileMetricsProvider provider; |
| 605 provider.OnRecordingDisabled(); | 598 provider.OnRecordingDisabled(); |
| 606 base::StackSamplingProfiler::CompletedCallback callback = | 599 base::StackSamplingProfiler::CompletedCallback callback = |
| 607 CallStackProfileMetricsProvider::GetProfilerCallback( | 600 CallStackProfileMetricsProvider::GetProfilerCallback( |
| 608 Params(CallStackProfileMetricsProvider::PROCESS_STARTUP, false)); | 601 Params(Params::PROCESS_STARTUP, false)); |
| 609 | 602 |
| 610 provider.OnRecordingEnabled(); | 603 provider.OnRecordingEnabled(); |
| 611 callback.Run(std::vector<Profile>(1, profile)); | 604 callback.Run(std::vector<Profile>(1, profile)); |
| 612 ChromeUserMetricsExtension uma_proto; | 605 ChromeUserMetricsExtension uma_proto; |
| 613 provider.ProvideGeneralMetrics(&uma_proto); | 606 provider.ProvideGeneralMetrics(&uma_proto); |
| 614 | 607 |
| 615 EXPECT_EQ(0, uma_proto.sampled_profile_size()); | 608 EXPECT_EQ(0, uma_proto.sampled_profile_size()); |
| 616 } | 609 } |
| 617 | 610 |
| 618 } // namespace metrics | 611 } // namespace metrics |
| OLD | NEW |