Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(318)

Side by Side Diff: components/startup_metric_utils/browser/startup_metric_utils.cc

Issue 2773973002: Add Startup.BrowserView.FirstPaint / .CompositingEnded histograms. (Closed)
Patch Set: Fix gab's and asvitkine's remarks. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/startup_metric_utils/browser/startup_metric_utils.h" 5 #include "components/startup_metric_utils/browser/startup_metric_utils.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <string> 10 #include <string>
(...skipping 21 matching lines...) Expand all
32 #include <winternl.h> 32 #include <winternl.h>
33 #include "base/win/win_util.h" 33 #include "base/win/win_util.h"
34 #endif 34 #endif
35 35
36 namespace startup_metric_utils { 36 namespace startup_metric_utils {
37 37
38 namespace { 38 namespace {
39 39
40 // Mark as volatile to defensively make sure usage is thread-safe. 40 // Mark as volatile to defensively make sure usage is thread-safe.
41 // Note that at the time of this writing, access is only on the UI thread. 41 // Note that at the time of this writing, access is only on the UI thread.
42 volatile bool g_non_browser_ui_displayed = false; 42 volatile bool g_main_window_startup_interrupted = false;
43 43
44 base::LazyInstance<base::TimeTicks>::Leaky g_process_creation_ticks = 44 base::LazyInstance<base::TimeTicks>::Leaky g_process_creation_ticks =
45 LAZY_INSTANCE_INITIALIZER; 45 LAZY_INSTANCE_INITIALIZER;
46 46
47 base::LazyInstance<base::TimeTicks>::Leaky g_browser_main_entry_point_ticks = 47 base::LazyInstance<base::TimeTicks>::Leaky g_browser_main_entry_point_ticks =
48 LAZY_INSTANCE_INITIALIZER; 48 LAZY_INSTANCE_INITIALIZER;
49 49
50 base::LazyInstance<base::TimeTicks>::Leaky g_renderer_main_entry_point_ticks = 50 base::LazyInstance<base::TimeTicks>::Leaky g_renderer_main_entry_point_ticks =
51 LAZY_INSTANCE_INITIALIZER; 51 LAZY_INSTANCE_INITIALIZER;
52 52
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 } else { 541 } else {
542 g_startups_with_current_version = 1; 542 g_startups_with_current_version = 1;
543 pref_service->SetString(prefs::kLastStartupVersion, current_version); 543 pref_service->SetString(prefs::kLastStartupVersion, current_version);
544 pref_service->SetInteger(prefs::kSameVersionStartupCount, 1); 544 pref_service->SetInteger(prefs::kSameVersionStartupCount, 1);
545 } 545 }
546 546
547 UMA_HISTOGRAM_COUNTS_100("Startup.SameVersionStartupCount", 547 UMA_HISTOGRAM_COUNTS_100("Startup.SameVersionStartupCount",
548 g_startups_with_current_version); 548 g_startups_with_current_version);
549 } 549 }
550 550
551 bool ShouldLogProcessCreationTicksHistogram() {
552 return !WasMainWindowStartupInterrupted() &&
553 !g_process_creation_ticks.Get().is_null();
554 }
555
551 } // namespace 556 } // namespace
552 557
553 void RegisterPrefs(PrefRegistrySimple* registry) { 558 void RegisterPrefs(PrefRegistrySimple* registry) {
554 DCHECK(registry); 559 DCHECK(registry);
555 registry->RegisterInt64Pref(prefs::kLastStartupTimestamp, 0); 560 registry->RegisterInt64Pref(prefs::kLastStartupTimestamp, 0);
556 registry->RegisterStringPref(prefs::kLastStartupVersion, std::string()); 561 registry->RegisterStringPref(prefs::kLastStartupVersion, std::string());
557 registry->RegisterIntegerPref(prefs::kSameVersionStartupCount, 0); 562 registry->RegisterIntegerPref(prefs::kSameVersionStartupCount, 0);
558 } 563 }
559 564
560 bool WasNonBrowserUIDisplayed() { 565 bool WasMainWindowStartupInterrupted() {
561 return g_non_browser_ui_displayed; 566 return g_main_window_startup_interrupted;
562 } 567 }
563 568
564 void SetNonBrowserUIDisplayed() { 569 void SetNonBrowserUIDisplayed() {
565 g_non_browser_ui_displayed = true; 570 g_main_window_startup_interrupted = true;
571 }
572
573 void SetBackgroundModeEnabled() {
574 g_main_window_startup_interrupted = true;
566 } 575 }
567 576
568 void RecordStartupProcessCreationTime(const base::Time& time) { 577 void RecordStartupProcessCreationTime(const base::Time& time) {
569 DCHECK(g_process_creation_ticks.Get().is_null()); 578 DCHECK(g_process_creation_ticks.Get().is_null());
570 g_process_creation_ticks.Get() = StartupTimeToTimeTicks(time); 579 g_process_creation_ticks.Get() = StartupTimeToTimeTicks(time);
571 DCHECK(!g_process_creation_ticks.Get().is_null()); 580 DCHECK(!g_process_creation_ticks.Get().is_null());
572 } 581 }
573 582
574 void RecordMainEntryPointTime(const base::Time& time) { 583 void RecordMainEntryPointTime(const base::Time& time) {
575 DCHECK(g_browser_main_entry_point_ticks.Get().is_null()); 584 DCHECK(g_browser_main_entry_point_ticks.Get().is_null());
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 UMA_HISTOGRAM_LONG_TIMES, "Startup.LoadTime.ProcessCreateToDllMain2", 664 UMA_HISTOGRAM_LONG_TIMES, "Startup.LoadTime.ProcessCreateToDllMain2",
656 main_entry_ticks - process_creation_ticks); 665 main_entry_ticks - process_creation_ticks);
657 } 666 }
658 } 667 }
659 668
660 void RecordBrowserWindowDisplay(const base::TimeTicks& ticks) { 669 void RecordBrowserWindowDisplay(const base::TimeTicks& ticks) {
661 static bool is_first_call = true; 670 static bool is_first_call = true;
662 if (!is_first_call || ticks.is_null()) 671 if (!is_first_call || ticks.is_null())
663 return; 672 return;
664 is_first_call = false; 673 is_first_call = false;
665 if (WasNonBrowserUIDisplayed() || g_process_creation_ticks.Get().is_null()) 674 if (!ShouldLogProcessCreationTicksHistogram())
666 return; 675 return;
667 676
668 UMA_HISTOGRAM_AND_TRACE_WITH_TEMPERATURE_AND_SAME_VERSION_COUNT( 677 UMA_HISTOGRAM_AND_TRACE_WITH_TEMPERATURE_AND_SAME_VERSION_COUNT(
669 UMA_HISTOGRAM_LONG_TIMES, "Startup.BrowserWindowDisplay", 678 UMA_HISTOGRAM_LONG_TIMES, "Startup.BrowserWindowDisplay",
670 g_process_creation_ticks.Get(), ticks); 679 g_process_creation_ticks.Get(), ticks);
671 } 680 }
672 681
673 void RecordBrowserOpenTabsDelta(const base::TimeDelta& delta) { 682 void RecordBrowserOpenTabsDelta(const base::TimeDelta& delta) {
674 static bool is_first_call = true; 683 static bool is_first_call = true;
675 if (!is_first_call) 684 if (!is_first_call)
676 return; 685 return;
677 is_first_call = false; 686 is_first_call = false;
678 687
679 UMA_HISTOGRAM_WITH_TEMPERATURE_AND_SAME_VERSION_COUNT( 688 UMA_HISTOGRAM_WITH_TEMPERATURE_AND_SAME_VERSION_COUNT(
680 UMA_HISTOGRAM_LONG_TIMES_100, "Startup.BrowserOpenTabs", delta); 689 UMA_HISTOGRAM_LONG_TIMES_100, "Startup.BrowserOpenTabs", delta);
681 } 690 }
682 691
683 void RecordRendererMainEntryTime(const base::TimeTicks& ticks) { 692 void RecordRendererMainEntryTime(const base::TimeTicks& ticks) {
684 // Record the renderer main entry time, but don't log the UMA metric 693 // Record the renderer main entry time, but don't log the UMA metric
685 // immediately because the startup temperature is not known yet. 694 // immediately because the startup temperature is not known yet.
686 if (g_renderer_main_entry_point_ticks.Get().is_null()) 695 if (g_renderer_main_entry_point_ticks.Get().is_null())
687 g_renderer_main_entry_point_ticks.Get() = ticks; 696 g_renderer_main_entry_point_ticks.Get() = ticks;
688 } 697 }
689 698
690 void RecordFirstWebContentsMainFrameLoad(const base::TimeTicks& ticks) { 699 void RecordFirstWebContentsMainFrameLoad(const base::TimeTicks& ticks) {
691 static bool is_first_call = true; 700 static bool is_first_call = true;
692 if (!is_first_call || ticks.is_null()) 701 if (!is_first_call || ticks.is_null())
693 return; 702 return;
694 is_first_call = false; 703 is_first_call = false;
695 if (WasNonBrowserUIDisplayed() || g_process_creation_ticks.Get().is_null()) 704 if (!ShouldLogProcessCreationTicksHistogram())
696 return; 705 return;
697 706
698 UMA_HISTOGRAM_AND_TRACE_WITH_TEMPERATURE_AND_SAME_VERSION_COUNT( 707 UMA_HISTOGRAM_AND_TRACE_WITH_TEMPERATURE_AND_SAME_VERSION_COUNT(
699 UMA_HISTOGRAM_LONG_TIMES_100, "Startup.FirstWebContents.MainFrameLoad2", 708 UMA_HISTOGRAM_LONG_TIMES_100, "Startup.FirstWebContents.MainFrameLoad2",
700 g_process_creation_ticks.Get(), ticks); 709 g_process_creation_ticks.Get(), ticks);
701 } 710 }
702 711
703 void RecordFirstWebContentsNonEmptyPaint(const base::TimeTicks& ticks) { 712 void RecordFirstWebContentsNonEmptyPaint(const base::TimeTicks& ticks) {
704 static bool is_first_call = true; 713 static bool is_first_call = true;
705 if (!is_first_call || ticks.is_null()) 714 if (!is_first_call || ticks.is_null())
706 return; 715 return;
707 is_first_call = false; 716 is_first_call = false;
708 717
709 // Log Startup.BrowserMainToRendererMain now that the first renderer main 718 // Log Startup.BrowserMainToRendererMain now that the first renderer main
710 // entry time and the startup temperature are known. 719 // entry time and the startup temperature are known.
711 RecordRendererMainEntryHistogram(); 720 RecordRendererMainEntryHistogram();
712 721
713 if (WasNonBrowserUIDisplayed() || g_process_creation_ticks.Get().is_null()) 722 if (!ShouldLogProcessCreationTicksHistogram())
714 return; 723 return;
715 724
716 base::StackSamplingProfiler::SetProcessMilestone( 725 base::StackSamplingProfiler::SetProcessMilestone(
717 metrics::CallStackProfileMetricsProvider::FIRST_NONEMPTY_PAINT); 726 metrics::CallStackProfileMetricsProvider::FIRST_NONEMPTY_PAINT);
718 UMA_HISTOGRAM_AND_TRACE_WITH_TEMPERATURE_AND_SAME_VERSION_COUNT( 727 UMA_HISTOGRAM_AND_TRACE_WITH_TEMPERATURE_AND_SAME_VERSION_COUNT(
719 UMA_HISTOGRAM_LONG_TIMES_100, "Startup.FirstWebContents.NonEmptyPaint2", 728 UMA_HISTOGRAM_LONG_TIMES_100, "Startup.FirstWebContents.NonEmptyPaint2",
720 g_process_creation_ticks.Get(), ticks); 729 g_process_creation_ticks.Get(), ticks);
721 } 730 }
722 731
723 void RecordFirstWebContentsMainNavigationStart(const base::TimeTicks& ticks, 732 void RecordFirstWebContentsMainNavigationStart(const base::TimeTicks& ticks,
724 WebContentsWorkload workload) { 733 WebContentsWorkload workload) {
725 static bool is_first_call = true; 734 static bool is_first_call = true;
726 if (!is_first_call || ticks.is_null()) 735 if (!is_first_call || ticks.is_null())
727 return; 736 return;
728 is_first_call = false; 737 is_first_call = false;
729 if (WasNonBrowserUIDisplayed() || g_process_creation_ticks.Get().is_null()) 738 if (!ShouldLogProcessCreationTicksHistogram())
730 return; 739 return;
731 740
732 base::StackSamplingProfiler::SetProcessMilestone( 741 base::StackSamplingProfiler::SetProcessMilestone(
733 metrics::CallStackProfileMetricsProvider::MAIN_NAVIGATION_START); 742 metrics::CallStackProfileMetricsProvider::MAIN_NAVIGATION_START);
734 UMA_HISTOGRAM_AND_TRACE_WITH_TEMPERATURE_AND_SAME_VERSION_COUNT( 743 UMA_HISTOGRAM_AND_TRACE_WITH_TEMPERATURE_AND_SAME_VERSION_COUNT(
735 UMA_HISTOGRAM_LONG_TIMES_100, 744 UMA_HISTOGRAM_LONG_TIMES_100,
736 "Startup.FirstWebContents.MainNavigationStart", 745 "Startup.FirstWebContents.MainNavigationStart",
737 g_process_creation_ticks.Get(), ticks); 746 g_process_creation_ticks.Get(), ticks);
738 747
739 // Log extra information about this startup's workload. Only added to this 748 // Log extra information about this startup's workload. Only added to this
(...skipping 11 matching lines...) Expand all
751 ticks - g_process_creation_ticks.Get()); 760 ticks - g_process_creation_ticks.Get());
752 } 761 }
753 } 762 }
754 763
755 void RecordFirstWebContentsMainNavigationFinished( 764 void RecordFirstWebContentsMainNavigationFinished(
756 const base::TimeTicks& ticks) { 765 const base::TimeTicks& ticks) {
757 static bool is_first_call = true; 766 static bool is_first_call = true;
758 if (!is_first_call || ticks.is_null()) 767 if (!is_first_call || ticks.is_null())
759 return; 768 return;
760 is_first_call = false; 769 is_first_call = false;
761 if (WasNonBrowserUIDisplayed() || g_process_creation_ticks.Get().is_null()) 770 if (!ShouldLogProcessCreationTicksHistogram())
762 return; 771 return;
763 772
764 base::StackSamplingProfiler::SetProcessMilestone( 773 base::StackSamplingProfiler::SetProcessMilestone(
765 metrics::CallStackProfileMetricsProvider::MAIN_NAVIGATION_FINISHED); 774 metrics::CallStackProfileMetricsProvider::MAIN_NAVIGATION_FINISHED);
766 UMA_HISTOGRAM_AND_TRACE_WITH_TEMPERATURE_AND_SAME_VERSION_COUNT( 775 UMA_HISTOGRAM_AND_TRACE_WITH_TEMPERATURE_AND_SAME_VERSION_COUNT(
767 UMA_HISTOGRAM_LONG_TIMES_100, 776 UMA_HISTOGRAM_LONG_TIMES_100,
768 "Startup.FirstWebContents.MainNavigationFinished", 777 "Startup.FirstWebContents.MainNavigationFinished",
769 g_process_creation_ticks.Get(), ticks); 778 g_process_creation_ticks.Get(), ticks);
770 } 779 }
771 780
781 void RecordBrowserWindowFirstPaint(const base::TimeTicks& ticks) {
782 static bool is_first_call = true;
783 if (!is_first_call || ticks.is_null())
784 return;
785 is_first_call = false;
786 if (!ShouldLogProcessCreationTicksHistogram())
787 return;
788
789 UMA_HISTOGRAM_AND_TRACE_WITH_TEMPERATURE(
790 UMA_HISTOGRAM_LONG_TIMES_100, "Startup.BrowserWindow.FirstPaint",
791 g_process_creation_ticks.Get(), ticks);
792 }
793
794 void RecordBrowserWindowFirstPaintCompositingEnded(
795 const base::TimeTicks& ticks) {
796 static bool is_first_call = true;
797 if (!is_first_call || ticks.is_null())
798 return;
799 is_first_call = false;
800 if (!ShouldLogProcessCreationTicksHistogram())
801 return;
802
803 UMA_HISTOGRAM_AND_TRACE_WITH_TEMPERATURE(
804 UMA_HISTOGRAM_LONG_TIMES_100,
805 "Startup.BrowserWindow.FirstPaint.CompositingEnded",
806 g_process_creation_ticks.Get(), ticks);
807 }
808
772 base::TimeTicks MainEntryPointTicks() { 809 base::TimeTicks MainEntryPointTicks() {
773 return g_browser_main_entry_point_ticks.Get(); 810 return g_browser_main_entry_point_ticks.Get();
774 } 811 }
775 812
776 } // namespace startup_metric_utils 813 } // namespace startup_metric_utils
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698