| 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 "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 : field_trial_list_(nullptr) { | 35 : field_trial_list_(nullptr) { |
| 36 base::FieldTrialList::CreateFieldTrial( | 36 base::FieldTrialList::CreateFieldTrial( |
| 37 TestState::kFieldTrialName, | 37 TestState::kFieldTrialName, |
| 38 TestState::kReportProfilesGroupName); | 38 TestState::kReportProfilesGroupName); |
| 39 TestState::ResetStaticStateForTesting(); | 39 TestState::ResetStaticStateForTesting(); |
| 40 } | 40 } |
| 41 | 41 |
| 42 ~CallStackProfileMetricsProviderTest() override {} | 42 ~CallStackProfileMetricsProviderTest() override {} |
| 43 | 43 |
| 44 // Utility function to append profiles to the metrics provider. | 44 // Utility function to append profiles to the metrics provider. |
| 45 void AppendProfiles(const CallStackProfileParams& params, | 45 void AppendProfiles(const CallStackProfileParams& params, Profiles profiles) { |
| 46 const Profiles& profiles) { | 46 CallStackProfileMetricsProvider::GetProfilerCallback(params).Run( |
| 47 CallStackProfileMetricsProvider::GetProfilerCallback(params).Run(profiles); | 47 std::move(profiles)); |
| 48 } | 48 } |
| 49 | 49 |
| 50 private: | 50 private: |
| 51 // Exposes field trial/group names from the CallStackProfileMetricsProvider. | 51 // Exposes field trial/group names from the CallStackProfileMetricsProvider. |
| 52 class TestState : public CallStackProfileMetricsProvider { | 52 class TestState : public CallStackProfileMetricsProvider { |
| 53 public: | 53 public: |
| 54 using CallStackProfileMetricsProvider::kFieldTrialName; | 54 using CallStackProfileMetricsProvider::kFieldTrialName; |
| 55 using CallStackProfileMetricsProvider::kReportProfilesGroupName; | 55 using CallStackProfileMetricsProvider::kReportProfilesGroupName; |
| 56 using CallStackProfileMetricsProvider::ResetStaticStateForTesting; | 56 using CallStackProfileMetricsProvider::ResetStaticStateForTesting; |
| 57 }; | 57 }; |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 profile.samples.push_back(Sample()); | 192 profile.samples.push_back(Sample()); |
| 193 Sample& sample = profile.samples.back(); | 193 Sample& sample = profile.samples.back(); |
| 194 sample.insert(sample.end(), &profile_sample_frames[i][j][0], | 194 sample.insert(sample.end(), &profile_sample_frames[i][j][0], |
| 195 &profile_sample_frames[i][j][0] + | 195 &profile_sample_frames[i][j][0] + |
| 196 arraysize(profile_sample_frames[i][j])); | 196 arraysize(profile_sample_frames[i][j])); |
| 197 } | 197 } |
| 198 | 198 |
| 199 profile.profile_duration = profile_durations[i]; | 199 profile.profile_duration = profile_durations[i]; |
| 200 profile.sampling_period = profile_sampling_periods[i]; | 200 profile.sampling_period = profile_sampling_periods[i]; |
| 201 | 201 |
| 202 profiles.push_back(profile); | 202 profiles.push_back(std::move(profile)); |
| 203 } | 203 } |
| 204 | 204 |
| 205 CallStackProfileMetricsProvider provider; | 205 CallStackProfileMetricsProvider provider; |
| 206 provider.OnRecordingEnabled(); | 206 provider.OnRecordingEnabled(); |
| 207 AppendProfiles( | 207 AppendProfiles( |
| 208 CallStackProfileParams(CallStackProfileParams::BROWSER_PROCESS, | 208 CallStackProfileParams(CallStackProfileParams::BROWSER_PROCESS, |
| 209 CallStackProfileParams::UI_THREAD, | 209 CallStackProfileParams::UI_THREAD, |
| 210 CallStackProfileParams::PROCESS_STARTUP, | 210 CallStackProfileParams::PROCESS_STARTUP, |
| 211 CallStackProfileParams::MAY_SHUFFLE), | 211 CallStackProfileParams::MAY_SHUFFLE), |
| 212 profiles); | 212 std::move(profiles)); |
| 213 ChromeUserMetricsExtension uma_proto; | 213 ChromeUserMetricsExtension uma_proto; |
| 214 provider.ProvideGeneralMetrics(&uma_proto); | 214 provider.ProvideGeneralMetrics(&uma_proto); |
| 215 | 215 |
| 216 ASSERT_EQ(static_cast<int>(arraysize(profile_sample_frames)), | 216 ASSERT_EQ(static_cast<int>(arraysize(profile_sample_frames)), |
| 217 uma_proto.sampled_profile().size()); | 217 uma_proto.sampled_profile().size()); |
| 218 for (size_t i = 0; i < arraysize(profile_sample_frames); ++i) { | 218 for (size_t i = 0; i < arraysize(profile_sample_frames); ++i) { |
| 219 SCOPED_TRACE("profile " + base::SizeTToString(i)); | 219 SCOPED_TRACE("profile " + base::SizeTToString(i)); |
| 220 const SampledProfile& sampled_profile = uma_proto.sampled_profile().Get(i); | 220 const SampledProfile& sampled_profile = uma_proto.sampled_profile().Get(i); |
| 221 ASSERT_TRUE(sampled_profile.has_call_stack_profile()); | 221 ASSERT_TRUE(sampled_profile.has_call_stack_profile()); |
| 222 const CallStackProfile& call_stack_profile = | 222 const CallStackProfile& call_stack_profile = |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 | 309 |
| 310 for (size_t i = 0; i < arraysize(sample_frames); ++i) { | 310 for (size_t i = 0; i < arraysize(sample_frames); ++i) { |
| 311 profile.samples.push_back(Sample()); | 311 profile.samples.push_back(Sample()); |
| 312 Sample& sample = profile.samples.back(); | 312 Sample& sample = profile.samples.back(); |
| 313 sample.insert(sample.end(), &sample_frames[i][0], | 313 sample.insert(sample.end(), &sample_frames[i][0], |
| 314 &sample_frames[i][0] + arraysize(sample_frames[i])); | 314 &sample_frames[i][0] + arraysize(sample_frames[i])); |
| 315 } | 315 } |
| 316 | 316 |
| 317 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); | 317 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); |
| 318 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); | 318 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); |
| 319 Profiles profiles; |
| 320 profiles.push_back(std::move(profile)); |
| 319 | 321 |
| 320 CallStackProfileMetricsProvider provider; | 322 CallStackProfileMetricsProvider provider; |
| 321 provider.OnRecordingEnabled(); | 323 provider.OnRecordingEnabled(); |
| 322 AppendProfiles( | 324 AppendProfiles( |
| 323 CallStackProfileParams(CallStackProfileParams::BROWSER_PROCESS, | 325 CallStackProfileParams(CallStackProfileParams::BROWSER_PROCESS, |
| 324 CallStackProfileParams::UI_THREAD, | 326 CallStackProfileParams::UI_THREAD, |
| 325 CallStackProfileParams::PROCESS_STARTUP, | 327 CallStackProfileParams::PROCESS_STARTUP, |
| 326 CallStackProfileParams::MAY_SHUFFLE), | 328 CallStackProfileParams::MAY_SHUFFLE), |
| 327 std::vector<Profile>(1, profile)); | 329 std::move(profiles)); |
| 328 ChromeUserMetricsExtension uma_proto; | 330 ChromeUserMetricsExtension uma_proto; |
| 329 provider.ProvideGeneralMetrics(&uma_proto); | 331 provider.ProvideGeneralMetrics(&uma_proto); |
| 330 | 332 |
| 331 ASSERT_EQ(1, uma_proto.sampled_profile().size()); | 333 ASSERT_EQ(1, uma_proto.sampled_profile().size()); |
| 332 const SampledProfile& sampled_profile = uma_proto.sampled_profile().Get(0); | 334 const SampledProfile& sampled_profile = uma_proto.sampled_profile().Get(0); |
| 333 ASSERT_TRUE(sampled_profile.has_call_stack_profile()); | 335 ASSERT_TRUE(sampled_profile.has_call_stack_profile()); |
| 334 const CallStackProfile& call_stack_profile = | 336 const CallStackProfile& call_stack_profile = |
| 335 sampled_profile.call_stack_profile(); | 337 sampled_profile.call_stack_profile(); |
| 336 | 338 |
| 337 ASSERT_EQ(2, call_stack_profile.sample().size()); | 339 ASSERT_EQ(2, call_stack_profile.sample().size()); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 | 394 |
| 393 for (size_t i = 0; i < arraysize(sample_frames); ++i) { | 395 for (size_t i = 0; i < arraysize(sample_frames); ++i) { |
| 394 profile.samples.push_back(Sample()); | 396 profile.samples.push_back(Sample()); |
| 395 Sample& sample = profile.samples.back(); | 397 Sample& sample = profile.samples.back(); |
| 396 sample.insert(sample.end(), &sample_frames[i][0], | 398 sample.insert(sample.end(), &sample_frames[i][0], |
| 397 &sample_frames[i][0] + arraysize(sample_frames[i])); | 399 &sample_frames[i][0] + arraysize(sample_frames[i])); |
| 398 } | 400 } |
| 399 | 401 |
| 400 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); | 402 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); |
| 401 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); | 403 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); |
| 404 Profiles profiles; |
| 405 profiles.push_back(std::move(profile)); |
| 402 | 406 |
| 403 CallStackProfileMetricsProvider provider; | 407 CallStackProfileMetricsProvider provider; |
| 404 provider.OnRecordingEnabled(); | 408 provider.OnRecordingEnabled(); |
| 405 AppendProfiles(CallStackProfileParams(CallStackProfileParams::BROWSER_PROCESS, | 409 AppendProfiles(CallStackProfileParams(CallStackProfileParams::BROWSER_PROCESS, |
| 406 CallStackProfileParams::UI_THREAD, | 410 CallStackProfileParams::UI_THREAD, |
| 407 CallStackProfileParams::PROCESS_STARTUP, | 411 CallStackProfileParams::PROCESS_STARTUP, |
| 408 CallStackProfileParams::PRESERVE_ORDER), | 412 CallStackProfileParams::PRESERVE_ORDER), |
| 409 std::vector<Profile>(1, profile)); | 413 std::move(profiles)); |
| 410 ChromeUserMetricsExtension uma_proto; | 414 ChromeUserMetricsExtension uma_proto; |
| 411 provider.ProvideGeneralMetrics(&uma_proto); | 415 provider.ProvideGeneralMetrics(&uma_proto); |
| 412 | 416 |
| 413 ASSERT_EQ(1, uma_proto.sampled_profile().size()); | 417 ASSERT_EQ(1, uma_proto.sampled_profile().size()); |
| 414 const SampledProfile& sampled_profile = uma_proto.sampled_profile().Get(0); | 418 const SampledProfile& sampled_profile = uma_proto.sampled_profile().Get(0); |
| 415 ASSERT_TRUE(sampled_profile.has_call_stack_profile()); | 419 ASSERT_TRUE(sampled_profile.has_call_stack_profile()); |
| 416 const CallStackProfile& call_stack_profile = | 420 const CallStackProfile& call_stack_profile = |
| 417 sampled_profile.call_stack_profile(); | 421 sampled_profile.call_stack_profile(); |
| 418 | 422 |
| 419 ASSERT_EQ(3, call_stack_profile.sample().size()); | 423 ASSERT_EQ(3, call_stack_profile.sample().size()); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 446 // Checks that unknown modules produce an empty Entry. | 450 // Checks that unknown modules produce an empty Entry. |
| 447 TEST_F(CallStackProfileMetricsProviderTest, UnknownModule) { | 451 TEST_F(CallStackProfileMetricsProviderTest, UnknownModule) { |
| 448 const Frame frame(0x1000, Frame::kUnknownModuleIndex); | 452 const Frame frame(0x1000, Frame::kUnknownModuleIndex); |
| 449 | 453 |
| 450 Profile profile; | 454 Profile profile; |
| 451 | 455 |
| 452 profile.samples.push_back(Sample(1, frame)); | 456 profile.samples.push_back(Sample(1, frame)); |
| 453 | 457 |
| 454 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); | 458 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); |
| 455 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); | 459 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); |
| 460 Profiles profiles; |
| 461 profiles.push_back(std::move(profile)); |
| 456 | 462 |
| 457 CallStackProfileMetricsProvider provider; | 463 CallStackProfileMetricsProvider provider; |
| 458 provider.OnRecordingEnabled(); | 464 provider.OnRecordingEnabled(); |
| 459 AppendProfiles( | 465 AppendProfiles( |
| 460 CallStackProfileParams(CallStackProfileParams::BROWSER_PROCESS, | 466 CallStackProfileParams(CallStackProfileParams::BROWSER_PROCESS, |
| 461 CallStackProfileParams::UI_THREAD, | 467 CallStackProfileParams::UI_THREAD, |
| 462 CallStackProfileParams::PROCESS_STARTUP, | 468 CallStackProfileParams::PROCESS_STARTUP, |
| 463 CallStackProfileParams::MAY_SHUFFLE), | 469 CallStackProfileParams::MAY_SHUFFLE), |
| 464 std::vector<Profile>(1, profile)); | 470 std::move(profiles)); |
| 465 ChromeUserMetricsExtension uma_proto; | 471 ChromeUserMetricsExtension uma_proto; |
| 466 provider.ProvideGeneralMetrics(&uma_proto); | 472 provider.ProvideGeneralMetrics(&uma_proto); |
| 467 | 473 |
| 468 ASSERT_EQ(1, uma_proto.sampled_profile().size()); | 474 ASSERT_EQ(1, uma_proto.sampled_profile().size()); |
| 469 const SampledProfile& sampled_profile = uma_proto.sampled_profile().Get(0); | 475 const SampledProfile& sampled_profile = uma_proto.sampled_profile().Get(0); |
| 470 ASSERT_TRUE(sampled_profile.has_call_stack_profile()); | 476 ASSERT_TRUE(sampled_profile.has_call_stack_profile()); |
| 471 const CallStackProfile& call_stack_profile = | 477 const CallStackProfile& call_stack_profile = |
| 472 sampled_profile.call_stack_profile(); | 478 sampled_profile.call_stack_profile(); |
| 473 | 479 |
| 474 ASSERT_EQ(1, call_stack_profile.sample().size()); | 480 ASSERT_EQ(1, call_stack_profile.sample().size()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 487 TEST_F(CallStackProfileMetricsProviderTest, ProfilesProvidedOnlyOnce) { | 493 TEST_F(CallStackProfileMetricsProviderTest, ProfilesProvidedOnlyOnce) { |
| 488 CallStackProfileMetricsProvider provider; | 494 CallStackProfileMetricsProvider provider; |
| 489 for (int i = 0; i < 2; ++i) { | 495 for (int i = 0; i < 2; ++i) { |
| 490 Profile profile; | 496 Profile profile; |
| 491 profile.samples.push_back( | 497 profile.samples.push_back( |
| 492 Sample(1, Frame(0x1000, Frame::kUnknownModuleIndex))); | 498 Sample(1, Frame(0x1000, Frame::kUnknownModuleIndex))); |
| 493 | 499 |
| 494 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); | 500 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); |
| 495 // Use the sampling period to distinguish the two profiles. | 501 // Use the sampling period to distinguish the two profiles. |
| 496 profile.sampling_period = base::TimeDelta::FromMilliseconds(i); | 502 profile.sampling_period = base::TimeDelta::FromMilliseconds(i); |
| 503 Profiles profiles; |
| 504 profiles.push_back(std::move(profile)); |
| 497 | 505 |
| 498 provider.OnRecordingEnabled(); | 506 provider.OnRecordingEnabled(); |
| 499 AppendProfiles( | 507 AppendProfiles( |
| 500 CallStackProfileParams(CallStackProfileParams::BROWSER_PROCESS, | 508 CallStackProfileParams(CallStackProfileParams::BROWSER_PROCESS, |
| 501 CallStackProfileParams::UI_THREAD, | 509 CallStackProfileParams::UI_THREAD, |
| 502 CallStackProfileParams::PROCESS_STARTUP, | 510 CallStackProfileParams::PROCESS_STARTUP, |
| 503 CallStackProfileParams::MAY_SHUFFLE), | 511 CallStackProfileParams::MAY_SHUFFLE), |
| 504 std::vector<Profile>(1, profile)); | 512 std::move(profiles)); |
| 505 ChromeUserMetricsExtension uma_proto; | 513 ChromeUserMetricsExtension uma_proto; |
| 506 provider.ProvideGeneralMetrics(&uma_proto); | 514 provider.ProvideGeneralMetrics(&uma_proto); |
| 507 | 515 |
| 508 ASSERT_EQ(1, uma_proto.sampled_profile().size()); | 516 ASSERT_EQ(1, uma_proto.sampled_profile().size()); |
| 509 const SampledProfile& sampled_profile = uma_proto.sampled_profile().Get(0); | 517 const SampledProfile& sampled_profile = uma_proto.sampled_profile().Get(0); |
| 510 ASSERT_TRUE(sampled_profile.has_call_stack_profile()); | 518 ASSERT_TRUE(sampled_profile.has_call_stack_profile()); |
| 511 const CallStackProfile& call_stack_profile = | 519 const CallStackProfile& call_stack_profile = |
| 512 sampled_profile.call_stack_profile(); | 520 sampled_profile.call_stack_profile(); |
| 513 ASSERT_TRUE(call_stack_profile.has_sampling_period_ms()); | 521 ASSERT_TRUE(call_stack_profile.has_sampling_period_ms()); |
| 514 EXPECT_EQ(i, call_stack_profile.sampling_period_ms()); | 522 EXPECT_EQ(i, call_stack_profile.sampling_period_ms()); |
| 515 } | 523 } |
| 516 } | 524 } |
| 517 | 525 |
| 518 // Checks that pending profiles are provided to ProvideGeneralMetrics | 526 // Checks that pending profiles are provided to ProvideGeneralMetrics |
| 519 // when collected before CallStackProfileMetricsProvider is instantiated. | 527 // when collected before CallStackProfileMetricsProvider is instantiated. |
| 520 TEST_F(CallStackProfileMetricsProviderTest, | 528 TEST_F(CallStackProfileMetricsProviderTest, |
| 521 ProfilesProvidedWhenCollectedBeforeInstantiation) { | 529 ProfilesProvidedWhenCollectedBeforeInstantiation) { |
| 522 Profile profile; | 530 Profile profile; |
| 523 profile.samples.push_back( | 531 profile.samples.push_back( |
| 524 Sample(1, Frame(0x1000, Frame::kUnknownModuleIndex))); | 532 Sample(1, Frame(0x1000, Frame::kUnknownModuleIndex))); |
| 525 | 533 |
| 526 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); | 534 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); |
| 527 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); | 535 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); |
| 536 Profiles profiles; |
| 537 profiles.push_back(std::move(profile)); |
| 528 | 538 |
| 529 AppendProfiles( | 539 AppendProfiles( |
| 530 CallStackProfileParams(CallStackProfileParams::BROWSER_PROCESS, | 540 CallStackProfileParams(CallStackProfileParams::BROWSER_PROCESS, |
| 531 CallStackProfileParams::UI_THREAD, | 541 CallStackProfileParams::UI_THREAD, |
| 532 CallStackProfileParams::PROCESS_STARTUP, | 542 CallStackProfileParams::PROCESS_STARTUP, |
| 533 CallStackProfileParams::MAY_SHUFFLE), | 543 CallStackProfileParams::MAY_SHUFFLE), |
| 534 std::vector<Profile>(1, profile)); | 544 std::move(profiles)); |
| 535 | 545 |
| 536 CallStackProfileMetricsProvider provider; | 546 CallStackProfileMetricsProvider provider; |
| 537 provider.OnRecordingEnabled(); | 547 provider.OnRecordingEnabled(); |
| 538 ChromeUserMetricsExtension uma_proto; | 548 ChromeUserMetricsExtension uma_proto; |
| 539 provider.ProvideGeneralMetrics(&uma_proto); | 549 provider.ProvideGeneralMetrics(&uma_proto); |
| 540 | 550 |
| 541 EXPECT_EQ(1, uma_proto.sampled_profile_size()); | 551 EXPECT_EQ(1, uma_proto.sampled_profile_size()); |
| 542 } | 552 } |
| 543 | 553 |
| 544 // Checks that pending profiles are not provided to ProvideGeneralMetrics | 554 // Checks that pending profiles are not provided to ProvideGeneralMetrics |
| 545 // while recording is disabled. | 555 // while recording is disabled. |
| 546 TEST_F(CallStackProfileMetricsProviderTest, ProfilesNotProvidedWhileDisabled) { | 556 TEST_F(CallStackProfileMetricsProviderTest, ProfilesNotProvidedWhileDisabled) { |
| 547 Profile profile; | 557 Profile profile; |
| 548 profile.samples.push_back( | 558 profile.samples.push_back( |
| 549 Sample(1, Frame(0x1000, Frame::kUnknownModuleIndex))); | 559 Sample(1, Frame(0x1000, Frame::kUnknownModuleIndex))); |
| 550 | 560 |
| 551 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); | 561 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); |
| 552 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); | 562 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); |
| 563 Profiles profiles; |
| 564 profiles.push_back(std::move(profile)); |
| 553 | 565 |
| 554 CallStackProfileMetricsProvider provider; | 566 CallStackProfileMetricsProvider provider; |
| 555 provider.OnRecordingDisabled(); | 567 provider.OnRecordingDisabled(); |
| 556 AppendProfiles( | 568 AppendProfiles( |
| 557 CallStackProfileParams(CallStackProfileParams::BROWSER_PROCESS, | 569 CallStackProfileParams(CallStackProfileParams::BROWSER_PROCESS, |
| 558 CallStackProfileParams::UI_THREAD, | 570 CallStackProfileParams::UI_THREAD, |
| 559 CallStackProfileParams::PROCESS_STARTUP, | 571 CallStackProfileParams::PROCESS_STARTUP, |
| 560 CallStackProfileParams::MAY_SHUFFLE), | 572 CallStackProfileParams::MAY_SHUFFLE), |
| 561 std::vector<Profile>(1, profile)); | 573 std::move(profiles)); |
| 562 ChromeUserMetricsExtension uma_proto; | 574 ChromeUserMetricsExtension uma_proto; |
| 563 provider.ProvideGeneralMetrics(&uma_proto); | 575 provider.ProvideGeneralMetrics(&uma_proto); |
| 564 | 576 |
| 565 EXPECT_EQ(0, uma_proto.sampled_profile_size()); | 577 EXPECT_EQ(0, uma_proto.sampled_profile_size()); |
| 566 } | 578 } |
| 567 | 579 |
| 568 // Checks that pending profiles are not provided to ProvideGeneralMetrics | 580 // Checks that pending profiles are not provided to ProvideGeneralMetrics |
| 569 // if recording is disabled while profiling. | 581 // if recording is disabled while profiling. |
| 570 TEST_F(CallStackProfileMetricsProviderTest, | 582 TEST_F(CallStackProfileMetricsProviderTest, |
| 571 ProfilesNotProvidedAfterChangeToDisabled) { | 583 ProfilesNotProvidedAfterChangeToDisabled) { |
| 572 Profile profile; | 584 Profile profile; |
| 573 profile.samples.push_back( | 585 profile.samples.push_back( |
| 574 Sample(1, Frame(0x1000, Frame::kUnknownModuleIndex))); | 586 Sample(1, Frame(0x1000, Frame::kUnknownModuleIndex))); |
| 575 | 587 |
| 576 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); | 588 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); |
| 577 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); | 589 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); |
| 578 | 590 |
| 579 CallStackProfileMetricsProvider provider; | 591 CallStackProfileMetricsProvider provider; |
| 580 provider.OnRecordingEnabled(); | 592 provider.OnRecordingEnabled(); |
| 581 base::StackSamplingProfiler::CompletedCallback callback = | 593 base::StackSamplingProfiler::CompletedCallback callback = |
| 582 CallStackProfileMetricsProvider::GetProfilerCallback( | 594 CallStackProfileMetricsProvider::GetProfilerCallback( |
| 583 CallStackProfileParams(CallStackProfileParams::BROWSER_PROCESS, | 595 CallStackProfileParams(CallStackProfileParams::BROWSER_PROCESS, |
| 584 CallStackProfileParams::UI_THREAD, | 596 CallStackProfileParams::UI_THREAD, |
| 585 CallStackProfileParams::PROCESS_STARTUP, | 597 CallStackProfileParams::PROCESS_STARTUP, |
| 586 CallStackProfileParams::MAY_SHUFFLE)); | 598 CallStackProfileParams::MAY_SHUFFLE)); |
| 587 | 599 |
| 588 provider.OnRecordingDisabled(); | 600 provider.OnRecordingDisabled(); |
| 589 callback.Run(std::vector<Profile>(1, profile)); | 601 Profiles profiles; |
| 602 profiles.push_back(std::move(profile)); |
| 603 callback.Run(std::move(profiles)); |
| 590 ChromeUserMetricsExtension uma_proto; | 604 ChromeUserMetricsExtension uma_proto; |
| 591 provider.ProvideGeneralMetrics(&uma_proto); | 605 provider.ProvideGeneralMetrics(&uma_proto); |
| 592 | 606 |
| 593 EXPECT_EQ(0, uma_proto.sampled_profile_size()); | 607 EXPECT_EQ(0, uma_proto.sampled_profile_size()); |
| 594 } | 608 } |
| 595 | 609 |
| 596 // Checks that pending profiles are not provided to ProvideGeneralMetrics if | 610 // Checks that pending profiles are not provided to ProvideGeneralMetrics if |
| 597 // recording is enabled, but then disabled and reenabled while profiling. | 611 // recording is enabled, but then disabled and reenabled while profiling. |
| 598 TEST_F(CallStackProfileMetricsProviderTest, | 612 TEST_F(CallStackProfileMetricsProviderTest, |
| 599 ProfilesNotProvidedAfterChangeToDisabledThenEnabled) { | 613 ProfilesNotProvidedAfterChangeToDisabledThenEnabled) { |
| 600 Profile profile; | 614 Profile profile; |
| 601 profile.samples.push_back( | 615 profile.samples.push_back( |
| 602 Sample(1, Frame(0x1000, Frame::kUnknownModuleIndex))); | 616 Sample(1, Frame(0x1000, Frame::kUnknownModuleIndex))); |
| 603 | 617 |
| 604 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); | 618 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); |
| 605 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); | 619 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); |
| 606 | 620 |
| 607 CallStackProfileMetricsProvider provider; | 621 CallStackProfileMetricsProvider provider; |
| 608 provider.OnRecordingEnabled(); | 622 provider.OnRecordingEnabled(); |
| 609 base::StackSamplingProfiler::CompletedCallback callback = | 623 base::StackSamplingProfiler::CompletedCallback callback = |
| 610 CallStackProfileMetricsProvider::GetProfilerCallback( | 624 CallStackProfileMetricsProvider::GetProfilerCallback( |
| 611 CallStackProfileParams(CallStackProfileParams::BROWSER_PROCESS, | 625 CallStackProfileParams(CallStackProfileParams::BROWSER_PROCESS, |
| 612 CallStackProfileParams::UI_THREAD, | 626 CallStackProfileParams::UI_THREAD, |
| 613 CallStackProfileParams::PROCESS_STARTUP, | 627 CallStackProfileParams::PROCESS_STARTUP, |
| 614 CallStackProfileParams::MAY_SHUFFLE)); | 628 CallStackProfileParams::MAY_SHUFFLE)); |
| 615 | 629 |
| 616 provider.OnRecordingDisabled(); | 630 provider.OnRecordingDisabled(); |
| 617 provider.OnRecordingEnabled(); | 631 provider.OnRecordingEnabled(); |
| 618 callback.Run(std::vector<Profile>(1, profile)); | 632 Profiles profiles; |
| 633 profiles.push_back(std::move(profile)); |
| 634 callback.Run(std::move(profiles)); |
| 619 ChromeUserMetricsExtension uma_proto; | 635 ChromeUserMetricsExtension uma_proto; |
| 620 provider.ProvideGeneralMetrics(&uma_proto); | 636 provider.ProvideGeneralMetrics(&uma_proto); |
| 621 | 637 |
| 622 EXPECT_EQ(0, uma_proto.sampled_profile_size()); | 638 EXPECT_EQ(0, uma_proto.sampled_profile_size()); |
| 623 } | 639 } |
| 624 | 640 |
| 625 // Checks that pending profiles are not provided to ProvideGeneralMetrics | 641 // Checks that pending profiles are not provided to ProvideGeneralMetrics |
| 626 // if recording is disabled, but then enabled while profiling. | 642 // if recording is disabled, but then enabled while profiling. |
| 627 TEST_F(CallStackProfileMetricsProviderTest, | 643 TEST_F(CallStackProfileMetricsProviderTest, |
| 628 ProfilesNotProvidedAfterChangeFromDisabled) { | 644 ProfilesNotProvidedAfterChangeFromDisabled) { |
| 629 Profile profile; | 645 Profile profile; |
| 630 profile.samples.push_back( | 646 profile.samples.push_back( |
| 631 Sample(1, Frame(0x1000, Frame::kUnknownModuleIndex))); | 647 Sample(1, Frame(0x1000, Frame::kUnknownModuleIndex))); |
| 632 | 648 |
| 633 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); | 649 profile.profile_duration = base::TimeDelta::FromMilliseconds(100); |
| 634 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); | 650 profile.sampling_period = base::TimeDelta::FromMilliseconds(10); |
| 635 | 651 |
| 636 CallStackProfileMetricsProvider provider; | 652 CallStackProfileMetricsProvider provider; |
| 637 provider.OnRecordingDisabled(); | 653 provider.OnRecordingDisabled(); |
| 638 base::StackSamplingProfiler::CompletedCallback callback = | 654 base::StackSamplingProfiler::CompletedCallback callback = |
| 639 CallStackProfileMetricsProvider::GetProfilerCallback( | 655 CallStackProfileMetricsProvider::GetProfilerCallback( |
| 640 CallStackProfileParams(CallStackProfileParams::BROWSER_PROCESS, | 656 CallStackProfileParams(CallStackProfileParams::BROWSER_PROCESS, |
| 641 CallStackProfileParams::UI_THREAD, | 657 CallStackProfileParams::UI_THREAD, |
| 642 CallStackProfileParams::PROCESS_STARTUP, | 658 CallStackProfileParams::PROCESS_STARTUP, |
| 643 CallStackProfileParams::MAY_SHUFFLE)); | 659 CallStackProfileParams::MAY_SHUFFLE)); |
| 644 | 660 |
| 645 provider.OnRecordingEnabled(); | 661 provider.OnRecordingEnabled(); |
| 646 callback.Run(std::vector<Profile>(1, profile)); | 662 Profiles profiles; |
| 663 profiles.push_back(std::move(profile)); |
| 664 callback.Run(std::move(profiles)); |
| 647 ChromeUserMetricsExtension uma_proto; | 665 ChromeUserMetricsExtension uma_proto; |
| 648 provider.ProvideGeneralMetrics(&uma_proto); | 666 provider.ProvideGeneralMetrics(&uma_proto); |
| 649 | 667 |
| 650 EXPECT_EQ(0, uma_proto.sampled_profile_size()); | 668 EXPECT_EQ(0, uma_proto.sampled_profile_size()); |
| 651 } | 669 } |
| 652 | 670 |
| 653 } // namespace metrics | 671 } // namespace metrics |
| OLD | NEW |