Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/ProfilerMarkerPayload.h
Line
Count
Source (jump to first uncovered line)
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/Maybe.h"
12
#include "mozilla/RefPtr.h"
13
#include "mozilla/TimeStamp.h"
14
#include "mozilla/UniquePtrExtensions.h"
15
#include "mozilla/net/TimingStruct.h"
16
17
#include "nsString.h"
18
#include "GeckoProfiler.h"
19
20
#include "js/Utility.h"
21
#include "gfxASurface.h"
22
#include "mozilla/ServoTraversalStatistics.h"
23
24
namespace mozilla {
25
namespace layers {
26
class Layer;
27
} // namespace layers
28
} // namespace mozilla
29
30
class SpliceableJSONWriter;
31
class UniqueStacks;
32
33
// This is an abstract class that can be implemented to supply data to be
34
// attached with a profiler marker.
35
//
36
// When subclassing this, note that the destructor can be called on any thread,
37
// i.e. not necessarily on the thread that created the object.
38
class ProfilerMarkerPayload
39
{
40
public:
41
  explicit ProfilerMarkerPayload(UniqueProfilerBacktrace aStack = nullptr)
42
    : mStack(std::move(aStack))
43
0
  {}
44
45
  ProfilerMarkerPayload(const mozilla::TimeStamp& aStartTime,
46
                        const mozilla::TimeStamp& aEndTime,
47
                        UniqueProfilerBacktrace aStack = nullptr)
48
    : mStartTime(aStartTime)
49
    , mEndTime(aEndTime)
50
    , mStack(std::move(aStack))
51
0
  {}
52
53
0
  virtual ~ProfilerMarkerPayload() {}
54
55
  virtual void StreamPayload(SpliceableJSONWriter& aWriter,
56
                             const mozilla::TimeStamp& aProcessStartTime,
57
                             UniqueStacks& aUniqueStacks) = 0;
58
59
0
  mozilla::TimeStamp GetStartTime() const { return mStartTime; }
60
61
protected:
62
  void StreamType(const char* aMarkerType, SpliceableJSONWriter& aWriter);
63
  void StreamCommonProps(const char* aMarkerType,
64
                         SpliceableJSONWriter& aWriter,
65
                         const mozilla::TimeStamp& aProcessStartTime,
66
                         UniqueStacks& aUniqueStacks);
67
68
  void SetStack(UniqueProfilerBacktrace aStack)
69
0
  {
70
0
    mStack = std::move(aStack);
71
0
  }
72
73
private:
74
  mozilla::TimeStamp mStartTime;
75
  mozilla::TimeStamp mEndTime;
76
  UniqueProfilerBacktrace mStack;
77
};
78
79
#define DECL_STREAM_PAYLOAD \
80
  virtual void StreamPayload(SpliceableJSONWriter& aWriter, \
81
                             const mozilla::TimeStamp& aProcessStartTime, \
82
                             UniqueStacks& aUniqueStacks) override;
83
84
class TracingMarkerPayload : public ProfilerMarkerPayload
85
{
86
public:
87
  TracingMarkerPayload(const char* aCategory, TracingKind aKind,
88
                       UniqueProfilerBacktrace aCause = nullptr)
89
    : mCategory(aCategory)
90
    , mKind(aKind)
91
0
  {
92
0
    if (aCause) {
93
0
      SetStack(std::move(aCause));
94
0
    }
95
0
  }
96
97
  DECL_STREAM_PAYLOAD
98
99
private:
100
  const char *mCategory;
101
  TracingKind mKind;
102
};
103
104
class IOMarkerPayload : public ProfilerMarkerPayload
105
{
106
public:
107
  IOMarkerPayload(const char* aSource, const char* aFilename,
108
                  const mozilla::TimeStamp& aStartTime,
109
                  const mozilla::TimeStamp& aEndTime,
110
                  UniqueProfilerBacktrace aStack)
111
    : ProfilerMarkerPayload(aStartTime, aEndTime, std::move(aStack))
112
    , mSource(aSource)
113
    , mFilename(aFilename ? strdup(aFilename) : nullptr)
114
0
  {
115
0
    MOZ_ASSERT(aSource);
116
0
  }
117
118
  DECL_STREAM_PAYLOAD
119
120
private:
121
  const char* mSource;
122
  mozilla::UniqueFreePtr<char> mFilename;
123
};
124
125
class DOMEventMarkerPayload : public TracingMarkerPayload
126
{
127
public:
128
  DOMEventMarkerPayload(const nsAString& aEventType,
129
                        const mozilla::TimeStamp& aTimeStamp,
130
                        const char* aCategory, TracingKind aKind)
131
    : TracingMarkerPayload(aCategory, aKind)
132
    , mTimeStamp(aTimeStamp)
133
    , mEventType(aEventType)
134
0
  {}
135
136
  DECL_STREAM_PAYLOAD
137
138
private:
139
  mozilla::TimeStamp mTimeStamp;
140
  nsString mEventType;
141
};
142
143
class UserTimingMarkerPayload : public ProfilerMarkerPayload
144
{
145
public:
146
  UserTimingMarkerPayload(const nsAString& aName,
147
                          const mozilla::TimeStamp& aStartTime)
148
    : ProfilerMarkerPayload(aStartTime, aStartTime)
149
    , mEntryType("mark")
150
    , mName(aName)
151
0
  {}
152
153
  UserTimingMarkerPayload(const nsAString& aName,
154
                          const mozilla::Maybe<nsString>& aStartMark,
155
                          const mozilla::Maybe<nsString>& aEndMark,
156
                          const mozilla::TimeStamp& aStartTime,
157
                          const mozilla::TimeStamp& aEndTime)
158
    : ProfilerMarkerPayload(aStartTime, aEndTime)
159
    , mEntryType("measure")
160
    , mName(aName)
161
    , mStartMark(aStartMark)
162
    , mEndMark(aEndMark)
163
0
  {}
164
165
  DECL_STREAM_PAYLOAD
166
167
private:
168
  // Either "mark" or "measure".
169
  const char* mEntryType;
170
  nsString mName;
171
  mozilla::Maybe<nsString> mStartMark;
172
  mozilla::Maybe<nsString> mEndMark;
173
};
174
175
// Contains the translation applied to a 2d layer so we can track the layer
176
// position at each frame.
177
class LayerTranslationMarkerPayload : public ProfilerMarkerPayload
178
{
179
public:
180
  LayerTranslationMarkerPayload(mozilla::layers::Layer* aLayer,
181
                                mozilla::gfx::Point aPoint,
182
                                mozilla::TimeStamp aStartTime)
183
    : ProfilerMarkerPayload(aStartTime, aStartTime)
184
    , mLayer(aLayer)
185
    , mPoint(aPoint)
186
0
  {}
187
188
  DECL_STREAM_PAYLOAD
189
190
private:
191
  mozilla::layers::Layer* mLayer;
192
  mozilla::gfx::Point mPoint;
193
};
194
195
#include "Units.h"    // For ScreenIntPoint
196
197
// Tracks when a vsync occurs according to the HardwareComposer.
198
class VsyncMarkerPayload : public ProfilerMarkerPayload
199
{
200
public:
201
  explicit VsyncMarkerPayload(mozilla::TimeStamp aVsyncTimestamp)
202
    : ProfilerMarkerPayload(aVsyncTimestamp, aVsyncTimestamp)
203
    , mVsyncTimestamp(aVsyncTimestamp)
204
0
  {}
205
206
  DECL_STREAM_PAYLOAD
207
208
private:
209
  mozilla::TimeStamp mVsyncTimestamp;
210
};
211
212
class NetworkMarkerPayload : public ProfilerMarkerPayload
213
{
214
public:
215
  NetworkMarkerPayload(int64_t aID, const char* aURI,
216
                       NetworkLoadType aType,
217
                       const mozilla::TimeStamp& aStartTime,
218
                       const mozilla::TimeStamp& aEndTime,
219
                       int32_t aPri,
220
                       int64_t aCount,
221
                       const mozilla::net::TimingStruct* aTimings = nullptr,
222
                       const char* aRedirectURI = nullptr)
223
    : ProfilerMarkerPayload(aStartTime, aEndTime)
224
    , mID(aID)
225
    , mURI(aURI ? strdup(aURI) : nullptr)
226
    , mRedirectURI(aRedirectURI && (strlen(aRedirectURI) > 0) ? strdup(aRedirectURI) : nullptr)
227
    , mType(aType)
228
    , mPri(aPri)
229
    , mCount(aCount)
230
  {
231
    if (aTimings) {
232
      mTimings = *aTimings;
233
    }
234
  }
235
236
  DECL_STREAM_PAYLOAD
237
238
private:
239
  int64_t mID;
240
  mozilla::UniqueFreePtr<char> mURI;
241
  mozilla::UniqueFreePtr<char> mRedirectURI;
242
  NetworkLoadType mType;
243
  int32_t mPri;
244
  int64_t mCount;
245
  mozilla::net::TimingStruct mTimings;
246
};
247
248
class ScreenshotPayload : public ProfilerMarkerPayload
249
{
250
public:
251
  explicit ScreenshotPayload(mozilla::TimeStamp aTimeStamp,
252
                             nsCString&& aScreenshotDataURL,
253
                             const mozilla::gfx::IntSize& aWindowSize,
254
                             uintptr_t aWindowIdentifier)
255
    : ProfilerMarkerPayload(aTimeStamp, mozilla::TimeStamp())
256
    , mScreenshotDataURL(std::move(aScreenshotDataURL))
257
    , mWindowSize(aWindowSize)
258
    , mWindowIdentifier(aWindowIdentifier)
259
0
  {}
260
261
  DECL_STREAM_PAYLOAD
262
263
private:
264
  nsCString mScreenshotDataURL;
265
  mozilla::gfx::IntSize mWindowSize;
266
  uintptr_t mWindowIdentifier;
267
};
268
269
class GCSliceMarkerPayload : public ProfilerMarkerPayload
270
{
271
public:
272
  GCSliceMarkerPayload(const mozilla::TimeStamp& aStartTime,
273
                       const mozilla::TimeStamp& aEndTime,
274
                       JS::UniqueChars&& aTimingJSON)
275
   : ProfilerMarkerPayload(aStartTime, aEndTime),
276
     mTimingJSON(std::move(aTimingJSON))
277
0
  {}
278
279
  DECL_STREAM_PAYLOAD
280
281
private:
282
  JS::UniqueChars mTimingJSON;
283
};
284
285
class GCMajorMarkerPayload : public ProfilerMarkerPayload
286
{
287
public:
288
  GCMajorMarkerPayload(const mozilla::TimeStamp& aStartTime,
289
                       const mozilla::TimeStamp& aEndTime,
290
                       JS::UniqueChars&& aTimingJSON)
291
   : ProfilerMarkerPayload(aStartTime, aEndTime),
292
     mTimingJSON(std::move(aTimingJSON))
293
0
  {}
294
295
  DECL_STREAM_PAYLOAD
296
297
private:
298
  JS::UniqueChars mTimingJSON;
299
};
300
301
class GCMinorMarkerPayload : public ProfilerMarkerPayload
302
{
303
public:
304
  GCMinorMarkerPayload(const mozilla::TimeStamp& aStartTime,
305
                       const mozilla::TimeStamp& aEndTime,
306
                       JS::UniqueChars&& aTimingData)
307
   : ProfilerMarkerPayload(aStartTime, aEndTime),
308
     mTimingData(std::move(aTimingData))
309
0
  {}
310
311
  DECL_STREAM_PAYLOAD
312
313
private:
314
  JS::UniqueChars mTimingData;
315
};
316
317
class HangMarkerPayload : public ProfilerMarkerPayload
318
{
319
public:
320
  HangMarkerPayload(const mozilla::TimeStamp& aStartTime,
321
                    const mozilla::TimeStamp& aEndTime)
322
   : ProfilerMarkerPayload(aStartTime, aEndTime)
323
0
  {}
324
325
  DECL_STREAM_PAYLOAD
326
private:
327
};
328
329
class StyleMarkerPayload : public ProfilerMarkerPayload
330
{
331
public:
332
  StyleMarkerPayload(const mozilla::TimeStamp& aStartTime,
333
                     const mozilla::TimeStamp& aEndTime,
334
                     UniqueProfilerBacktrace aCause,
335
                     const mozilla::ServoTraversalStatistics& aStats)
336
    : ProfilerMarkerPayload(aStartTime, aEndTime)
337
    , mStats(aStats)
338
0
  {
339
0
    if (aCause) {
340
0
      SetStack(std::move(aCause));
341
0
    }
342
0
  }
343
344
  DECL_STREAM_PAYLOAD
345
346
private:
347
  mozilla::ServoTraversalStatistics mStats;
348
};
349
350
#endif // ProfilerMarkerPayload_h