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 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 } | 377 } |
378 | 378 |
379 sampled_profiles->swap(cached_perf_data_); | 379 sampled_profiles->swap(cached_perf_data_); |
380 cached_perf_data_.clear(); | 380 cached_perf_data_.clear(); |
381 | 381 |
382 AddToPerfHistogram(SUCCESS); | 382 AddToPerfHistogram(SUCCESS); |
383 return true; | 383 return true; |
384 } | 384 } |
385 | 385 |
386 void PerfProvider::ParseOutputProtoIfValid( | 386 void PerfProvider::ParseOutputProtoIfValid( |
387 scoped_ptr<WindowedIncognitoObserver> incognito_observer, | 387 std::unique_ptr<WindowedIncognitoObserver> incognito_observer, |
388 scoped_ptr<SampledProfile> sampled_profile, | 388 std::unique_ptr<SampledProfile> sampled_profile, |
389 int result, | 389 int result, |
390 const std::vector<uint8_t>& perf_data, | 390 const std::vector<uint8_t>& perf_data, |
391 const std::vector<uint8_t>& perf_stat) { | 391 const std::vector<uint8_t>& perf_stat) { |
392 DCHECK(CalledOnValidThread()); | 392 DCHECK(CalledOnValidThread()); |
393 | 393 |
394 if (incognito_observer->incognito_launched()) { | 394 if (incognito_observer->incognito_launched()) { |
395 AddToPerfHistogram(INCOGNITO_LAUNCHED); | 395 AddToPerfHistogram(INCOGNITO_LAUNCHED); |
396 return; | 396 return; |
397 } | 397 } |
398 | 398 |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 scheduled_time = now; | 546 scheduled_time = now; |
547 | 547 |
548 timer_.Start(FROM_HERE, scheduled_time - now, this, | 548 timer_.Start(FROM_HERE, scheduled_time - now, this, |
549 &PerfProvider::DoPeriodicCollection); | 549 &PerfProvider::DoPeriodicCollection); |
550 | 550 |
551 // Update the profiling interval tracker to the start of the next interval. | 551 // Update the profiling interval tracker to the start of the next interval. |
552 next_profiling_interval_start_ += collection_params_.periodic_interval(); | 552 next_profiling_interval_start_ += collection_params_.periodic_interval(); |
553 } | 553 } |
554 | 554 |
555 void PerfProvider::CollectIfNecessary( | 555 void PerfProvider::CollectIfNecessary( |
556 scoped_ptr<SampledProfile> sampled_profile) { | 556 std::unique_ptr<SampledProfile> sampled_profile) { |
557 DCHECK(CalledOnValidThread()); | 557 DCHECK(CalledOnValidThread()); |
558 | 558 |
559 // Schedule another interval collection. This call makes sense regardless of | 559 // Schedule another interval collection. This call makes sense regardless of |
560 // whether or not the current collection was interval-triggered. If it had | 560 // whether or not the current collection was interval-triggered. If it had |
561 // been another type of trigger event, the interval timer would have been | 561 // been another type of trigger event, the interval timer would have been |
562 // halted, so it makes sense to reschedule a new interval collection. | 562 // halted, so it makes sense to reschedule a new interval collection. |
563 ScheduleIntervalCollection(); | 563 ScheduleIntervalCollection(); |
564 | 564 |
565 // Do not collect further data if we've already collected a substantial amount | 565 // Do not collect further data if we've already collected a substantial amount |
566 // of data, as indicated by |kCachedPerfDataProtobufSizeThreshold|. | 566 // of data, as indicated by |kCachedPerfDataProtobufSizeThreshold|. |
567 size_t cached_perf_data_size = 0; | 567 size_t cached_perf_data_size = 0; |
568 for (size_t i = 0; i < cached_perf_data_.size(); ++i) { | 568 for (size_t i = 0; i < cached_perf_data_.size(); ++i) { |
569 cached_perf_data_size += cached_perf_data_[i].ByteSize(); | 569 cached_perf_data_size += cached_perf_data_[i].ByteSize(); |
570 } | 570 } |
571 if (cached_perf_data_size >= kCachedPerfDataProtobufSizeThreshold) { | 571 if (cached_perf_data_size >= kCachedPerfDataProtobufSizeThreshold) { |
572 AddToPerfHistogram(NOT_READY_TO_COLLECT); | 572 AddToPerfHistogram(NOT_READY_TO_COLLECT); |
573 return; | 573 return; |
574 } | 574 } |
575 | 575 |
576 // For privacy reasons, Chrome should only collect perf data if there is no | 576 // For privacy reasons, Chrome should only collect perf data if there is no |
577 // incognito session active (or gets spawned during the collection). | 577 // incognito session active (or gets spawned during the collection). |
578 if (BrowserList::IsOffTheRecordSessionActive()) { | 578 if (BrowserList::IsOffTheRecordSessionActive()) { |
579 AddToPerfHistogram(INCOGNITO_ACTIVE); | 579 AddToPerfHistogram(INCOGNITO_ACTIVE); |
580 return; | 580 return; |
581 } | 581 } |
582 | 582 |
583 scoped_ptr<WindowedIncognitoObserver> incognito_observer( | 583 std::unique_ptr<WindowedIncognitoObserver> incognito_observer( |
584 new WindowedIncognitoObserver); | 584 new WindowedIncognitoObserver); |
585 | 585 |
586 chromeos::DebugDaemonClient* client = | 586 chromeos::DebugDaemonClient* client = |
587 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient(); | 587 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient(); |
588 | 588 |
589 std::vector<std::string> command = base::SplitString( | 589 std::vector<std::string> command = base::SplitString( |
590 command_selector_.Select(), kPerfCommandDelimiter, | 590 command_selector_.Select(), kPerfCommandDelimiter, |
591 base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL); | 591 base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL); |
592 client->GetPerfOutput( | 592 client->GetPerfOutput( |
593 collection_params_.collection_duration().InSeconds(), command, | 593 collection_params_.collection_duration().InSeconds(), command, |
594 base::Bind(&PerfProvider::ParseOutputProtoIfValid, | 594 base::Bind(&PerfProvider::ParseOutputProtoIfValid, |
595 weak_factory_.GetWeakPtr(), base::Passed(&incognito_observer), | 595 weak_factory_.GetWeakPtr(), base::Passed(&incognito_observer), |
596 base::Passed(&sampled_profile))); | 596 base::Passed(&sampled_profile))); |
597 } | 597 } |
598 | 598 |
599 void PerfProvider::DoPeriodicCollection() { | 599 void PerfProvider::DoPeriodicCollection() { |
600 scoped_ptr<SampledProfile> sampled_profile(new SampledProfile); | 600 std::unique_ptr<SampledProfile> sampled_profile(new SampledProfile); |
601 sampled_profile->set_trigger_event(SampledProfile::PERIODIC_COLLECTION); | 601 sampled_profile->set_trigger_event(SampledProfile::PERIODIC_COLLECTION); |
602 | 602 |
603 CollectIfNecessary(std::move(sampled_profile)); | 603 CollectIfNecessary(std::move(sampled_profile)); |
604 } | 604 } |
605 | 605 |
606 void PerfProvider::CollectPerfDataAfterResume( | 606 void PerfProvider::CollectPerfDataAfterResume( |
607 const base::TimeDelta& sleep_duration, | 607 const base::TimeDelta& sleep_duration, |
608 const base::TimeDelta& time_after_resume) { | 608 const base::TimeDelta& time_after_resume) { |
609 // Fill out a SampledProfile protobuf that will contain the collected data. | 609 // Fill out a SampledProfile protobuf that will contain the collected data. |
610 scoped_ptr<SampledProfile> sampled_profile(new SampledProfile); | 610 std::unique_ptr<SampledProfile> sampled_profile(new SampledProfile); |
611 sampled_profile->set_trigger_event(SampledProfile::RESUME_FROM_SUSPEND); | 611 sampled_profile->set_trigger_event(SampledProfile::RESUME_FROM_SUSPEND); |
612 sampled_profile->set_suspend_duration_ms(sleep_duration.InMilliseconds()); | 612 sampled_profile->set_suspend_duration_ms(sleep_duration.InMilliseconds()); |
613 sampled_profile->set_ms_after_resume(time_after_resume.InMilliseconds()); | 613 sampled_profile->set_ms_after_resume(time_after_resume.InMilliseconds()); |
614 | 614 |
615 CollectIfNecessary(std::move(sampled_profile)); | 615 CollectIfNecessary(std::move(sampled_profile)); |
616 } | 616 } |
617 | 617 |
618 void PerfProvider::CollectPerfDataAfterSessionRestore( | 618 void PerfProvider::CollectPerfDataAfterSessionRestore( |
619 const base::TimeDelta& time_after_restore, | 619 const base::TimeDelta& time_after_restore, |
620 int num_tabs_restored) { | 620 int num_tabs_restored) { |
621 // Fill out a SampledProfile protobuf that will contain the collected data. | 621 // Fill out a SampledProfile protobuf that will contain the collected data. |
622 scoped_ptr<SampledProfile> sampled_profile(new SampledProfile); | 622 std::unique_ptr<SampledProfile> sampled_profile(new SampledProfile); |
623 sampled_profile->set_trigger_event(SampledProfile::RESTORE_SESSION); | 623 sampled_profile->set_trigger_event(SampledProfile::RESTORE_SESSION); |
624 sampled_profile->set_ms_after_restore(time_after_restore.InMilliseconds()); | 624 sampled_profile->set_ms_after_restore(time_after_restore.InMilliseconds()); |
625 sampled_profile->set_num_tabs_restored(num_tabs_restored); | 625 sampled_profile->set_num_tabs_restored(num_tabs_restored); |
626 | 626 |
627 CollectIfNecessary(std::move(sampled_profile)); | 627 CollectIfNecessary(std::move(sampled_profile)); |
628 last_session_restore_collection_time_ = base::TimeTicks::Now(); | 628 last_session_restore_collection_time_ = base::TimeTicks::Now(); |
629 } | 629 } |
630 | 630 |
631 } // namespace metrics | 631 } // namespace metrics |
OLD | NEW |