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/. */
4 
5 #include "StartupTimeline.h"
6 #include "mozilla/Telemetry.h"
7 #include "mozilla/TimeStamp.h"
8 #include "nsXULAppAPI.h"
9 
10 namespace mozilla {
11 
12 TimeStamp StartupTimeline::sStartupTimeline[StartupTimeline::MAX_EVENT_ID];
13 const char*
14     StartupTimeline::sStartupTimelineDesc[StartupTimeline::MAX_EVENT_ID] = {
15 #define mozilla_StartupTimeline_Event(ev, desc) desc,
16 #include "StartupTimeline.h"
17 #undef mozilla_StartupTimeline_Event
18 };
19 
20 } /* namespace mozilla */
21 
22 using mozilla::StartupTimeline;
23 using mozilla::TimeStamp;
24 
25 /**
26  * The XRE_StartupTimeline_Record function is to be used by embedding
27  * applications that can't use mozilla::StartupTimeline::Record() directly.
28  *
29  * @param aEvent The event to be recorded, must correspond to an element of the
30  *               mozilla::StartupTimeline::Event enumartion
31  * @param aWhen  The time at which the event happened
32  */
XRE_StartupTimelineRecord(int aEvent,TimeStamp aWhen)33 void XRE_StartupTimelineRecord(int aEvent, TimeStamp aWhen) {
34   StartupTimeline::Record((StartupTimeline::Event)aEvent, aWhen);
35 }
36 
RecordOnce(Event ev)37 void StartupTimeline::RecordOnce(Event ev) { RecordOnce(ev, TimeStamp::Now()); }
38 
RecordOnce(Event ev,const TimeStamp & aWhen)39 void StartupTimeline::RecordOnce(Event ev, const TimeStamp& aWhen) {
40   if (HasRecord(ev)) {
41     return;
42   }
43 
44   Record(ev, aWhen);
45 
46   // Record first paint timestamp as a scalar.
47   if (ev == FIRST_PAINT || ev == FIRST_PAINT2) {
48     uint32_t firstPaintTime =
49         (uint32_t)(aWhen - TimeStamp::ProcessCreation()).ToMilliseconds();
50     Telemetry::ScalarSet(ev == FIRST_PAINT
51                              ? Telemetry::ScalarID::TIMESTAMPS_FIRST_PAINT
52                              : Telemetry::ScalarID::TIMESTAMPS_FIRST_PAINT_TWO,
53                          firstPaintTime);
54   }
55 }
56