michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "GeckoProfiler.h" michael@0: #include "ProfilerBacktrace.h" michael@0: #include "ProfilerMarkers.h" michael@0: #include "gfxASurface.h" michael@0: #include "SyncProfile.h" michael@0: michael@0: ProfilerMarkerPayload::ProfilerMarkerPayload(ProfilerBacktrace* aStack) michael@0: : mStack(aStack) michael@0: {} michael@0: michael@0: ProfilerMarkerPayload::ProfilerMarkerPayload(const mozilla::TimeStamp& aStartTime, michael@0: const mozilla::TimeStamp& aEndTime, michael@0: ProfilerBacktrace* aStack) michael@0: : mStartTime(aStartTime) michael@0: , mEndTime(aEndTime) michael@0: , mStack(aStack) michael@0: {} michael@0: michael@0: ProfilerMarkerPayload::~ProfilerMarkerPayload() michael@0: { michael@0: profiler_free_backtrace(mStack); michael@0: } michael@0: michael@0: void michael@0: ProfilerMarkerPayload::streamCommonProps(const char* aMarkerType, michael@0: JSStreamWriter& b) michael@0: { michael@0: MOZ_ASSERT(aMarkerType); michael@0: b.NameValue("type", aMarkerType); michael@0: if (!mStartTime.IsNull()) { michael@0: b.NameValue("startTime", profiler_time(mStartTime)); michael@0: } michael@0: if (!mEndTime.IsNull()) { michael@0: b.NameValue("endTime", profiler_time(mEndTime)); michael@0: } michael@0: if (mStack) { michael@0: b.Name("stack"); michael@0: mStack->StreamJSObject(b); michael@0: } michael@0: } michael@0: michael@0: ProfilerMarkerTracing::ProfilerMarkerTracing(const char* aCategory, TracingMetadata aMetaData) michael@0: : mCategory(aCategory) michael@0: , mMetaData(aMetaData) michael@0: {} michael@0: michael@0: void michael@0: ProfilerMarkerTracing::streamPayloadImp(JSStreamWriter& b) michael@0: { michael@0: b.BeginObject(); michael@0: streamCommonProps("tracing", b); michael@0: michael@0: if (GetCategory()) { michael@0: b.NameValue("category", GetCategory()); michael@0: } michael@0: if (GetMetaData() != TRACING_DEFAULT) { michael@0: if (GetMetaData() == TRACING_INTERVAL_START) { michael@0: b.NameValue("interval", "start"); michael@0: } else if (GetMetaData() == TRACING_INTERVAL_END) { michael@0: b.NameValue("interval", "end"); michael@0: } michael@0: } michael@0: b.EndObject(); michael@0: } michael@0: michael@0: ProfilerMarkerImagePayload::ProfilerMarkerImagePayload(gfxASurface *aImg) michael@0: : mImg(aImg) michael@0: {} michael@0: michael@0: void michael@0: ProfilerMarkerImagePayload::streamPayloadImp(JSStreamWriter& b) michael@0: { michael@0: b.BeginObject(); michael@0: streamCommonProps("innerHTML", b); michael@0: // TODO: Finish me michael@0: //b.NameValue("innerHTML", ""); michael@0: b.EndObject(); michael@0: } michael@0: michael@0: IOMarkerPayload::IOMarkerPayload(const char* aSource, michael@0: const char* aFilename, michael@0: const mozilla::TimeStamp& aStartTime, michael@0: const mozilla::TimeStamp& aEndTime, michael@0: ProfilerBacktrace* aStack) michael@0: : ProfilerMarkerPayload(aStartTime, aEndTime, aStack), michael@0: mSource(aSource) michael@0: { michael@0: mFilename = aFilename ? strdup(aFilename) : nullptr; michael@0: MOZ_ASSERT(aSource); michael@0: } michael@0: michael@0: IOMarkerPayload::~IOMarkerPayload(){ michael@0: free(mFilename); michael@0: } michael@0: michael@0: void michael@0: IOMarkerPayload::streamPayloadImp(JSStreamWriter& b) michael@0: { michael@0: b.BeginObject(); michael@0: streamCommonProps("io", b); michael@0: b.NameValue("source", mSource); michael@0: if (mFilename != nullptr) { michael@0: b.NameValue("filename", mFilename); michael@0: } michael@0: b.EndObject(); michael@0: } michael@0: michael@0: michael@0: void michael@0: ProfilerJSEventMarker(const char *event) michael@0: { michael@0: PROFILER_MARKER(event); michael@0: }