Add WiVRn-native Perfetto via Perfetto SDK
Optional server profiling built on the Perfetto SDK. Adds CPU spans (compositor, encoder, network), GPU encode/copy slices from Vulkan timestamp queries (Vulkan/NVENC/VAAPI), and headset feedback markers from dump_time. WIVRN_TRACING enables tracing and selects the backend (system, inprocess, or both); WIVRN_USE_PERFETTO gates it at build time and compiles it out otherwise. WIVRN_TRACE_MONADO additionally drives Monado's percetto tracing from the same switch so WiVRn and Monado land on one timeline. Tooling: server-tracing[-monado] presets and a CI build, two Perfetto configs (WiVRn-only and full-system), a wivrn_capture.py capture wrapper, a pftrace summary script, and docs/profiling.md.
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
#include "video_encoder_ffmpeg.h"
|
||||
|
||||
#include "util/u_logging.h"
|
||||
#include "utils/wivrn_trace.h"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
@@ -83,9 +84,13 @@ std::optional<wivrn::video_encoder::data> video_encoder_ffmpeg::encode(uint8_t s
|
||||
|
||||
bool is_idr = idr_handler.get_type(frame_index) == default_idr_handler::frame_type::i;
|
||||
|
||||
push_frame(is_idr, slot);
|
||||
std::shared_ptr<AVPacket> enc_pkt(av_packet_alloc(), [](AVPacket * d) { av_packet_free(&d); });
|
||||
int err = avcodec_receive_packet(encoder_ctx.get(), enc_pkt.get());
|
||||
int err;
|
||||
{
|
||||
wivrn::trace::scope trace_send_recv(wivrn::trace::cpu_track::encoder, stream_idx, frame_index, "avcodec_send+receive");
|
||||
push_frame(is_idr, slot);
|
||||
err = avcodec_receive_packet(encoder_ctx.get(), enc_pkt.get());
|
||||
}
|
||||
if (err == 0)
|
||||
{
|
||||
return data{
|
||||
|
||||
@@ -23,7 +23,9 @@
|
||||
|
||||
#include "encoder/encoder_settings.h"
|
||||
|
||||
#include "os/os_time.h"
|
||||
#include "util/u_logging.h"
|
||||
#include "utils/wivrn_trace.h"
|
||||
#include "utils/wivrn_vk_bundle.h"
|
||||
|
||||
#include <drm_fourcc.h>
|
||||
@@ -430,9 +432,11 @@ video_encoder_va::video_encoder_va(wivrn::vk_bundle & vk,
|
||||
vk.device.bindImageMemory2(bind_info);
|
||||
}
|
||||
}
|
||||
|
||||
ts_pool = gpu_timestamp_pool(vk, vk.queue.family_index, num_slots, std::format("va encoder {} pixel copy", stream_idx));
|
||||
}
|
||||
|
||||
void video_encoder_va::present_image(vk::Image y_cbcr, vk::SemaphoreSubmitInfo, uint8_t slot, uint64_t)
|
||||
void video_encoder_va::present_image(vk::Image y_cbcr, vk::SemaphoreSubmitInfo, uint8_t slot, uint64_t frame_index)
|
||||
{
|
||||
if (vk.device.waitForFences(*in[slot].fence, true, 1'000'000'000) == vk::Result::eTimeout)
|
||||
{
|
||||
@@ -468,6 +472,8 @@ void video_encoder_va::present_image(vk::Image y_cbcr, vk::SemaphoreSubmitInfo,
|
||||
auto & cmd = in[slot].cmd;
|
||||
cmd.begin({.flags = vk::CommandBufferUsageFlagBits::eOneTimeSubmit});
|
||||
|
||||
ts_pool.cmd_begin(cmd, slot, frame_index, vk::PipelineStageFlagBits2::eTopOfPipe);
|
||||
|
||||
cmd.pipelineBarrier(
|
||||
vk::PipelineStageFlagBits::eAllCommands,
|
||||
vk::PipelineStageFlagBits::eTransfer,
|
||||
@@ -534,6 +540,8 @@ void video_encoder_va::present_image(vk::Image y_cbcr, vk::SemaphoreSubmitInfo,
|
||||
nullptr,
|
||||
im_barriers);
|
||||
|
||||
ts_pool.cmd_end(cmd, slot, vk::PipelineStageFlagBits2::eAllTransfer);
|
||||
|
||||
cmd.end();
|
||||
|
||||
std::unique_lock lock(vk.queue.mutex);
|
||||
@@ -553,6 +561,17 @@ void video_encoder_va::push_frame(bool idr, uint8_t slot)
|
||||
{
|
||||
if (vk.device.waitForFences(*in[slot].fence, true, 1'000'000'000) == vk::Result::eTimeout)
|
||||
throw std::runtime_error("timeout");
|
||||
|
||||
if (auto s = ts_pool.collect(slot))
|
||||
{
|
||||
wivrn::trace::gpu_slice(wivrn::trace::gpu_track::va_copy,
|
||||
"vk_copy_luma_chroma",
|
||||
s->begin_ns,
|
||||
s->end_ns,
|
||||
s->frame_index,
|
||||
stream_idx);
|
||||
}
|
||||
|
||||
auto & va_frame = in[slot].va_frame;
|
||||
va_frame->pict_type = idr ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P;
|
||||
int err = avcodec_send_frame(encoder_ctx.get(), va_frame.get());
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "ffmpeg_helper.h"
|
||||
#include "utils/gpu_timestamp_pool.h"
|
||||
#include "video_encoder_ffmpeg.h"
|
||||
|
||||
#include <array>
|
||||
@@ -47,6 +48,8 @@ class video_encoder_va : public video_encoder_ffmpeg
|
||||
av_buffer_ptr drm_frame_ctx;
|
||||
std::array<in_t, num_slots> in;
|
||||
|
||||
gpu_timestamp_pool ts_pool;
|
||||
|
||||
public:
|
||||
video_encoder_va(wivrn::vk_bundle &, const wivrn::encoder_settings & settings, uint8_t stream_index);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user