| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/metrics/perf/perf_provider_chromeos.h" | 5 #include "chrome/browser/metrics/perf/perf_provider_chromeos.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 base::TimeDelta max_collection_delay) | 309 base::TimeDelta max_collection_delay) |
| 310 : sampling_factor_(sampling_factor), | 310 : sampling_factor_(sampling_factor), |
| 311 max_collection_delay_(max_collection_delay.ToInternalValue()) {} | 311 max_collection_delay_(max_collection_delay.ToInternalValue()) {} |
| 312 | 312 |
| 313 PerfProvider::PerfProvider() | 313 PerfProvider::PerfProvider() |
| 314 : login_observer_(this), | 314 : login_observer_(this), |
| 315 weak_factory_(this) { | 315 weak_factory_(this) { |
| 316 } | 316 } |
| 317 | 317 |
| 318 PerfProvider::~PerfProvider() { | 318 PerfProvider::~PerfProvider() { |
| 319 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 319 chromeos::LoginState::Get()->RemoveObserver(&login_observer_); | 320 chromeos::LoginState::Get()->RemoveObserver(&login_observer_); |
| 320 } | 321 } |
| 321 | 322 |
| 322 void PerfProvider::Init() { | 323 void PerfProvider::Init() { |
| 323 CHECK(command_selector_.SetOdds( | 324 CHECK(command_selector_.SetOdds( |
| 324 internal::GetDefaultCommandsForCpu(GetCPUIdentity()))); | 325 internal::GetDefaultCommandsForCpu(GetCPUIdentity()))); |
| 325 std::map<std::string, std::string> params; | 326 std::map<std::string, std::string> params; |
| 326 if (variations::GetVariationParams(kCWPFieldTrialName, ¶ms)) | 327 if (variations::GetVariationParams(kCWPFieldTrialName, ¶ms)) |
| 327 SetCollectionParamsFromVariationParams(params); | 328 SetCollectionParamsFromVariationParams(params); |
| 328 | 329 |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 if (!(base::StringToDouble(weight_str, &weight) && weight > 0.0)) | 454 if (!(base::StringToDouble(weight_str, &weight) && weight > 0.0)) |
| 454 continue; // Just drop invalid commands. | 455 continue; // Just drop invalid commands. |
| 455 std::string command(val.begin() + split + 1, val.end()); | 456 std::string command(val.begin() + split + 1, val.end()); |
| 456 commands.push_back(RandomSelector::WeightAndValue(weight, command)); | 457 commands.push_back(RandomSelector::WeightAndValue(weight, command)); |
| 457 } | 458 } |
| 458 command_selector_.SetOdds(commands); | 459 command_selector_.SetOdds(commands); |
| 459 } | 460 } |
| 460 | 461 |
| 461 bool PerfProvider::GetSampledProfiles( | 462 bool PerfProvider::GetSampledProfiles( |
| 462 std::vector<SampledProfile>* sampled_profiles) { | 463 std::vector<SampledProfile>* sampled_profiles) { |
| 463 DCHECK(CalledOnValidThread()); | 464 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 464 if (cached_perf_data_.empty()) { | 465 if (cached_perf_data_.empty()) { |
| 465 AddToPerfHistogram(NOT_READY_TO_UPLOAD); | 466 AddToPerfHistogram(NOT_READY_TO_UPLOAD); |
| 466 return false; | 467 return false; |
| 467 } | 468 } |
| 468 | 469 |
| 469 sampled_profiles->swap(cached_perf_data_); | 470 sampled_profiles->swap(cached_perf_data_); |
| 470 cached_perf_data_.clear(); | 471 cached_perf_data_.clear(); |
| 471 | 472 |
| 472 AddToPerfHistogram(SUCCESS); | 473 AddToPerfHistogram(SUCCESS); |
| 473 return true; | 474 return true; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 488 } | 489 } |
| 489 | 490 |
| 490 return PerfSubcommand::PERF_COMMAND_UNSUPPORTED; | 491 return PerfSubcommand::PERF_COMMAND_UNSUPPORTED; |
| 491 } | 492 } |
| 492 | 493 |
| 493 void PerfProvider::ParseOutputProtoIfValid( | 494 void PerfProvider::ParseOutputProtoIfValid( |
| 494 std::unique_ptr<WindowedIncognitoObserver> incognito_observer, | 495 std::unique_ptr<WindowedIncognitoObserver> incognito_observer, |
| 495 std::unique_ptr<SampledProfile> sampled_profile, | 496 std::unique_ptr<SampledProfile> sampled_profile, |
| 496 PerfSubcommand subcommand, | 497 PerfSubcommand subcommand, |
| 497 const std::string& perf_stdout) { | 498 const std::string& perf_stdout) { |
| 498 DCHECK(CalledOnValidThread()); | 499 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 499 | 500 |
| 500 // |perf_output_call_| called us, and owns |perf_stdout|. We must delete it, | 501 // |perf_output_call_| called us, and owns |perf_stdout|. We must delete it, |
| 501 // but not before parsing |perf_stdout|, and we may return early. | 502 // but not before parsing |perf_stdout|, and we may return early. |
| 502 std::unique_ptr<PerfOutputCall> call_deleter(std::move(perf_output_call_)); | 503 std::unique_ptr<PerfOutputCall> call_deleter(std::move(perf_output_call_)); |
| 503 | 504 |
| 504 if (incognito_observer->incognito_launched()) { | 505 if (incognito_observer->incognito_launched()) { |
| 505 AddToPerfHistogram(INCOGNITO_LAUNCHED); | 506 AddToPerfHistogram(INCOGNITO_LAUNCHED); |
| 506 return; | 507 return; |
| 507 } | 508 } |
| 508 | 509 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 639 next_profiling_interval_start_ = now; | 640 next_profiling_interval_start_ = now; |
| 640 ScheduleIntervalCollection(); | 641 ScheduleIntervalCollection(); |
| 641 } | 642 } |
| 642 | 643 |
| 643 void PerfProvider::Deactivate() { | 644 void PerfProvider::Deactivate() { |
| 644 // Stop the timer, but leave |cached_perf_data_| intact. | 645 // Stop the timer, but leave |cached_perf_data_| intact. |
| 645 timer_.Stop(); | 646 timer_.Stop(); |
| 646 } | 647 } |
| 647 | 648 |
| 648 void PerfProvider::ScheduleIntervalCollection() { | 649 void PerfProvider::ScheduleIntervalCollection() { |
| 649 DCHECK(CalledOnValidThread()); | 650 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 650 if (timer_.IsRunning()) | 651 if (timer_.IsRunning()) |
| 651 return; | 652 return; |
| 652 | 653 |
| 653 const base::TimeTicks now = base::TimeTicks::Now(); | 654 const base::TimeTicks now = base::TimeTicks::Now(); |
| 654 | 655 |
| 655 base::TimeTicks interval_end = | 656 base::TimeTicks interval_end = |
| 656 next_profiling_interval_start_ + collection_params_.periodic_interval(); | 657 next_profiling_interval_start_ + collection_params_.periodic_interval(); |
| 657 if (now > interval_end) { | 658 if (now > interval_end) { |
| 658 // We somehow missed at least one window. Start over. | 659 // We somehow missed at least one window. Start over. |
| 659 next_profiling_interval_start_ = now; | 660 next_profiling_interval_start_ = now; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 671 | 672 |
| 672 timer_.Start(FROM_HERE, scheduled_time - now, this, | 673 timer_.Start(FROM_HERE, scheduled_time - now, this, |
| 673 &PerfProvider::DoPeriodicCollection); | 674 &PerfProvider::DoPeriodicCollection); |
| 674 | 675 |
| 675 // Update the profiling interval tracker to the start of the next interval. | 676 // Update the profiling interval tracker to the start of the next interval. |
| 676 next_profiling_interval_start_ = interval_end; | 677 next_profiling_interval_start_ = interval_end; |
| 677 } | 678 } |
| 678 | 679 |
| 679 void PerfProvider::CollectIfNecessary( | 680 void PerfProvider::CollectIfNecessary( |
| 680 std::unique_ptr<SampledProfile> sampled_profile) { | 681 std::unique_ptr<SampledProfile> sampled_profile) { |
| 681 DCHECK(CalledOnValidThread()); | 682 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 682 | 683 |
| 683 // Schedule another interval collection. This call makes sense regardless of | 684 // Schedule another interval collection. This call makes sense regardless of |
| 684 // whether or not the current collection was interval-triggered. If it had | 685 // whether or not the current collection was interval-triggered. If it had |
| 685 // been another type of trigger event, the interval timer would have been | 686 // been another type of trigger event, the interval timer would have been |
| 686 // halted, so it makes sense to reschedule a new interval collection. | 687 // halted, so it makes sense to reschedule a new interval collection. |
| 687 ScheduleIntervalCollection(); | 688 ScheduleIntervalCollection(); |
| 688 | 689 |
| 689 // Only allow one active collection. | 690 // Only allow one active collection. |
| 690 if (perf_output_call_) { | 691 if (perf_output_call_) { |
| 691 AddToPerfHistogram(ALREADY_COLLECTING); | 692 AddToPerfHistogram(ALREADY_COLLECTING); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 752 std::unique_ptr<SampledProfile> sampled_profile(new SampledProfile); | 753 std::unique_ptr<SampledProfile> sampled_profile(new SampledProfile); |
| 753 sampled_profile->set_trigger_event(SampledProfile::RESTORE_SESSION); | 754 sampled_profile->set_trigger_event(SampledProfile::RESTORE_SESSION); |
| 754 sampled_profile->set_ms_after_restore(time_after_restore.InMilliseconds()); | 755 sampled_profile->set_ms_after_restore(time_after_restore.InMilliseconds()); |
| 755 sampled_profile->set_num_tabs_restored(num_tabs_restored); | 756 sampled_profile->set_num_tabs_restored(num_tabs_restored); |
| 756 | 757 |
| 757 CollectIfNecessary(std::move(sampled_profile)); | 758 CollectIfNecessary(std::move(sampled_profile)); |
| 758 last_session_restore_collection_time_ = base::TimeTicks::Now(); | 759 last_session_restore_collection_time_ = base::TimeTicks::Now(); |
| 759 } | 760 } |
| 760 | 761 |
| 761 } // namespace metrics | 762 } // namespace metrics |
| OLD | NEW |