re-do "Use the Perfetto SDK instead of ATRACE" (#8701) (#8728)

* re-do "Use the Perfetto SDK instead of ATRACE" (#8701)

This time we create an entirely new private header: Tracing.h which
uses the perfetto SDK instead of ATRACE. The old Systrace.h is
unchanged to presever backward compatibility but is essentially
deprecated and no longer used within the filament repo.

The new TRACING_ macros use an explicit CATEGORY parameter, which is
declared in Tracing.h.

Moreover, tracing can be compiled out by defining
FILAMENT_TRACING_ENABLED to false before including Tracing.h

iOS tracing is still supported and still controlled via
FILAMENT_APPLE_SYSTRACE.

There are three perfetto categories defined:

- "filament/filament"
- "filament/jobsystem"
- "filament/gltfio"

The "filament/jobsystem" category is compiled out by default.

And they can be enabled in AGI / perfetto by adding:

```
data_sources {
  config {
    name: "track_event"
    track_event_config {
      disabled_categories: "*"
      enabled_categories: "filament/filament"
      enabled_categories: "filament/jobsystem"
      enabled_categories: "filament/gltfio"
    }
  }
}
```

* Update libs/utils/include/private/utils/Tracing.h

Co-authored-by: Powei Feng <powei@google.com>

* Update libs/utils/src/android/Tracing.cpp

Co-authored-by: Powei Feng <powei@google.com>

* remove all references to SYSTRACE_TAG

---------

Co-authored-by: Powei Feng <powei@google.com>
This commit is contained in:
Mathias Agopian
2025-05-14 20:51:57 -07:00
committed by GitHub
parent e7a8f471a1
commit bbabf3480b
39 changed files with 738 additions and 213 deletions

View File

@@ -14,23 +14,21 @@
* limitations under the License.
*/
// Note: The overhead of SYSTRACE_TAG_JOBSYSTEM is not negligible especially with parallel_for().
#ifndef SYSTRACE_TAG
//#define SYSTRACE_TAG SYSTRACE_TAG_JOBSYSTEM
#define SYSTRACE_TAG SYSTRACE_TAG_NEVER
#endif
// Note: The overhead of TRACING is not negligible especially with parallel_for().
#define FILAMENT_TRACING_ENABLED false
// when SYSTRACE_TAG_JOBSYSTEM is used, enables even heavier systraces
#define HEAVY_SYSTRACE 0
// when FILAMENT_TRACING_ENABLED is true, enables even heavier tracing
#define HEAVY_TRACING 0
#include <utils/JobSystem.h>
#include <private/utils/Tracing.h>
#include <utils/compiler.h>
#include <utils/debug.h>
#include <utils/Log.h>
#include <utils/ostream.h>
#include <utils/Panic.h>
#include <utils/Systrace.h>
#include <algorithm>
#include <atomic>
@@ -80,14 +78,14 @@
# define gettid() syscall(SYS_gettid)
#endif
#if HEAVY_SYSTRACE
# define HEAVY_SYSTRACE_CALL() SYSTRACE_CALL()
# define HEAVY_SYSTRACE_NAME(name) SYSTRACE_NAME(name)
# define HEAVY_SYSTRACE_VALUE32(name, v) SYSTRACE_VALUE32(name, v)
#if HEAVY_TRACING
# define HEAVY_FILAMENT_TRACING_CALL(tag) FILAMENT_TRACING_CALL(tag)
# define HEAVY_FILAMENT_TRACING_NAME(tag, name) FILAMENT_TRACING_NAME(tag, name)
# define HEAVY_FILAMENT_TRACING_VALUE(tag, name, v) FILAMENT_TRACING_VALUE(tag, name, v)
#else
# define HEAVY_SYSTRACE_CALL()
# define HEAVY_SYSTRACE_NAME(name)
# define HEAVY_SYSTRACE_VALUE32(name, v)
# define HEAVY_FILAMENT_TRACING_CALL(tag)
# define HEAVY_FILAMENT_TRACING_NAME(tag, name)
# define HEAVY_FILAMENT_TRACING_VALUE(tag, name, v)
#endif
namespace utils {
@@ -174,7 +172,7 @@ JobSystem::JobSystem(const size_t userThreadCount, const size_t adoptableThreads
: mJobPool("JobSystem Job pool", MAX_JOB_COUNT * sizeof(Job)),
mJobStorageBase(static_cast<Job *>(mJobPool.getAllocator().getCurrent()))
{
SYSTRACE_ENABLE();
FILAMENT_TRACING_ENABLE(FILAMENT_TRACING_CATEGORY_JOBSYSTEM);
unsigned int threadPoolCount = userThreadCount;
if (threadPoolCount == 0) {
@@ -274,12 +272,12 @@ inline bool JobSystem::hasJobCompleted(Job const* job) noexcept {
}
inline void JobSystem::wait(std::unique_lock<Mutex>& lock) noexcept {
HEAVY_SYSTRACE_CALL();
HEAVY_FILAMENT_TRACING_CALL(FILAMENT_TRACING_CATEGORY_JOBSYSTEM);
mWaiterCondition.wait(lock);
}
inline uint32_t JobSystem::wait(std::unique_lock<Mutex>& lock, Job* const job) noexcept {
HEAVY_SYSTRACE_CALL();
HEAVY_FILAMENT_TRACING_CALL(FILAMENT_TRACING_CATEGORY_JOBSYSTEM);
// signal we are waiting
if (hasActiveJobs() || exitRequested()) {
@@ -304,7 +302,7 @@ inline uint32_t JobSystem::wait(std::unique_lock<Mutex>& lock, Job* const job) n
UTILS_NOINLINE
void JobSystem::wakeAll() noexcept {
// wakeAll() is called when a job finishes (to wake up any thread that might be waiting on it)
SYSTRACE_CALL();
FILAMENT_TRACING_CALL(FILAMENT_TRACING_CATEGORY_JOBSYSTEM);
mWaiterLock.lock();
// this empty critical section is needed -- it guarantees that notify_all() happens
// either before the condition is checked, or after the condition variable sleeps.
@@ -315,7 +313,7 @@ void JobSystem::wakeAll() noexcept {
void JobSystem::wakeOne() noexcept {
// wakeOne() is called when a new job is added to a queue
HEAVY_SYSTRACE_CALL();
HEAVY_FILAMENT_TRACING_CALL(FILAMENT_TRACING_CATEGORY_JOBSYSTEM);
mWaiterLock.lock();
// this empty critical section is needed -- it guarantees that notify_one() happens
// either before the condition is checked, or after the condition variable sleeps.
@@ -397,7 +395,7 @@ inline JobSystem::ThreadState* JobSystem::getStateToStealFrom(ThreadState& state
}
JobSystem::Job* JobSystem::steal(ThreadState& state) noexcept {
HEAVY_SYSTRACE_CALL();
HEAVY_FILAMENT_TRACING_CALL(FILAMENT_TRACING_CATEGORY_JOBSYSTEM);
Job* job = nullptr;
do {
ThreadState* const stateToStealFrom = getStateToStealFrom(state);
@@ -411,7 +409,7 @@ JobSystem::Job* JobSystem::steal(ThreadState& state) noexcept {
}
bool JobSystem::execute(ThreadState& state) noexcept {
HEAVY_SYSTRACE_CALL();
HEAVY_FILAMENT_TRACING_CALL(FILAMENT_TRACING_CATEGORY_JOBSYSTEM);
Job* job = pop(state.workQueue);
@@ -427,7 +425,7 @@ bool JobSystem::execute(ThreadState& state) noexcept {
if (UTILS_LIKELY(job)) {
assert((job->runningJobCount.load(std::memory_order_relaxed) & JOB_COUNT_MASK) >= 1);
if (UTILS_LIKELY(job->function)) {
HEAVY_SYSTRACE_NAME("job->function");
HEAVY_FILAMENT_TRACING_NAME(FILAMENT_TRACING_CATEGORY_JOBSYSTEM, "job->function");
job->id = std::distance(mThreadStates.data(), &state);
job->function(job->storage, *this, job);
job->id = invalidThreadId;
@@ -461,7 +459,7 @@ void JobSystem::loop(ThreadState* state) noexcept {
UTILS_NOINLINE
void JobSystem::finish(Job* job) noexcept {
HEAVY_SYSTRACE_CALL();
HEAVY_FILAMENT_TRACING_CALL(FILAMENT_TRACING_CATEGORY_JOBSYSTEM);
bool notify = false;
@@ -541,7 +539,7 @@ void JobSystem::release(Job*& job) noexcept {
}
void JobSystem::run(Job*& job) noexcept {
HEAVY_SYSTRACE_CALL();
HEAVY_FILAMENT_TRACING_CALL(FILAMENT_TRACING_CATEGORY_JOBSYSTEM);
ThreadState& state(getState());
@@ -552,7 +550,7 @@ void JobSystem::run(Job*& job) noexcept {
}
void JobSystem::run(Job*& job, uint8_t id) noexcept {
HEAVY_SYSTRACE_CALL();
HEAVY_FILAMENT_TRACING_CALL(FILAMENT_TRACING_CATEGORY_JOBSYSTEM);
ThreadState& state = mThreadStates[id];
assert_invariant(&state == &getState());
@@ -570,7 +568,7 @@ JobSystem::Job* JobSystem::runAndRetain(Job* job) noexcept {
}
void JobSystem::waitAndRelease(Job*& job) noexcept {
SYSTRACE_CALL();
FILAMENT_TRACING_CALL(FILAMENT_TRACING_CATEGORY_JOBSYSTEM);
assert(job);
assert(job->refCount.load(std::memory_order_relaxed) >= 1);
@@ -619,7 +617,7 @@ void JobSystem::waitAndRelease(Job*& job) noexcept {
}
void JobSystem::runAndWait(Job*& job) noexcept {
SYSTRACE_CALL();
FILAMENT_TRACING_CALL(FILAMENT_TRACING_CATEGORY_JOBSYSTEM);
runAndRetain(job);
waitAndRelease(job);
}