2013-07-10 21:27:04 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef PROFILER_MARKERS_H
|
|
|
|
#define PROFILER_MARKERS_H
|
|
|
|
|
|
|
|
#include "JSCustomObjectBuilder.h"
|
|
|
|
#include "JSObjectBuilder.h"
|
2013-09-25 08:28:34 -07:00
|
|
|
#include "mozilla/TimeStamp.h"
|
2013-07-10 21:27:04 -07:00
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is an abstract object that can be implied to supply
|
|
|
|
* data to be attached with a profiler marker. Most data inserted
|
|
|
|
* into a profile is stored in a circular buffer. This buffer
|
|
|
|
* typically wraps around and overwrites most entries. Because
|
|
|
|
* of this, this structure is designed to defer the work of
|
|
|
|
* prepare the payload only when 'preparePayload' is called.
|
|
|
|
*
|
|
|
|
* Note when implementing that this object is typically constructed
|
|
|
|
* on a particular thread but 'preparePayload' and the destructor
|
|
|
|
* is called from the main thread.
|
|
|
|
*/
|
2013-09-25 08:28:34 -07:00
|
|
|
class ProfilerMarkerPayload
|
|
|
|
{
|
2013-07-10 21:27:04 -07:00
|
|
|
public:
|
2013-09-25 08:28:34 -07:00
|
|
|
/**
|
|
|
|
* ProfilerMarkerPayload takes ownership of aStack
|
|
|
|
*/
|
|
|
|
ProfilerMarkerPayload(ProfilerBacktrace* aStack = nullptr);
|
|
|
|
ProfilerMarkerPayload(const mozilla::TimeStamp& aStartTime,
|
|
|
|
const mozilla::TimeStamp& aEndTime,
|
|
|
|
ProfilerBacktrace* aStack = nullptr);
|
2013-07-10 21:27:04 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Called from the main thread
|
|
|
|
*/
|
2013-09-25 08:28:34 -07:00
|
|
|
virtual ~ProfilerMarkerPayload();
|
2013-07-10 21:27:04 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Called from the main thread
|
|
|
|
*/
|
|
|
|
template<typename Builder>
|
|
|
|
typename Builder::Object PreparePayload(Builder& b)
|
|
|
|
{
|
|
|
|
return preparePayload(b);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2013-09-25 08:28:34 -07:00
|
|
|
/**
|
|
|
|
* Called from the main thread
|
|
|
|
*/
|
|
|
|
template<typename Builder>
|
|
|
|
void prepareCommonProps(const char* aMarkerType, Builder& aBuilder,
|
|
|
|
typename Builder::ObjectHandle aObject);
|
|
|
|
|
2013-07-10 21:27:04 -07:00
|
|
|
/**
|
|
|
|
* Called from the main thread
|
|
|
|
*/
|
|
|
|
virtual JSCustomObjectBuilder::Object
|
|
|
|
preparePayload(JSCustomObjectBuilder& b) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called from the main thread
|
|
|
|
*/
|
|
|
|
virtual JSObjectBuilder::Object
|
|
|
|
preparePayload(JSObjectBuilder& b) = 0;
|
2013-09-25 08:28:34 -07:00
|
|
|
|
|
|
|
private:
|
|
|
|
mozilla::TimeStamp mStartTime;
|
|
|
|
mozilla::TimeStamp mEndTime;
|
|
|
|
ProfilerBacktrace* mStack;
|
2013-07-10 21:27:04 -07:00
|
|
|
};
|
|
|
|
|
2013-09-27 09:08:45 -07:00
|
|
|
class ProfilerMarkerTracing : public ProfilerMarkerPayload
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ProfilerMarkerTracing(const char* aCategory, TracingMetadata aMetaData);
|
|
|
|
|
|
|
|
const char *GetCategory() const { return mCategory; }
|
|
|
|
TracingMetadata GetMetaData() const { return mMetaData; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual JSCustomObjectBuilder::Object
|
|
|
|
preparePayload(JSCustomObjectBuilder& b) { return preparePayloadImp(b); }
|
|
|
|
virtual JSObjectBuilder::Object
|
|
|
|
preparePayload(JSObjectBuilder& b) { return preparePayloadImp(b); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
template<typename Builder>
|
|
|
|
typename Builder::Object preparePayloadImp(Builder& b);
|
|
|
|
|
|
|
|
private:
|
|
|
|
const char *mCategory;
|
|
|
|
TracingMetadata mMetaData;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-07-10 21:27:04 -07:00
|
|
|
class gfxASurface;
|
2013-09-25 08:28:34 -07:00
|
|
|
class ProfilerMarkerImagePayload : public ProfilerMarkerPayload
|
|
|
|
{
|
2013-07-10 21:27:04 -07:00
|
|
|
public:
|
|
|
|
ProfilerMarkerImagePayload(gfxASurface *aImg);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual JSCustomObjectBuilder::Object
|
|
|
|
preparePayload(JSCustomObjectBuilder& b) { return preparePayloadImp(b); }
|
|
|
|
virtual JSObjectBuilder::Object
|
|
|
|
preparePayload(JSObjectBuilder& b) { return preparePayloadImp(b); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
template<typename Builder>
|
|
|
|
typename Builder::Object preparePayloadImp(Builder& b);
|
2013-09-27 09:08:45 -07:00
|
|
|
|
2013-07-10 21:27:04 -07:00
|
|
|
nsRefPtr<gfxASurface> mImg;
|
|
|
|
};
|
|
|
|
|
2013-09-25 08:28:34 -07:00
|
|
|
class IOMarkerPayload : public ProfilerMarkerPayload
|
|
|
|
{
|
|
|
|
public:
|
2014-02-13 10:32:38 -08:00
|
|
|
IOMarkerPayload(const char* aSource, const char* aFilename, const mozilla::TimeStamp& aStartTime,
|
2013-09-25 08:28:34 -07:00
|
|
|
const mozilla::TimeStamp& aEndTime,
|
|
|
|
ProfilerBacktrace* aStack);
|
2014-02-13 10:32:38 -08:00
|
|
|
~IOMarkerPayload();
|
2013-09-25 08:28:34 -07:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual JSCustomObjectBuilder::Object
|
|
|
|
preparePayload(JSCustomObjectBuilder& b) { return preparePayloadImp(b); }
|
|
|
|
virtual JSObjectBuilder::Object
|
|
|
|
preparePayload(JSObjectBuilder& b) { return preparePayloadImp(b); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
template<typename Builder>
|
|
|
|
typename Builder::Object preparePayloadImp(Builder& b);
|
2013-09-27 09:08:45 -07:00
|
|
|
|
2013-09-25 08:28:34 -07:00
|
|
|
const char* mSource;
|
2014-02-13 10:32:38 -08:00
|
|
|
char* mFilename;
|
2013-09-25 08:28:34 -07:00
|
|
|
};
|
|
|
|
|
2013-07-10 21:27:04 -07:00
|
|
|
#endif // PROFILER_MARKERS_H
|