tools/profiler/ProfilerMarkers.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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 #include "GeckoProfiler.h"
     7 #include "ProfilerBacktrace.h"
     8 #include "ProfilerMarkers.h"
     9 #include "gfxASurface.h"
    10 #include "SyncProfile.h"
    12 ProfilerMarkerPayload::ProfilerMarkerPayload(ProfilerBacktrace* aStack)
    13   : mStack(aStack)
    14 {}
    16 ProfilerMarkerPayload::ProfilerMarkerPayload(const mozilla::TimeStamp& aStartTime,
    17                                              const mozilla::TimeStamp& aEndTime,
    18                                              ProfilerBacktrace* aStack)
    19   : mStartTime(aStartTime)
    20   , mEndTime(aEndTime)
    21   , mStack(aStack)
    22 {}
    24 ProfilerMarkerPayload::~ProfilerMarkerPayload()
    25 {
    26   profiler_free_backtrace(mStack);
    27 }
    29 void
    30 ProfilerMarkerPayload::streamCommonProps(const char* aMarkerType,
    31                                           JSStreamWriter& b)
    32 {
    33   MOZ_ASSERT(aMarkerType);
    34   b.NameValue("type", aMarkerType);
    35   if (!mStartTime.IsNull()) {
    36     b.NameValue("startTime", profiler_time(mStartTime));
    37   }
    38   if (!mEndTime.IsNull()) {
    39     b.NameValue("endTime", profiler_time(mEndTime));
    40   }
    41   if (mStack) {
    42     b.Name("stack");
    43     mStack->StreamJSObject(b);
    44   }
    45 }
    47 ProfilerMarkerTracing::ProfilerMarkerTracing(const char* aCategory, TracingMetadata aMetaData)
    48   : mCategory(aCategory)
    49   , mMetaData(aMetaData)
    50 {}
    52 void
    53 ProfilerMarkerTracing::streamPayloadImp(JSStreamWriter& b)
    54 {
    55   b.BeginObject();
    56     streamCommonProps("tracing", b);
    58     if (GetCategory()) {
    59       b.NameValue("category", GetCategory());
    60     }
    61     if (GetMetaData() != TRACING_DEFAULT) {
    62       if (GetMetaData() == TRACING_INTERVAL_START) {
    63         b.NameValue("interval", "start");
    64       } else if (GetMetaData() == TRACING_INTERVAL_END) {
    65         b.NameValue("interval", "end");
    66       }
    67     }
    68   b.EndObject();
    69 }
    71 ProfilerMarkerImagePayload::ProfilerMarkerImagePayload(gfxASurface *aImg)
    72   : mImg(aImg)
    73 {}
    75 void
    76 ProfilerMarkerImagePayload::streamPayloadImp(JSStreamWriter& b)
    77 {
    78   b.BeginObject();
    79     streamCommonProps("innerHTML", b);
    80     // TODO: Finish me
    81     //b.NameValue("innerHTML", "<img src=''/>");
    82   b.EndObject();
    83 }
    85 IOMarkerPayload::IOMarkerPayload(const char* aSource,
    86                                  const char* aFilename,
    87                                  const mozilla::TimeStamp& aStartTime,
    88                                  const mozilla::TimeStamp& aEndTime,
    89                                  ProfilerBacktrace* aStack)
    90   : ProfilerMarkerPayload(aStartTime, aEndTime, aStack),
    91     mSource(aSource)
    92 {
    93   mFilename = aFilename ? strdup(aFilename) : nullptr;
    94   MOZ_ASSERT(aSource);
    95 }
    97 IOMarkerPayload::~IOMarkerPayload(){
    98   free(mFilename);
    99 }
   101 void
   102 IOMarkerPayload::streamPayloadImp(JSStreamWriter& b)
   103 {
   104   b.BeginObject();
   105     streamCommonProps("io", b);
   106     b.NameValue("source", mSource);
   107     if (mFilename != nullptr) {
   108       b.NameValue("filename", mFilename);
   109     }
   110   b.EndObject();
   111 }
   114 void
   115 ProfilerJSEventMarker(const char *event)
   116 {
   117     PROFILER_MARKER(event);
   118 }

mercurial