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 | 8 |
9 #include "base/containers/hash_tables.h" | 9 #include "base/containers/hash_tables.h" |
10 #include "base/environment.h" | 10 #include "base/environment.h" |
11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/metrics/histogram_macros.h" | 13 #include "base/metrics/histogram_macros.h" |
14 #include "base/prefs/pref_registry_simple.h" | 14 #include "base/prefs/pref_registry_simple.h" |
15 #include "base/prefs/pref_service.h" | 15 #include "base/prefs/pref_service.h" |
16 #include "base/process/process_info.h" | 16 #include "base/process/process_info.h" |
17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
18 #include "base/sys_info.h" | 18 #include "base/sys_info.h" |
19 #include "base/threading/platform_thread.h" | 19 #include "base/threading/platform_thread.h" |
20 #include "base/trace_event/trace_event.h" | 20 #include "base/trace_event/trace_event.h" |
21 #include "build/build_config.h" | 21 #include "build/build_config.h" |
| 22 #include "components/startup_metric_utils/browser/pref_names.h" |
| 23 #include "components/version_info/version_info.h" |
22 | 24 |
23 #if defined(OS_WIN) | 25 #if defined(OS_WIN) |
24 #include <winternl.h> | 26 #include <winternl.h> |
25 #include "base/win/win_util.h" | 27 #include "base/win/win_util.h" |
26 #include "base/win/windows_version.h" | 28 #include "base/win/windows_version.h" |
27 #endif | 29 #endif |
28 | 30 |
29 namespace startup_metric_utils { | 31 namespace startup_metric_utils { |
30 | 32 |
31 namespace { | 33 namespace { |
32 | 34 |
33 const char kLastStartupTimestampPref[] = | |
34 "startup_metric.last_startup_timestamp"; | |
35 | |
36 // Mark as volatile to defensively make sure usage is thread-safe. | 35 // Mark as volatile to defensively make sure usage is thread-safe. |
37 // Note that at the time of this writing, access is only on the UI thread. | 36 // Note that at the time of this writing, access is only on the UI thread. |
38 volatile bool g_non_browser_ui_displayed = false; | 37 volatile bool g_non_browser_ui_displayed = false; |
39 | 38 |
40 base::LazyInstance<base::TimeTicks>::Leaky g_process_creation_ticks = | 39 base::LazyInstance<base::TimeTicks>::Leaky g_process_creation_ticks = |
41 LAZY_INSTANCE_INITIALIZER; | 40 LAZY_INSTANCE_INITIALIZER; |
42 | 41 |
43 base::LazyInstance<base::TimeTicks>::Leaky g_browser_main_entry_point_ticks = | 42 base::LazyInstance<base::TimeTicks>::Leaky g_browser_main_entry_point_ticks = |
44 LAZY_INSTANCE_INITIALIZER; | 43 LAZY_INSTANCE_INITIALIZER; |
45 | 44 |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 return false; | 398 return false; |
400 index += proc_info->NextEntryOffset; | 399 index += proc_info->NextEntryOffset; |
401 } | 400 } |
402 | 401 |
403 return false; | 402 return false; |
404 } | 403 } |
405 #endif // defined(OS_WIN) | 404 #endif // defined(OS_WIN) |
406 | 405 |
407 void RegisterPrefs(PrefRegistrySimple* registry) { | 406 void RegisterPrefs(PrefRegistrySimple* registry) { |
408 DCHECK(registry); | 407 DCHECK(registry); |
409 registry->RegisterInt64Pref(kLastStartupTimestampPref, 0); | 408 registry->RegisterInt64Pref(prefs::kLastStartupTimestamp, 0); |
| 409 registry->RegisterStringPref(prefs::kLastStartupVersion, std::string()); |
| 410 registry->RegisterIntegerPref(prefs::kSameVersionStartupCount, 0); |
410 } | 411 } |
411 | 412 |
412 bool WasNonBrowserUIDisplayed() { | 413 bool WasNonBrowserUIDisplayed() { |
413 return g_non_browser_ui_displayed; | 414 return g_non_browser_ui_displayed; |
414 } | 415 } |
415 | 416 |
416 void SetNonBrowserUIDisplayed() { | 417 void SetNonBrowserUIDisplayed() { |
417 g_non_browser_ui_displayed = true; | 418 g_non_browser_ui_displayed = true; |
418 } | 419 } |
419 | 420 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 void RecordTimeSinceLastStartup(PrefService* pref_service) { | 508 void RecordTimeSinceLastStartup(PrefService* pref_service) { |
508 #if defined(OS_MACOSX) || defined(OS_WIN) || defined(OS_LINUX) | 509 #if defined(OS_MACOSX) || defined(OS_WIN) || defined(OS_LINUX) |
509 DCHECK(pref_service); | 510 DCHECK(pref_service); |
510 | 511 |
511 // Get the timestamp of the current startup. | 512 // Get the timestamp of the current startup. |
512 const base::Time process_start_time = | 513 const base::Time process_start_time = |
513 base::CurrentProcessInfo::CreationTime(); | 514 base::CurrentProcessInfo::CreationTime(); |
514 | 515 |
515 // Get the timestamp of the last startup from |pref_service|. | 516 // Get the timestamp of the last startup from |pref_service|. |
516 const int64_t last_startup_timestamp_internal = | 517 const int64_t last_startup_timestamp_internal = |
517 pref_service->GetInt64(kLastStartupTimestampPref); | 518 pref_service->GetInt64(prefs::kLastStartupTimestamp); |
518 if (last_startup_timestamp_internal != 0) { | 519 if (last_startup_timestamp_internal != 0) { |
519 // Log the Startup.TimeSinceLastStartup histogram. | 520 // Log the Startup.TimeSinceLastStartup histogram. |
520 const base::Time last_startup_timestamp = | 521 const base::Time last_startup_timestamp = |
521 base::Time::FromInternalValue(last_startup_timestamp_internal); | 522 base::Time::FromInternalValue(last_startup_timestamp_internal); |
522 const base::TimeDelta time_since_last_startup = | 523 const base::TimeDelta time_since_last_startup = |
523 process_start_time - last_startup_timestamp; | 524 process_start_time - last_startup_timestamp; |
524 const int minutes_since_last_startup = time_since_last_startup.InMinutes(); | 525 const int minutes_since_last_startup = time_since_last_startup.InMinutes(); |
525 | 526 |
526 // Ignore negative values, which can be caused by system clock changes. | 527 // Ignore negative values, which can be caused by system clock changes. |
527 if (minutes_since_last_startup >= 0) { | 528 if (minutes_since_last_startup >= 0) { |
528 UMA_HISTOGRAM_WITH_STARTUP_TEMPERATURE( | 529 UMA_HISTOGRAM_WITH_STARTUP_TEMPERATURE( |
529 UMA_HISTOGRAM_TIME_IN_MINUTES_MONTH_RANGE, | 530 UMA_HISTOGRAM_TIME_IN_MINUTES_MONTH_RANGE, |
530 "Startup.TimeSinceLastStartup", minutes_since_last_startup); | 531 "Startup.TimeSinceLastStartup", minutes_since_last_startup); |
531 } | 532 } |
532 } | 533 } |
533 | 534 |
534 // Write the timestamp of the current startup in |pref_service|. | 535 // Write the timestamp of the current startup in |pref_service|. |
535 pref_service->SetInt64(kLastStartupTimestampPref, | 536 pref_service->SetInt64(prefs::kLastStartupTimestamp, |
536 process_start_time.ToInternalValue()); | 537 process_start_time.ToInternalValue()); |
537 #endif // defined(OS_MACOSX) || defined(OS_WIN) || defined(OS_LINUX) | 538 #endif // defined(OS_MACOSX) || defined(OS_WIN) || defined(OS_LINUX) |
538 } | 539 } |
539 | 540 |
| 541 void RecordStartupCount(PrefService* pref_service) { |
| 542 DCHECK(pref_service); |
| 543 |
| 544 const std::string current_version = version_info::GetVersionNumber(); |
| 545 |
| 546 int startups_with_current_version = 0; |
| 547 if (current_version == pref_service->GetString(prefs::kLastStartupVersion)) { |
| 548 startups_with_current_version = |
| 549 pref_service->GetInteger(prefs::kSameVersionStartupCount); |
| 550 ++startups_with_current_version; |
| 551 pref_service->SetInteger(prefs::kSameVersionStartupCount, |
| 552 startups_with_current_version); |
| 553 } else { |
| 554 startups_with_current_version = 1; |
| 555 pref_service->SetString(prefs::kLastStartupVersion, current_version); |
| 556 pref_service->SetInteger(prefs::kSameVersionStartupCount, 1); |
| 557 } |
| 558 |
| 559 UMA_HISTOGRAM_COUNTS_100("Startup.SameVersionStartupCount", |
| 560 startups_with_current_version); |
| 561 } |
| 562 |
540 void RecordBrowserWindowDisplay(const base::TimeTicks& ticks) { | 563 void RecordBrowserWindowDisplay(const base::TimeTicks& ticks) { |
541 static bool is_first_call = true; | 564 static bool is_first_call = true; |
542 if (!is_first_call || ticks.is_null()) | 565 if (!is_first_call || ticks.is_null()) |
543 return; | 566 return; |
544 is_first_call = false; | 567 is_first_call = false; |
545 if (WasNonBrowserUIDisplayed() || g_process_creation_ticks.Get().is_null()) | 568 if (WasNonBrowserUIDisplayed() || g_process_creation_ticks.Get().is_null()) |
546 return; | 569 return; |
547 | 570 |
548 UMA_HISTOGRAM_AND_TRACE_WITH_STARTUP_TEMPERATURE( | 571 UMA_HISTOGRAM_AND_TRACE_WITH_STARTUP_TEMPERATURE( |
549 UMA_HISTOGRAM_LONG_TIMES, "Startup.BrowserWindowDisplay", | 572 UMA_HISTOGRAM_LONG_TIMES, "Startup.BrowserWindowDisplay", |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 | 652 |
630 base::TimeTicks MainEntryPointTicks() { | 653 base::TimeTicks MainEntryPointTicks() { |
631 return g_browser_main_entry_point_ticks.Get(); | 654 return g_browser_main_entry_point_ticks.Get(); |
632 } | 655 } |
633 | 656 |
634 StartupTemperature GetStartupTemperature() { | 657 StartupTemperature GetStartupTemperature() { |
635 return g_startup_temperature; | 658 return g_startup_temperature; |
636 } | 659 } |
637 | 660 |
638 } // namespace startup_metric_utils | 661 } // namespace startup_metric_utils |
OLD | NEW |