1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/startup/StartupTimeline.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,97 @@ 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 +#ifdef mozilla_StartupTimeline_Event 1.9 +mozilla_StartupTimeline_Event(PROCESS_CREATION, "process") 1.10 +mozilla_StartupTimeline_Event(START, "start") 1.11 +mozilla_StartupTimeline_Event(MAIN, "main") 1.12 +mozilla_StartupTimeline_Event(SELECT_PROFILE, "selectProfile") 1.13 +mozilla_StartupTimeline_Event(AFTER_PROFILE_LOCKED, "afterProfileLocked") 1.14 +// Record the beginning and end of startup crash detection to compare with crash stats to know whether 1.15 +// detection should be improved to start or end sooner. 1.16 +mozilla_StartupTimeline_Event(STARTUP_CRASH_DETECTION_BEGIN, "startupCrashDetectionBegin") 1.17 +mozilla_StartupTimeline_Event(STARTUP_CRASH_DETECTION_END, "startupCrashDetectionEnd") 1.18 +mozilla_StartupTimeline_Event(FIRST_PAINT, "firstPaint") 1.19 +mozilla_StartupTimeline_Event(SESSION_RESTORE_INIT, "sessionRestoreInit") 1.20 +mozilla_StartupTimeline_Event(SESSION_RESTORED, "sessionRestored") 1.21 +mozilla_StartupTimeline_Event(CREATE_TOP_LEVEL_WINDOW, "createTopLevelWindow") 1.22 +mozilla_StartupTimeline_Event(LINKER_INITIALIZED, "linkerInitialized") 1.23 +mozilla_StartupTimeline_Event(LIBRARIES_LOADED, "librariesLoaded") 1.24 +mozilla_StartupTimeline_Event(FIRST_LOAD_URI, "firstLoadURI") 1.25 +#else 1.26 + 1.27 +#ifndef mozilla_StartupTimeline 1.28 +#define mozilla_StartupTimeline 1.29 + 1.30 +#include "mozilla/TimeStamp.h" 1.31 +#include "nscore.h" 1.32 +#include "GeckoProfiler.h" 1.33 + 1.34 +#ifdef MOZ_LINKER 1.35 +extern "C" { 1.36 +/* This symbol is resolved by the custom linker. The function it resolves 1.37 + * to dumps some statistics about the linker at the key events recorded 1.38 + * by the startup timeline. */ 1.39 +extern void __moz_linker_stats(const char *str) 1.40 +NS_VISIBILITY_DEFAULT __attribute__((weak)); 1.41 +} /* extern "C" */ 1.42 +#else 1.43 + 1.44 +#endif 1.45 + 1.46 +namespace mozilla { 1.47 + 1.48 +void RecordShutdownEndTimeStamp(); 1.49 +void RecordShutdownStartTimeStamp(); 1.50 +void StartupTimelineRecordExternal(int, uint64_t); 1.51 + 1.52 +class StartupTimeline { 1.53 +public: 1.54 + enum Event { 1.55 + #define mozilla_StartupTimeline_Event(ev, z) ev, 1.56 + #include "StartupTimeline.h" 1.57 + #undef mozilla_StartupTimeline_Event 1.58 + MAX_EVENT_ID 1.59 + }; 1.60 + 1.61 + static TimeStamp Get(Event ev) { 1.62 + return sStartupTimeline[ev]; 1.63 + } 1.64 + 1.65 + static const char *Describe(Event ev) { 1.66 + return sStartupTimelineDesc[ev]; 1.67 + } 1.68 + 1.69 + static void Record(Event ev) { 1.70 + PROFILER_MARKER(Describe(ev)); 1.71 + Record(ev, TimeStamp::Now()); 1.72 + } 1.73 + 1.74 + static void Record(Event ev, TimeStamp when) { 1.75 + sStartupTimeline[ev] = when; 1.76 +#ifdef MOZ_LINKER 1.77 + if (__moz_linker_stats) 1.78 + __moz_linker_stats(Describe(ev)); 1.79 +#endif 1.80 + } 1.81 + 1.82 + static void RecordOnce(Event ev) { 1.83 + if (!HasRecord(ev)) 1.84 + Record(ev); 1.85 + } 1.86 + 1.87 + static bool HasRecord(Event ev) { 1.88 + return !sStartupTimeline[ev].IsNull(); 1.89 + } 1.90 + 1.91 +private: 1.92 + static NS_EXTERNAL_VIS_(TimeStamp) sStartupTimeline[MAX_EVENT_ID]; 1.93 + static NS_EXTERNAL_VIS_(const char *) sStartupTimelineDesc[MAX_EVENT_ID]; 1.94 +}; 1.95 + 1.96 +} 1.97 + 1.98 +#endif /* mozilla_StartupTimeline */ 1.99 + 1.100 +#endif /* mozilla_StartupTimeline_Event */