From 17358b10b88f94af1f0e13e04529417b5119ecf7 Mon Sep 17 00:00:00 2001 From: Gabriele Svelto Date: Mon, 6 Jul 2015 18:01:09 +0200 Subject: [PATCH] Bug 858928 - Switch XRE_StartupTimelineRecord() from PRTime to TimeStamp. r=froydnj --HG-- extra : rebase_source : b39bf19f68a124cefaf5ceac2adccb20e05bf279 --- browser/app/nsBrowserApp.cpp | 81 +------------------ mozglue/android/APKOpen.cpp | 31 ++----- .../components/startup/StartupTimeline.cpp | 43 ++-------- toolkit/components/startup/StartupTimeline.h | 1 - xpcom/build/nsXULAppAPI.h | 3 +- 5 files changed, 16 insertions(+), 143 deletions(-) diff --git a/browser/app/nsBrowserApp.cpp b/browser/app/nsBrowserApp.cpp index 33c75f020f97..b6753d30f62c 100644 --- a/browser/app/nsBrowserApp.cpp +++ b/browser/app/nsBrowserApp.cpp @@ -14,12 +14,10 @@ #include #elif defined(XP_UNIX) #include -#include #include #endif #ifdef XP_MACOSX -#include #include "MacQuirks.h" #endif @@ -214,83 +212,6 @@ static int do_main(int argc, char* argv[], nsIFile *xreDirectory) return XRE_main(argc, argv, &appData, mainFlags); } -#ifdef XP_WIN - -/** - * Used only when GetTickCount64 is not available on the platform. - * Last result of GetTickCount call. Kept in [ms]. - */ -static DWORD sLastGTCResult = 0; - -/** - * Higher part of the 64-bit value of MozGetTickCount64, - * incremented atomically. - */ -static DWORD sLastGTCRollover = 0; - -/** - * Function protecting GetTickCount result from rolling over. The original - * code comes from the Windows implementation of the TimeStamp class minus the - * locking harness which isn't needed here. - * - * @returns The current time in milliseconds - */ -static ULONGLONG WINAPI -MozGetTickCount64() -{ - DWORD GTC = ::GetTickCount(); - - /* Pull the rollover counter forward only if new value of GTC goes way - * down under the last saved result */ - if ((sLastGTCResult > GTC) && ((sLastGTCResult - GTC) > (1UL << 30))) - ++sLastGTCRollover; - - sLastGTCResult = GTC; - return (ULONGLONG)sLastGTCRollover << 32 | sLastGTCResult; -} - -typedef ULONGLONG (WINAPI* GetTickCount64_t)(); -static GetTickCount64_t sGetTickCount64 = nullptr; - -#endif - -/** - * Local TimeStamp::Now()-compatible implementation used to record timestamps - * which will be passed to XRE_StartupTimelineRecord(). - */ -static uint64_t -TimeStamp_Now() -{ -#ifdef XP_WIN - LARGE_INTEGER freq; - ::QueryPerformanceFrequency(&freq); - - HMODULE kernelDLL = GetModuleHandleW(L"kernel32.dll"); - sGetTickCount64 = reinterpret_cast - (GetProcAddress(kernelDLL, "GetTickCount64")); - - if (!sGetTickCount64) { - /* If the platform does not support the GetTickCount64 (Windows XP doesn't), - * then use our fallback implementation based on GetTickCount. */ - sGetTickCount64 = MozGetTickCount64; - } - - return sGetTickCount64() * freq.QuadPart; -#elif defined(XP_MACOSX) - return mach_absolute_time(); -#elif defined(HAVE_CLOCK_MONOTONIC) - struct timespec ts; - int rv = clock_gettime(CLOCK_MONOTONIC, &ts); - - if (rv != 0) { - return 0; - } - - uint64_t baseNs = (uint64_t)ts.tv_sec * 1000000000; - return baseNs + (uint64_t)ts.tv_nsec; -#endif -} - static bool FileExists(const char *path) { @@ -411,7 +332,7 @@ InitXPCOMGlue(const char *argv0, nsIFile **xreDirectory) int main(int argc, char* argv[]) { - uint64_t start = TimeStamp_Now(); + mozilla::TimeStamp start = mozilla::TimeStamp::Now(); #ifdef XP_MACOSX TriggerQuirks(); diff --git a/mozglue/android/APKOpen.cpp b/mozglue/android/APKOpen.cpp index 1a52ea0d7c27..3ab995f89c4b 100644 --- a/mozglue/android/APKOpen.cpp +++ b/mozglue/android/APKOpen.cpp @@ -19,7 +19,6 @@ #include #include #include -#include #include #include #include @@ -34,6 +33,8 @@ #include "ElfLoader.h" #include "application.ini.h" +#include "mozilla/TimeStamp.h" + /* Android headers don't define RUSAGE_THREAD */ #ifndef RUSAGE_THREAD #define RUSAGE_THREAD 1 @@ -80,24 +81,6 @@ enum StartupEvent { using namespace mozilla; -/** - * Local TimeStamp::Now()-compatible implementation used to record timestamps - * which will be passed to XRE_StartupTimelineRecord(). - */ - -static uint64_t TimeStamp_Now() -{ - struct timespec ts; - int rv = clock_gettime(CLOCK_MONOTONIC, &ts); - - if (rv != 0) { - return 0; - } - - uint64_t baseNs = (uint64_t)ts.tv_sec * 1000000000; - return baseNs + (uint64_t)ts.tv_nsec; -} - static struct mapping_info * lib_mapping = nullptr; NS_EXPORT const struct mapping_info * @@ -209,7 +192,7 @@ report_mapping(char *name, void *base, uint32_t len, uint32_t offset) static mozglueresult loadGeckoLibs(const char *apkName) { - uint64_t t0 = TimeStamp_Now(); + TimeStamp t0 = TimeStamp::Now(); struct rusage usage1_thread, usage1; getrusage(RUSAGE_THREAD, &usage1_thread); getrusage(RUSAGE_SELF, &usage1); @@ -228,10 +211,10 @@ loadGeckoLibs(const char *apkName) #include "jni-stubs.inc" #undef JNI_BINDINGS - void (*XRE_StartupTimelineRecord)(int, uint64_t); + void (*XRE_StartupTimelineRecord)(int, TimeStamp); xul_dlsym("XRE_StartupTimelineRecord", &XRE_StartupTimelineRecord); - uint64_t t1 = TimeStamp_Now(); + TimeStamp t1 = TimeStamp::Now(); struct rusage usage2_thread, usage2; getrusage(RUSAGE_THREAD, &usage2_thread); getrusage(RUSAGE_SELF, &usage2); @@ -240,8 +223,8 @@ loadGeckoLibs(const char *apkName) ((u2.ru_ ## field.tv_sec - u1.ru_ ## field.tv_sec) * 1000 + \ (u2.ru_ ## field.tv_usec - u1.ru_ ## field.tv_usec) / 1000) - __android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad", "Loaded libs in %lldms total, %ldms(%ldms) user, %ldms(%ldms) system, %ld(%ld) faults", - (t1 - t0) / 1000000, + __android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad", "Loaded libs in %fms total, %ldms(%ldms) user, %ldms(%ldms) system, %ld(%ld) faults", + (t1 - t0).ToMilliseconds(), RUSAGE_TIMEDIFF(usage1_thread, usage2_thread, utime), RUSAGE_TIMEDIFF(usage1, usage2, utime), RUSAGE_TIMEDIFF(usage1_thread, usage2_thread, stime), diff --git a/toolkit/components/startup/StartupTimeline.cpp b/toolkit/components/startup/StartupTimeline.cpp index 240190146b5f..e4762af15ba7 100644 --- a/toolkit/components/startup/StartupTimeline.cpp +++ b/toolkit/components/startup/StartupTimeline.cpp @@ -16,52 +16,21 @@ const char *StartupTimeline::sStartupTimelineDesc[StartupTimeline::MAX_EVENT_ID] #undef mozilla_StartupTimeline_Event }; -/** - * Implementation of XRE_StartupTimelineRecord() - * - * @param aEvent Same as XRE_StartupTimelineRecord() equivalent argument - * @param aWhen Same as XRE_StartupTimelineRecord() equivalent argument - */ -void -StartupTimelineRecordExternal(int aEvent, uint64_t aWhen) -{ -#if XP_WIN - TimeStamp ts = TimeStampValue(aWhen, 0, 0); -#else - TimeStamp ts = TimeStampValue(aWhen); -#endif - bool error = false; - - // Since the timestamp comes from an external source validate it before - // recording it and log a telemetry error if it appears inconsistent. - if (ts < TimeStamp::ProcessCreation(error)) { - Telemetry::Accumulate(Telemetry::STARTUP_MEASUREMENT_ERRORS, - (StartupTimeline::Event)aEvent); - } else { - StartupTimeline::Record((StartupTimeline::Event)aEvent, ts); - } -} - } /* namespace mozilla */ +using mozilla::StartupTimeline; +using mozilla::TimeStamp; + /** * The XRE_StartupTimeline_Record function is to be used by embedding * applications that can't use mozilla::StartupTimeline::Record() directly. * - * It can create timestamps from arbitrary time values and sanitizies them to - * ensure that they are not inconsistent with those captured using monotonic - * timers. The value of aWhen must have been captured using the same timer - * used by the platform's mozilla::TimeStamp implementation. Erroneous values - * will be flagged as telemetry errors. - * * @param aEvent The event to be recorded, must correspond to an element of the * mozilla::StartupTimeline::Event enumartion - * @param aWhen The time at which the event happened, must have been recorded - * using the same timer as the platform's mozilla::TimeStamp - * implementation + * @param aWhen The time at which the event happened */ void -XRE_StartupTimelineRecord(int aEvent, PRTime aWhen) +XRE_StartupTimelineRecord(int aEvent, TimeStamp aWhen) { - mozilla::StartupTimelineRecordExternal(aEvent, aWhen); + StartupTimeline::Record((StartupTimeline::Event)aEvent, aWhen); } diff --git a/toolkit/components/startup/StartupTimeline.h b/toolkit/components/startup/StartupTimeline.h index 4694cbc3edb1..ff871e493793 100644 --- a/toolkit/components/startup/StartupTimeline.h +++ b/toolkit/components/startup/StartupTimeline.h @@ -48,7 +48,6 @@ namespace mozilla { void RecordShutdownEndTimeStamp(); void RecordShutdownStartTimeStamp(); -void StartupTimelineRecordExternal(int, uint64_t); class StartupTimeline { public: diff --git a/xpcom/build/nsXULAppAPI.h b/xpcom/build/nsXULAppAPI.h index 8b3c1be36376..975b7b21fa30 100644 --- a/xpcom/build/nsXULAppAPI.h +++ b/xpcom/build/nsXULAppAPI.h @@ -18,6 +18,7 @@ #include "mozilla/ArrayUtils.h" #include "mozilla/Assertions.h" #include "mozilla/Vector.h" +#include "mozilla/TimeStamp.h" /** * A directory service key which provides the platform-correct "application @@ -453,7 +454,7 @@ XRE_API(void, XRE_TelemetryAccumulate, (int aID, uint32_t aSample)) XRE_API(void, - XRE_StartupTimelineRecord, (int aEvent, PRTime aWhen)) + XRE_StartupTimelineRecord, (int aEvent, mozilla::TimeStamp aWhen)) XRE_API(void, XRE_InitOmnijar, (nsIFile* aGreOmni,