1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/tools/profiler/ProfilerMarkers.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,122 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef PROFILER_MARKERS_H 1.10 +#define PROFILER_MARKERS_H 1.11 + 1.12 +#include "JSStreamWriter.h" 1.13 +#include "mozilla/TimeStamp.h" 1.14 +#include "nsAutoPtr.h" 1.15 + 1.16 +/** 1.17 + * This is an abstract object that can be implied to supply 1.18 + * data to be attached with a profiler marker. Most data inserted 1.19 + * into a profile is stored in a circular buffer. This buffer 1.20 + * typically wraps around and overwrites most entries. Because 1.21 + * of this, this structure is designed to defer the work of 1.22 + * prepare the payload only when 'preparePayload' is called. 1.23 + * 1.24 + * Note when implementing that this object is typically constructed 1.25 + * on a particular thread but 'preparePayload' and the destructor 1.26 + * is called from the main thread. 1.27 + */ 1.28 +class ProfilerMarkerPayload 1.29 +{ 1.30 +public: 1.31 + /** 1.32 + * ProfilerMarkerPayload takes ownership of aStack 1.33 + */ 1.34 + ProfilerMarkerPayload(ProfilerBacktrace* aStack = nullptr); 1.35 + ProfilerMarkerPayload(const mozilla::TimeStamp& aStartTime, 1.36 + const mozilla::TimeStamp& aEndTime, 1.37 + ProfilerBacktrace* aStack = nullptr); 1.38 + 1.39 + /** 1.40 + * Called from the main thread 1.41 + */ 1.42 + virtual ~ProfilerMarkerPayload(); 1.43 + 1.44 + /** 1.45 + * Called from the main thread 1.46 + */ 1.47 + void StreamPayload(JSStreamWriter& b) { 1.48 + return streamPayload(b); 1.49 + } 1.50 + 1.51 +protected: 1.52 + /** 1.53 + * Called from the main thread 1.54 + */ 1.55 + void streamCommonProps(const char* aMarkerType, JSStreamWriter& b); 1.56 + 1.57 + /** 1.58 + * Called from the main thread 1.59 + */ 1.60 + virtual void 1.61 + streamPayload(JSStreamWriter& b) = 0; 1.62 + 1.63 +private: 1.64 + mozilla::TimeStamp mStartTime; 1.65 + mozilla::TimeStamp mEndTime; 1.66 + ProfilerBacktrace* mStack; 1.67 +}; 1.68 + 1.69 +class ProfilerMarkerTracing : public ProfilerMarkerPayload 1.70 +{ 1.71 +public: 1.72 + ProfilerMarkerTracing(const char* aCategory, TracingMetadata aMetaData); 1.73 + 1.74 + const char *GetCategory() const { return mCategory; } 1.75 + TracingMetadata GetMetaData() const { return mMetaData; } 1.76 + 1.77 +protected: 1.78 + virtual void 1.79 + streamPayload(JSStreamWriter& b) { return streamPayloadImp(b); } 1.80 + 1.81 +private: 1.82 + void streamPayloadImp(JSStreamWriter& b); 1.83 + 1.84 +private: 1.85 + const char *mCategory; 1.86 + TracingMetadata mMetaData; 1.87 +}; 1.88 + 1.89 + 1.90 +class gfxASurface; 1.91 +class ProfilerMarkerImagePayload : public ProfilerMarkerPayload 1.92 +{ 1.93 +public: 1.94 + ProfilerMarkerImagePayload(gfxASurface *aImg); 1.95 + 1.96 +protected: 1.97 + virtual void 1.98 + streamPayload(JSStreamWriter& b) { return streamPayloadImp(b); } 1.99 + 1.100 +private: 1.101 + void streamPayloadImp(JSStreamWriter& b); 1.102 + 1.103 + nsRefPtr<gfxASurface> mImg; 1.104 +}; 1.105 + 1.106 +class IOMarkerPayload : public ProfilerMarkerPayload 1.107 +{ 1.108 +public: 1.109 + IOMarkerPayload(const char* aSource, const char* aFilename, const mozilla::TimeStamp& aStartTime, 1.110 + const mozilla::TimeStamp& aEndTime, 1.111 + ProfilerBacktrace* aStack); 1.112 + ~IOMarkerPayload(); 1.113 + 1.114 +protected: 1.115 + virtual void 1.116 + streamPayload(JSStreamWriter& b) { return streamPayloadImp(b); } 1.117 + 1.118 +private: 1.119 + void streamPayloadImp(JSStreamWriter& b); 1.120 + 1.121 + const char* mSource; 1.122 + char* mFilename; 1.123 +}; 1.124 + 1.125 +#endif // PROFILER_MARKERS_H