|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 #ifndef PROFILER_MARKERS_H |
|
7 #define PROFILER_MARKERS_H |
|
8 |
|
9 #include "JSStreamWriter.h" |
|
10 #include "mozilla/TimeStamp.h" |
|
11 #include "nsAutoPtr.h" |
|
12 |
|
13 /** |
|
14 * This is an abstract object that can be implied to supply |
|
15 * data to be attached with a profiler marker. Most data inserted |
|
16 * into a profile is stored in a circular buffer. This buffer |
|
17 * typically wraps around and overwrites most entries. Because |
|
18 * of this, this structure is designed to defer the work of |
|
19 * prepare the payload only when 'preparePayload' is called. |
|
20 * |
|
21 * Note when implementing that this object is typically constructed |
|
22 * on a particular thread but 'preparePayload' and the destructor |
|
23 * is called from the main thread. |
|
24 */ |
|
25 class ProfilerMarkerPayload |
|
26 { |
|
27 public: |
|
28 /** |
|
29 * ProfilerMarkerPayload takes ownership of aStack |
|
30 */ |
|
31 ProfilerMarkerPayload(ProfilerBacktrace* aStack = nullptr); |
|
32 ProfilerMarkerPayload(const mozilla::TimeStamp& aStartTime, |
|
33 const mozilla::TimeStamp& aEndTime, |
|
34 ProfilerBacktrace* aStack = nullptr); |
|
35 |
|
36 /** |
|
37 * Called from the main thread |
|
38 */ |
|
39 virtual ~ProfilerMarkerPayload(); |
|
40 |
|
41 /** |
|
42 * Called from the main thread |
|
43 */ |
|
44 void StreamPayload(JSStreamWriter& b) { |
|
45 return streamPayload(b); |
|
46 } |
|
47 |
|
48 protected: |
|
49 /** |
|
50 * Called from the main thread |
|
51 */ |
|
52 void streamCommonProps(const char* aMarkerType, JSStreamWriter& b); |
|
53 |
|
54 /** |
|
55 * Called from the main thread |
|
56 */ |
|
57 virtual void |
|
58 streamPayload(JSStreamWriter& b) = 0; |
|
59 |
|
60 private: |
|
61 mozilla::TimeStamp mStartTime; |
|
62 mozilla::TimeStamp mEndTime; |
|
63 ProfilerBacktrace* mStack; |
|
64 }; |
|
65 |
|
66 class ProfilerMarkerTracing : public ProfilerMarkerPayload |
|
67 { |
|
68 public: |
|
69 ProfilerMarkerTracing(const char* aCategory, TracingMetadata aMetaData); |
|
70 |
|
71 const char *GetCategory() const { return mCategory; } |
|
72 TracingMetadata GetMetaData() const { return mMetaData; } |
|
73 |
|
74 protected: |
|
75 virtual void |
|
76 streamPayload(JSStreamWriter& b) { return streamPayloadImp(b); } |
|
77 |
|
78 private: |
|
79 void streamPayloadImp(JSStreamWriter& b); |
|
80 |
|
81 private: |
|
82 const char *mCategory; |
|
83 TracingMetadata mMetaData; |
|
84 }; |
|
85 |
|
86 |
|
87 class gfxASurface; |
|
88 class ProfilerMarkerImagePayload : public ProfilerMarkerPayload |
|
89 { |
|
90 public: |
|
91 ProfilerMarkerImagePayload(gfxASurface *aImg); |
|
92 |
|
93 protected: |
|
94 virtual void |
|
95 streamPayload(JSStreamWriter& b) { return streamPayloadImp(b); } |
|
96 |
|
97 private: |
|
98 void streamPayloadImp(JSStreamWriter& b); |
|
99 |
|
100 nsRefPtr<gfxASurface> mImg; |
|
101 }; |
|
102 |
|
103 class IOMarkerPayload : public ProfilerMarkerPayload |
|
104 { |
|
105 public: |
|
106 IOMarkerPayload(const char* aSource, const char* aFilename, const mozilla::TimeStamp& aStartTime, |
|
107 const mozilla::TimeStamp& aEndTime, |
|
108 ProfilerBacktrace* aStack); |
|
109 ~IOMarkerPayload(); |
|
110 |
|
111 protected: |
|
112 virtual void |
|
113 streamPayload(JSStreamWriter& b) { return streamPayloadImp(b); } |
|
114 |
|
115 private: |
|
116 void streamPayloadImp(JSStreamWriter& b); |
|
117 |
|
118 const char* mSource; |
|
119 char* mFilename; |
|
120 }; |
|
121 |
|
122 #endif // PROFILER_MARKERS_H |