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"
14 ProfilerMarkerPayload::ProfilerMarkerPayload(ProfilerBacktrace
* aStack
)
18 ProfilerMarkerPayload::ProfilerMarkerPayload(const mozilla::TimeStamp
& aStartTime
,
19 const mozilla::TimeStamp
& aEndTime
,
20 ProfilerBacktrace
* aStack
)
21 : mStartTime(aStartTime
)
26 ProfilerMarkerPayload::~ProfilerMarkerPayload()
28 profiler_free_backtrace(mStack
);
32 ProfilerMarkerPayload::streamCommonProps(const char* aMarkerType
,
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
));
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
)
69 ProfilerMarkerTracing::streamPayloadImp(JSStreamWriter
& b
)
72 streamCommonProps("tracing", b
);
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");
87 GPUMarkerPayload::GPUMarkerPayload(
88 const mozilla::TimeStamp
& aCpuTimeStart
,
89 const mozilla::TimeStamp
& aCpuTimeEnd
,
90 uint64_t aGpuTimeStart
,
93 : ProfilerMarkerPayload(aCpuTimeStart
, aCpuTimeEnd
)
94 , mCpuTimeStart(aCpuTimeStart
)
95 , mCpuTimeEnd(aCpuTimeEnd
)
96 , mGpuTimeStart(aGpuTimeStart
)
97 , mGpuTimeEnd(aGpuTimeEnd
)
103 GPUMarkerPayload::streamPayloadImp(JSStreamWriter
& b
)
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
);
115 ProfilerMarkerImagePayload::ProfilerMarkerImagePayload(gfxASurface
*aImg
)
120 ProfilerMarkerImagePayload::streamPayloadImp(JSStreamWriter
& b
)
123 streamCommonProps("innerHTML", b
);
125 //b.NameValue("innerHTML", "<img src=''/>");
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
),
137 mFilename
= aFilename
? strdup(aFilename
) : nullptr;
141 IOMarkerPayload::~IOMarkerPayload(){
146 IOMarkerPayload::streamPayloadImp(JSStreamWriter
& b
)
149 streamCommonProps("io", b
);
150 b
.NameValue("source", mSource
);
151 if (mFilename
!= nullptr) {
152 b
.NameValue("filename", mFilename
);
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)
172 LayerTranslationPayload::streamPayloadImpl(JSStreamWriter
& b
)
174 const size_t bufferSize
= 32;
175 char buffer
[bufferSize
];
176 PR_snprintf(buffer
, bufferSize
, "%p", mLayer
);
179 b
.NameValue("layer", buffer
);
180 b
.NameValue("x", mPoint
.x
);
181 b
.NameValue("y", mPoint
.y
);
182 b
.NameValue("category", "LayerTranslation");
186 TouchDataPayload::TouchDataPayload(const mozilla::ScreenIntPoint
& aPoint
)
187 : ProfilerMarkerPayload(mozilla::TimeStamp::Now(), mozilla::TimeStamp::Now(), nullptr)
193 TouchDataPayload::streamPayloadImpl(JSStreamWriter
& b
)
196 b
.NameValue("x", mPoint
.x
);
197 b
.NameValue("y", mPoint
.y
);
201 VsyncPayload::VsyncPayload(mozilla::TimeStamp aVsyncTimestamp
)
202 : ProfilerMarkerPayload(aVsyncTimestamp
, aVsyncTimestamp
, nullptr)
203 , mVsyncTimestamp(aVsyncTimestamp
)
208 VsyncPayload::streamPayloadImpl(JSStreamWriter
& b
)
211 b
.NameValue("vsync", profiler_time(mVsyncTimestamp
));
212 b
.NameValue("category", "VsyncTimestamp");