diff --git a/browser/components/BrowserGlue.jsm b/browser/components/BrowserGlue.jsm index 4ff81475ac7b..b3386a20ca3f 100644 --- a/browser/components/BrowserGlue.jsm +++ b/browser/components/BrowserGlue.jsm @@ -1254,6 +1254,24 @@ BrowserGlue.prototype = { } catch (ex) {} }, + _collectStartupConditionsTelemetry() { + let nowSeconds = Math.round(Date.now() / 1000); + // Don't include cases where we don't have the pref. This rules out the first install + // as well as the first run of a build since this was introduced. These could by some + // definitions be referred to as "cold" startups, but probably not since we likely + // just wrote many of the files we use to disk. This way we should approximate a lower + // bound to the number of cold startups rather than an upper bound. + let lastCheckSeconds = Services.prefs.getIntPref("browser.startup.lastColdStartupCheck", nowSeconds); + Services.prefs.setIntPref("browser.startup.lastColdStartupCheck", nowSeconds); + try { + let secondsSinceLastOSRestart = Services.startup.secondsSinceLastOSRestart; + let isColdStartup = nowSeconds - secondsSinceLastOSRestart > lastCheckSeconds; + Services.telemetry.scalarSet("startup.is_cold", isColdStartup); + } catch (ex) { + Cu.reportError(ex); + } + }, + // the first browser window has finished initializing _onFirstWindowLoaded: function BG__onFirstWindowLoaded(aWindow) { TabCrashHandler.init(); @@ -1329,6 +1347,8 @@ BrowserGlue.prototype = { this._firstWindowTelemetry(aWindow); this._firstWindowLoaded(); + this._collectStartupConditionsTelemetry(); + // Set the default favicon size for UI views that use the page-icon protocol. PlacesUtils.favicons.setDefaultIconURIPreferredSize(16 * aWindow.devicePixelRatio); this._setPrefExpectations(); diff --git a/toolkit/components/startup/nsAppStartup.cpp b/toolkit/components/startup/nsAppStartup.cpp index 4bbe0e643731..aa82d28dacc9 100644 --- a/toolkit/components/startup/nsAppStartup.cpp +++ b/toolkit/components/startup/nsAppStartup.cpp @@ -47,6 +47,10 @@ #if defined(XP_WIN) // Prevent collisions with nsAppStartup::GetStartupInfo() # undef GetStartupInfo + +# include +#elif defined(XP_DARWIN) +# include #endif #include "mozilla/IOInterposer.h" @@ -60,6 +64,8 @@ static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID); #define kPrefRecentCrashes "toolkit.startup.recent_crashes" #define kPrefAlwaysUseSafeMode "toolkit.startup.always_use_safe_mode" +#define kNanosecondsPerSecond 1000000000.0 + #if defined(XP_WIN) # include "mozilla/perfprobe.h" /** @@ -541,6 +547,25 @@ nsAppStartup::GetWasRestarted(bool *aResult) { return NS_OK; } +NS_IMETHODIMP +nsAppStartup::GetSecondsSinceLastOSRestart(int64_t *aResult) { +#if defined(XP_WIN) + *aResult = int64_t(GetTickCount64() / 1000ull); + return NS_OK; +#elif defined(XP_DARWIN) + uint64_t absTime = mach_absolute_time(); + mach_timebase_info_data_t timebaseInfo; + mach_timebase_info(&timebaseInfo); + double toNanoseconds = + double(timebaseInfo.numer) / double(timebaseInfo.denom); + *aResult = + std::llround(double(absTime) * toNanoseconds / kNanosecondsPerSecond); + return NS_OK; +#else + return NS_ERROR_NOT_IMPLEMENTED; +#endif +} + NS_IMETHODIMP nsAppStartup::SetInterrupted(bool aInterrupted) { mInterrupted = aInterrupted; diff --git a/toolkit/components/startup/public/nsIAppStartup.idl b/toolkit/components/startup/public/nsIAppStartup.idl index b88d53d4504d..d6d056ee0bf1 100644 --- a/toolkit/components/startup/public/nsIAppStartup.idl +++ b/toolkit/components/startup/public/nsIAppStartup.idl @@ -156,6 +156,11 @@ interface nsIAppStartup : nsISupports */ readonly attribute boolean wasRestarted; + /** + * The number of seconds since the OS was last rebooted + */ + readonly attribute int64_t secondsSinceLastOSRestart; + /** * Returns an object with main, process, firstPaint, sessionRestored properties. * Properties may not be available depending on platform or application diff --git a/toolkit/components/telemetry/Scalars.yaml b/toolkit/components/telemetry/Scalars.yaml index 8a414f7ce9a5..4e3790a2122b 100644 --- a/toolkit/components/telemetry/Scalars.yaml +++ b/toolkit/components/telemetry/Scalars.yaml @@ -3589,6 +3589,20 @@ startup: record_in_processes: - main + is_cold: + bug_numbers: + - 1542833 + description: > + Whether or not this startup is the first startup since OS reboot (according to our + best guess.) + expires: never + kind: boolean + notification_emails: + - dothayer@mozilla.com + release_channel_collection: opt-out + record_in_processes: + - 'main' + script.preloader: mainthread_recompile: bug_numbers: