1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/startup/StartupTimeline.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,67 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#include "StartupTimeline.h" 1.9 +#include "mozilla/Telemetry.h" 1.10 +#include "mozilla/TimeStamp.h" 1.11 +#include "nsXULAppAPI.h" 1.12 + 1.13 +namespace mozilla { 1.14 + 1.15 +TimeStamp StartupTimeline::sStartupTimeline[StartupTimeline::MAX_EVENT_ID]; 1.16 +const char *StartupTimeline::sStartupTimelineDesc[StartupTimeline::MAX_EVENT_ID] = { 1.17 +#define mozilla_StartupTimeline_Event(ev, desc) desc, 1.18 +#include "StartupTimeline.h" 1.19 +#undef mozilla_StartupTimeline_Event 1.20 +}; 1.21 + 1.22 +/** 1.23 + * Implementation of XRE_StartupTimelineRecord() 1.24 + * 1.25 + * @param aEvent Same as XRE_StartupTimelineRecord() equivalent argument 1.26 + * @param aWhen Same as XRE_StartupTimelineRecord() equivalent argument 1.27 + */ 1.28 +void 1.29 +StartupTimelineRecordExternal(int aEvent, uint64_t aWhen) 1.30 +{ 1.31 +#if XP_WIN 1.32 + TimeStamp ts = TimeStampValue(aWhen, 0, 0); 1.33 +#else 1.34 + TimeStamp ts = TimeStampValue(aWhen); 1.35 +#endif 1.36 + bool error = false; 1.37 + 1.38 + // Since the timestamp comes from an external source validate it before 1.39 + // recording it and log a telemetry error if it appears inconsistent. 1.40 + if (ts < TimeStamp::ProcessCreation(error)) { 1.41 + Telemetry::Accumulate(Telemetry::STARTUP_MEASUREMENT_ERRORS, 1.42 + (StartupTimeline::Event)aEvent); 1.43 + } else { 1.44 + StartupTimeline::Record((StartupTimeline::Event)aEvent, ts); 1.45 + } 1.46 +} 1.47 + 1.48 +} /* namespace mozilla */ 1.49 + 1.50 +/** 1.51 + * The XRE_StartupTimeline_Record function is to be used by embedding 1.52 + * applications that can't use mozilla::StartupTimeline::Record() directly. 1.53 + * 1.54 + * It can create timestamps from arbitrary time values and sanitizies them to 1.55 + * ensure that they are not inconsistent with those captured using monotonic 1.56 + * timers. The value of aWhen must have been captured using the same timer 1.57 + * used by the platform's mozilla::TimeStamp implementation. Erroneous values 1.58 + * will be flagged as telemetry errors. 1.59 + * 1.60 + * @param aEvent The event to be recorded, must correspond to an element of the 1.61 + * mozilla::StartupTimeline::Event enumartion 1.62 + * @param aWhen The time at which the event happened, must have been recorded 1.63 + * using the same timer as the platform's mozilla::TimeStamp 1.64 + * implementation 1.65 + */ 1.66 +void 1.67 +XRE_StartupTimelineRecord(int aEvent, PRTime aWhen) 1.68 +{ 1.69 + mozilla::StartupTimelineRecordExternal(aEvent, aWhen); 1.70 +}