Bug 1073336 part 5 - Add AnimationPlayerCollection::PlayerUpdated; r=dbaron
[gecko.git] / tools / profiler / ProfilerMarkers.cpp
blob21d9093200b08d904d30ee9c4e9ff845f2e28fc6
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/. */
6 #include "GeckoProfiler.h"
7 #include "ProfilerBacktrace.h"
8 #include "ProfilerMarkers.h"
9 #include "gfxASurface.h"
10 #include "SyncProfile.h"
11 #include "Layers.h"
12 #include "prprf.h"
14 ProfilerMarkerPayload::ProfilerMarkerPayload(ProfilerBacktrace* aStack)
15 : mStack(aStack)
18 ProfilerMarkerPayload::ProfilerMarkerPayload(const mozilla::TimeStamp& aStartTime,
19 const mozilla::TimeStamp& aEndTime,
20 ProfilerBacktrace* aStack)
21 : mStartTime(aStartTime)
22 , mEndTime(aEndTime)
23 , mStack(aStack)
26 ProfilerMarkerPayload::~ProfilerMarkerPayload()
28 profiler_free_backtrace(mStack);
31 void
32 ProfilerMarkerPayload::streamCommonProps(const char* aMarkerType,
33 JSStreamWriter& b)
35 MOZ_ASSERT(aMarkerType);
36 b.NameValue("type", aMarkerType);
37 if (!mStartTime.IsNull()) {
38 b.NameValue("startTime", profiler_time(mStartTime));
40 if (!mEndTime.IsNull()) {
41 b.NameValue("endTime", profiler_time(mEndTime));
43 if (mStack) {
44 b.Name("stack");
45 mStack->StreamJSObject(b);
49 ProfilerMarkerTracing::ProfilerMarkerTracing(const char* aCategory, TracingMetadata aMetaData)
50 : mCategory(aCategory)
51 , mMetaData(aMetaData)
53 if (aMetaData == TRACING_EVENT_BACKTRACE) {
54 SetStack(profiler_get_backtrace());
58 ProfilerMarkerTracing::ProfilerMarkerTracing(const char* aCategory, TracingMetadata aMetaData,
59 ProfilerBacktrace* aCause)
60 : mCategory(aCategory)
61 , mMetaData(aMetaData)
63 if (aCause) {
64 SetStack(aCause);
68 void
69 ProfilerMarkerTracing::streamPayloadImp(JSStreamWriter& b)
71 b.BeginObject();
72 streamCommonProps("tracing", b);
74 if (GetCategory()) {
75 b.NameValue("category", GetCategory());
77 if (GetMetaData() != TRACING_DEFAULT) {
78 if (GetMetaData() == TRACING_INTERVAL_START) {
79 b.NameValue("interval", "start");
80 } else if (GetMetaData() == TRACING_INTERVAL_END) {
81 b.NameValue("interval", "end");
84 b.EndObject();
87 GPUMarkerPayload::GPUMarkerPayload(
88 const mozilla::TimeStamp& aCpuTimeStart,
89 const mozilla::TimeStamp& aCpuTimeEnd,
90 uint64_t aGpuTimeStart,
91 uint64_t aGpuTimeEnd)
93 : ProfilerMarkerPayload(aCpuTimeStart, aCpuTimeEnd)
94 , mCpuTimeStart(aCpuTimeStart)
95 , mCpuTimeEnd(aCpuTimeEnd)
96 , mGpuTimeStart(aGpuTimeStart)
97 , mGpuTimeEnd(aGpuTimeEnd)
102 void
103 GPUMarkerPayload::streamPayloadImp(JSStreamWriter& b)
105 b.BeginObject();
106 streamCommonProps("gpu_timer_query", b);
108 b.NameValue("cpustart", profiler_time(mCpuTimeStart));
109 b.NameValue("cpuend", profiler_time(mCpuTimeEnd));
110 b.NameValue("gpustart", (int)mGpuTimeStart);
111 b.NameValue("gpuend", (int)mGpuTimeEnd);
112 b.EndObject();
115 ProfilerMarkerImagePayload::ProfilerMarkerImagePayload(gfxASurface *aImg)
116 : mImg(aImg)
119 void
120 ProfilerMarkerImagePayload::streamPayloadImp(JSStreamWriter& b)
122 b.BeginObject();
123 streamCommonProps("innerHTML", b);
124 // TODO: Finish me
125 //b.NameValue("innerHTML", "<img src=''/>");
126 b.EndObject();
129 IOMarkerPayload::IOMarkerPayload(const char* aSource,
130 const char* aFilename,
131 const mozilla::TimeStamp& aStartTime,
132 const mozilla::TimeStamp& aEndTime,
133 ProfilerBacktrace* aStack)
134 : ProfilerMarkerPayload(aStartTime, aEndTime, aStack),
135 mSource(aSource)
137 mFilename = aFilename ? strdup(aFilename) : nullptr;
138 MOZ_ASSERT(aSource);
141 IOMarkerPayload::~IOMarkerPayload(){
142 free(mFilename);
145 void
146 IOMarkerPayload::streamPayloadImp(JSStreamWriter& b)
148 b.BeginObject();
149 streamCommonProps("io", b);
150 b.NameValue("source", mSource);
151 if (mFilename != nullptr) {
152 b.NameValue("filename", mFilename);
154 b.EndObject();
157 void
158 ProfilerJSEventMarker(const char *event)
160 PROFILER_MARKER(event);
163 LayerTranslationPayload::LayerTranslationPayload(mozilla::layers::Layer* aLayer,
164 mozilla::gfx::Point aPoint)
165 : ProfilerMarkerPayload(mozilla::TimeStamp::Now(), mozilla::TimeStamp::Now(), nullptr)
166 , mLayer(aLayer)
167 , mPoint(aPoint)
171 void
172 LayerTranslationPayload::streamPayloadImpl(JSStreamWriter& b)
174 const size_t bufferSize = 32;
175 char buffer[bufferSize];
176 PR_snprintf(buffer, bufferSize, "%p", mLayer);
178 b.BeginObject();
179 b.NameValue("layer", buffer);
180 b.NameValue("x", mPoint.x);
181 b.NameValue("y", mPoint.y);
182 b.NameValue("category", "LayerTranslation");
183 b.EndObject();
186 TouchDataPayload::TouchDataPayload(const mozilla::ScreenIntPoint& aPoint)
187 : ProfilerMarkerPayload(mozilla::TimeStamp::Now(), mozilla::TimeStamp::Now(), nullptr)
189 mPoint = aPoint;
192 void
193 TouchDataPayload::streamPayloadImpl(JSStreamWriter& b)
195 b.BeginObject();
196 b.NameValue("x", mPoint.x);
197 b.NameValue("y", mPoint.y);
198 b.EndObject();
201 VsyncPayload::VsyncPayload(mozilla::TimeStamp aVsyncTimestamp)
202 : ProfilerMarkerPayload(aVsyncTimestamp, aVsyncTimestamp, nullptr)
203 , mVsyncTimestamp(aVsyncTimestamp)
207 void
208 VsyncPayload::streamPayloadImpl(JSStreamWriter& b)
210 b.BeginObject();
211 b.NameValue("vsync", profiler_time(mVsyncTimestamp));
212 b.NameValue("category", "VsyncTimestamp");
213 b.EndObject();