Fri, 16 Jan 2015 18:13:44 +0100
Integrate suggestion from review to improve consistency with existing code.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #ifdef mozilla_StartupTimeline_Event |
michael@0 | 6 | mozilla_StartupTimeline_Event(PROCESS_CREATION, "process") |
michael@0 | 7 | mozilla_StartupTimeline_Event(START, "start") |
michael@0 | 8 | mozilla_StartupTimeline_Event(MAIN, "main") |
michael@0 | 9 | mozilla_StartupTimeline_Event(SELECT_PROFILE, "selectProfile") |
michael@0 | 10 | mozilla_StartupTimeline_Event(AFTER_PROFILE_LOCKED, "afterProfileLocked") |
michael@0 | 11 | // Record the beginning and end of startup crash detection to compare with crash stats to know whether |
michael@0 | 12 | // detection should be improved to start or end sooner. |
michael@0 | 13 | mozilla_StartupTimeline_Event(STARTUP_CRASH_DETECTION_BEGIN, "startupCrashDetectionBegin") |
michael@0 | 14 | mozilla_StartupTimeline_Event(STARTUP_CRASH_DETECTION_END, "startupCrashDetectionEnd") |
michael@0 | 15 | mozilla_StartupTimeline_Event(FIRST_PAINT, "firstPaint") |
michael@0 | 16 | mozilla_StartupTimeline_Event(SESSION_RESTORE_INIT, "sessionRestoreInit") |
michael@0 | 17 | mozilla_StartupTimeline_Event(SESSION_RESTORED, "sessionRestored") |
michael@0 | 18 | mozilla_StartupTimeline_Event(CREATE_TOP_LEVEL_WINDOW, "createTopLevelWindow") |
michael@0 | 19 | mozilla_StartupTimeline_Event(LINKER_INITIALIZED, "linkerInitialized") |
michael@0 | 20 | mozilla_StartupTimeline_Event(LIBRARIES_LOADED, "librariesLoaded") |
michael@0 | 21 | mozilla_StartupTimeline_Event(FIRST_LOAD_URI, "firstLoadURI") |
michael@0 | 22 | #else |
michael@0 | 23 | |
michael@0 | 24 | #ifndef mozilla_StartupTimeline |
michael@0 | 25 | #define mozilla_StartupTimeline |
michael@0 | 26 | |
michael@0 | 27 | #include "mozilla/TimeStamp.h" |
michael@0 | 28 | #include "nscore.h" |
michael@0 | 29 | #include "GeckoProfiler.h" |
michael@0 | 30 | |
michael@0 | 31 | #ifdef MOZ_LINKER |
michael@0 | 32 | extern "C" { |
michael@0 | 33 | /* This symbol is resolved by the custom linker. The function it resolves |
michael@0 | 34 | * to dumps some statistics about the linker at the key events recorded |
michael@0 | 35 | * by the startup timeline. */ |
michael@0 | 36 | extern void __moz_linker_stats(const char *str) |
michael@0 | 37 | NS_VISIBILITY_DEFAULT __attribute__((weak)); |
michael@0 | 38 | } /* extern "C" */ |
michael@0 | 39 | #else |
michael@0 | 40 | |
michael@0 | 41 | #endif |
michael@0 | 42 | |
michael@0 | 43 | namespace mozilla { |
michael@0 | 44 | |
michael@0 | 45 | void RecordShutdownEndTimeStamp(); |
michael@0 | 46 | void RecordShutdownStartTimeStamp(); |
michael@0 | 47 | void StartupTimelineRecordExternal(int, uint64_t); |
michael@0 | 48 | |
michael@0 | 49 | class StartupTimeline { |
michael@0 | 50 | public: |
michael@0 | 51 | enum Event { |
michael@0 | 52 | #define mozilla_StartupTimeline_Event(ev, z) ev, |
michael@0 | 53 | #include "StartupTimeline.h" |
michael@0 | 54 | #undef mozilla_StartupTimeline_Event |
michael@0 | 55 | MAX_EVENT_ID |
michael@0 | 56 | }; |
michael@0 | 57 | |
michael@0 | 58 | static TimeStamp Get(Event ev) { |
michael@0 | 59 | return sStartupTimeline[ev]; |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | static const char *Describe(Event ev) { |
michael@0 | 63 | return sStartupTimelineDesc[ev]; |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | static void Record(Event ev) { |
michael@0 | 67 | PROFILER_MARKER(Describe(ev)); |
michael@0 | 68 | Record(ev, TimeStamp::Now()); |
michael@0 | 69 | } |
michael@0 | 70 | |
michael@0 | 71 | static void Record(Event ev, TimeStamp when) { |
michael@0 | 72 | sStartupTimeline[ev] = when; |
michael@0 | 73 | #ifdef MOZ_LINKER |
michael@0 | 74 | if (__moz_linker_stats) |
michael@0 | 75 | __moz_linker_stats(Describe(ev)); |
michael@0 | 76 | #endif |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | static void RecordOnce(Event ev) { |
michael@0 | 80 | if (!HasRecord(ev)) |
michael@0 | 81 | Record(ev); |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | static bool HasRecord(Event ev) { |
michael@0 | 85 | return !sStartupTimeline[ev].IsNull(); |
michael@0 | 86 | } |
michael@0 | 87 | |
michael@0 | 88 | private: |
michael@0 | 89 | static NS_EXTERNAL_VIS_(TimeStamp) sStartupTimeline[MAX_EVENT_ID]; |
michael@0 | 90 | static NS_EXTERNAL_VIS_(const char *) sStartupTimelineDesc[MAX_EVENT_ID]; |
michael@0 | 91 | }; |
michael@0 | 92 | |
michael@0 | 93 | } |
michael@0 | 94 | |
michael@0 | 95 | #endif /* mozilla_StartupTimeline */ |
michael@0 | 96 | |
michael@0 | 97 | #endif /* mozilla_StartupTimeline_Event */ |