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)); |
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 callback.Run(std::move(profiles)); |
687 ChromeUserMetricsExtension uma_proto; | 677 ChromeUserMetricsExtension uma_proto; |
688 provider.ProvideGeneralMetrics(&uma_proto); | 678 provider.ProvideGeneralMetrics(&uma_proto); |
689 | 679 |
690 EXPECT_EQ(0, uma_proto.sampled_profile_size()); | 680 EXPECT_EQ(0, uma_proto.sampled_profile_size()); |
691 } | 681 } |
692 | 682 |
693 // Checks that pending profiles are not provided to ProvideGeneralMetrics if | 683 // Checks that pending profiles are not provided to ProvideGeneralMetrics if |
694 // recording is enabled, but then disabled and reenabled while profiling. | 684 // recording is enabled, but then disabled and reenabled while profiling. |
695 TEST_F(CallStackProfileMetricsProviderTest, | 685 TEST_F(CallStackProfileMetricsProviderTest, |
696 ProfilesNotProvidedAfterChangeToDisabledThenEnabled) { | 686 ProfilesNotProvidedAfterChangeToDisabledThenEnabled) { |
697 CallStackProfileMetricsProvider provider; | 687 CallStackProfileMetricsProvider provider; |
698 provider.OnRecordingEnabled(); | 688 provider.OnRecordingEnabled(); |
| 689 CallStackProfileParams params(CallStackProfileParams::BROWSER_PROCESS, |
| 690 CallStackProfileParams::UI_THREAD, |
| 691 CallStackProfileParams::PROCESS_STARTUP, |
| 692 CallStackProfileParams::MAY_SHUFFLE); |
699 base::StackSamplingProfiler::CompletedCallback callback = | 693 base::StackSamplingProfiler::CompletedCallback callback = |
700 CallStackProfileMetricsProvider::GetProfilerCallback( | 694 CallStackProfileMetricsProvider::GetProfilerCallback(¶ms); |
701 CallStackProfileParams(CallStackProfileParams::BROWSER_PROCESS, | |
702 CallStackProfileParams::UI_THREAD, | |
703 CallStackProfileParams::PROCESS_STARTUP, | |
704 CallStackProfileParams::MAY_SHUFFLE)); | |
705 provider.OnRecordingDisabled(); | 695 provider.OnRecordingDisabled(); |
706 provider.OnRecordingEnabled(); | 696 provider.OnRecordingEnabled(); |
707 | 697 |
708 Profiles profiles = ProfilesFactory() | 698 Profiles profiles = ProfilesFactory() |
709 .NewProfile(100, 10) | 699 .NewProfile(100, 10) |
710 .NewSample() | 700 .NewSample() |
711 .AddFrame(Frame::kUnknownModuleIndex, 0x1234) | 701 .AddFrame(Frame::kUnknownModuleIndex, 0x1234) |
712 .Build(); | 702 .Build(); |
713 callback.Run(std::move(profiles)); | 703 callback.Run(std::move(profiles)); |
714 ChromeUserMetricsExtension uma_proto; | 704 ChromeUserMetricsExtension uma_proto; |
715 provider.ProvideGeneralMetrics(&uma_proto); | 705 provider.ProvideGeneralMetrics(&uma_proto); |
716 | 706 |
717 EXPECT_EQ(0, uma_proto.sampled_profile_size()); | 707 EXPECT_EQ(0, uma_proto.sampled_profile_size()); |
718 } | 708 } |
719 | 709 |
720 // Checks that pending profiles are not provided to ProvideGeneralMetrics | 710 // Checks that pending profiles are not provided to ProvideGeneralMetrics |
721 // if recording is disabled, but then enabled while profiling. | 711 // if recording is disabled, but then enabled while profiling. |
722 TEST_F(CallStackProfileMetricsProviderTest, | 712 TEST_F(CallStackProfileMetricsProviderTest, |
723 ProfilesNotProvidedAfterChangeFromDisabled) { | 713 ProfilesNotProvidedAfterChangeFromDisabled) { |
724 CallStackProfileMetricsProvider provider; | 714 CallStackProfileMetricsProvider provider; |
725 provider.OnRecordingDisabled(); | 715 provider.OnRecordingDisabled(); |
| 716 CallStackProfileParams params(CallStackProfileParams::BROWSER_PROCESS, |
| 717 CallStackProfileParams::UI_THREAD, |
| 718 CallStackProfileParams::PROCESS_STARTUP, |
| 719 CallStackProfileParams::MAY_SHUFFLE); |
726 base::StackSamplingProfiler::CompletedCallback callback = | 720 base::StackSamplingProfiler::CompletedCallback callback = |
727 CallStackProfileMetricsProvider::GetProfilerCallback( | 721 CallStackProfileMetricsProvider::GetProfilerCallback(¶ms); |
728 CallStackProfileParams(CallStackProfileParams::BROWSER_PROCESS, | |
729 CallStackProfileParams::UI_THREAD, | |
730 CallStackProfileParams::PROCESS_STARTUP, | |
731 CallStackProfileParams::MAY_SHUFFLE)); | |
732 provider.OnRecordingEnabled(); | 722 provider.OnRecordingEnabled(); |
733 | 723 |
734 Profiles profiles = ProfilesFactory() | 724 Profiles profiles = ProfilesFactory() |
735 .NewProfile(100, 10) | 725 .NewProfile(100, 10) |
736 .NewSample() | 726 .NewSample() |
737 .AddFrame(Frame::kUnknownModuleIndex, 0x1234) | 727 .AddFrame(Frame::kUnknownModuleIndex, 0x1234) |
738 .Build(); | 728 .Build(); |
739 callback.Run(std::move(profiles)); | 729 callback.Run(std::move(profiles)); |
740 ChromeUserMetricsExtension uma_proto; | 730 ChromeUserMetricsExtension uma_proto; |
741 provider.ProvideGeneralMetrics(&uma_proto); | 731 provider.ProvideGeneralMetrics(&uma_proto); |
742 | 732 |
743 EXPECT_EQ(0, uma_proto.sampled_profile_size()); | 733 EXPECT_EQ(0, uma_proto.sampled_profile_size()); |
744 } | 734 } |
745 | 735 |
746 } // namespace metrics | 736 } // namespace metrics |
OLD | NEW |