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