diff --git a/src/freedreno/vulkan/tu_perfetto.cc b/src/freedreno/vulkan/tu_perfetto.cc index 45df6f9c96a..53e5149bdce 100644 --- a/src/freedreno/vulkan/tu_perfetto.cc +++ b/src/freedreno/vulkan/tu_perfetto.cc @@ -9,6 +9,7 @@ #include "util/hash_table.h" #include "util/perf/u_perfetto.h" +#include "util/perf/u_perfetto_renderpass.h" #include "tu_tracepoints.h" #include "tu_tracepoints_perfetto.h" @@ -104,21 +105,11 @@ struct TuRenderpassTraits : public perfetto::DefaultDataSourceTraits { using IncrementalStateType = TuRenderpassIncrementalState; }; -class TuRenderpassDataSource : public perfetto::DataSource { -public: - void OnSetup(const SetupArgs &) override +class TuRenderpassDataSource : public MesaRenderpassDataSource { + void OnStart(const StartArgs &args) override { - // Use this callback to apply any custom configuration to your data source - // based on the TraceConfig in SetupArgs. - } - - void OnStart(const StartArgs &) override - { - // This notification can be used to initialize the GPU driver, enable - // counters, etc. StartArgs will contains the DataSourceDescriptor, - // which can be extended. - u_trace_perfetto_start(); - PERFETTO_LOG("Tracing started"); + MesaRenderpassDataSource::OnStart(args); /* Note: clock_id's below 128 are reserved.. for custom clock sources, * using the hash of a namespaced string is the recommended approach. @@ -131,21 +122,6 @@ public: gpu_max_timestamp = 0; last_suspend_count = 0; } - - void OnStop(const StopArgs &) override - { - PERFETTO_LOG("Tracing stopped"); - - // Undo any initialization done in OnStart. - u_trace_perfetto_stop(); - // TODO we should perhaps block until queued traces are flushed? - - Trace([](TuRenderpassDataSource::TraceContext ctx) { - auto packet = ctx.NewTracePacket(); - packet->Finalize(); - ctx.Flush(); - }); - } }; PERFETTO_DECLARE_DATA_SOURCE_STATIC_MEMBERS(TuRenderpassDataSource); diff --git a/src/gallium/drivers/freedreno/freedreno_perfetto.cc b/src/gallium/drivers/freedreno/freedreno_perfetto.cc index d76dabe1329..046fd581837 100644 --- a/src/gallium/drivers/freedreno/freedreno_perfetto.cc +++ b/src/gallium/drivers/freedreno/freedreno_perfetto.cc @@ -24,6 +24,7 @@ #include #include "util/perf/u_perfetto.h" +#include "util/perf/u_perfetto_renderpass.h" #include "freedreno_tracepoints.h" @@ -47,21 +48,12 @@ struct FdRenderpassTraits : public perfetto::DefaultDataSourceTraits { using IncrementalStateType = FdRenderpassIncrementalState; }; -class FdRenderpassDataSource : public perfetto::DataSource { +class FdRenderpassDataSource : public MesaRenderpassDataSource { public: - void OnSetup(const SetupArgs &) override - { - // Use this callback to apply any custom configuration to your data source - // based on the TraceConfig in SetupArgs. - } - void OnStart(const StartArgs &) override + void OnStart(const StartArgs &args) override { - // This notification can be used to initialize the GPU driver, enable - // counters, etc. StartArgs will contains the DataSourceDescriptor, - // which can be extended. - u_trace_perfetto_start(); - PERFETTO_LOG("Tracing started"); + MesaRenderpassDataSource::OnStart(args); /* Note: clock_id's below 128 are reserved.. for custom clock sources, * using the hash of a namespaced string is the recommended approach. @@ -70,21 +62,6 @@ public: gpu_clock_id = _mesa_hash_string("org.freedesktop.mesa.freedreno") | 0x80000000; } - - void OnStop(const StopArgs &) override - { - PERFETTO_LOG("Tracing stopped"); - - // Undo any initialization done in OnStart. - u_trace_perfetto_stop(); - // TODO we should perhaps block until queued traces are flushed? - - Trace([](FdRenderpassDataSource::TraceContext ctx) { - auto packet = ctx.NewTracePacket(); - packet->Finalize(); - ctx.Flush(); - }); - } }; PERFETTO_DECLARE_DATA_SOURCE_STATIC_MEMBERS(FdRenderpassDataSource); diff --git a/src/intel/ds/intel_driver_ds.cc b/src/intel/ds/intel_driver_ds.cc index 42b0ac8d943..d7195155a38 100644 --- a/src/intel/ds/intel_driver_ds.cc +++ b/src/intel/ds/intel_driver_ds.cc @@ -37,6 +37,7 @@ #ifdef HAVE_PERFETTO #include "util/perf/u_perfetto.h" +#include "util/perf/u_perfetto_renderpass.h" #include "intel_tracepoints_perfetto.h" @@ -100,38 +101,8 @@ struct IntelRenderpassTraits : public perfetto::DefaultDataSourceTraits { using IncrementalStateType = IntelRenderpassIncrementalState; }; -class IntelRenderpassDataSource : public perfetto::DataSource { -public: - void OnSetup(const SetupArgs &) override - { - // Use this callback to apply any custom configuration to your data source - // based on the TraceConfig in SetupArgs. - } - - void OnStart(const StartArgs &) override - { - // This notification can be used to initialize the GPU driver, enable - // counters, etc. StartArgs will contains the DataSourceDescriptor, - // which can be extended. - u_trace_perfetto_start(); - PERFETTO_LOG("Tracing started"); - } - - void OnStop(const StopArgs &) override - { - PERFETTO_LOG("Tracing stopped"); - - // Undo any initialization done in OnStart. - u_trace_perfetto_stop(); - // TODO we should perhaps block until queued traces are flushed? - - Trace([](IntelRenderpassDataSource::TraceContext ctx) { - auto packet = ctx.NewTracePacket(); - packet->Finalize(); - ctx.Flush(); - }); - } +class IntelRenderpassDataSource : public MesaRenderpassDataSource { }; PERFETTO_DECLARE_DATA_SOURCE_STATIC_MEMBERS(IntelRenderpassDataSource); diff --git a/src/util/perf/u_perfetto_renderpass.h b/src/util/perf/u_perfetto_renderpass.h new file mode 100644 index 00000000000..0491d8c38b4 --- /dev/null +++ b/src/util/perf/u_perfetto_renderpass.h @@ -0,0 +1,64 @@ +/* + * Copyright © 2023 Google LLC + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include "perfetto.h" + +#include "util/perf/u_trace.h" + +using perfetto::DataSource; +template +class MesaRenderpassDataSource + : public perfetto::DataSource { + public: + void OnSetup(const perfetto::DataSourceBase::SetupArgs &) override + { + // Use this callback to apply any custom configuration to your data + // source based on the TraceConfig in SetupArgs. + } + + void OnStart(const perfetto::DataSourceBase::StartArgs &) override + { + // This notification can be used to initialize the GPU driver, enable + // counters, etc. StartArgs will contains the DataSourceDescriptor, + // which can be extended. + u_trace_perfetto_start(); + PERFETTO_LOG("Tracing started"); + } + + void OnStop(const perfetto::DataSourceBase::StopArgs &) override + { + PERFETTO_LOG("Tracing stopped"); + + // Undo any initialization done in OnStart. + u_trace_perfetto_stop(); + // TODO we should perhaps block until queued traces are flushed? + + static_cast(this)->Trace([](auto ctx) { + auto packet = ctx.NewTracePacket(); + packet->Finalize(); + ctx.Flush(); + }); + } +}; + +/* Begin the C API section. */