| OLD | NEW |
| 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 <memory> | |
| 11 #include <string> | 10 #include <string> |
| 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/containers/hash_tables.h" | 13 #include "base/containers/hash_tables.h" |
| 14 #include "base/environment.h" | |
| 15 #include "base/lazy_instance.h" | 14 #include "base/lazy_instance.h" |
| 16 #include "base/logging.h" | 15 #include "base/logging.h" |
| 17 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
| 18 #include "base/metrics/histogram_macros.h" | 17 #include "base/metrics/histogram_macros.h" |
| 19 #include "base/process/process_info.h" | 18 #include "base/process/process_info.h" |
| 20 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
| 21 #include "base/sys_info.h" | 20 #include "base/sys_info.h" |
| 22 #include "base/threading/platform_thread.h" | 21 #include "base/threading/platform_thread.h" |
| 23 #include "base/trace_event/trace_event.h" | 22 #include "base/trace_event/trace_event.h" |
| 24 #include "build/build_config.h" | 23 #include "build/build_config.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 42 | 41 |
| 43 base::LazyInstance<base::TimeTicks>::Leaky g_process_creation_ticks = | 42 base::LazyInstance<base::TimeTicks>::Leaky g_process_creation_ticks = |
| 44 LAZY_INSTANCE_INITIALIZER; | 43 LAZY_INSTANCE_INITIALIZER; |
| 45 | 44 |
| 46 base::LazyInstance<base::TimeTicks>::Leaky g_browser_main_entry_point_ticks = | 45 base::LazyInstance<base::TimeTicks>::Leaky g_browser_main_entry_point_ticks = |
| 47 LAZY_INSTANCE_INITIALIZER; | 46 LAZY_INSTANCE_INITIALIZER; |
| 48 | 47 |
| 49 base::LazyInstance<base::TimeTicks>::Leaky g_renderer_main_entry_point_ticks = | 48 base::LazyInstance<base::TimeTicks>::Leaky g_renderer_main_entry_point_ticks = |
| 50 LAZY_INSTANCE_INITIALIZER; | 49 LAZY_INSTANCE_INITIALIZER; |
| 51 | 50 |
| 51 base::LazyInstance<base::TimeTicks>::Leaky |
| 52 g_browser_exe_main_entry_point_ticks = LAZY_INSTANCE_INITIALIZER; |
| 53 |
| 52 // Only used by RecordMainEntryTimeHistogram(), should go away with it (do not | 54 // Only used by RecordMainEntryTimeHistogram(), should go away with it (do not |
| 53 // add new uses of this), see crbug.com/317481 for discussion on why it was kept | 55 // add new uses of this), see crbug.com/317481 for discussion on why it was kept |
| 54 // as-is for now. | 56 // as-is for now. |
| 55 base::LazyInstance<base::Time>::Leaky g_browser_main_entry_point_time = | 57 base::LazyInstance<base::Time>::Leaky g_browser_main_entry_point_time = |
| 56 LAZY_INSTANCE_INITIALIZER; | 58 LAZY_INSTANCE_INITIALIZER; |
| 57 | 59 |
| 58 // An enumeration of startup temperatures. This must be kept in sync with the | 60 // An enumeration of startup temperatures. This must be kept in sync with the |
| 59 // UMA StartupType enumeration defined in histograms.xml. | 61 // UMA StartupType enumeration defined in histograms.xml. |
| 60 enum StartupTemperature { | 62 enum StartupTemperature { |
| 61 // The startup was a cold start: nearly all of the binaries and resources were | 63 // The startup was a cold start: nearly all of the binaries and resources were |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 g_renderer_main_entry_point_ticks.Get(); | 459 g_renderer_main_entry_point_ticks.Get(); |
| 458 | 460 |
| 459 if (!browser_main_entry_point_ticks.is_null() && | 461 if (!browser_main_entry_point_ticks.is_null() && |
| 460 !renderer_main_entry_point_ticks.is_null()) { | 462 !renderer_main_entry_point_ticks.is_null()) { |
| 461 UMA_HISTOGRAM_AND_TRACE_WITH_TEMPERATURE_AND_SAME_VERSION_COUNT( | 463 UMA_HISTOGRAM_AND_TRACE_WITH_TEMPERATURE_AND_SAME_VERSION_COUNT( |
| 462 UMA_HISTOGRAM_LONG_TIMES_100, "Startup.BrowserMainToRendererMain", | 464 UMA_HISTOGRAM_LONG_TIMES_100, "Startup.BrowserMainToRendererMain", |
| 463 browser_main_entry_point_ticks, renderer_main_entry_point_ticks); | 465 browser_main_entry_point_ticks, renderer_main_entry_point_ticks); |
| 464 } | 466 } |
| 465 } | 467 } |
| 466 | 468 |
| 467 // Environment variable that stores the timestamp when the executable's main() | |
| 468 // function was entered in TimeTicks. This is required because chrome.exe and | |
| 469 // chrome.dll don't share the same static storage. | |
| 470 const char kChromeMainTicksEnvVar[] = "CHROME_MAIN_TICKS"; | |
| 471 | |
| 472 // Returns the time of main entry recorded from RecordExeMainEntryTime. | |
| 473 base::TimeTicks ExeMainEntryPointTicks() { | |
| 474 std::unique_ptr<base::Environment> env(base::Environment::Create()); | |
| 475 std::string ticks_string; | |
| 476 int64_t time_int = 0; | |
| 477 if (env->GetVar(kChromeMainTicksEnvVar, &ticks_string) && | |
| 478 base::StringToInt64(ticks_string, &time_int)) { | |
| 479 return base::TimeTicks::FromInternalValue(time_int); | |
| 480 } | |
| 481 return base::TimeTicks(); | |
| 482 } | |
| 483 | |
| 484 void AddStartupEventsForTelemetry() | 469 void AddStartupEventsForTelemetry() |
| 485 { | 470 { |
| 486 DCHECK(!g_browser_main_entry_point_ticks.Get().is_null()); | 471 DCHECK(!g_browser_main_entry_point_ticks.Get().is_null()); |
| 487 | 472 |
| 488 TRACE_EVENT_INSTANT_WITH_TIMESTAMP0( | 473 TRACE_EVENT_INSTANT_WITH_TIMESTAMP0( |
| 489 "startup", "Startup.BrowserMainEntryPoint", 0, | 474 "startup", "Startup.BrowserMainEntryPoint", 0, |
| 490 g_browser_main_entry_point_ticks.Get().ToInternalValue()); | 475 g_browser_main_entry_point_ticks.Get().ToInternalValue()); |
| 491 | 476 |
| 492 if (!g_process_creation_ticks.Get().is_null()) | 477 if (!g_process_creation_ticks.Get().is_null()) |
| 493 { | 478 { |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 g_browser_main_entry_point_ticks.Get() = StartupTimeToTimeTicks(time); | 574 g_browser_main_entry_point_ticks.Get() = StartupTimeToTimeTicks(time); |
| 590 DCHECK(!g_browser_main_entry_point_ticks.Get().is_null()); | 575 DCHECK(!g_browser_main_entry_point_ticks.Get().is_null()); |
| 591 | 576 |
| 592 // TODO(jeremy): Remove this with RecordMainEntryTimeHistogram() when | 577 // TODO(jeremy): Remove this with RecordMainEntryTimeHistogram() when |
| 593 // resolving crbug.com/317481. | 578 // resolving crbug.com/317481. |
| 594 DCHECK(g_browser_main_entry_point_time.Get().is_null()); | 579 DCHECK(g_browser_main_entry_point_time.Get().is_null()); |
| 595 g_browser_main_entry_point_time.Get() = time; | 580 g_browser_main_entry_point_time.Get() = time; |
| 596 DCHECK(!g_browser_main_entry_point_time.Get().is_null()); | 581 DCHECK(!g_browser_main_entry_point_time.Get().is_null()); |
| 597 } | 582 } |
| 598 | 583 |
| 599 void RecordExeMainEntryPointTime(const base::Time& time) { | 584 void RecordExeMainEntryPointTicks(const base::TimeTicks& ticks) { |
| 600 const std::string exe_load_ticks = | 585 DCHECK(g_browser_exe_main_entry_point_ticks.Get().is_null()); |
| 601 base::Int64ToString(StartupTimeToTimeTicks(time).ToInternalValue()); | 586 g_browser_exe_main_entry_point_ticks.Get() = ticks; |
| 602 std::unique_ptr<base::Environment> env(base::Environment::Create()); | 587 DCHECK(!g_browser_exe_main_entry_point_ticks.Get().is_null()); |
| 603 env->SetVar(kChromeMainTicksEnvVar, exe_load_ticks); | |
| 604 } | 588 } |
| 605 | 589 |
| 606 void RecordBrowserMainMessageLoopStart(const base::TimeTicks& ticks, | 590 void RecordBrowserMainMessageLoopStart(const base::TimeTicks& ticks, |
| 607 bool is_first_run, | 591 bool is_first_run, |
| 608 PrefService* pref_service) { | 592 PrefService* pref_service) { |
| 609 DCHECK(pref_service); | 593 DCHECK(pref_service); |
| 610 | 594 |
| 611 RecordSameVersionStartupCount(pref_service); | 595 RecordSameVersionStartupCount(pref_service); |
| 612 // Keep RecordHardFaultHistogram() first as much as possible as many other | 596 // Keep RecordHardFaultHistogram() first as much as possible as many other |
| 613 // histograms depend on it setting |g_startup_temperature|. | 597 // histograms depend on it setting |g_startup_temperature|. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 653 if (is_seven_minutes_after_boot) { | 637 if (is_seven_minutes_after_boot) { |
| 654 UMA_HISTOGRAM_WITH_TEMPERATURE_AND_SAME_VERSION_COUNT( | 638 UMA_HISTOGRAM_WITH_TEMPERATURE_AND_SAME_VERSION_COUNT( |
| 655 UMA_HISTOGRAM_LONG_TIMES, | 639 UMA_HISTOGRAM_LONG_TIMES, |
| 656 "Startup.BrowserMessageLoopStartTimeFromMainEntry", | 640 "Startup.BrowserMessageLoopStartTimeFromMainEntry", |
| 657 ticks - g_browser_main_entry_point_ticks.Get()); | 641 ticks - g_browser_main_entry_point_ticks.Get()); |
| 658 } | 642 } |
| 659 } | 643 } |
| 660 | 644 |
| 661 // Record timings between process creation, the main() in the executable being | 645 // Record timings between process creation, the main() in the executable being |
| 662 // reached and the main() in the shared library being reached. | 646 // reached and the main() in the shared library being reached. |
| 663 if (!process_creation_ticks.is_null()) { | 647 if (!process_creation_ticks.is_null() && |
| 664 const base::TimeTicks exe_main_ticks = ExeMainEntryPointTicks(); | 648 !g_browser_exe_main_entry_point_ticks.Get().is_null()) { |
| 665 if (!exe_main_ticks.is_null()) { | 649 const base::TimeTicks exe_main_ticks = |
| 666 // Process create to chrome.exe:main(). | 650 g_browser_exe_main_entry_point_ticks.Get(); |
| 667 UMA_HISTOGRAM_AND_TRACE_WITH_TEMPERATURE_AND_SAME_VERSION_COUNT( | 651 const base::TimeTicks main_entry_ticks = |
| 668 UMA_HISTOGRAM_LONG_TIMES, "Startup.LoadTime.ProcessCreateToExeMain2", | 652 g_browser_main_entry_point_ticks.Get(); |
| 669 process_creation_ticks, exe_main_ticks); | 653 // Process create to chrome.exe:main(). |
| 654 UMA_HISTOGRAM_AND_TRACE_WITH_TEMPERATURE_AND_SAME_VERSION_COUNT( |
| 655 UMA_HISTOGRAM_LONG_TIMES, "Startup.LoadTime.ProcessCreateToExeMain2", |
| 656 process_creation_ticks, exe_main_ticks); |
| 670 | 657 |
| 671 // chrome.exe:main() to chrome.dll:main(). | 658 // chrome.exe:main() to chrome.dll:main(). |
| 672 UMA_HISTOGRAM_AND_TRACE_WITH_TEMPERATURE_AND_SAME_VERSION_COUNT( | 659 UMA_HISTOGRAM_AND_TRACE_WITH_TEMPERATURE_AND_SAME_VERSION_COUNT( |
| 673 UMA_HISTOGRAM_LONG_TIMES, "Startup.LoadTime.ExeMainToDllMain2", | 660 UMA_HISTOGRAM_LONG_TIMES, "Startup.LoadTime.ExeMainToDllMain2", |
| 674 exe_main_ticks, g_browser_main_entry_point_ticks.Get()); | 661 exe_main_ticks, main_entry_ticks); |
| 675 | 662 |
| 676 // Process create to chrome.dll:main(). Reported as a histogram only as | 663 // Process create to chrome.dll:main(). Reported as a histogram only as |
| 677 // the other two events above are sufficient for tracing purposes. | 664 // the other two events above are sufficient for tracing purposes. |
| 665 UMA_HISTOGRAM_WITH_TEMPERATURE_AND_SAME_VERSION_COUNT( |
| 666 UMA_HISTOGRAM_LONG_TIMES, "Startup.LoadTime.ProcessCreateToDllMain2", |
| 667 main_entry_ticks - process_creation_ticks); |
| 668 |
| 669 if (is_seven_minutes_after_boot) { |
| 678 UMA_HISTOGRAM_WITH_TEMPERATURE_AND_SAME_VERSION_COUNT( | 670 UMA_HISTOGRAM_WITH_TEMPERATURE_AND_SAME_VERSION_COUNT( |
| 679 UMA_HISTOGRAM_LONG_TIMES, "Startup.LoadTime.ProcessCreateToDllMain2", | 671 UMA_HISTOGRAM_LONG_TIMES, "Startup.LoadTime.ProcessCreateToExeMain", |
| 680 g_browser_main_entry_point_ticks.Get() - process_creation_ticks); | 672 exe_main_ticks - process_creation_ticks); |
| 681 | 673 UMA_HISTOGRAM_WITH_TEMPERATURE_AND_SAME_VERSION_COUNT( |
| 682 if (is_seven_minutes_after_boot) { | 674 UMA_HISTOGRAM_LONG_TIMES, "Startup.LoadTime.ExeMainToDllMain", |
| 683 UMA_HISTOGRAM_WITH_TEMPERATURE_AND_SAME_VERSION_COUNT( | 675 main_entry_ticks - exe_main_ticks); |
| 684 UMA_HISTOGRAM_LONG_TIMES, "Startup.LoadTime.ProcessCreateToExeMain", | 676 UMA_HISTOGRAM_WITH_TEMPERATURE_AND_SAME_VERSION_COUNT( |
| 685 exe_main_ticks - process_creation_ticks); | 677 UMA_HISTOGRAM_LONG_TIMES, "Startup.LoadTime.ProcessCreateToDllMain", |
| 686 UMA_HISTOGRAM_WITH_TEMPERATURE_AND_SAME_VERSION_COUNT( | 678 main_entry_ticks - process_creation_ticks); |
| 687 UMA_HISTOGRAM_LONG_TIMES, "Startup.LoadTime.ExeMainToDllMain", | |
| 688 g_browser_main_entry_point_ticks.Get() - exe_main_ticks); | |
| 689 UMA_HISTOGRAM_WITH_TEMPERATURE_AND_SAME_VERSION_COUNT( | |
| 690 UMA_HISTOGRAM_LONG_TIMES, "Startup.LoadTime.ProcessCreateToDllMain", | |
| 691 g_browser_main_entry_point_ticks.Get() - process_creation_ticks); | |
| 692 } | |
| 693 } | 679 } |
| 694 } | 680 } |
| 695 } | 681 } |
| 696 | 682 |
| 697 void RecordBrowserWindowDisplay(const base::TimeTicks& ticks) { | 683 void RecordBrowserWindowDisplay(const base::TimeTicks& ticks) { |
| 698 static bool is_first_call = true; | 684 static bool is_first_call = true; |
| 699 if (!is_first_call || ticks.is_null()) | 685 if (!is_first_call || ticks.is_null()) |
| 700 return; | 686 return; |
| 701 is_first_call = false; | 687 is_first_call = false; |
| 702 if (WasNonBrowserUIDisplayed() || g_process_creation_ticks.Get().is_null()) | 688 if (WasNonBrowserUIDisplayed() || g_process_creation_ticks.Get().is_null()) |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 782 UMA_HISTOGRAM_LONG_TIMES_100, | 768 UMA_HISTOGRAM_LONG_TIMES_100, |
| 783 "Startup.FirstWebContents.MainNavigationFinished", | 769 "Startup.FirstWebContents.MainNavigationFinished", |
| 784 g_process_creation_ticks.Get(), ticks); | 770 g_process_creation_ticks.Get(), ticks); |
| 785 } | 771 } |
| 786 | 772 |
| 787 base::TimeTicks MainEntryPointTicks() { | 773 base::TimeTicks MainEntryPointTicks() { |
| 788 return g_browser_main_entry_point_ticks.Get(); | 774 return g_browser_main_entry_point_ticks.Get(); |
| 789 } | 775 } |
| 790 | 776 |
| 791 } // namespace startup_metric_utils | 777 } // namespace startup_metric_utils |
| OLD | NEW |