Chromium Code Reviews| 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 "chrome/browser/ui/app_list/app_list_service.h" | 5 #include "chrome/browser/ui/app_list/app_list_service.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | |
| 8 #include "base/callback.h" | |
| 7 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 8 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| 9 #include "base/prefs/pref_registry_simple.h" | 11 #include "base/prefs/pref_registry_simple.h" |
| 10 #include "base/process/process_info.h" | 12 #include "base/process/process_info.h" |
| 11 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 12 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 13 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
| 14 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
| 15 | 17 |
| 16 namespace { | 18 namespace { |
| 17 | 19 |
| 18 base::TimeDelta GetTimeFromOriginalProcessStart( | 20 enum StartupType { |
| 19 const CommandLine& command_line) { | 21 COLD_START, |
| 20 std::string start_time_string = | 22 WARM_START, |
| 21 command_line.GetSwitchValueASCII(switches::kOriginalProcessStartTime); | 23 WARM_START_FAST, |
| 22 int64 remote_start_time; | 24 }; |
| 23 base::StringToInt64(start_time_string, &remote_start_time); | 25 |
| 24 return base::Time::Now() - base::Time::FromInternalValue(remote_start_time); | 26 base::Time GetOriginalProcessStartTime(const CommandLine& command_line) { |
| 27 if (command_line.HasSwitch(switches::kOriginalProcessStartTime)) { | |
| 28 std::string start_time_string = | |
| 29 command_line.GetSwitchValueASCII(switches::kOriginalProcessStartTime); | |
| 30 int64 remote_start_time; | |
| 31 base::StringToInt64(start_time_string, &remote_start_time); | |
| 32 return base::Time::FromInternalValue(remote_start_time); | |
| 33 } | |
| 34 | |
| 35 // base::CurrentProcessInfo::CreationTime() is only defined on some | |
| 36 // platforms. | |
| 37 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) | |
| 38 return base::CurrentProcessInfo::CreationTime(); | |
|
benwells
2013/08/21 04:54:09
Nit - indenting should be back two chars, this is
koz (OOO until 15th September)
2013/08/21 06:54:32
Done.
| |
| 39 #endif | |
| 40 return base::Time(); | |
| 41 } | |
| 42 | |
| 43 StartupType GetStartupType(const CommandLine& command_line) { | |
| 44 // The presence of kOriginalProcessStartTime implies that another process | |
| 45 // has sent us its command line to handle, ie: we are already running. | |
| 46 if (command_line.HasSwitch(switches::kOriginalProcessStartTime)) { | |
| 47 return command_line.HasSwitch(switches::kFastStart) ? | |
| 48 WARM_START_FAST : WARM_START; | |
| 49 } | |
| 50 return COLD_START; | |
| 51 } | |
| 52 | |
| 53 void RecordFirstPaintTiming(StartupType startup_type, | |
| 54 const base::Time& start_time) { | |
| 55 base::TimeDelta elapsed = base::Time::Now() - start_time; | |
| 56 switch (startup_type) { | |
| 57 case WARM_START_FAST: | |
|
benwells
2013/08/21 04:54:09
Nit: inside switch {} should be indented 2 more ch
koz (OOO until 15th September)
2013/08/21 06:54:32
Done.
| |
| 58 UMA_HISTOGRAM_LONG_TIMES("Startup.AppListFirstPaintWarmStartFast", elapsed); | |
| 59 break; | |
| 60 case WARM_START: | |
| 61 UMA_HISTOGRAM_LONG_TIMES("Startup.AppListFirstPaintWarmStart", elapsed); | |
| 62 break; | |
| 63 case COLD_START: | |
| 64 UMA_HISTOGRAM_LONG_TIMES("Startup.AppListFirstPaintColdStart", elapsed); | |
| 65 break; | |
| 66 } | |
| 25 } | 67 } |
| 26 | 68 |
| 27 } // namespace | 69 } // namespace |
| 28 | 70 |
| 29 // static | 71 // static |
| 30 void AppListService::RegisterPrefs(PrefRegistrySimple* registry) { | 72 void AppListService::RegisterPrefs(PrefRegistrySimple* registry) { |
| 31 registry->RegisterInt64Pref(prefs::kLastAppListLaunchPing, 0); | 73 registry->RegisterInt64Pref(prefs::kLastAppListLaunchPing, 0); |
| 32 registry->RegisterIntegerPref(prefs::kAppListLaunchCount, 0); | 74 registry->RegisterIntegerPref(prefs::kAppListLaunchCount, 0); |
| 33 registry->RegisterInt64Pref(prefs::kLastAppListAppLaunchPing, 0); | 75 registry->RegisterInt64Pref(prefs::kLastAppListAppLaunchPing, 0); |
| 34 registry->RegisterIntegerPref(prefs::kAppListAppLaunchCount, 0); | 76 registry->RegisterIntegerPref(prefs::kAppListAppLaunchCount, 0); |
| 35 registry->RegisterStringPref(prefs::kAppListProfile, std::string()); | 77 registry->RegisterStringPref(prefs::kAppListProfile, std::string()); |
| 36 registry->RegisterBooleanPref(prefs::kRestartWithAppList, false); | 78 registry->RegisterBooleanPref(prefs::kRestartWithAppList, false); |
| 37 } | 79 } |
| 38 | 80 |
| 39 // static | 81 // static |
| 40 void AppListService::RecordShowTimings(const CommandLine& command_line) { | 82 void AppListService::RecordShowTimings(const CommandLine& command_line) { |
| 41 // The presence of kOriginalProcessStartTime implies that another process | 83 base::Time start_time = GetOriginalProcessStartTime(command_line); |
| 42 // has sent us its command line to handle, ie: we are already running. | 84 if (start_time.is_null()) |
| 43 if (command_line.HasSwitch(switches::kOriginalProcessStartTime)) { | 85 return; |
| 44 base::TimeDelta elapsed = GetTimeFromOriginalProcessStart(command_line); | 86 |
| 45 if (command_line.HasSwitch(switches::kFastStart)) | 87 base::TimeDelta elapsed = base::Time::Now() - start_time; |
| 46 UMA_HISTOGRAM_LONG_TIMES("Startup.ShowAppListWarmStartFast", elapsed); | 88 StartupType startup = GetStartupType(command_line); |
| 47 else | 89 switch (startup) { |
| 48 UMA_HISTOGRAM_LONG_TIMES("Startup.ShowAppListWarmStart", elapsed); | 90 case COLD_START: |
|
benwells
2013/08/21 04:54:09
Super nit: use same ordering of enum here as in th
koz (OOO until 15th September)
2013/08/21 06:54:32
Done.
| |
| 49 } else { | 91 UMA_HISTOGRAM_LONG_TIMES("Startup.ShowAppListColdStart", elapsed); |
| 50 // base::CurrentProcessInfo::CreationTime() is only defined on some | 92 break; |
| 51 // platforms. | 93 case WARM_START: |
| 52 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) | 94 UMA_HISTOGRAM_LONG_TIMES("Startup.ShowAppListWarmStart", elapsed); |
| 53 UMA_HISTOGRAM_LONG_TIMES( | 95 break; |
| 54 "Startup.ShowAppListColdStart", | 96 case WARM_START_FAST: |
| 55 base::Time::Now() - base::CurrentProcessInfo::CreationTime()); | 97 UMA_HISTOGRAM_LONG_TIMES("Startup.ShowAppListWarmStartFast", elapsed); |
| 56 #endif | 98 break; |
| 57 } | 99 } |
| 100 | |
| 101 AppListService::Get()->SetAppListNextPaintCallback( | |
| 102 base::Bind(RecordFirstPaintTiming, startup, start_time)); | |
| 58 } | 103 } |
| OLD | NEW |