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: #ifndef PROFILER_MARKERS_H michael@0: #define PROFILER_MARKERS_H michael@0: michael@0: #include "JSStreamWriter.h" michael@0: #include "mozilla/TimeStamp.h" michael@0: #include "nsAutoPtr.h" michael@0: michael@0: /** michael@0: * This is an abstract object that can be implied to supply michael@0: * data to be attached with a profiler marker. Most data inserted michael@0: * into a profile is stored in a circular buffer. This buffer michael@0: * typically wraps around and overwrites most entries. Because michael@0: * of this, this structure is designed to defer the work of michael@0: * prepare the payload only when 'preparePayload' is called. michael@0: * michael@0: * Note when implementing that this object is typically constructed michael@0: * on a particular thread but 'preparePayload' and the destructor michael@0: * is called from the main thread. michael@0: */ michael@0: class ProfilerMarkerPayload michael@0: { michael@0: public: michael@0: /** michael@0: * ProfilerMarkerPayload takes ownership of aStack michael@0: */ michael@0: ProfilerMarkerPayload(ProfilerBacktrace* aStack = nullptr); michael@0: ProfilerMarkerPayload(const mozilla::TimeStamp& aStartTime, michael@0: const mozilla::TimeStamp& aEndTime, michael@0: ProfilerBacktrace* aStack = nullptr); michael@0: michael@0: /** michael@0: * Called from the main thread michael@0: */ michael@0: virtual ~ProfilerMarkerPayload(); michael@0: michael@0: /** michael@0: * Called from the main thread michael@0: */ michael@0: void StreamPayload(JSStreamWriter& b) { michael@0: return streamPayload(b); michael@0: } michael@0: michael@0: protected: michael@0: /** michael@0: * Called from the main thread michael@0: */ michael@0: void streamCommonProps(const char* aMarkerType, JSStreamWriter& b); michael@0: michael@0: /** michael@0: * Called from the main thread michael@0: */ michael@0: virtual void michael@0: streamPayload(JSStreamWriter& b) = 0; michael@0: michael@0: private: michael@0: mozilla::TimeStamp mStartTime; michael@0: mozilla::TimeStamp mEndTime; michael@0: ProfilerBacktrace* mStack; michael@0: }; michael@0: michael@0: class ProfilerMarkerTracing : public ProfilerMarkerPayload michael@0: { michael@0: public: michael@0: ProfilerMarkerTracing(const char* aCategory, TracingMetadata aMetaData); michael@0: michael@0: const char *GetCategory() const { return mCategory; } michael@0: TracingMetadata GetMetaData() const { return mMetaData; } michael@0: michael@0: protected: michael@0: virtual void michael@0: streamPayload(JSStreamWriter& b) { return streamPayloadImp(b); } michael@0: michael@0: private: michael@0: void streamPayloadImp(JSStreamWriter& b); michael@0: michael@0: private: michael@0: const char *mCategory; michael@0: TracingMetadata mMetaData; michael@0: }; michael@0: michael@0: michael@0: class gfxASurface; michael@0: class ProfilerMarkerImagePayload : public ProfilerMarkerPayload michael@0: { michael@0: public: michael@0: ProfilerMarkerImagePayload(gfxASurface *aImg); michael@0: michael@0: protected: michael@0: virtual void michael@0: streamPayload(JSStreamWriter& b) { return streamPayloadImp(b); } michael@0: michael@0: private: michael@0: void streamPayloadImp(JSStreamWriter& b); michael@0: michael@0: nsRefPtr mImg; michael@0: }; michael@0: michael@0: class IOMarkerPayload : public ProfilerMarkerPayload michael@0: { michael@0: public: michael@0: IOMarkerPayload(const char* aSource, const char* aFilename, const mozilla::TimeStamp& aStartTime, michael@0: const mozilla::TimeStamp& aEndTime, michael@0: ProfilerBacktrace* aStack); michael@0: ~IOMarkerPayload(); michael@0: michael@0: protected: michael@0: virtual void michael@0: streamPayload(JSStreamWriter& b) { return streamPayloadImp(b); } michael@0: michael@0: private: michael@0: void streamPayloadImp(JSStreamWriter& b); michael@0: michael@0: const char* mSource; michael@0: char* mFilename; michael@0: }; michael@0: michael@0: #endif // PROFILER_MARKERS_H