michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "StartupTimeline.h" michael@0: #include "mozilla/Telemetry.h" michael@0: #include "mozilla/TimeStamp.h" michael@0: #include "nsXULAppAPI.h" michael@0: michael@0: namespace mozilla { michael@0: michael@0: TimeStamp StartupTimeline::sStartupTimeline[StartupTimeline::MAX_EVENT_ID]; michael@0: const char *StartupTimeline::sStartupTimelineDesc[StartupTimeline::MAX_EVENT_ID] = { michael@0: #define mozilla_StartupTimeline_Event(ev, desc) desc, michael@0: #include "StartupTimeline.h" michael@0: #undef mozilla_StartupTimeline_Event michael@0: }; michael@0: michael@0: /** michael@0: * Implementation of XRE_StartupTimelineRecord() michael@0: * michael@0: * @param aEvent Same as XRE_StartupTimelineRecord() equivalent argument michael@0: * @param aWhen Same as XRE_StartupTimelineRecord() equivalent argument michael@0: */ michael@0: void michael@0: StartupTimelineRecordExternal(int aEvent, uint64_t aWhen) michael@0: { michael@0: #if XP_WIN michael@0: TimeStamp ts = TimeStampValue(aWhen, 0, 0); michael@0: #else michael@0: TimeStamp ts = TimeStampValue(aWhen); michael@0: #endif michael@0: bool error = false; michael@0: michael@0: // Since the timestamp comes from an external source validate it before michael@0: // recording it and log a telemetry error if it appears inconsistent. michael@0: if (ts < TimeStamp::ProcessCreation(error)) { michael@0: Telemetry::Accumulate(Telemetry::STARTUP_MEASUREMENT_ERRORS, michael@0: (StartupTimeline::Event)aEvent); michael@0: } else { michael@0: StartupTimeline::Record((StartupTimeline::Event)aEvent, ts); michael@0: } michael@0: } michael@0: michael@0: } /* namespace mozilla */ michael@0: michael@0: /** michael@0: * The XRE_StartupTimeline_Record function is to be used by embedding michael@0: * applications that can't use mozilla::StartupTimeline::Record() directly. michael@0: * michael@0: * It can create timestamps from arbitrary time values and sanitizies them to michael@0: * ensure that they are not inconsistent with those captured using monotonic michael@0: * timers. The value of aWhen must have been captured using the same timer michael@0: * used by the platform's mozilla::TimeStamp implementation. Erroneous values michael@0: * will be flagged as telemetry errors. michael@0: * michael@0: * @param aEvent The event to be recorded, must correspond to an element of the michael@0: * mozilla::StartupTimeline::Event enumartion michael@0: * @param aWhen The time at which the event happened, must have been recorded michael@0: * using the same timer as the platform's mozilla::TimeStamp michael@0: * implementation michael@0: */ michael@0: void michael@0: XRE_StartupTimelineRecord(int aEvent, PRTime aWhen) michael@0: { michael@0: mozilla::StartupTimelineRecordExternal(aEvent, aWhen); michael@0: }