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

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

Issue 1619273003: Add Startup.SameVersionStartupCount histogram (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@b0_lukewarm_startup_stats
Patch Set: make OWNERS change specific to gypi file not * Created 4 years, 11 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 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 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 return false; 395 return false;
397 index += proc_info->NextEntryOffset; 396 index += proc_info->NextEntryOffset;
398 } 397 }
399 398
400 return false; 399 return false;
401 } 400 }
402 #endif // defined(OS_WIN) 401 #endif // defined(OS_WIN)
403 402
404 void RegisterPrefs(PrefRegistrySimple* registry) { 403 void RegisterPrefs(PrefRegistrySimple* registry) {
405 DCHECK(registry); 404 DCHECK(registry);
406 registry->RegisterInt64Pref(kLastStartupTimestampPref, 0); 405 registry->RegisterInt64Pref(prefs::kLastStartupTimestamp, 0);
406 registry->RegisterStringPref(prefs::kLastStartupVersion, std::string());
407 registry->RegisterIntegerPref(prefs::kSameVersionStartupCount, 0);
407 } 408 }
408 409
409 bool WasNonBrowserUIDisplayed() { 410 bool WasNonBrowserUIDisplayed() {
410 return g_non_browser_ui_displayed; 411 return g_non_browser_ui_displayed;
411 } 412 }
412 413
413 void SetNonBrowserUIDisplayed() { 414 void SetNonBrowserUIDisplayed() {
414 g_non_browser_ui_displayed = true; 415 g_non_browser_ui_displayed = true;
415 } 416 }
416 417
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 void RecordTimeSinceLastStartup(PrefService* pref_service) { 505 void RecordTimeSinceLastStartup(PrefService* pref_service) {
505 #if defined(OS_MACOSX) || defined(OS_WIN) || defined(OS_LINUX) 506 #if defined(OS_MACOSX) || defined(OS_WIN) || defined(OS_LINUX)
506 DCHECK(pref_service); 507 DCHECK(pref_service);
507 508
508 // Get the timestamp of the current startup. 509 // Get the timestamp of the current startup.
509 const base::Time process_start_time = 510 const base::Time process_start_time =
510 base::CurrentProcessInfo::CreationTime(); 511 base::CurrentProcessInfo::CreationTime();
511 512
512 // Get the timestamp of the last startup from |pref_service|. 513 // Get the timestamp of the last startup from |pref_service|.
513 const int64_t last_startup_timestamp_internal = 514 const int64_t last_startup_timestamp_internal =
514 pref_service->GetInt64(kLastStartupTimestampPref); 515 pref_service->GetInt64(prefs::kLastStartupTimestamp);
515 if (last_startup_timestamp_internal != 0) { 516 if (last_startup_timestamp_internal != 0) {
516 // Log the Startup.TimeSinceLastStartup histogram. 517 // Log the Startup.TimeSinceLastStartup histogram.
517 const base::Time last_startup_timestamp = 518 const base::Time last_startup_timestamp =
518 base::Time::FromInternalValue(last_startup_timestamp_internal); 519 base::Time::FromInternalValue(last_startup_timestamp_internal);
519 const base::TimeDelta time_since_last_startup = 520 const base::TimeDelta time_since_last_startup =
520 process_start_time - last_startup_timestamp; 521 process_start_time - last_startup_timestamp;
521 const int minutes_since_last_startup = time_since_last_startup.InMinutes(); 522 const int minutes_since_last_startup = time_since_last_startup.InMinutes();
522 523
523 // Ignore negative values, which can be caused by system clock changes. 524 // Ignore negative values, which can be caused by system clock changes.
524 if (minutes_since_last_startup >= 0) { 525 if (minutes_since_last_startup >= 0) {
525 UMA_HISTOGRAM_WITH_STARTUP_TEMPERATURE( 526 UMA_HISTOGRAM_WITH_STARTUP_TEMPERATURE(
526 UMA_HISTOGRAM_TIME_IN_MINUTES_MONTH_RANGE, 527 UMA_HISTOGRAM_TIME_IN_MINUTES_MONTH_RANGE,
527 "Startup.TimeSinceLastStartup", minutes_since_last_startup); 528 "Startup.TimeSinceLastStartup", minutes_since_last_startup);
528 } 529 }
529 } 530 }
530 531
531 // Write the timestamp of the current startup in |pref_service|. 532 // Write the timestamp of the current startup in |pref_service|.
532 pref_service->SetInt64(kLastStartupTimestampPref, 533 pref_service->SetInt64(prefs::kLastStartupTimestamp,
533 process_start_time.ToInternalValue()); 534 process_start_time.ToInternalValue());
534 #endif // defined(OS_MACOSX) || defined(OS_WIN) || defined(OS_LINUX) 535 #endif // defined(OS_MACOSX) || defined(OS_WIN) || defined(OS_LINUX)
535 } 536 }
536 537
538 void RecordStartupCount(PrefService* pref_service) {
539 DCHECK(pref_service);
540
541 const std::string current_version = version_info::GetVersionNumber();
542
543 int startups_with_current_version = 0;
544 if (current_version == pref_service->GetString(prefs::kLastStartupVersion)) {
545 startups_with_current_version =
546 pref_service->GetInteger(prefs::kSameVersionStartupCount);
547 ++startups_with_current_version;
548 pref_service->SetInteger(prefs::kSameVersionStartupCount,
549 startups_with_current_version);
550 } else {
551 startups_with_current_version = 1;
552 pref_service->SetString(prefs::kLastStartupVersion, current_version);
553 pref_service->SetInteger(prefs::kSameVersionStartupCount, 1);
554 }
555
556 UMA_HISTOGRAM_COUNTS_100("Startup.SameVersionStartupCount",
557 startups_with_current_version);
558 }
559
537 void RecordBrowserWindowDisplay(const base::TimeTicks& ticks) { 560 void RecordBrowserWindowDisplay(const base::TimeTicks& ticks) {
538 static bool is_first_call = true; 561 static bool is_first_call = true;
539 if (!is_first_call || ticks.is_null()) 562 if (!is_first_call || ticks.is_null())
540 return; 563 return;
541 is_first_call = false; 564 is_first_call = false;
542 if (WasNonBrowserUIDisplayed() || g_process_creation_ticks.Get().is_null()) 565 if (WasNonBrowserUIDisplayed() || g_process_creation_ticks.Get().is_null())
543 return; 566 return;
544 567
545 UMA_HISTOGRAM_AND_TRACE_WITH_STARTUP_TEMPERATURE( 568 UMA_HISTOGRAM_AND_TRACE_WITH_STARTUP_TEMPERATURE(
546 UMA_HISTOGRAM_LONG_TIMES, "Startup.BrowserWindowDisplay", 569 UMA_HISTOGRAM_LONG_TIMES, "Startup.BrowserWindowDisplay",
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 649
627 base::TimeTicks MainEntryPointTicks() { 650 base::TimeTicks MainEntryPointTicks() {
628 return g_browser_main_entry_point_ticks.Get(); 651 return g_browser_main_entry_point_ticks.Get();
629 } 652 }
630 653
631 StartupTemperature GetStartupTemperature() { 654 StartupTemperature GetStartupTemperature() {
632 return g_startup_temperature; 655 return g_startup_temperature;
633 } 656 }
634 657
635 } // namespace startup_metric_utils 658 } // namespace startup_metric_utils
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698