From 62d0f9f03393b3482ef4668cf014ee7bb739cddf Mon Sep 17 00:00:00 2001 From: Pixelflinger Date: Wed, 27 May 2020 15:04:35 -0700 Subject: [PATCH] perfcounters are now disabled by default To enable some basic profiling of the gl thread using performance counters, the "filament.perfcounters" property must be set to 1 (before the Filament Engine is created): adb shell setprop filament.perfcounters 1 This is so that filament doesn't interfere with simpleperf by default. --- .../include/private/backend/CommandStream.h | 2 ++ filament/backend/src/CommandStream.cpp | 35 ++++++++++++------- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/filament/backend/include/private/backend/CommandStream.h b/filament/backend/include/private/backend/CommandStream.h index 529a1bae38..93b53be6e1 100644 --- a/filament/backend/include/private/backend/CommandStream.h +++ b/filament/backend/include/private/backend/CommandStream.h @@ -297,6 +297,8 @@ private: std::thread::id mThreadId; #endif + bool mUsePerformanceCounter = false; + inline void* allocateCommand(size_t size) { assert(mThreadId == std::this_thread::get_id()); return mCurrentBuffer->allocate(size); diff --git a/filament/backend/src/CommandStream.cpp b/filament/backend/src/CommandStream.cpp index c732ecc626..7697e809c1 100644 --- a/filament/backend/src/CommandStream.cpp +++ b/filament/backend/src/CommandStream.cpp @@ -23,6 +23,10 @@ #include +#ifdef ANDROID +#include +#endif + using namespace utils; namespace filament { @@ -60,6 +64,11 @@ CommandStream::CommandStream(Driver& driver, CircularBuffer& buffer) noexcept , mThreadId(std::this_thread::get_id()) #endif { +#ifdef ANDROID + char property[PROP_VALUE_MAX]; + __system_property_get("filament.perfcounters", property); + mUsePerformanceCounter = bool(atoi(property)); +#endif } void CommandStream::execute(void* buffer) { @@ -68,9 +77,11 @@ void CommandStream::execute(void* buffer) { Profiler profiler; if (SYSTRACE_TAG) { - // we want to remove all this when tracing is completely disabled - profiler.resetEvents(Profiler::EV_CPU_CYCLES | Profiler::EV_L1D_RATES | Profiler::EV_BPU_RATES); - profiler.start(); + if (UTILS_UNLIKELY(mUsePerformanceCounter)) { + // we want to remove all this when tracing is completely disabled + profiler.resetEvents(Profiler::EV_CPU_CYCLES | Profiler::EV_BPU_MISSES); + profiler.start(); + } } mDriver->execute([this, buffer]() { @@ -82,16 +93,16 @@ void CommandStream::execute(void* buffer) { }); if (SYSTRACE_TAG) { - // we want to remove all this when tracing is completely disabled - UTILS_UNUSED Profiler::Counters counters = profiler.readCounters(); - SYSTRACE_VALUE32("GLThread (I)", counters.getInstructions()); - SYSTRACE_VALUE32("GLThread (C)", counters.getCpuCycles()); - SYSTRACE_VALUE32("GLThread (CPI x10)", counters.getCPI() * 10); - SYSTRACE_VALUE32("GLThread (L1D HR%)", counters.getL1DHitRate() * 100); - if (profiler.hasBranchRates()) { - SYSTRACE_VALUE32("GLThread (BHR%)", counters.getBranchHitRate() * 100); - } else { + if (UTILS_UNLIKELY(mUsePerformanceCounter)) { + // we want to remove all this when tracing is completely disabled + profiler.stop(); + UTILS_UNUSED Profiler::Counters counters = profiler.readCounters(); + SYSTRACE_VALUE32("GLThread (I)", counters.getInstructions()); + SYSTRACE_VALUE32("GLThread (C)", counters.getCpuCycles()); + SYSTRACE_VALUE32("GLThread (CPI x10)", counters.getCPI() * 10); SYSTRACE_VALUE32("GLThread (BPU miss)", counters.getBranchMisses()); + SYSTRACE_VALUE32("GLThread (I / BPU miss)", + counters.getInstructions() / counters.getBranchMisses()); } } }