Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 : /* This Source Code Form is subject to the terms of the Mozilla Public
4 : * License, v. 2.0. If a copy of the MPL was not distributed with this
5 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 : #ifndef ProfilerMarkerPayload_h
8 : #define ProfilerMarkerPayload_h
9 :
10 : #include "mozilla/Attributes.h"
11 : #include "mozilla/RefPtr.h"
12 : #include "mozilla/TimeStamp.h"
13 : #include "mozilla/UniquePtrExtensions.h"
14 :
15 : #include "nsString.h"
16 : #include "GeckoProfiler.h"
17 :
18 : #include "js/Utility.h"
19 : #include "gfxASurface.h"
20 :
21 : namespace mozilla {
22 : namespace layers {
23 : class Layer;
24 : } // namespace layers
25 : } // namespace mozilla
26 :
27 : class SpliceableJSONWriter;
28 : class UniqueStacks;
29 :
30 : // This is an abstract class that can be implemented to supply data to be
31 : // attached with a profiler marker.
32 : //
33 : // When subclassing this, note that the destructor can be called on any thread,
34 : // i.e. not necessarily on the thread that created the object.
35 : class ProfilerMarkerPayload
36 : {
37 : public:
38 0 : explicit ProfilerMarkerPayload(UniqueProfilerBacktrace aStack = nullptr)
39 0 : : mStack(Move(aStack))
40 0 : {}
41 :
42 0 : ProfilerMarkerPayload(const mozilla::TimeStamp& aStartTime,
43 : const mozilla::TimeStamp& aEndTime,
44 : UniqueProfilerBacktrace aStack = nullptr)
45 0 : : mStartTime(aStartTime)
46 : , mEndTime(aEndTime)
47 0 : , mStack(Move(aStack))
48 0 : {}
49 :
50 0 : virtual ~ProfilerMarkerPayload() {}
51 :
52 : virtual void StreamPayload(SpliceableJSONWriter& aWriter,
53 : const mozilla::TimeStamp& aProcessStartTime,
54 : UniqueStacks& aUniqueStacks) = 0;
55 :
56 0 : mozilla::TimeStamp GetStartTime() const { return mStartTime; }
57 :
58 : protected:
59 : void StreamCommonProps(const char* aMarkerType,
60 : SpliceableJSONWriter& aWriter,
61 : const mozilla::TimeStamp& aProcessStartTime,
62 : UniqueStacks& aUniqueStacks);
63 :
64 0 : void SetStack(UniqueProfilerBacktrace aStack)
65 : {
66 0 : mStack = mozilla::Move(aStack);
67 0 : }
68 :
69 : private:
70 : mozilla::TimeStamp mStartTime;
71 : mozilla::TimeStamp mEndTime;
72 : UniqueProfilerBacktrace mStack;
73 : };
74 :
75 : #define DECL_STREAM_PAYLOAD_BASE \
76 : virtual void StreamPayload(SpliceableJSONWriter& aWriter, \
77 : const mozilla::TimeStamp& aProcessStartTime, \
78 : UniqueStacks& aUniqueStacks) override
79 :
80 : // If the profiler is disabled then StreamPayload() will never be called.
81 : #ifdef MOZ_GECKO_PROFILER
82 : # define DECL_STREAM_PAYLOAD DECL_STREAM_PAYLOAD_BASE ;
83 : #else
84 : # define DECL_STREAM_PAYLOAD DECL_STREAM_PAYLOAD_BASE { MOZ_CRASH(); }
85 : #endif
86 :
87 0 : class TracingMarkerPayload : public ProfilerMarkerPayload
88 : {
89 : public:
90 0 : TracingMarkerPayload(const char* aCategory, TracingKind aKind,
91 : UniqueProfilerBacktrace aCause = nullptr)
92 0 : : mCategory(aCategory)
93 0 : , mKind(aKind)
94 : {
95 0 : if (aCause) {
96 0 : SetStack(Move(aCause));
97 : }
98 0 : }
99 :
100 : DECL_STREAM_PAYLOAD
101 :
102 : private:
103 : const char *mCategory;
104 : TracingKind mKind;
105 : };
106 :
107 0 : class IOMarkerPayload : public ProfilerMarkerPayload
108 : {
109 : public:
110 0 : IOMarkerPayload(const char* aSource, const char* aFilename,
111 : const mozilla::TimeStamp& aStartTime,
112 : const mozilla::TimeStamp& aEndTime,
113 : UniqueProfilerBacktrace aStack)
114 0 : : ProfilerMarkerPayload(aStartTime, aEndTime, Move(aStack))
115 : , mSource(aSource)
116 0 : , mFilename(aFilename ? strdup(aFilename) : nullptr)
117 : {
118 0 : MOZ_ASSERT(aSource);
119 0 : }
120 :
121 : DECL_STREAM_PAYLOAD
122 :
123 : private:
124 : const char* mSource;
125 : mozilla::UniqueFreePtr<char> mFilename;
126 : };
127 :
128 0 : class DOMEventMarkerPayload : public ProfilerMarkerPayload
129 : {
130 : public:
131 0 : DOMEventMarkerPayload(const nsAString& aType, uint16_t aPhase,
132 : const mozilla::TimeStamp& aStartTime,
133 : const mozilla::TimeStamp& aEndTime)
134 0 : : ProfilerMarkerPayload(aStartTime, aEndTime)
135 : , mType(aType)
136 0 : , mPhase(aPhase)
137 0 : {}
138 :
139 : DECL_STREAM_PAYLOAD
140 :
141 : private:
142 : nsString mType;
143 : uint16_t mPhase;
144 : };
145 :
146 0 : class UserTimingMarkerPayload : public ProfilerMarkerPayload
147 : {
148 : public:
149 0 : UserTimingMarkerPayload(const nsAString& aName,
150 : const mozilla::TimeStamp& aStartTime)
151 0 : : ProfilerMarkerPayload(aStartTime, aStartTime)
152 : , mEntryType("mark")
153 0 : , mName(aName)
154 0 : {}
155 :
156 0 : UserTimingMarkerPayload(const nsAString& aName,
157 : const mozilla::TimeStamp& aStartTime,
158 : const mozilla::TimeStamp& aEndTime)
159 0 : : ProfilerMarkerPayload(aStartTime, aEndTime)
160 : , mEntryType("measure")
161 0 : , mName(aName)
162 0 : {}
163 :
164 : DECL_STREAM_PAYLOAD
165 :
166 : private:
167 : // Either "mark" or "measure".
168 : const char* mEntryType;
169 : nsString mName;
170 : };
171 :
172 : // Contains the translation applied to a 2d layer so we can track the layer
173 : // position at each frame.
174 0 : class LayerTranslationMarkerPayload : public ProfilerMarkerPayload
175 : {
176 : public:
177 0 : LayerTranslationMarkerPayload(mozilla::layers::Layer* aLayer,
178 : mozilla::gfx::Point aPoint,
179 : mozilla::TimeStamp aStartTime)
180 0 : : ProfilerMarkerPayload(aStartTime, aStartTime)
181 : , mLayer(aLayer)
182 0 : , mPoint(aPoint)
183 0 : {}
184 :
185 : DECL_STREAM_PAYLOAD
186 :
187 : private:
188 : mozilla::layers::Layer* mLayer;
189 : mozilla::gfx::Point mPoint;
190 : };
191 :
192 : #include "Units.h" // For ScreenIntPoint
193 :
194 : // Tracks when a vsync occurs according to the HardwareComposer.
195 0 : class VsyncMarkerPayload : public ProfilerMarkerPayload
196 : {
197 : public:
198 0 : explicit VsyncMarkerPayload(mozilla::TimeStamp aVsyncTimestamp)
199 0 : : ProfilerMarkerPayload(aVsyncTimestamp, aVsyncTimestamp)
200 0 : , mVsyncTimestamp(aVsyncTimestamp)
201 0 : {}
202 :
203 : DECL_STREAM_PAYLOAD
204 :
205 : private:
206 : mozilla::TimeStamp mVsyncTimestamp;
207 : };
208 :
209 0 : class GPUMarkerPayload : public ProfilerMarkerPayload
210 : {
211 : public:
212 0 : GPUMarkerPayload(const mozilla::TimeStamp& aCpuTimeStart,
213 : const mozilla::TimeStamp& aCpuTimeEnd,
214 : uint64_t aGpuTimeStart,
215 : uint64_t aGpuTimeEnd)
216 0 : : ProfilerMarkerPayload(aCpuTimeStart, aCpuTimeEnd)
217 : , mCpuTimeStart(aCpuTimeStart)
218 : , mCpuTimeEnd(aCpuTimeEnd)
219 : , mGpuTimeStart(aGpuTimeStart)
220 0 : , mGpuTimeEnd(aGpuTimeEnd)
221 0 : {}
222 :
223 : DECL_STREAM_PAYLOAD
224 :
225 : private:
226 : mozilla::TimeStamp mCpuTimeStart;
227 : mozilla::TimeStamp mCpuTimeEnd;
228 : uint64_t mGpuTimeStart;
229 : uint64_t mGpuTimeEnd;
230 : };
231 :
232 0 : class GCSliceMarkerPayload : public ProfilerMarkerPayload
233 : {
234 : public:
235 0 : GCSliceMarkerPayload(const mozilla::TimeStamp& aStartTime,
236 : const mozilla::TimeStamp& aEndTime,
237 : JS::UniqueChars&& aTimingJSON)
238 0 : : ProfilerMarkerPayload(aStartTime, aEndTime),
239 0 : mTimingJSON(mozilla::Move(aTimingJSON))
240 0 : {}
241 :
242 : DECL_STREAM_PAYLOAD
243 :
244 : private:
245 : JS::UniqueChars mTimingJSON;
246 : };
247 :
248 0 : class GCMajorMarkerPayload : public ProfilerMarkerPayload
249 : {
250 : public:
251 0 : GCMajorMarkerPayload(const mozilla::TimeStamp& aStartTime,
252 : const mozilla::TimeStamp& aEndTime,
253 : JS::UniqueChars&& aTimingJSON)
254 0 : : ProfilerMarkerPayload(aStartTime, aEndTime),
255 0 : mTimingJSON(mozilla::Move(aTimingJSON))
256 0 : {}
257 :
258 : DECL_STREAM_PAYLOAD
259 :
260 : private:
261 : JS::UniqueChars mTimingJSON;
262 : };
263 :
264 0 : class GCMinorMarkerPayload : public ProfilerMarkerPayload
265 : {
266 : public:
267 0 : GCMinorMarkerPayload(const mozilla::TimeStamp& aStartTime,
268 : const mozilla::TimeStamp& aEndTime,
269 : JS::UniqueChars&& aTimingData)
270 0 : : ProfilerMarkerPayload(aStartTime, aEndTime),
271 0 : mTimingData(mozilla::Move(aTimingData))
272 0 : {}
273 :
274 : DECL_STREAM_PAYLOAD
275 :
276 : private:
277 : JS::UniqueChars mTimingData;
278 : };
279 :
280 : #endif // ProfilerMarkerPayload_h
|