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

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

Issue 1663273002: [Merge M48] "[Merge M49] Add Startup.SameVersionStartupCount histogram" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@merge_m48_b1_time_since_last_startup
Patch Set: Created 4 years, 10 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 "base/containers/hash_tables.h" 7 #include "base/containers/hash_tables.h"
8 #include "base/environment.h" 8 #include "base/environment.h"
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/metrics/histogram_macros.h" 11 #include "base/metrics/histogram_macros.h"
12 #include "base/prefs/pref_registry_simple.h" 12 #include "base/prefs/pref_registry_simple.h"
13 #include "base/prefs/pref_service.h" 13 #include "base/prefs/pref_service.h"
14 #include "base/process/process_info.h" 14 #include "base/process/process_info.h"
15 #include "base/strings/string_number_conversions.h" 15 #include "base/strings/string_number_conversions.h"
16 #include "base/sys_info.h" 16 #include "base/sys_info.h"
17 #include "base/threading/platform_thread.h" 17 #include "base/threading/platform_thread.h"
18 #include "base/trace_event/trace_event.h" 18 #include "base/trace_event/trace_event.h"
19 #include "build/build_config.h"
20 #include "components/startup_metric_utils/browser/pref_names.h"
21 #include "components/version_info/version_info.h"
19 22
20 #if defined(OS_WIN) 23 #if defined(OS_WIN)
21 #include <winternl.h> 24 #include <winternl.h>
22 #include "base/win/windows_version.h" 25 #include "base/win/windows_version.h"
23 #endif 26 #endif
24 27
25 namespace startup_metric_utils { 28 namespace startup_metric_utils {
26 29
27 namespace { 30 namespace {
28 31
29 const char kLastStartupTimestampPref[] =
30 "startup_metric.last_startup_timestamp";
31
32 // Mark as volatile to defensively make sure usage is thread-safe. 32 // Mark as volatile to defensively make sure usage is thread-safe.
33 // Note that at the time of this writing, access is only on the UI thread. 33 // Note that at the time of this writing, access is only on the UI thread.
34 volatile bool g_non_browser_ui_displayed = false; 34 volatile bool g_non_browser_ui_displayed = false;
35 35
36 base::LazyInstance<base::TimeTicks>::Leaky g_process_creation_ticks = 36 base::LazyInstance<base::TimeTicks>::Leaky g_process_creation_ticks =
37 LAZY_INSTANCE_INITIALIZER; 37 LAZY_INSTANCE_INITIALIZER;
38 38
39 base::LazyInstance<base::TimeTicks>::Leaky g_main_entry_point_ticks = 39 base::LazyInstance<base::TimeTicks>::Leaky g_main_entry_point_ticks =
40 LAZY_INSTANCE_INITIALIZER; 40 LAZY_INSTANCE_INITIALIZER;
41 41
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 base::StringToInt64(ticks_string, &time_int)) { 382 base::StringToInt64(ticks_string, &time_int)) {
383 return base::TimeTicks::FromInternalValue(time_int); 383 return base::TimeTicks::FromInternalValue(time_int);
384 } 384 }
385 return base::TimeTicks(); 385 return base::TimeTicks();
386 } 386 }
387 387
388 } // namespace 388 } // namespace
389 389
390 void RegisterPrefs(PrefRegistrySimple* registry) { 390 void RegisterPrefs(PrefRegistrySimple* registry) {
391 DCHECK(registry); 391 DCHECK(registry);
392 registry->RegisterInt64Pref(kLastStartupTimestampPref, 0); 392 registry->RegisterInt64Pref(prefs::kLastStartupTimestamp, 0);
393 registry->RegisterStringPref(prefs::kLastStartupVersion, std::string());
394 registry->RegisterIntegerPref(prefs::kSameVersionStartupCount, 0);
393 } 395 }
394 396
395 bool WasNonBrowserUIDisplayed() { 397 bool WasNonBrowserUIDisplayed() {
396 return g_non_browser_ui_displayed; 398 return g_non_browser_ui_displayed;
397 } 399 }
398 400
399 void SetNonBrowserUIDisplayed() { 401 void SetNonBrowserUIDisplayed() {
400 g_non_browser_ui_displayed = true; 402 g_non_browser_ui_displayed = true;
401 } 403 }
402 404
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 void RecordTimeSinceLastStartup(PrefService* pref_service) { 491 void RecordTimeSinceLastStartup(PrefService* pref_service) {
490 #if defined(OS_MACOSX) || defined(OS_WIN) || defined(OS_LINUX) 492 #if defined(OS_MACOSX) || defined(OS_WIN) || defined(OS_LINUX)
491 DCHECK(pref_service); 493 DCHECK(pref_service);
492 494
493 // Get the timestamp of the current startup. 495 // Get the timestamp of the current startup.
494 const base::Time process_start_time = 496 const base::Time process_start_time =
495 base::CurrentProcessInfo::CreationTime(); 497 base::CurrentProcessInfo::CreationTime();
496 498
497 // Get the timestamp of the last startup from |pref_service|. 499 // Get the timestamp of the last startup from |pref_service|.
498 const int64_t last_startup_timestamp_internal = 500 const int64_t last_startup_timestamp_internal =
499 pref_service->GetInt64(kLastStartupTimestampPref); 501 pref_service->GetInt64(prefs::kLastStartupTimestamp);
500 if (last_startup_timestamp_internal != 0) { 502 if (last_startup_timestamp_internal != 0) {
501 // Log the Startup.TimeSinceLastStartup histogram. 503 // Log the Startup.TimeSinceLastStartup histogram.
502 const base::Time last_startup_timestamp = 504 const base::Time last_startup_timestamp =
503 base::Time::FromInternalValue(last_startup_timestamp_internal); 505 base::Time::FromInternalValue(last_startup_timestamp_internal);
504 const base::TimeDelta time_since_last_startup = 506 const base::TimeDelta time_since_last_startup =
505 process_start_time - last_startup_timestamp; 507 process_start_time - last_startup_timestamp;
506 const int minutes_since_last_startup = time_since_last_startup.InMinutes(); 508 const int minutes_since_last_startup = time_since_last_startup.InMinutes();
507 509
508 // Ignore negative values, which can be caused by system clock changes. 510 // Ignore negative values, which can be caused by system clock changes.
509 if (minutes_since_last_startup >= 0) { 511 if (minutes_since_last_startup >= 0) {
510 UMA_HISTOGRAM_WITH_STARTUP_TEMPERATURE( 512 UMA_HISTOGRAM_WITH_STARTUP_TEMPERATURE(
511 UMA_HISTOGRAM_TIME_IN_MINUTES_MONTH_RANGE, 513 UMA_HISTOGRAM_TIME_IN_MINUTES_MONTH_RANGE,
512 "Startup.TimeSinceLastStartup", minutes_since_last_startup); 514 "Startup.TimeSinceLastStartup", minutes_since_last_startup);
513 } 515 }
514 } 516 }
515 517
516 // Write the timestamp of the current startup in |pref_service|. 518 // Write the timestamp of the current startup in |pref_service|.
517 pref_service->SetInt64(kLastStartupTimestampPref, 519 pref_service->SetInt64(prefs::kLastStartupTimestamp,
518 process_start_time.ToInternalValue()); 520 process_start_time.ToInternalValue());
519 #endif // defined(OS_MACOSX) || defined(OS_WIN) || defined(OS_LINUX) 521 #endif // defined(OS_MACOSX) || defined(OS_WIN) || defined(OS_LINUX)
520 } 522 }
521 523
524 void RecordStartupCount(PrefService* pref_service) {
525 DCHECK(pref_service);
526
527 const std::string current_version = version_info::GetVersionNumber();
528
529 int startups_with_current_version = 0;
530 if (current_version == pref_service->GetString(prefs::kLastStartupVersion)) {
531 startups_with_current_version =
532 pref_service->GetInteger(prefs::kSameVersionStartupCount);
533 ++startups_with_current_version;
534 pref_service->SetInteger(prefs::kSameVersionStartupCount,
535 startups_with_current_version);
536 } else {
537 startups_with_current_version = 1;
538 pref_service->SetString(prefs::kLastStartupVersion, current_version);
539 pref_service->SetInteger(prefs::kSameVersionStartupCount, 1);
540 }
541
542 UMA_HISTOGRAM_COUNTS_100("Startup.SameVersionStartupCount",
543 startups_with_current_version);
544 }
545
522 void RecordBrowserWindowDisplay(const base::TimeTicks& ticks) { 546 void RecordBrowserWindowDisplay(const base::TimeTicks& ticks) {
523 static bool is_first_call = true; 547 static bool is_first_call = true;
524 if (!is_first_call || ticks.is_null()) 548 if (!is_first_call || ticks.is_null())
525 return; 549 return;
526 is_first_call = false; 550 is_first_call = false;
527 if (WasNonBrowserUIDisplayed() || g_process_creation_ticks.Get().is_null()) 551 if (WasNonBrowserUIDisplayed() || g_process_creation_ticks.Get().is_null())
528 return; 552 return;
529 553
530 UMA_HISTOGRAM_AND_TRACE_WITH_STARTUP_TEMPERATURE( 554 UMA_HISTOGRAM_AND_TRACE_WITH_STARTUP_TEMPERATURE(
531 UMA_HISTOGRAM_LONG_TIMES, "Startup.BrowserWindowDisplay", 555 UMA_HISTOGRAM_LONG_TIMES, "Startup.BrowserWindowDisplay",
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 651
628 base::TimeTicks MainEntryPointTicks() { 652 base::TimeTicks MainEntryPointTicks() {
629 return g_main_entry_point_ticks.Get(); 653 return g_main_entry_point_ticks.Get();
630 } 654 }
631 655
632 StartupTemperature GetStartupTemperature() { 656 StartupTemperature GetStartupTemperature() {
633 return g_startup_temperature; 657 return g_startup_temperature;
634 } 658 }
635 659
636 } // namespace startup_metric_utils 660 } // namespace startup_metric_utils
OLDNEW
« no previous file with comments | « components/startup_metric_utils/browser/startup_metric_utils.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698