1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/tools/profiler/ProfilerMarkers.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,118 @@ 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 +#include "GeckoProfiler.h" 1.10 +#include "ProfilerBacktrace.h" 1.11 +#include "ProfilerMarkers.h" 1.12 +#include "gfxASurface.h" 1.13 +#include "SyncProfile.h" 1.14 + 1.15 +ProfilerMarkerPayload::ProfilerMarkerPayload(ProfilerBacktrace* aStack) 1.16 + : mStack(aStack) 1.17 +{} 1.18 + 1.19 +ProfilerMarkerPayload::ProfilerMarkerPayload(const mozilla::TimeStamp& aStartTime, 1.20 + const mozilla::TimeStamp& aEndTime, 1.21 + ProfilerBacktrace* aStack) 1.22 + : mStartTime(aStartTime) 1.23 + , mEndTime(aEndTime) 1.24 + , mStack(aStack) 1.25 +{} 1.26 + 1.27 +ProfilerMarkerPayload::~ProfilerMarkerPayload() 1.28 +{ 1.29 + profiler_free_backtrace(mStack); 1.30 +} 1.31 + 1.32 +void 1.33 +ProfilerMarkerPayload::streamCommonProps(const char* aMarkerType, 1.34 + JSStreamWriter& b) 1.35 +{ 1.36 + MOZ_ASSERT(aMarkerType); 1.37 + b.NameValue("type", aMarkerType); 1.38 + if (!mStartTime.IsNull()) { 1.39 + b.NameValue("startTime", profiler_time(mStartTime)); 1.40 + } 1.41 + if (!mEndTime.IsNull()) { 1.42 + b.NameValue("endTime", profiler_time(mEndTime)); 1.43 + } 1.44 + if (mStack) { 1.45 + b.Name("stack"); 1.46 + mStack->StreamJSObject(b); 1.47 + } 1.48 +} 1.49 + 1.50 +ProfilerMarkerTracing::ProfilerMarkerTracing(const char* aCategory, TracingMetadata aMetaData) 1.51 + : mCategory(aCategory) 1.52 + , mMetaData(aMetaData) 1.53 +{} 1.54 + 1.55 +void 1.56 +ProfilerMarkerTracing::streamPayloadImp(JSStreamWriter& b) 1.57 +{ 1.58 + b.BeginObject(); 1.59 + streamCommonProps("tracing", b); 1.60 + 1.61 + if (GetCategory()) { 1.62 + b.NameValue("category", GetCategory()); 1.63 + } 1.64 + if (GetMetaData() != TRACING_DEFAULT) { 1.65 + if (GetMetaData() == TRACING_INTERVAL_START) { 1.66 + b.NameValue("interval", "start"); 1.67 + } else if (GetMetaData() == TRACING_INTERVAL_END) { 1.68 + b.NameValue("interval", "end"); 1.69 + } 1.70 + } 1.71 + b.EndObject(); 1.72 +} 1.73 + 1.74 +ProfilerMarkerImagePayload::ProfilerMarkerImagePayload(gfxASurface *aImg) 1.75 + : mImg(aImg) 1.76 +{} 1.77 + 1.78 +void 1.79 +ProfilerMarkerImagePayload::streamPayloadImp(JSStreamWriter& b) 1.80 +{ 1.81 + b.BeginObject(); 1.82 + streamCommonProps("innerHTML", b); 1.83 + // TODO: Finish me 1.84 + //b.NameValue("innerHTML", "<img src=''/>"); 1.85 + b.EndObject(); 1.86 +} 1.87 + 1.88 +IOMarkerPayload::IOMarkerPayload(const char* aSource, 1.89 + const char* aFilename, 1.90 + const mozilla::TimeStamp& aStartTime, 1.91 + const mozilla::TimeStamp& aEndTime, 1.92 + ProfilerBacktrace* aStack) 1.93 + : ProfilerMarkerPayload(aStartTime, aEndTime, aStack), 1.94 + mSource(aSource) 1.95 +{ 1.96 + mFilename = aFilename ? strdup(aFilename) : nullptr; 1.97 + MOZ_ASSERT(aSource); 1.98 +} 1.99 + 1.100 +IOMarkerPayload::~IOMarkerPayload(){ 1.101 + free(mFilename); 1.102 +} 1.103 + 1.104 +void 1.105 +IOMarkerPayload::streamPayloadImp(JSStreamWriter& b) 1.106 +{ 1.107 + b.BeginObject(); 1.108 + streamCommonProps("io", b); 1.109 + b.NameValue("source", mSource); 1.110 + if (mFilename != nullptr) { 1.111 + b.NameValue("filename", mFilename); 1.112 + } 1.113 + b.EndObject(); 1.114 +} 1.115 + 1.116 + 1.117 +void 1.118 +ProfilerJSEventMarker(const char *event) 1.119 +{ 1.120 + PROFILER_MARKER(event); 1.121 +}