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