toolkit/components/startup/StartupTimeline.cpp

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 #include "StartupTimeline.h"
     6 #include "mozilla/Telemetry.h"
     7 #include "mozilla/TimeStamp.h"
     8 #include "nsXULAppAPI.h"
    10 namespace mozilla {
    12 TimeStamp StartupTimeline::sStartupTimeline[StartupTimeline::MAX_EVENT_ID];
    13 const char *StartupTimeline::sStartupTimelineDesc[StartupTimeline::MAX_EVENT_ID] = {
    14 #define mozilla_StartupTimeline_Event(ev, desc) desc,
    15 #include "StartupTimeline.h"
    16 #undef mozilla_StartupTimeline_Event
    17 };
    19 /**
    20  * Implementation of XRE_StartupTimelineRecord()
    21  *
    22  * @param aEvent Same as XRE_StartupTimelineRecord() equivalent argument
    23  * @param aWhen  Same as XRE_StartupTimelineRecord() equivalent argument
    24  */
    25 void
    26 StartupTimelineRecordExternal(int aEvent, uint64_t aWhen)
    27 {
    28 #if XP_WIN
    29   TimeStamp ts = TimeStampValue(aWhen, 0, 0);
    30 #else
    31   TimeStamp ts = TimeStampValue(aWhen);
    32 #endif
    33   bool error = false;
    35   // Since the timestamp comes from an external source validate it before
    36   // recording it and log a telemetry error if it appears inconsistent.
    37   if (ts < TimeStamp::ProcessCreation(error)) {
    38     Telemetry::Accumulate(Telemetry::STARTUP_MEASUREMENT_ERRORS,
    39       (StartupTimeline::Event)aEvent);
    40   } else {
    41     StartupTimeline::Record((StartupTimeline::Event)aEvent, ts);
    42   }
    43 }
    45 } /* namespace mozilla */
    47 /**
    48  * The XRE_StartupTimeline_Record function is to be used by embedding
    49  * applications that can't use mozilla::StartupTimeline::Record() directly.
    50  *
    51  * It can create timestamps from arbitrary time values and sanitizies them to
    52  * ensure that they are not inconsistent with those captured using monotonic
    53  * timers. The value of aWhen must have been captured using the same timer
    54  * used by the platform's mozilla::TimeStamp implementation. Erroneous values
    55  * will be flagged as telemetry errors.
    56  *
    57  * @param aEvent The event to be recorded, must correspond to an element of the
    58  *               mozilla::StartupTimeline::Event enumartion
    59  * @param aWhen  The time at which the event happened, must have been recorded
    60  *               using the same timer as the platform's mozilla::TimeStamp
    61  *               implementation
    62  */
    63 void
    64 XRE_StartupTimelineRecord(int aEvent, PRTime aWhen)
    65 {
    66   mozilla::StartupTimelineRecordExternal(aEvent, aWhen);
    67 }

mercurial