xpcom/base/VisualEventTracer.h

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 /* Visual event tracer, creates a log of events on each thread for visualization */
     7 /**
     8  * The event tracer code is by default disabled in both build and run time.
     9  *
    10  * To enable this code at build time, add --enable-visual-profiling to your 
    11  * configure options.
    12  *
    13  * To enable this code at run time, export MOZ_TRACE_FILE env var with a
    14  * path to the file to write the log to. This is all you need to * produce
    15  * the log of all events instrumentation in the mozilla code. Check
    16  * MOZ_EVENT_TRACER_* macros below to add your own.
    17  *
    18  * To let the event tracer log only some events to save disk space, export 
    19  * MOZ_PROFILING_EVENTS with comma separated list of event names you want 
    20  * to record in the log.
    21  */
    23 #ifndef VisualEventTracer_h___
    24 #define VisualEventTracer_h___
    26 #include <stdint.h>
    27 #include "mozilla/Attributes.h"
    28 #include "mozilla/GuardObjects.h"
    30 #ifdef MOZ_VISUAL_EVENT_TRACER
    31 #include "nsIVisualEventTracer.h"
    33 // Bind an object instance, usually |this|, to a name, usually URL or 
    34 // host name, the instance deals with for its lifetime.  The name string 
    35 // is duplicated.
    36 // IMPORTANT: it is up to the caller to pass the correct static_cast
    37 // of the |instance| pointer to all these macros ; otherwise the linking
    38 // of events and objects will not work!
    39 // The name will show in details of the events on the timeline and also
    40 // will allow events filtering by host names, URLs etc.
    41 #define MOZ_EVENT_TRACER_NAME_OBJECT(instance, name) \
    42   mozilla::eventtracer::Mark(mozilla::eventtracer::eName, instance, name)
    44 // The same as MOZ_EVENT_TRACER_NAME_OBJECT, just simplifies building
    45 // names when it consists of two parts
    46 #define MOZ_EVENT_TRACER_COMPOUND_NAME(instance, name, name2) \
    47   mozilla::eventtracer::Mark(mozilla::eventtracer::eName, instance, name, name2)
    50 // Call the followings with the same |instance| reference as you have 
    51 // previously called MOZ_EVENT_TRACER_NAME_OBJECT.
    52 // Let |name| be the name of the event happening, like "resolving", 
    53 // "connecting", "loading" etc.
    55 // This will crate a single-point-in-time event marked with an arrow 
    56 // on the timeline, this is a way to indicate an event without a duration.
    57 #define MOZ_EVENT_TRACER_MARK(instance, name) \
    58   mozilla::eventtracer::Mark(mozilla::eventtracer::eShot, instance, name)
    60 // Following macros are used to log events with duration.
    61 // There always has to be complete WAIT,EXEC,DONE or EXEC,DONE 
    62 // uninterrupted and non-interferring tuple(s) for an event to be correctly 
    63 // shown on the timeline.  Each can be called on any thread, the event tape is
    64 // finally displayed on the thread where it has been EXECuted.
    66 // Example of 3 phases usage for "HTTP request channel":
    67 // WAIT: we've just created the channel and called AsyncOpen on it
    68 // EXEC: we've just got first call to OnDataAvailable, so we are actually
    69 //       receiving the content after some time like connection establising,
    70 //       opening a cache entry, sending the GET request...
    71 // DONE: we've just got OnStopRequest call that indicates the content
    72 //       has been completely delivered and the request is now finished
    74 // Indicate an event pending start, on the timeline this will 
    75 // start the event's interval tape with a pale color, the time will
    76 // show in details.  Usually used when an event is being posted or
    77 // we wait for a lock acquisition.
    78 // WAITING is not mandatory, some events don't have a pending phase.
    79 #define MOZ_EVENT_TRACER_WAIT(instance, name) \
    80   mozilla::eventtracer::Mark(mozilla::eventtracer::eWait, instance, name)
    82 // Indicate start of an event actual execution, on the timeline this will 
    83 // change the event's tape to a deeper color, the time will show in details.
    84 #define MOZ_EVENT_TRACER_EXEC(instance, name) \
    85   mozilla::eventtracer::Mark(mozilla::eventtracer::eExec, instance, name)
    87 // Indicate the end of an event execution (the event has been done),
    88 // on the timeline this will end the event's tape and show the time in
    89 // event details.
    90 // NOTE: when the event duration is extremely short, like 1ms, it will convert
    91 // to an event w/o a duration - the same as MOZ_EVENT_TRACER_MARK would be used.
    92 #define MOZ_EVENT_TRACER_DONE(instance, name) \
    93   mozilla::eventtracer::Mark(mozilla::eventtracer::eDone, instance, name)
    95 // The same meaning as the above macros, just for concurent events.
    96 // Concurent event means it can happen for the same instance on more
    97 // then just a single thread, e.g. a service method call, a global lock 
    98 // acquisition, enter and release.
    99 #define MOZ_EVENT_TRACER_WAIT_THREADSAFE(instance, name) \
   100   mozilla::eventtracer::Mark(mozilla::eventtracer::eWait | mozilla::eventtracer::eThreadConcurrent, instance, name)
   101 #define MOZ_EVENT_TRACER_EXEC_THREADSAFE(instance, name) \
   102   mozilla::eventtracer::Mark(mozilla::eventtracer::eExec | mozilla::eventtracer::eThreadConcurrent, instance, name)
   103 #define MOZ_EVENT_TRACER_DONE_THREASAFE(instance, name) \
   104   mozilla::eventtracer::Mark(mozilla::eventtracer::eDone | mozilla::eventtracer::eThreadConcurrent, instance, name)
   106 #else 
   108 // MOZ_VISUAL_EVENT_TRACER disabled
   110 #define MOZ_EVENT_TRACER_NAME_OBJECT(instance, name) (void)0
   111 #define MOZ_EVENT_TRACER_COMPOUND_NAME(instance, name, name2) (void)0
   112 #define MOZ_EVENT_TRACER_MARK(instance, name) (void)0
   113 #define MOZ_EVENT_TRACER_WAIT(instance, name) (void)0
   114 #define MOZ_EVENT_TRACER_EXEC(instance, name) (void)0
   115 #define MOZ_EVENT_TRACER_DONE(instance, name) (void)0
   116 #define MOZ_EVENT_TRACER_WAIT_THREADSAFE(instance, name) (void)0
   117 #define MOZ_EVENT_TRACER_EXEC_THREADSAFE(instance, name) (void)0
   118 #define MOZ_EVENT_TRACER_DONE_THREASAFE(instance, name) (void)0
   120 #endif
   123 namespace mozilla {
   124 namespace eventtracer {
   126 // Initialize the event tracer engine, called automatically on XPCOM startup.
   127 void Init();
   129 // Shuts the event tracer engine down and closes the log file, called 
   130 // automatically during XPCOM shutdown.
   131 void Shutdown();
   133 enum MarkType {
   134   eNone, // No operation, ignored
   135   eName, // This is used to bind an object instance with a name
   137   eShot, // An event with no duration
   138   eWait, // Start of waiting for execution (lock acquire, post...)
   139   eExec, // Start of the execution it self
   140   eDone, // End of the execution
   141   eLast, // Sentinel
   143   // Flags
   145   // The same object can execute the same event on several threads concurently
   146   eThreadConcurrent = 0x10000
   147 };
   149 // Records an event on the calling thread. 
   150 // @param aType 
   151 //    One of MarkType fields, can be bitwise or'ed with the flags.
   152 // @param aItem
   153 //    Reference to the object we want to bind a name to or the event is
   154 //    happening on.  Can be actually anything, but valid poitners should
   155 //    be used.
   156 // @param aText
   157 //    Text of the name (for eName) or event's name for others.  The string
   158 //    is duplicated.
   159 // @param aText2
   160 //    Optional second part of the instnace name, or event name.
   161 //    Event filtering does apply only to the first part (aText).
   162 void Mark(uint32_t aType, void * aItem, 
   163           const char * aText, const char * aText2 = 0);
   166 // Helper guard object.  Use to mark an event in the constructor and a different
   167 // event in the destructor.
   168 //
   169 // Example:
   170 // int class::func()
   171 // {
   172 //    AutoEventTracer tracer(this, eventtracer::eExec, eventtracer::eDone, "func");
   173 //
   174 //    do_something_taking_a_long_time();
   175 // }
   176 class MOZ_STACK_CLASS AutoEventTracer
   177 {
   178 public:
   179   AutoEventTracer(void * aInstance, 
   180                uint32_t aTypeOn, // MarkType marked in constructor
   181                uint32_t aTypeOff, // MarkType marked in destructor
   182                const char * aName, 
   183                const char * aName2 = 0 
   184                MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
   185     : mInstance(aInstance)
   186     , mName(aName)
   187     , mName2(aName2)
   188     , mTypeOn(aTypeOn)
   189     , mTypeOff(aTypeOff)
   190   {
   191     MOZ_GUARD_OBJECT_NOTIFIER_INIT;
   193     ::mozilla::eventtracer::Mark(mTypeOn, mInstance, mName, mName2);
   194   }
   196   ~AutoEventTracer()
   197   {
   198     ::mozilla::eventtracer::Mark(mTypeOff, mInstance, mName, mName2);
   199   }
   201 private:
   202   void * mInstance;
   203   const char * mName;
   204   const char * mName2;
   205   uint32_t mTypeOn;
   206   uint32_t mTypeOff;
   208   MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
   209 };
   211 #ifdef MOZ_VISUAL_EVENT_TRACER
   213 // The scriptable class that drives the event tracer
   215 class VisualEventTracer : public nsIVisualEventTracer
   216 {
   217   NS_DECL_ISUPPORTS
   218   NS_DECL_NSIVISUALEVENTTRACER
   219 };
   221 #define NS_VISUALEVENTTRACER_CID \
   222   { 0xb9e5e102, 0xc2f4, 0x497a,  \
   223     { 0xa6, 0xe4, 0x54, 0xde, 0xf3, 0x71, 0xf3, 0x9d } }
   224 #define NS_VISUALEVENTTRACER_CONTRACTID "@mozilla.org/base/visual-event-tracer;1"
   225 #define NS_VISUALEVENTTRACER_CLASSNAME "Visual Event Tracer"
   227 #endif
   229 } // eventtracer
   230 } // mozilla
   232 #endif /* VisualEventTracer_h___ */

mercurial