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.

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

mercurial