pps: classify counters into Perfetto counter groups

Perfetto's GpuCounterDescriptor exposes a per-counter "groups" field
that classifies a counter into well-known buckets (VERTICES, FRAGMENTS,
COMPUTE, MEMORY, PRIMITIVES, RAY_TRACING). Tools such as Android CTS'
CtsGpuProfilingDataTest#testProfilingDataProducersAvailable iterate the
counter specs and union their group lists to determine the set of
"supported" GPU counter groups.

Until now PPS never populated this field, so all Mesa-backed producers
exposed counters with an empty groups list. Add a virtual
Driver::classify_counter_groups() hook so each driver can map its own
counter naming conventions onto the Perfetto categories without having
to include Perfetto headers, then call it from add_descriptors() to
emit the per-spec groups field.

A neutral CounterGroupType enum is introduced in pps_driver.h and
mirrors the values of perfetto::protos::pbzero::GpuCounterDescriptor::
CounterGroup so driver implementations stay decoupled from the Perfetto
SDK headers. The default implementation does nothing, leaving counters
unclassified for drivers that have not opted in yet.

Signed-off-by: Nemallapudi, Jaikrishna <nemallapudi.jaikrishna@intel.com>
This commit is contained in:
Nemallapudi, Jaikrishna 2026-05-07 09:34:58 +00:00 committed by Jaikrishna Nemallapudi
parent d4b2e53ef3
commit 51d96c9f75
2 changed files with 47 additions and 0 deletions

View file

@ -187,6 +187,32 @@ template <typename GpuCounterDescriptor> void add_descriptors(GpuCounterDescript
}
spec->add_numerator_units(units);
spec->set_select_by_default(true);
// Classify counter into Perfetto counter groups via driver's virtual method.
// Each driver maps its own counter naming conventions; unrecognised counters
// are left without a group (which is valid).
driver.classify_counter_groups(counter.name, [&](CounterGroupType group) {
switch (group) {
case CounterGroupType::VERTICES:
spec->add_groups(GpuCounterDescriptor::VERTICES);
break;
case CounterGroupType::FRAGMENTS:
spec->add_groups(GpuCounterDescriptor::FRAGMENTS);
break;
case CounterGroupType::COMPUTE:
spec->add_groups(GpuCounterDescriptor::COMPUTE);
break;
case CounterGroupType::MEMORY:
spec->add_groups(GpuCounterDescriptor::MEMORY);
break;
case CounterGroupType::PRIMITIVES:
spec->add_groups(GpuCounterDescriptor::PRIMITIVES);
break;
case CounterGroupType::RAY_TRACING:
spec->add_groups(GpuCounterDescriptor::RAY_TRACING);
break;
}
});
}
}

View file

@ -9,6 +9,7 @@
#pragma once
#include <functional>
#include <memory>
#include <string>
#include <unordered_map>
@ -19,6 +20,18 @@
namespace pps
{
/// @brief Perfetto-compatible counter group categories for classifying GPU counters.
/// These mirror the values in perfetto::protos::pbzero::GpuCounterDescriptor::CounterGroup
/// so that driver implementations do not need to include Perfetto headers.
enum class CounterGroupType {
VERTICES,
FRAGMENTS,
COMPUTE,
MEMORY,
PRIMITIVES,
RAY_TRACING,
};
/// @brief Abstract Driver class
class Driver
{
@ -90,6 +103,14 @@ class Driver
/// than sampling separately CPU & GPU timestamps.
virtual bool cpu_gpu_timestamp(uint64_t &cpu_timestamp, uint64_t &gpu_timestamp) const = 0;
/// @brief Classify a counter name into Perfetto counter groups.
/// Drivers should call add_group(CounterGroupType::XYZ) for each group
/// that applies to the given counter name.
/// The default implementation does nothing (counters are left unclassified).
virtual void classify_counter_groups(
const std::string & /*counter_name*/,
const std::function<void(CounterGroupType)> & /*add_group*/) const {}
DrmDevice drm_device;
/// List of counter groups