Bug 1142197 - manage ProfilerBacktrace with UniquePtr; r=mstange
Smart pointers are better than raw pointers.
This commit is contained in:
@@ -62,7 +62,7 @@ RestyleTracker::Document() const {
|
||||
struct RestyleEnumerateData : RestyleTracker::Hints {
|
||||
RefPtr<dom::Element> mElement;
|
||||
#if defined(MOZ_ENABLE_PROFILER_SPS)
|
||||
UniquePtr<ProfilerBacktrace> mBacktrace;
|
||||
UniqueProfilerBacktrace mBacktrace;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
@@ -129,7 +129,7 @@ public:
|
||||
// the RestyleData for as its nearest restyle root.
|
||||
nsTArray<RefPtr<Element>> mDescendants;
|
||||
#if defined(MOZ_ENABLE_PROFILER_SPS)
|
||||
UniquePtr<ProfilerBacktrace> mBacktrace;
|
||||
UniqueProfilerBacktrace mBacktrace;
|
||||
#endif
|
||||
};
|
||||
|
||||
@@ -267,7 +267,7 @@ RestyleTracker::AddPendingRestyleToTable(Element* aElement,
|
||||
new RestyleData(aRestyleHint, aMinChangeHint, aRestyleHintData);
|
||||
#if defined(MOZ_ENABLE_PROFILER_SPS)
|
||||
if (profiler_feature_active("restyle")) {
|
||||
rd->mBacktrace.reset(profiler_get_backtrace());
|
||||
rd->mBacktrace = profiler_get_backtrace();
|
||||
}
|
||||
#endif
|
||||
mPendingRestyles.Put(aElement, rd);
|
||||
|
||||
@@ -1091,8 +1091,6 @@ nsRefreshDriver::ChooseTimer() const
|
||||
|
||||
nsRefreshDriver::nsRefreshDriver(nsPresContext* aPresContext)
|
||||
: mActiveTimer(nullptr),
|
||||
mReflowCause(nullptr),
|
||||
mStyleCause(nullptr),
|
||||
mPresContext(aPresContext),
|
||||
mRootRefresh(nullptr),
|
||||
mPendingTransaction(0),
|
||||
@@ -1146,9 +1144,6 @@ nsRefreshDriver::~nsRefreshDriver()
|
||||
shell->InvalidatePresShellIfHidden();
|
||||
}
|
||||
mPresShellsToInvalidateIfHidden.Clear();
|
||||
|
||||
profiler_free_backtrace(mStyleCause);
|
||||
profiler_free_backtrace(mReflowCause);
|
||||
}
|
||||
|
||||
// Method for testing. See nsIDOMWindowUtils.advanceTimeAndRefresh
|
||||
@@ -1829,7 +1824,7 @@ nsRefreshDriver::Tick(int64_t aNowEpoch, TimeStamp aNowTime)
|
||||
|
||||
if (!tracingStyleFlush) {
|
||||
tracingStyleFlush = true;
|
||||
profiler_tracing("Paint", "Styles", mStyleCause, TRACING_INTERVAL_START);
|
||||
profiler_tracing("Paint", "Styles", Move(mStyleCause), TRACING_INTERVAL_START);
|
||||
mStyleCause = nullptr;
|
||||
}
|
||||
|
||||
@@ -1869,7 +1864,7 @@ nsRefreshDriver::Tick(int64_t aNowEpoch, TimeStamp aNowTime)
|
||||
|
||||
if (!tracingLayoutFlush) {
|
||||
tracingLayoutFlush = true;
|
||||
profiler_tracing("Paint", "Reflow", mReflowCause, TRACING_INTERVAL_START);
|
||||
profiler_tracing("Paint", "Reflow", Move(mReflowCause), TRACING_INTERVAL_START);
|
||||
mReflowCause = nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -419,8 +419,8 @@ private:
|
||||
mozilla::RefreshDriverTimer* ChooseTimer() const;
|
||||
mozilla::RefreshDriverTimer* mActiveTimer;
|
||||
|
||||
ProfilerBacktrace* mReflowCause;
|
||||
ProfilerBacktrace* mStyleCause;
|
||||
UniqueProfilerBacktrace mReflowCause;
|
||||
UniqueProfilerBacktrace mStyleCause;
|
||||
|
||||
// nsPresContext passed in constructor and unset in Disconnect.
|
||||
mozilla::WeakPtr<nsPresContext> mPresContext;
|
||||
|
||||
@@ -13,21 +13,20 @@
|
||||
#include "mozilla/Sprintf.h"
|
||||
#endif
|
||||
|
||||
ProfilerMarkerPayload::ProfilerMarkerPayload(ProfilerBacktrace* aStack)
|
||||
: mStack(aStack)
|
||||
ProfilerMarkerPayload::ProfilerMarkerPayload(UniqueProfilerBacktrace aStack)
|
||||
: mStack(mozilla::Move(aStack))
|
||||
{}
|
||||
|
||||
ProfilerMarkerPayload::ProfilerMarkerPayload(const mozilla::TimeStamp& aStartTime,
|
||||
const mozilla::TimeStamp& aEndTime,
|
||||
ProfilerBacktrace* aStack)
|
||||
UniqueProfilerBacktrace aStack)
|
||||
: mStartTime(aStartTime)
|
||||
, mEndTime(aEndTime)
|
||||
, mStack(aStack)
|
||||
, mStack(mozilla::Move(aStack))
|
||||
{}
|
||||
|
||||
ProfilerMarkerPayload::~ProfilerMarkerPayload()
|
||||
{
|
||||
profiler_free_backtrace(mStack);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -62,12 +61,12 @@ ProfilerMarkerTracing::ProfilerMarkerTracing(const char* aCategory, TracingMetad
|
||||
}
|
||||
|
||||
ProfilerMarkerTracing::ProfilerMarkerTracing(const char* aCategory, TracingMetadata aMetaData,
|
||||
ProfilerBacktrace* aCause)
|
||||
UniqueProfilerBacktrace aCause)
|
||||
: mCategory(aCategory)
|
||||
, mMetaData(aMetaData)
|
||||
{
|
||||
if (aCause) {
|
||||
SetStack(aCause);
|
||||
SetStack(mozilla::Move(aCause));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,8 +131,9 @@ IOMarkerPayload::IOMarkerPayload(const char* aSource,
|
||||
const char* aFilename,
|
||||
const mozilla::TimeStamp& aStartTime,
|
||||
const mozilla::TimeStamp& aEndTime,
|
||||
ProfilerBacktrace* aStack)
|
||||
: ProfilerMarkerPayload(aStartTime, aEndTime, aStack),
|
||||
UniqueProfilerBacktrace aStack)
|
||||
: ProfilerMarkerPayload(aStartTime, aEndTime,
|
||||
mozilla::Move(aStack)),
|
||||
mSource(aSource)
|
||||
{
|
||||
mFilename = aFilename ? strdup(aFilename) : nullptr;
|
||||
|
||||
@@ -1184,7 +1184,7 @@ double mozilla_sampler_time()
|
||||
return mozilla_sampler_time(mozilla::TimeStamp::Now());
|
||||
}
|
||||
|
||||
ProfilerBacktrace* mozilla_sampler_get_backtrace()
|
||||
UniqueProfilerBacktrace mozilla_sampler_get_backtrace()
|
||||
{
|
||||
if (!stack_key_initialized)
|
||||
return nullptr;
|
||||
@@ -1204,10 +1204,11 @@ ProfilerBacktrace* mozilla_sampler_get_backtrace()
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return new ProfilerBacktrace(t->GetBacktrace());
|
||||
return UniqueProfilerBacktrace(new ProfilerBacktrace(t->GetBacktrace()));
|
||||
}
|
||||
|
||||
void mozilla_sampler_free_backtrace(ProfilerBacktrace* aBacktrace)
|
||||
void
|
||||
ProfilerBacktraceDestructor::operator()(ProfilerBacktrace* aBacktrace)
|
||||
{
|
||||
delete aBacktrace;
|
||||
}
|
||||
@@ -1246,10 +1247,11 @@ void mozilla_sampler_tracing(const char* aCategory, const char* aInfo,
|
||||
}
|
||||
|
||||
void mozilla_sampler_tracing(const char* aCategory, const char* aInfo,
|
||||
ProfilerBacktrace* aCause,
|
||||
UniqueProfilerBacktrace aCause,
|
||||
TracingMetadata aMetaData)
|
||||
{
|
||||
mozilla_sampler_add_marker(aInfo, new ProfilerMarkerTracing(aCategory, aMetaData, aCause));
|
||||
mozilla_sampler_add_marker(aInfo, new ProfilerMarkerTracing(aCategory, aMetaData,
|
||||
mozilla::Move(aCause)));
|
||||
}
|
||||
|
||||
void mozilla_sampler_add_marker(const char *aMarker, ProfilerMarkerPayload *aPayload)
|
||||
|
||||
@@ -14,7 +14,7 @@ void ProfilerIOInterposeObserver::Observe(Observation& aObservation)
|
||||
return;
|
||||
}
|
||||
|
||||
ProfilerBacktrace* stack = profiler_get_backtrace();
|
||||
UniqueProfilerBacktrace stack = profiler_get_backtrace();
|
||||
|
||||
nsCString filename;
|
||||
if (aObservation.Filename()) {
|
||||
@@ -25,6 +25,6 @@ void ProfilerIOInterposeObserver::Observe(Observation& aObservation)
|
||||
filename.get(),
|
||||
aObservation.Start(),
|
||||
aObservation.End(),
|
||||
stack);
|
||||
Move(stack));
|
||||
PROFILER_MARKER_PAYLOAD(aObservation.ObservedOperationString(), markerPayload);
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ if CONFIG['MOZ_ENABLE_PROFILER_SPS']:
|
||||
EXPORTS += [
|
||||
'public/GeckoProfilerFunc.h',
|
||||
'public/GeckoProfilerImpl.h',
|
||||
'public/GeckoProfilerTypes.h',
|
||||
'public/ProfilerBacktrace.h',
|
||||
'public/ProfilerMarkers.h',
|
||||
'public/PseudoStack.h',
|
||||
|
||||
@@ -56,6 +56,7 @@
|
||||
#endif
|
||||
#include "mozilla/UniquePtr.h"
|
||||
#include "mozilla/Vector.h"
|
||||
#include "GeckoProfilerTypes.h"
|
||||
|
||||
namespace mozilla {
|
||||
class TimeStamp;
|
||||
@@ -155,12 +156,9 @@ static inline void profiler_resume() {}
|
||||
|
||||
|
||||
// Immediately capture the current thread's call stack and return it
|
||||
static inline ProfilerBacktrace* profiler_get_backtrace() { return nullptr; }
|
||||
static inline UniqueProfilerBacktrace profiler_get_backtrace() { return nullptr; }
|
||||
static inline void profiler_get_backtrace_noalloc(char *output, size_t outputSize) { return; }
|
||||
|
||||
// Free a ProfilerBacktrace returned by profiler_get_backtrace()
|
||||
static inline void profiler_free_backtrace(ProfilerBacktrace* aBacktrace) {}
|
||||
|
||||
static inline bool profiler_is_active() { return false; }
|
||||
|
||||
// Check if an external profiler feature is active.
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "js/ProfilingStack.h"
|
||||
#include "mozilla/UniquePtr.h"
|
||||
#include "mozilla/Vector.h"
|
||||
#include "GeckoProfilerTypes.h"
|
||||
#include <stdint.h>
|
||||
|
||||
class nsISupports;
|
||||
@@ -49,8 +50,7 @@ bool mozilla_sampler_is_paused();
|
||||
void mozilla_sampler_pause();
|
||||
void mozilla_sampler_resume();
|
||||
|
||||
ProfilerBacktrace* mozilla_sampler_get_backtrace();
|
||||
void mozilla_sampler_free_backtrace(ProfilerBacktrace* aBacktrace);
|
||||
UniqueProfilerBacktrace mozilla_sampler_get_backtrace();
|
||||
void mozilla_sampler_get_backtrace_noalloc(char *output, size_t outputSize);
|
||||
|
||||
bool mozilla_sampler_is_active();
|
||||
@@ -119,7 +119,7 @@ void mozilla_sampler_tracing(const char* aCategory, const char* aInfo,
|
||||
TracingMetadata aMetaData);
|
||||
|
||||
void mozilla_sampler_tracing(const char* aCategory, const char* aInfo,
|
||||
ProfilerBacktrace* aCause,
|
||||
UniqueProfilerBacktrace aCause,
|
||||
TracingMetadata aMetaData);
|
||||
|
||||
void mozilla_sampler_log(const char *fmt, va_list args);
|
||||
|
||||
@@ -94,17 +94,11 @@ void profiler_resume()
|
||||
}
|
||||
|
||||
static inline
|
||||
ProfilerBacktrace* profiler_get_backtrace()
|
||||
UniqueProfilerBacktrace profiler_get_backtrace()
|
||||
{
|
||||
return mozilla_sampler_get_backtrace();
|
||||
}
|
||||
|
||||
static inline
|
||||
void profiler_free_backtrace(ProfilerBacktrace* aBacktrace)
|
||||
{
|
||||
mozilla_sampler_free_backtrace(aBacktrace);
|
||||
}
|
||||
|
||||
static inline
|
||||
void profiler_get_backtrace_noalloc(char *output, size_t outputSize)
|
||||
{
|
||||
@@ -269,17 +263,16 @@ bool profiler_in_privacy_mode()
|
||||
}
|
||||
|
||||
static inline void profiler_tracing(const char* aCategory, const char* aInfo,
|
||||
ProfilerBacktrace* aCause,
|
||||
UniqueProfilerBacktrace aCause,
|
||||
TracingMetadata aMetaData = TRACING_DEFAULT)
|
||||
{
|
||||
// Don't insert a marker if we're not profiling to avoid
|
||||
// the heap copy (malloc).
|
||||
if (!stack_key_initialized || !profiler_is_active()) {
|
||||
delete aCause;
|
||||
return;
|
||||
}
|
||||
|
||||
mozilla_sampler_tracing(aCategory, aInfo, aCause, aMetaData);
|
||||
mozilla_sampler_tracing(aCategory, aInfo, mozilla::Move(aCause), aMetaData);
|
||||
}
|
||||
|
||||
static inline void profiler_tracing(const char* aCategory, const char* aInfo,
|
||||
@@ -392,13 +385,13 @@ namespace mozilla {
|
||||
class MOZ_RAII GeckoProfilerTracingRAII {
|
||||
public:
|
||||
GeckoProfilerTracingRAII(const char* aCategory, const char* aInfo,
|
||||
mozilla::UniquePtr<ProfilerBacktrace> aBacktrace
|
||||
UniqueProfilerBacktrace aBacktrace
|
||||
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
||||
: mCategory(aCategory)
|
||||
, mInfo(aInfo)
|
||||
{
|
||||
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
||||
profiler_tracing(mCategory, mInfo, aBacktrace.release(), TRACING_INTERVAL_START);
|
||||
profiler_tracing(mCategory, mInfo, Move(aBacktrace), TRACING_INTERVAL_START);
|
||||
}
|
||||
|
||||
~GeckoProfilerTracingRAII() {
|
||||
|
||||
21
tools/profiler/public/GeckoProfilerTypes.h
Normal file
21
tools/profiler/public/GeckoProfilerTypes.h
Normal file
@@ -0,0 +1,21 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
// IWYU pragma: private, include "GeckoProfiler.h"
|
||||
|
||||
#ifndef PROFILER_TYPES_H
|
||||
#define PROFILER_TYPES_H
|
||||
|
||||
#include "mozilla/UniquePtr.h"
|
||||
|
||||
class ProfilerBacktrace;
|
||||
|
||||
struct ProfilerBacktraceDestructor
|
||||
{
|
||||
void operator()(ProfilerBacktrace*);
|
||||
};
|
||||
using UniqueProfilerBacktrace =
|
||||
mozilla::UniquePtr<ProfilerBacktrace, ProfilerBacktraceDestructor>;
|
||||
|
||||
#endif // PROFILER_TYPES_H
|
||||
@@ -9,6 +9,8 @@
|
||||
#include "mozilla/TimeStamp.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
|
||||
#include "GeckoProfiler.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace layers {
|
||||
class Layer;
|
||||
@@ -33,13 +35,10 @@ class UniqueStacks;
|
||||
class ProfilerMarkerPayload
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* ProfilerMarkerPayload takes ownership of aStack
|
||||
*/
|
||||
explicit ProfilerMarkerPayload(ProfilerBacktrace* aStack = nullptr);
|
||||
explicit ProfilerMarkerPayload(UniqueProfilerBacktrace aStack = nullptr);
|
||||
ProfilerMarkerPayload(const mozilla::TimeStamp& aStartTime,
|
||||
const mozilla::TimeStamp& aEndTime,
|
||||
ProfilerBacktrace* aStack = nullptr);
|
||||
UniqueProfilerBacktrace aStack = nullptr);
|
||||
|
||||
/**
|
||||
* Called from the main thread
|
||||
@@ -61,19 +60,20 @@ protected:
|
||||
void streamCommonProps(const char* aMarkerType, SpliceableJSONWriter& aWriter,
|
||||
UniqueStacks& aUniqueStacks);
|
||||
|
||||
void SetStack(ProfilerBacktrace* aStack) { mStack = aStack; }
|
||||
void SetStack(UniqueProfilerBacktrace aStack) { mStack = mozilla::Move(aStack); }
|
||||
|
||||
private:
|
||||
mozilla::TimeStamp mStartTime;
|
||||
mozilla::TimeStamp mEndTime;
|
||||
ProfilerBacktrace* mStack;
|
||||
UniqueProfilerBacktrace mStack;
|
||||
};
|
||||
|
||||
class ProfilerMarkerTracing : public ProfilerMarkerPayload
|
||||
{
|
||||
public:
|
||||
ProfilerMarkerTracing(const char* aCategory, TracingMetadata aMetaData);
|
||||
ProfilerMarkerTracing(const char* aCategory, TracingMetadata aMetaData, ProfilerBacktrace* aCause);
|
||||
ProfilerMarkerTracing(const char* aCategory, TracingMetadata aMetaData,
|
||||
UniqueProfilerBacktrace aCause);
|
||||
|
||||
const char *GetCategory() const { return mCategory; }
|
||||
TracingMetadata GetMetaData() const { return mMetaData; }
|
||||
@@ -106,7 +106,7 @@ class IOMarkerPayload : public ProfilerMarkerPayload
|
||||
public:
|
||||
IOMarkerPayload(const char* aSource, const char* aFilename, const mozilla::TimeStamp& aStartTime,
|
||||
const mozilla::TimeStamp& aEndTime,
|
||||
ProfilerBacktrace* aStack);
|
||||
UniqueProfilerBacktrace aStack);
|
||||
~IOMarkerPayload();
|
||||
|
||||
virtual void StreamPayload(SpliceableJSONWriter& aWriter,
|
||||
|
||||
@@ -172,12 +172,8 @@ MainThreadIOLoggerImpl::IOThreadFunc()
|
||||
(i->mObservation.Start() - mLogStartTime).ToMilliseconds(),
|
||||
i->mObservation.ObservedOperationString(), durationMs,
|
||||
i->mObservation.Reference(), nativeFilename.get()) > 0) {
|
||||
ProfilerBacktrace* stack = i->mStack;
|
||||
if (stack) {
|
||||
// TODO: Write out the callstack
|
||||
// (This will be added in a later bug)
|
||||
profiler_free_backtrace(stack);
|
||||
}
|
||||
// TODO: Write out the callstack
|
||||
i->mStack = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user