Bug 858928 - Switch XRE_StartupTimelineRecord() from PRTime to TimeStamp. r=froydnj

--HG--
extra : rebase_source : b39bf19f68a124cefaf5ceac2adccb20e05bf279
This commit is contained in:
Gabriele Svelto 2015-07-06 18:01:09 +02:00
parent ef8951b111
commit 17358b10b8
5 changed files with 16 additions and 143 deletions

View File

@ -14,12 +14,10 @@
#include <fcntl.h>
#elif defined(XP_UNIX)
#include <sys/resource.h>
#include <time.h>
#include <unistd.h>
#endif
#ifdef XP_MACOSX
#include <mach/mach_time.h>
#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<GetTickCount64_t>
(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();

View File

@ -19,7 +19,6 @@
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <fcntl.h>
#include <unistd.h>
#include <zlib.h>
@ -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),

View File

@ -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);
}

View File

@ -48,7 +48,6 @@ namespace mozilla {
void RecordShutdownEndTimeStamp();
void RecordShutdownStartTimeStamp();
void StartupTimelineRecordExternal(int, uint64_t);
class StartupTimeline {
public:

View File

@ -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,