Commit 51d32876 authored by Antonio Caggiano's avatar Antonio Caggiano 🦀
Browse files

gpu/datasource: Use dump timestamp



While using the timestamp returned by a driver, generate a separate
trace packet with an incremental state cleared sequence flag, then
send counter descriptors within another packet.
Signed-off-by: Antonio Caggiano's avatarAntonio Caggiano <antonio.caggiano@collabora.com>
Reviewed-by: default avatarRohan Garg <rohan.garg@collabora.com>
parent 05b15dbe
Pipeline #230743 passed with stages
in 2 minutes
......@@ -197,10 +197,14 @@ void add_descriptors(perfetto::protos::pbzero::GpuCounterEvent *event,
}
}
static void add_samples(perfetto::protos::pbzero::GpuCounterEvent *event, Driver &driver)
void add_samples(perfetto::protos::pbzero::GpuCounterEvent &event, const Driver &driver)
{
if (driver.enabled_counters.size() == 0) {
PPS_LOG_FATAL("There are no counters enabled");
}
for (const auto &counter : driver.enabled_counters) {
auto counter_event = event->add_counters();
auto counter_event = event.add_counters();
counter_event->set_counter_id(COUNTER_ID(driver.drm_device.gpu_num, counter.id));
......@@ -209,6 +213,8 @@ static void add_samples(perfetto::protos::pbzero::GpuCounterEvent *event, Driver
counter_event->set_double_value(*d_value);
} else if (auto i_value = std::get_if<int64_t>(&value)) {
counter_event->set_int_value(*i_value);
} else {
PPS_LOG_ERROR("Failed to get value for counter %s", counter.name.c_str());
}
}
}
......@@ -217,32 +223,40 @@ void GpuDataSource::trace(TraceContext &ctx, uint64_t sampling_period_ns)
{
using namespace perfetto::protos::pbzero;
auto state = ctx.GetIncrementalState();
auto timestamp = perfetto::base::GetBootTimeNs().count();
if (auto state = ctx.GetIncrementalState(); state->was_cleared) {
// Mark any incremental state before this point invalid
{
auto packet = ctx.NewTracePacket();
packet->set_timestamp(perfetto::base::GetBootTimeNs().count());
packet->set_sequence_flags(TracePacket::SEQ_INCREMENTAL_STATE_CLEARED);
}
for (auto &driver : drivers) {
auto packet = ctx.NewTracePacket();
packet->set_timestamp(timestamp);
for (auto &driver : drivers) {
auto packet = ctx.NewTracePacket();
packet->set_timestamp(perfetto::base::GetBootTimeNs().count());
auto event = packet->set_gpu_counter_event();
event->set_gpu_id(driver->drm_device.gpu_num);
auto event = packet->set_gpu_counter_event();
event->set_gpu_id(driver->drm_device.gpu_num);
if (state->was_cleared) {
/// @todo Do we need to send descriptions again
/// when restarting this producer during a perfetto tracing session?
auto &groups = driver->groups;
auto &counters = driver->counters;
PPS_LOG("Sending counter descriptors");
add_descriptors(event, groups, counters, *driver, sampling_period_ns);
state->was_cleared = false;
}
if (!driver->dump_perfcnt()) {
PERFETTO_ELOG("Skipping sample for %s", driver->drm_device.name.c_str());
return;
}
state->was_cleared = false;
}
for (auto &driver : drivers) {
if (auto timestamp = driver->dump_perfcnt()) {
auto packet = ctx.NewTracePacket();
packet->set_timestamp(timestamp);
auto event = packet->set_gpu_counter_event();
event->set_gpu_id(driver->drm_device.gpu_num);
add_samples(event, *driver);
add_samples(*event, *driver);
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment