tools/profiler/ProfilerMarkers.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef PROFILER_MARKERS_H
michael@0 7 #define PROFILER_MARKERS_H
michael@0 8
michael@0 9 #include "JSStreamWriter.h"
michael@0 10 #include "mozilla/TimeStamp.h"
michael@0 11 #include "nsAutoPtr.h"
michael@0 12
michael@0 13 /**
michael@0 14 * This is an abstract object that can be implied to supply
michael@0 15 * data to be attached with a profiler marker. Most data inserted
michael@0 16 * into a profile is stored in a circular buffer. This buffer
michael@0 17 * typically wraps around and overwrites most entries. Because
michael@0 18 * of this, this structure is designed to defer the work of
michael@0 19 * prepare the payload only when 'preparePayload' is called.
michael@0 20 *
michael@0 21 * Note when implementing that this object is typically constructed
michael@0 22 * on a particular thread but 'preparePayload' and the destructor
michael@0 23 * is called from the main thread.
michael@0 24 */
michael@0 25 class ProfilerMarkerPayload
michael@0 26 {
michael@0 27 public:
michael@0 28 /**
michael@0 29 * ProfilerMarkerPayload takes ownership of aStack
michael@0 30 */
michael@0 31 ProfilerMarkerPayload(ProfilerBacktrace* aStack = nullptr);
michael@0 32 ProfilerMarkerPayload(const mozilla::TimeStamp& aStartTime,
michael@0 33 const mozilla::TimeStamp& aEndTime,
michael@0 34 ProfilerBacktrace* aStack = nullptr);
michael@0 35
michael@0 36 /**
michael@0 37 * Called from the main thread
michael@0 38 */
michael@0 39 virtual ~ProfilerMarkerPayload();
michael@0 40
michael@0 41 /**
michael@0 42 * Called from the main thread
michael@0 43 */
michael@0 44 void StreamPayload(JSStreamWriter& b) {
michael@0 45 return streamPayload(b);
michael@0 46 }
michael@0 47
michael@0 48 protected:
michael@0 49 /**
michael@0 50 * Called from the main thread
michael@0 51 */
michael@0 52 void streamCommonProps(const char* aMarkerType, JSStreamWriter& b);
michael@0 53
michael@0 54 /**
michael@0 55 * Called from the main thread
michael@0 56 */
michael@0 57 virtual void
michael@0 58 streamPayload(JSStreamWriter& b) = 0;
michael@0 59
michael@0 60 private:
michael@0 61 mozilla::TimeStamp mStartTime;
michael@0 62 mozilla::TimeStamp mEndTime;
michael@0 63 ProfilerBacktrace* mStack;
michael@0 64 };
michael@0 65
michael@0 66 class ProfilerMarkerTracing : public ProfilerMarkerPayload
michael@0 67 {
michael@0 68 public:
michael@0 69 ProfilerMarkerTracing(const char* aCategory, TracingMetadata aMetaData);
michael@0 70
michael@0 71 const char *GetCategory() const { return mCategory; }
michael@0 72 TracingMetadata GetMetaData() const { return mMetaData; }
michael@0 73
michael@0 74 protected:
michael@0 75 virtual void
michael@0 76 streamPayload(JSStreamWriter& b) { return streamPayloadImp(b); }
michael@0 77
michael@0 78 private:
michael@0 79 void streamPayloadImp(JSStreamWriter& b);
michael@0 80
michael@0 81 private:
michael@0 82 const char *mCategory;
michael@0 83 TracingMetadata mMetaData;
michael@0 84 };
michael@0 85
michael@0 86
michael@0 87 class gfxASurface;
michael@0 88 class ProfilerMarkerImagePayload : public ProfilerMarkerPayload
michael@0 89 {
michael@0 90 public:
michael@0 91 ProfilerMarkerImagePayload(gfxASurface *aImg);
michael@0 92
michael@0 93 protected:
michael@0 94 virtual void
michael@0 95 streamPayload(JSStreamWriter& b) { return streamPayloadImp(b); }
michael@0 96
michael@0 97 private:
michael@0 98 void streamPayloadImp(JSStreamWriter& b);
michael@0 99
michael@0 100 nsRefPtr<gfxASurface> mImg;
michael@0 101 };
michael@0 102
michael@0 103 class IOMarkerPayload : public ProfilerMarkerPayload
michael@0 104 {
michael@0 105 public:
michael@0 106 IOMarkerPayload(const char* aSource, const char* aFilename, const mozilla::TimeStamp& aStartTime,
michael@0 107 const mozilla::TimeStamp& aEndTime,
michael@0 108 ProfilerBacktrace* aStack);
michael@0 109 ~IOMarkerPayload();
michael@0 110
michael@0 111 protected:
michael@0 112 virtual void
michael@0 113 streamPayload(JSStreamWriter& b) { return streamPayloadImp(b); }
michael@0 114
michael@0 115 private:
michael@0 116 void streamPayloadImp(JSStreamWriter& b);
michael@0 117
michael@0 118 const char* mSource;
michael@0 119 char* mFilename;
michael@0 120 };
michael@0 121
michael@0 122 #endif // PROFILER_MARKERS_H

mercurial