зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1575453 - AUTO_PROFILER_STATS (off by default) - r=gregtatum
AUTO_PROFILER_STATS(name) can be used to time a {block}. Statistics are gathered in a function-static variable, and printf'd when the program ends. Differential Revision: https://phabricator.services.mozilla.com/D42825 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
608cb489b5
Коммит
74485a5d46
|
@ -78,6 +78,8 @@
|
|||
# define AUTO_BASE_PROFILER_TEXT_MARKER_DOCSHELL_CAUSE( \
|
||||
markerName, text, categoryPair, docShell, cause)
|
||||
|
||||
# define AUTO_PROFILER_STATS(name)
|
||||
|
||||
#else // !MOZ_BASE_PROFILER
|
||||
|
||||
# include "BaseProfilingStack.h"
|
||||
|
@ -528,6 +530,62 @@ struct ProfilerBufferInfo {
|
|||
// buffer is being written to, and how much data is visible.
|
||||
MFBT_API Maybe<ProfilerBufferInfo> profiler_get_buffer_info();
|
||||
|
||||
// Uncomment the following line to display profiler runtime statistics at
|
||||
// shutdown.
|
||||
// # define PROFILER_RUNTIME_STATS
|
||||
|
||||
# ifdef PROFILER_RUNTIME_STATS
|
||||
struct StaticBaseProfilerStats {
|
||||
explicit StaticBaseProfilerStats(const char* aName) : mName(aName) {}
|
||||
~StaticBaseProfilerStats() {
|
||||
long long n = static_cast<long long>(mNumberDurations);
|
||||
if (n != 0) {
|
||||
long long sumNs = static_cast<long long>(mSumDurationsNs);
|
||||
printf("Profiler stats `%s`: %lld ns / %lld = %lld ns\n", mName, sumNs, n,
|
||||
sumNs / n);
|
||||
} else {
|
||||
printf("Profiler stats `%s`: (nothing)\n", mName);
|
||||
}
|
||||
}
|
||||
Atomic<long long> mSumDurationsNs{0};
|
||||
Atomic<long long> mNumberDurations{0};
|
||||
|
||||
private:
|
||||
const char* mName;
|
||||
};
|
||||
|
||||
class MOZ_RAII AutoProfilerStats {
|
||||
public:
|
||||
explicit AutoProfilerStats(
|
||||
StaticBaseProfilerStats& aStats MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
||||
: mStats(aStats), mStart(TimeStamp::NowUnfuzzed()) {
|
||||
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
||||
}
|
||||
|
||||
~AutoProfilerStats() {
|
||||
mStats.mSumDurationsNs += int64_t(
|
||||
(TimeStamp::NowUnfuzzed() - mStart).ToMicroseconds() * 1000 + 0.5);
|
||||
++mStats.mNumberDurations;
|
||||
}
|
||||
|
||||
private:
|
||||
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
||||
|
||||
StaticBaseProfilerStats& mStats;
|
||||
TimeStamp mStart;
|
||||
};
|
||||
|
||||
# define AUTO_PROFILER_STATS(name) \
|
||||
static ::mozilla::baseprofiler::StaticBaseProfilerStats sStat##name( \
|
||||
#name); \
|
||||
::mozilla::baseprofiler::AutoProfilerStats autoStat##name(sStat##name);
|
||||
|
||||
# else // PROFILER_RUNTIME_STATS
|
||||
|
||||
# define AUTO_PROFILER_STATS(name)
|
||||
|
||||
# endif // PROFILER_RUNTIME_STATS else
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Put profiling data into the profiler (labels and markers)
|
||||
//---------------------------------------------------------------------------
|
||||
|
|
Загрузка…
Ссылка в новой задаче