toolkit/components/startup/StartupTimeline.h

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 #ifdef mozilla_StartupTimeline_Event
     6 mozilla_StartupTimeline_Event(PROCESS_CREATION, "process")
     7 mozilla_StartupTimeline_Event(START, "start")
     8 mozilla_StartupTimeline_Event(MAIN, "main")
     9 mozilla_StartupTimeline_Event(SELECT_PROFILE, "selectProfile")
    10 mozilla_StartupTimeline_Event(AFTER_PROFILE_LOCKED, "afterProfileLocked")
    11 // Record the beginning and end of startup crash detection to compare with crash stats to know whether
    12 // detection should be improved to start or end sooner.
    13 mozilla_StartupTimeline_Event(STARTUP_CRASH_DETECTION_BEGIN, "startupCrashDetectionBegin")
    14 mozilla_StartupTimeline_Event(STARTUP_CRASH_DETECTION_END, "startupCrashDetectionEnd")
    15 mozilla_StartupTimeline_Event(FIRST_PAINT, "firstPaint")
    16 mozilla_StartupTimeline_Event(SESSION_RESTORE_INIT, "sessionRestoreInit")
    17 mozilla_StartupTimeline_Event(SESSION_RESTORED, "sessionRestored")
    18 mozilla_StartupTimeline_Event(CREATE_TOP_LEVEL_WINDOW, "createTopLevelWindow")
    19 mozilla_StartupTimeline_Event(LINKER_INITIALIZED, "linkerInitialized")
    20 mozilla_StartupTimeline_Event(LIBRARIES_LOADED, "librariesLoaded")
    21 mozilla_StartupTimeline_Event(FIRST_LOAD_URI, "firstLoadURI")
    22 #else
    24 #ifndef mozilla_StartupTimeline
    25 #define mozilla_StartupTimeline
    27 #include "mozilla/TimeStamp.h"
    28 #include "nscore.h"
    29 #include "GeckoProfiler.h"
    31 #ifdef MOZ_LINKER
    32 extern "C" {
    33 /* This symbol is resolved by the custom linker. The function it resolves
    34  * to dumps some statistics about the linker at the key events recorded
    35  * by the startup timeline. */
    36 extern void __moz_linker_stats(const char *str)
    37 NS_VISIBILITY_DEFAULT __attribute__((weak));
    38 } /* extern "C" */
    39 #else
    41 #endif
    43 namespace mozilla {
    45 void RecordShutdownEndTimeStamp();
    46 void RecordShutdownStartTimeStamp();
    47 void StartupTimelineRecordExternal(int, uint64_t);
    49 class StartupTimeline {
    50 public:
    51   enum Event {
    52     #define mozilla_StartupTimeline_Event(ev, z) ev,
    53     #include "StartupTimeline.h"
    54     #undef mozilla_StartupTimeline_Event
    55     MAX_EVENT_ID
    56   };
    58   static TimeStamp Get(Event ev) {
    59     return sStartupTimeline[ev];
    60   }
    62   static const char *Describe(Event ev) {
    63     return sStartupTimelineDesc[ev];
    64   }
    66   static void Record(Event ev) {
    67     PROFILER_MARKER(Describe(ev));
    68     Record(ev, TimeStamp::Now());
    69   }
    71   static void Record(Event ev, TimeStamp when) {
    72     sStartupTimeline[ev] = when;
    73 #ifdef MOZ_LINKER
    74     if (__moz_linker_stats)
    75       __moz_linker_stats(Describe(ev));
    76 #endif
    77   }
    79   static void RecordOnce(Event ev) {
    80     if (!HasRecord(ev))
    81       Record(ev);
    82   }
    84   static bool HasRecord(Event ev) {
    85     return !sStartupTimeline[ev].IsNull();
    86   }
    88 private:
    89   static NS_EXTERNAL_VIS_(TimeStamp) sStartupTimeline[MAX_EVENT_ID];
    90   static NS_EXTERNAL_VIS_(const char *) sStartupTimelineDesc[MAX_EVENT_ID];
    91 };
    93 }
    95 #endif /* mozilla_StartupTimeline */
    97 #endif /* mozilla_StartupTimeline_Event */

mercurial