| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/metrics/field_trial.h" | |
| 14 #include "base/profiler/stack_sampling_profiler.h" | 13 #include "base/profiler/stack_sampling_profiler.h" |
| 15 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 16 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 16 #include "base/test/scoped_feature_list.h" |
| 17 #include "build/build_config.h" | 17 #include "build/build_config.h" |
| 18 #include "components/metrics/call_stack_profile_params.h" | 18 #include "components/metrics/call_stack_profile_params.h" |
| 19 #include "components/metrics/proto/chrome_user_metrics_extension.pb.h" | 19 #include "components/metrics/proto/chrome_user_metrics_extension.pb.h" |
| 20 #include "components/variations/entropy_provider.h" | 20 #include "components/variations/entropy_provider.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 22 | 22 |
| 23 using base::StackSamplingProfiler; | 23 using base::StackSamplingProfiler; |
| 24 using Frame = StackSamplingProfiler::Frame; | 24 using Frame = StackSamplingProfiler::Frame; |
| 25 using Module = StackSamplingProfiler::Module; | 25 using Module = StackSamplingProfiler::Module; |
| 26 using Profile = StackSamplingProfiler::CallStackProfile; | 26 using Profile = StackSamplingProfiler::CallStackProfile; |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 } | 110 } |
| 111 | 111 |
| 112 Profiles ProfilesFactory::Build() { | 112 Profiles ProfilesFactory::Build() { |
| 113 return std::move(profiles_); | 113 return std::move(profiles_); |
| 114 } | 114 } |
| 115 | 115 |
| 116 } // namespace | 116 } // namespace |
| 117 | 117 |
| 118 namespace metrics { | 118 namespace metrics { |
| 119 | 119 |
| 120 // This test fixture enables the field trial that | 120 // This test fixture enables the feature that |
| 121 // CallStackProfileMetricsProvider depends on to report profiles. | 121 // CallStackProfileMetricsProvider depends on to report profiles. |
| 122 class CallStackProfileMetricsProviderTest : public testing::Test { | 122 class CallStackProfileMetricsProviderTest : public testing::Test { |
| 123 public: | 123 public: |
| 124 CallStackProfileMetricsProviderTest() | 124 CallStackProfileMetricsProviderTest() { |
| 125 : field_trial_list_(nullptr) { | 125 scoped_feature_list_.InitAndEnableFeature(TestState::kEnableReporting); |
| 126 base::FieldTrialList::CreateFieldTrial( | |
| 127 TestState::kFieldTrialName, | |
| 128 TestState::kReportProfilesGroupName); | |
| 129 TestState::ResetStaticStateForTesting(); | 126 TestState::ResetStaticStateForTesting(); |
| 130 } | 127 } |
| 131 | 128 |
| 132 ~CallStackProfileMetricsProviderTest() override {} | 129 ~CallStackProfileMetricsProviderTest() override {} |
| 133 | 130 |
| 134 // Utility function to append profiles to the metrics provider. | 131 // Utility function to append profiles to the metrics provider. |
| 135 void AppendProfiles(const CallStackProfileParams& params, Profiles profiles) { | 132 void AppendProfiles(CallStackProfileParams* params, Profiles profiles) { |
| 136 CallStackProfileMetricsProvider::GetProfilerCallback(params).Run( | 133 CallStackProfileMetricsProvider::GetProfilerCallback(params).Run( |
| 137 std::move(profiles)); | 134 std::move(profiles), nullptr); |
| 138 } | 135 } |
| 139 | 136 |
| 140 void VerifyProfileProto(const ExpectedProtoProfile& expected, | 137 void VerifyProfileProto(const ExpectedProtoProfile& expected, |
| 141 const SampledProfile& proto); | 138 const SampledProfile& proto); |
| 142 | 139 |
| 143 private: | 140 private: |
| 144 // Exposes field trial/group names from the CallStackProfileMetricsProvider. | 141 // Exposes the feature from the CallStackProfileMetricsProvider. |
| 145 class TestState : public CallStackProfileMetricsProvider { | 142 class TestState : public CallStackProfileMetricsProvider { |
| 146 public: | 143 public: |
| 147 using CallStackProfileMetricsProvider::kFieldTrialName; | 144 using CallStackProfileMetricsProvider::kEnableReporting; |
| 148 using CallStackProfileMetricsProvider::kReportProfilesGroupName; | |
| 149 using CallStackProfileMetricsProvider::ResetStaticStateForTesting; | 145 using CallStackProfileMetricsProvider::ResetStaticStateForTesting; |
| 150 }; | 146 }; |
| 151 | 147 |
| 152 base::FieldTrialList field_trial_list_; | 148 base::test::ScopedFeatureList scoped_feature_list_; |
| 153 | 149 |
| 154 DISALLOW_COPY_AND_ASSIGN(CallStackProfileMetricsProviderTest); | 150 DISALLOW_COPY_AND_ASSIGN(CallStackProfileMetricsProviderTest); |
| 155 }; | 151 }; |
| 156 | 152 |
| 157 void CallStackProfileMetricsProviderTest::VerifyProfileProto( | 153 void CallStackProfileMetricsProviderTest::VerifyProfileProto( |
| 158 const ExpectedProtoProfile& expected, | 154 const ExpectedProtoProfile& expected, |
| 159 const SampledProfile& proto) { | 155 const SampledProfile& proto) { |
| 160 ASSERT_TRUE(proto.has_call_stack_profile()); | 156 ASSERT_TRUE(proto.has_call_stack_profile()); |
| 161 const CallStackProfile& stack = proto.call_stack_profile(); | 157 const CallStackProfile& stack = proto.call_stack_profile(); |
| 162 | 158 |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 200, 20, | 332 200, 20, |
| 337 expected_proto_modules2, arraysize(expected_proto_modules2), | 333 expected_proto_modules2, arraysize(expected_proto_modules2), |
| 338 expected_proto_samples2, arraysize(expected_proto_samples2), | 334 expected_proto_samples2, arraysize(expected_proto_samples2), |
| 339 }, | 335 }, |
| 340 }; | 336 }; |
| 341 | 337 |
| 342 ASSERT_EQ(arraysize(expected_proto_profiles), profiles.size()); | 338 ASSERT_EQ(arraysize(expected_proto_profiles), profiles.size()); |
| 343 | 339 |
| 344 CallStackProfileMetricsProvider provider; | 340 CallStackProfileMetricsProvider provider; |
| 345 provider.OnRecordingEnabled(); | 341 provider.OnRecordingEnabled(); |
| 346 AppendProfiles( | 342 CallStackProfileParams params(CallStackProfileParams::BROWSER_PROCESS, |
| 347 CallStackProfileParams(CallStackProfileParams::BROWSER_PROCESS, | 343 CallStackProfileParams::UI_THREAD, |
| 348 CallStackProfileParams::UI_THREAD, | 344 CallStackProfileParams::PROCESS_STARTUP, |
| 349 CallStackProfileParams::PROCESS_STARTUP, | 345 CallStackProfileParams::MAY_SHUFFLE); |
| 350 CallStackProfileParams::MAY_SHUFFLE), | 346 AppendProfiles(¶ms, std::move(profiles)); |
| 351 std::move(profiles)); | |
| 352 ChromeUserMetricsExtension uma_proto; | 347 ChromeUserMetricsExtension uma_proto; |
| 353 provider.ProvideGeneralMetrics(&uma_proto); | 348 provider.ProvideGeneralMetrics(&uma_proto); |
| 354 | 349 |
| 355 ASSERT_EQ(static_cast<int>(arraysize(expected_proto_profiles)), | 350 ASSERT_EQ(static_cast<int>(arraysize(expected_proto_profiles)), |
| 356 uma_proto.sampled_profile().size()); | 351 uma_proto.sampled_profile().size()); |
| 357 for (size_t p = 0; p < arraysize(expected_proto_profiles); ++p) { | 352 for (size_t p = 0; p < arraysize(expected_proto_profiles); ++p) { |
| 358 SCOPED_TRACE("profile " + base::SizeTToString(p)); | 353 SCOPED_TRACE("profile " + base::SizeTToString(p)); |
| 359 VerifyProfileProto(expected_proto_profiles[p], | 354 VerifyProfileProto(expected_proto_profiles[p], |
| 360 uma_proto.sampled_profile().Get(p)); | 355 uma_proto.sampled_profile().Get(p)); |
| 361 } | 356 } |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 100, 10, | 416 100, 10, |
| 422 expected_proto_modules, arraysize(expected_proto_modules), | 417 expected_proto_modules, arraysize(expected_proto_modules), |
| 423 expected_proto_samples, arraysize(expected_proto_samples), | 418 expected_proto_samples, arraysize(expected_proto_samples), |
| 424 }, | 419 }, |
| 425 }; | 420 }; |
| 426 | 421 |
| 427 ASSERT_EQ(arraysize(expected_proto_profiles), profiles.size()); | 422 ASSERT_EQ(arraysize(expected_proto_profiles), profiles.size()); |
| 428 | 423 |
| 429 CallStackProfileMetricsProvider provider; | 424 CallStackProfileMetricsProvider provider; |
| 430 provider.OnRecordingEnabled(); | 425 provider.OnRecordingEnabled(); |
| 431 AppendProfiles( | 426 CallStackProfileParams params(CallStackProfileParams::BROWSER_PROCESS, |
| 432 CallStackProfileParams(CallStackProfileParams::BROWSER_PROCESS, | 427 CallStackProfileParams::UI_THREAD, |
| 433 CallStackProfileParams::UI_THREAD, | 428 CallStackProfileParams::PROCESS_STARTUP, |
| 434 CallStackProfileParams::PROCESS_STARTUP, | 429 CallStackProfileParams::MAY_SHUFFLE); |
| 435 CallStackProfileParams::MAY_SHUFFLE), | 430 AppendProfiles(¶ms, std::move(profiles)); |
| 436 std::move(profiles)); | |
| 437 ChromeUserMetricsExtension uma_proto; | 431 ChromeUserMetricsExtension uma_proto; |
| 438 provider.ProvideGeneralMetrics(&uma_proto); | 432 provider.ProvideGeneralMetrics(&uma_proto); |
| 439 | 433 |
| 440 ASSERT_EQ(static_cast<int>(arraysize(expected_proto_profiles)), | 434 ASSERT_EQ(static_cast<int>(arraysize(expected_proto_profiles)), |
| 441 uma_proto.sampled_profile().size()); | 435 uma_proto.sampled_profile().size()); |
| 442 for (size_t p = 0; p < arraysize(expected_proto_profiles); ++p) { | 436 for (size_t p = 0; p < arraysize(expected_proto_profiles); ++p) { |
| 443 SCOPED_TRACE("profile " + base::SizeTToString(p)); | 437 SCOPED_TRACE("profile " + base::SizeTToString(p)); |
| 444 VerifyProfileProto(expected_proto_profiles[p], | 438 VerifyProfileProto(expected_proto_profiles[p], |
| 445 uma_proto.sampled_profile().Get(p)); | 439 uma_proto.sampled_profile().Get(p)); |
| 446 } | 440 } |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 100, 10, | 502 100, 10, |
| 509 expected_proto_modules, arraysize(expected_proto_modules), | 503 expected_proto_modules, arraysize(expected_proto_modules), |
| 510 expected_proto_samples, arraysize(expected_proto_samples), | 504 expected_proto_samples, arraysize(expected_proto_samples), |
| 511 }, | 505 }, |
| 512 }; | 506 }; |
| 513 | 507 |
| 514 ASSERT_EQ(arraysize(expected_proto_profiles), profiles.size()); | 508 ASSERT_EQ(arraysize(expected_proto_profiles), profiles.size()); |
| 515 | 509 |
| 516 CallStackProfileMetricsProvider provider; | 510 CallStackProfileMetricsProvider provider; |
| 517 provider.OnRecordingEnabled(); | 511 provider.OnRecordingEnabled(); |
| 518 AppendProfiles(CallStackProfileParams(CallStackProfileParams::BROWSER_PROCESS, | 512 CallStackProfileParams params(CallStackProfileParams::BROWSER_PROCESS, |
| 519 CallStackProfileParams::UI_THREAD, | 513 CallStackProfileParams::UI_THREAD, |
| 520 CallStackProfileParams::PROCESS_STARTUP, | 514 CallStackProfileParams::PROCESS_STARTUP, |
| 521 CallStackProfileParams::PRESERVE_ORDER), | 515 CallStackProfileParams::PRESERVE_ORDER); |
| 522 std::move(profiles)); | 516 AppendProfiles(¶ms, std::move(profiles)); |
| 523 ChromeUserMetricsExtension uma_proto; | 517 ChromeUserMetricsExtension uma_proto; |
| 524 provider.ProvideGeneralMetrics(&uma_proto); | 518 provider.ProvideGeneralMetrics(&uma_proto); |
| 525 | 519 |
| 526 ASSERT_EQ(static_cast<int>(arraysize(expected_proto_profiles)), | 520 ASSERT_EQ(static_cast<int>(arraysize(expected_proto_profiles)), |
| 527 uma_proto.sampled_profile().size()); | 521 uma_proto.sampled_profile().size()); |
| 528 for (size_t p = 0; p < arraysize(expected_proto_profiles); ++p) { | 522 for (size_t p = 0; p < arraysize(expected_proto_profiles); ++p) { |
| 529 SCOPED_TRACE("profile " + base::SizeTToString(p)); | 523 SCOPED_TRACE("profile " + base::SizeTToString(p)); |
| 530 VerifyProfileProto(expected_proto_profiles[p], | 524 VerifyProfileProto(expected_proto_profiles[p], |
| 531 uma_proto.sampled_profile().Get(p)); | 525 uma_proto.sampled_profile().Get(p)); |
| 532 } | 526 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 552 100, 10, | 546 100, 10, |
| 553 nullptr, 0, | 547 nullptr, 0, |
| 554 expected_proto_samples, arraysize(expected_proto_samples), | 548 expected_proto_samples, arraysize(expected_proto_samples), |
| 555 }, | 549 }, |
| 556 }; | 550 }; |
| 557 | 551 |
| 558 ASSERT_EQ(arraysize(expected_proto_profiles), profiles.size()); | 552 ASSERT_EQ(arraysize(expected_proto_profiles), profiles.size()); |
| 559 | 553 |
| 560 CallStackProfileMetricsProvider provider; | 554 CallStackProfileMetricsProvider provider; |
| 561 provider.OnRecordingEnabled(); | 555 provider.OnRecordingEnabled(); |
| 562 AppendProfiles( | 556 CallStackProfileParams params(CallStackProfileParams::BROWSER_PROCESS, |
| 563 CallStackProfileParams(CallStackProfileParams::BROWSER_PROCESS, | 557 CallStackProfileParams::UI_THREAD, |
| 564 CallStackProfileParams::UI_THREAD, | 558 CallStackProfileParams::PROCESS_STARTUP, |
| 565 CallStackProfileParams::PROCESS_STARTUP, | 559 CallStackProfileParams::MAY_SHUFFLE); |
| 566 CallStackProfileParams::MAY_SHUFFLE), | 560 AppendProfiles(¶ms, std::move(profiles)); |
| 567 std::move(profiles)); | |
| 568 ChromeUserMetricsExtension uma_proto; | 561 ChromeUserMetricsExtension uma_proto; |
| 569 provider.ProvideGeneralMetrics(&uma_proto); | 562 provider.ProvideGeneralMetrics(&uma_proto); |
| 570 | 563 |
| 571 ASSERT_EQ(static_cast<int>(arraysize(expected_proto_profiles)), | 564 ASSERT_EQ(static_cast<int>(arraysize(expected_proto_profiles)), |
| 572 uma_proto.sampled_profile().size()); | 565 uma_proto.sampled_profile().size()); |
| 573 for (size_t p = 0; p < arraysize(expected_proto_profiles); ++p) { | 566 for (size_t p = 0; p < arraysize(expected_proto_profiles); ++p) { |
| 574 SCOPED_TRACE("profile " + base::SizeTToString(p)); | 567 SCOPED_TRACE("profile " + base::SizeTToString(p)); |
| 575 VerifyProfileProto(expected_proto_profiles[p], | 568 VerifyProfileProto(expected_proto_profiles[p], |
| 576 uma_proto.sampled_profile().Get(p)); | 569 uma_proto.sampled_profile().Get(p)); |
| 577 } | 570 } |
| 578 } | 571 } |
| 579 | 572 |
| 580 // Checks that pending profiles are only passed back to ProvideGeneralMetrics | 573 // Checks that pending profiles are only passed back to ProvideGeneralMetrics |
| 581 // once. | 574 // once. |
| 582 TEST_F(CallStackProfileMetricsProviderTest, ProfilesProvidedOnlyOnce) { | 575 TEST_F(CallStackProfileMetricsProviderTest, ProfilesProvidedOnlyOnce) { |
| 583 CallStackProfileMetricsProvider provider; | 576 CallStackProfileMetricsProvider provider; |
| 584 for (int r = 0; r < 2; ++r) { | 577 for (int r = 0; r < 2; ++r) { |
| 585 Profiles profiles = ProfilesFactory() | 578 Profiles profiles = ProfilesFactory() |
| 586 // Use the sampling period to distinguish the two profiles. | 579 // Use the sampling period to distinguish the two profiles. |
| 587 .NewProfile(100, r) | 580 .NewProfile(100, r) |
| 588 .NewSample() | 581 .NewSample() |
| 589 .AddFrame(Frame::kUnknownModuleIndex, 0x1234) | 582 .AddFrame(Frame::kUnknownModuleIndex, 0x1234) |
| 590 .Build(); | 583 .Build(); |
| 591 | 584 |
| 592 ASSERT_EQ(1U, profiles.size()); | 585 ASSERT_EQ(1U, profiles.size()); |
| 593 | 586 |
| 594 CallStackProfileMetricsProvider provider; | 587 CallStackProfileMetricsProvider provider; |
| 595 provider.OnRecordingEnabled(); | 588 provider.OnRecordingEnabled(); |
| 596 AppendProfiles( | 589 CallStackProfileParams params(CallStackProfileParams::BROWSER_PROCESS, |
| 597 CallStackProfileParams(CallStackProfileParams::BROWSER_PROCESS, | 590 CallStackProfileParams::UI_THREAD, |
| 598 CallStackProfileParams::UI_THREAD, | 591 CallStackProfileParams::PROCESS_STARTUP, |
| 599 CallStackProfileParams::PROCESS_STARTUP, | 592 CallStackProfileParams::MAY_SHUFFLE); |
| 600 CallStackProfileParams::MAY_SHUFFLE), | 593 AppendProfiles(¶ms, std::move(profiles)); |
| 601 std::move(profiles)); | |
| 602 ChromeUserMetricsExtension uma_proto; | 594 ChromeUserMetricsExtension uma_proto; |
| 603 provider.ProvideGeneralMetrics(&uma_proto); | 595 provider.ProvideGeneralMetrics(&uma_proto); |
| 604 | 596 |
| 605 ASSERT_EQ(1, uma_proto.sampled_profile().size()); | 597 ASSERT_EQ(1, uma_proto.sampled_profile().size()); |
| 606 const SampledProfile& sampled_profile = uma_proto.sampled_profile().Get(0); | 598 const SampledProfile& sampled_profile = uma_proto.sampled_profile().Get(0); |
| 607 ASSERT_TRUE(sampled_profile.has_call_stack_profile()); | 599 ASSERT_TRUE(sampled_profile.has_call_stack_profile()); |
| 608 const CallStackProfile& call_stack_profile = | 600 const CallStackProfile& call_stack_profile = |
| 609 sampled_profile.call_stack_profile(); | 601 sampled_profile.call_stack_profile(); |
| 610 ASSERT_TRUE(call_stack_profile.has_sampling_period_ms()); | 602 ASSERT_TRUE(call_stack_profile.has_sampling_period_ms()); |
| 611 EXPECT_EQ(r, call_stack_profile.sampling_period_ms()); | 603 EXPECT_EQ(r, call_stack_profile.sampling_period_ms()); |
| 612 } | 604 } |
| 613 } | 605 } |
| 614 | 606 |
| 615 // Checks that pending profiles are provided to ProvideGeneralMetrics | 607 // Checks that pending profiles are provided to ProvideGeneralMetrics |
| 616 // when collected before CallStackProfileMetricsProvider is instantiated. | 608 // when collected before CallStackProfileMetricsProvider is instantiated. |
| 617 TEST_F(CallStackProfileMetricsProviderTest, | 609 TEST_F(CallStackProfileMetricsProviderTest, |
| 618 ProfilesProvidedWhenCollectedBeforeInstantiation) { | 610 ProfilesProvidedWhenCollectedBeforeInstantiation) { |
| 619 Profiles profiles = ProfilesFactory() | 611 Profiles profiles = ProfilesFactory() |
| 620 .NewProfile(100, 10) | 612 .NewProfile(100, 10) |
| 621 .NewSample() | 613 .NewSample() |
| 622 .AddFrame(Frame::kUnknownModuleIndex, 0x1234) | 614 .AddFrame(Frame::kUnknownModuleIndex, 0x1234) |
| 623 .Build(); | 615 .Build(); |
| 624 | 616 |
| 625 ASSERT_EQ(1U, profiles.size()); | 617 ASSERT_EQ(1U, profiles.size()); |
| 626 | 618 |
| 627 AppendProfiles( | 619 CallStackProfileParams params(CallStackProfileParams::BROWSER_PROCESS, |
| 628 CallStackProfileParams(CallStackProfileParams::BROWSER_PROCESS, | 620 CallStackProfileParams::UI_THREAD, |
| 629 CallStackProfileParams::UI_THREAD, | 621 CallStackProfileParams::PROCESS_STARTUP, |
| 630 CallStackProfileParams::PROCESS_STARTUP, | 622 CallStackProfileParams::MAY_SHUFFLE); |
| 631 CallStackProfileParams::MAY_SHUFFLE), | 623 AppendProfiles(¶ms, std::move(profiles)); |
| 632 std::move(profiles)); | |
| 633 | 624 |
| 634 CallStackProfileMetricsProvider provider; | 625 CallStackProfileMetricsProvider provider; |
| 635 provider.OnRecordingEnabled(); | 626 provider.OnRecordingEnabled(); |
| 636 ChromeUserMetricsExtension uma_proto; | 627 ChromeUserMetricsExtension uma_proto; |
| 637 provider.ProvideGeneralMetrics(&uma_proto); | 628 provider.ProvideGeneralMetrics(&uma_proto); |
| 638 | 629 |
| 639 EXPECT_EQ(1, uma_proto.sampled_profile_size()); | 630 EXPECT_EQ(1, uma_proto.sampled_profile_size()); |
| 640 } | 631 } |
| 641 | 632 |
| 642 // Checks that pending profiles are not provided to ProvideGeneralMetrics | 633 // Checks that pending profiles are not provided to ProvideGeneralMetrics |
| 643 // while recording is disabled. | 634 // while recording is disabled. |
| 644 TEST_F(CallStackProfileMetricsProviderTest, ProfilesNotProvidedWhileDisabled) { | 635 TEST_F(CallStackProfileMetricsProviderTest, ProfilesNotProvidedWhileDisabled) { |
| 645 Profiles profiles = ProfilesFactory() | 636 Profiles profiles = ProfilesFactory() |
| 646 .NewProfile(100, 10) | 637 .NewProfile(100, 10) |
| 647 .NewSample() | 638 .NewSample() |
| 648 .AddFrame(Frame::kUnknownModuleIndex, 0x1234) | 639 .AddFrame(Frame::kUnknownModuleIndex, 0x1234) |
| 649 .Build(); | 640 .Build(); |
| 650 | 641 |
| 651 ASSERT_EQ(1U, profiles.size()); | 642 ASSERT_EQ(1U, profiles.size()); |
| 652 | 643 |
| 653 CallStackProfileMetricsProvider provider; | 644 CallStackProfileMetricsProvider provider; |
| 654 provider.OnRecordingDisabled(); | 645 provider.OnRecordingDisabled(); |
| 655 AppendProfiles( | 646 CallStackProfileParams params(CallStackProfileParams::BROWSER_PROCESS, |
| 656 CallStackProfileParams(CallStackProfileParams::BROWSER_PROCESS, | 647 CallStackProfileParams::UI_THREAD, |
| 657 CallStackProfileParams::UI_THREAD, | 648 CallStackProfileParams::PROCESS_STARTUP, |
| 658 CallStackProfileParams::PROCESS_STARTUP, | 649 CallStackProfileParams::MAY_SHUFFLE); |
| 659 CallStackProfileParams::MAY_SHUFFLE), | 650 AppendProfiles(¶ms, std::move(profiles)); |
| 660 std::move(profiles)); | |
| 661 ChromeUserMetricsExtension uma_proto; | 651 ChromeUserMetricsExtension uma_proto; |
| 662 provider.ProvideGeneralMetrics(&uma_proto); | 652 provider.ProvideGeneralMetrics(&uma_proto); |
| 663 | 653 |
| 664 EXPECT_EQ(0, uma_proto.sampled_profile_size()); | 654 EXPECT_EQ(0, uma_proto.sampled_profile_size()); |
| 665 } | 655 } |
| 666 | 656 |
| 667 // Checks that pending profiles are not provided to ProvideGeneralMetrics | 657 // Checks that pending profiles are not provided to ProvideGeneralMetrics |
| 668 // if recording is disabled while profiling. | 658 // if recording is disabled while profiling. |
| 669 TEST_F(CallStackProfileMetricsProviderTest, | 659 TEST_F(CallStackProfileMetricsProviderTest, |
| 670 ProfilesNotProvidedAfterChangeToDisabled) { | 660 ProfilesNotProvidedAfterChangeToDisabled) { |
| 671 CallStackProfileMetricsProvider provider; | 661 CallStackProfileMetricsProvider provider; |
| 672 provider.OnRecordingEnabled(); | 662 provider.OnRecordingEnabled(); |
| 663 CallStackProfileParams params(CallStackProfileParams::BROWSER_PROCESS, |
| 664 CallStackProfileParams::UI_THREAD, |
| 665 CallStackProfileParams::PROCESS_STARTUP, |
| 666 CallStackProfileParams::MAY_SHUFFLE); |
| 673 base::StackSamplingProfiler::CompletedCallback callback = | 667 base::StackSamplingProfiler::CompletedCallback callback = |
| 674 CallStackProfileMetricsProvider::GetProfilerCallback( | 668 CallStackProfileMetricsProvider::GetProfilerCallback(¶ms); |
| 675 CallStackProfileParams(CallStackProfileParams::BROWSER_PROCESS, | |
| 676 CallStackProfileParams::UI_THREAD, | |
| 677 CallStackProfileParams::PROCESS_STARTUP, | |
| 678 CallStackProfileParams::MAY_SHUFFLE)); | |
| 679 provider.OnRecordingDisabled(); | 669 provider.OnRecordingDisabled(); |
| 680 | 670 |
| 681 Profiles profiles = ProfilesFactory() | 671 Profiles profiles = ProfilesFactory() |
| 682 .NewProfile(100, 10) | 672 .NewProfile(100, 10) |
| 683 .NewSample() | 673 .NewSample() |
| 684 .AddFrame(Frame::kUnknownModuleIndex, 0x1234) | 674 .AddFrame(Frame::kUnknownModuleIndex, 0x1234) |
| 685 .Build(); | 675 .Build(); |
| 686 callback.Run(std::move(profiles)); | 676 base::StackSamplingProfiler::SamplingParams sampling_params; |
| 677 callback.Run(std::move(profiles), &sampling_params); |
| 687 ChromeUserMetricsExtension uma_proto; | 678 ChromeUserMetricsExtension uma_proto; |
| 688 provider.ProvideGeneralMetrics(&uma_proto); | 679 provider.ProvideGeneralMetrics(&uma_proto); |
| 689 | 680 |
| 690 EXPECT_EQ(0, uma_proto.sampled_profile_size()); | 681 EXPECT_EQ(0, uma_proto.sampled_profile_size()); |
| 691 } | 682 } |
| 692 | 683 |
| 693 // Checks that pending profiles are not provided to ProvideGeneralMetrics if | 684 // Checks that pending profiles are not provided to ProvideGeneralMetrics if |
| 694 // recording is enabled, but then disabled and reenabled while profiling. | 685 // recording is enabled, but then disabled and reenabled while profiling. |
| 695 TEST_F(CallStackProfileMetricsProviderTest, | 686 TEST_F(CallStackProfileMetricsProviderTest, |
| 696 ProfilesNotProvidedAfterChangeToDisabledThenEnabled) { | 687 ProfilesNotProvidedAfterChangeToDisabledThenEnabled) { |
| 697 CallStackProfileMetricsProvider provider; | 688 CallStackProfileMetricsProvider provider; |
| 698 provider.OnRecordingEnabled(); | 689 provider.OnRecordingEnabled(); |
| 690 CallStackProfileParams params(CallStackProfileParams::BROWSER_PROCESS, |
| 691 CallStackProfileParams::UI_THREAD, |
| 692 CallStackProfileParams::PROCESS_STARTUP, |
| 693 CallStackProfileParams::MAY_SHUFFLE); |
| 699 base::StackSamplingProfiler::CompletedCallback callback = | 694 base::StackSamplingProfiler::CompletedCallback callback = |
| 700 CallStackProfileMetricsProvider::GetProfilerCallback( | 695 CallStackProfileMetricsProvider::GetProfilerCallback(¶ms); |
| 701 CallStackProfileParams(CallStackProfileParams::BROWSER_PROCESS, | |
| 702 CallStackProfileParams::UI_THREAD, | |
| 703 CallStackProfileParams::PROCESS_STARTUP, | |
| 704 CallStackProfileParams::MAY_SHUFFLE)); | |
| 705 provider.OnRecordingDisabled(); | 696 provider.OnRecordingDisabled(); |
| 706 provider.OnRecordingEnabled(); | 697 provider.OnRecordingEnabled(); |
| 707 | 698 |
| 708 Profiles profiles = ProfilesFactory() | 699 Profiles profiles = ProfilesFactory() |
| 709 .NewProfile(100, 10) | 700 .NewProfile(100, 10) |
| 710 .NewSample() | 701 .NewSample() |
| 711 .AddFrame(Frame::kUnknownModuleIndex, 0x1234) | 702 .AddFrame(Frame::kUnknownModuleIndex, 0x1234) |
| 712 .Build(); | 703 .Build(); |
| 713 callback.Run(std::move(profiles)); | 704 base::StackSamplingProfiler::SamplingParams sampling_params; |
| 705 callback.Run(std::move(profiles), &sampling_params); |
| 714 ChromeUserMetricsExtension uma_proto; | 706 ChromeUserMetricsExtension uma_proto; |
| 715 provider.ProvideGeneralMetrics(&uma_proto); | 707 provider.ProvideGeneralMetrics(&uma_proto); |
| 716 | 708 |
| 717 EXPECT_EQ(0, uma_proto.sampled_profile_size()); | 709 EXPECT_EQ(0, uma_proto.sampled_profile_size()); |
| 718 } | 710 } |
| 719 | 711 |
| 720 // Checks that pending profiles are not provided to ProvideGeneralMetrics | 712 // Checks that pending profiles are not provided to ProvideGeneralMetrics |
| 721 // if recording is disabled, but then enabled while profiling. | 713 // if recording is disabled, but then enabled while profiling. |
| 722 TEST_F(CallStackProfileMetricsProviderTest, | 714 TEST_F(CallStackProfileMetricsProviderTest, |
| 723 ProfilesNotProvidedAfterChangeFromDisabled) { | 715 ProfilesNotProvidedAfterChangeFromDisabled) { |
| 724 CallStackProfileMetricsProvider provider; | 716 CallStackProfileMetricsProvider provider; |
| 725 provider.OnRecordingDisabled(); | 717 provider.OnRecordingDisabled(); |
| 718 CallStackProfileParams params(CallStackProfileParams::BROWSER_PROCESS, |
| 719 CallStackProfileParams::UI_THREAD, |
| 720 CallStackProfileParams::PROCESS_STARTUP, |
| 721 CallStackProfileParams::MAY_SHUFFLE); |
| 726 base::StackSamplingProfiler::CompletedCallback callback = | 722 base::StackSamplingProfiler::CompletedCallback callback = |
| 727 CallStackProfileMetricsProvider::GetProfilerCallback( | 723 CallStackProfileMetricsProvider::GetProfilerCallback(¶ms); |
| 728 CallStackProfileParams(CallStackProfileParams::BROWSER_PROCESS, | |
| 729 CallStackProfileParams::UI_THREAD, | |
| 730 CallStackProfileParams::PROCESS_STARTUP, | |
| 731 CallStackProfileParams::MAY_SHUFFLE)); | |
| 732 provider.OnRecordingEnabled(); | 724 provider.OnRecordingEnabled(); |
| 733 | 725 |
| 734 Profiles profiles = ProfilesFactory() | 726 Profiles profiles = ProfilesFactory() |
| 735 .NewProfile(100, 10) | 727 .NewProfile(100, 10) |
| 736 .NewSample() | 728 .NewSample() |
| 737 .AddFrame(Frame::kUnknownModuleIndex, 0x1234) | 729 .AddFrame(Frame::kUnknownModuleIndex, 0x1234) |
| 738 .Build(); | 730 .Build(); |
| 739 callback.Run(std::move(profiles)); | 731 base::StackSamplingProfiler::SamplingParams sampling_params; |
| 732 callback.Run(std::move(profiles), &sampling_params); |
| 740 ChromeUserMetricsExtension uma_proto; | 733 ChromeUserMetricsExtension uma_proto; |
| 741 provider.ProvideGeneralMetrics(&uma_proto); | 734 provider.ProvideGeneralMetrics(&uma_proto); |
| 742 | 735 |
| 743 EXPECT_EQ(0, uma_proto.sampled_profile_size()); | 736 EXPECT_EQ(0, uma_proto.sampled_profile_size()); |
| 744 } | 737 } |
| 745 | 738 |
| 746 } // namespace metrics | 739 } // namespace metrics |
| OLD | NEW |