Flutter Engine
The Flutter Engine
Classes | Public Member Functions | Private Member Functions | Friends | List of all members
impeller::GPUTracerVK Class Referenceabstract

A class that uses timestamp queries to record the approximate GPU execution time. More...

#include <gpu_tracer_vk.h>

Inheritance diagram for impeller::GPUTracerVK:

Public Member Functions

 GPUTracerVK (std::weak_ptr< ContextVK > context, bool enable_gpu_tracing)
 
 ~GPUTracerVK ()=default
 
std::unique_ptr< GPUProbeCreateGPUProbe ()
 Create a GPUProbe to trace the execution of a command buffer on the GPU. More...
 
void MarkFrameStart ()
 Signal the start of a frame workload. More...
 
void MarkFrameEnd ()
 Signal the end of a frame workload. More...
 
bool IsEnabled () const
 
void InitializeQueryPool (const ContextVK &context)
 Initialize the set of query pools. More...
 

Private Member Functions

size_t current_state_ IPLR_GUARDED_BY (trace_state_mutex_)=0u
 

Friends

class GPUProbe
 

Detailed Description

A class that uses timestamp queries to record the approximate GPU execution time.

To enable, add the following metadata to the application's Android manifest: <meta-data android:name="io.flutter.embedding.android.EnableVulkanGPUTracing" android:value="false" />

Definition at line 26 of file gpu_tracer_vk.h.

Constructor & Destructor Documentation

◆ GPUTracerVK()

impeller::GPUTracerVK::GPUTracerVK ( std::weak_ptr< ContextVK context,
bool  enable_gpu_tracing 
)

Definition at line 25 of file gpu_tracer_vk.cc.

27 : context_(std::move(context)) {
28 if (!enable_gpu_tracing) {
29 return;
30 }
31 timestamp_period_ = context_.lock()
32 ->GetDeviceHolder()
33 ->GetPhysicalDevice()
34 .getProperties()
35 .limits.timestampPeriod;
36 if (timestamp_period_ <= 0) {
37 // The device does not support timestamp queries.
38 return;
39 }
40// Disable tracing in release mode.
41#ifdef IMPELLER_DEBUG
42 enabled_ = true;
43#endif // IMPELLER_DEBUG
44}

◆ ~GPUTracerVK()

impeller::GPUTracerVK::~GPUTracerVK ( )
default

Member Function Documentation

◆ CreateGPUProbe()

std::unique_ptr< GPUProbe > impeller::GPUTracerVK::CreateGPUProbe ( )

Create a GPUProbe to trace the execution of a command buffer on the GPU.

Definition at line 108 of file gpu_tracer_vk.cc.

108 {
109 return std::make_unique<GPUProbe>(weak_from_this());
110}

◆ InitializeQueryPool()

void impeller::GPUTracerVK::InitializeQueryPool ( const ContextVK context)

Initialize the set of query pools.

Definition at line 46 of file gpu_tracer_vk.cc.

46 {
47 if (!enabled_) {
48 return;
49 }
50 Lock lock(trace_state_mutex_);
51 std::shared_ptr<CommandBuffer> buffer = context.CreateCommandBuffer();
52 CommandBufferVK& buffer_vk = CommandBufferVK::Cast(*buffer);
53
54 for (auto i = 0u; i < kTraceStatesSize; i++) {
55 vk::QueryPoolCreateInfo info;
56 info.queryCount = kPoolSize;
57 info.queryType = vk::QueryType::eTimestamp;
58
59 auto [status, pool] = context.GetDevice().createQueryPoolUnique(info);
60 if (status != vk::Result::eSuccess) {
61 VALIDATION_LOG << "Failed to create query pool.";
62 return;
63 }
64 trace_states_[i].query_pool = std::move(pool);
65 buffer_vk.GetEncoder()->GetCommandBuffer().resetQueryPool(
66 trace_states_[i].query_pool.get(), 0, kPoolSize);
67 }
68 if (!context.GetCommandQueue()->Submit({buffer}).ok()) {
69 VALIDATION_LOG << "Failed to reset query pool for trace events.";
70 enabled_ = false;
71 }
72}
AutoreleasePool pool
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
static CommandBufferVK & Cast(CommandBuffer &base)
Definition: backend_cast.h:13
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126
static constexpr uint32_t kPoolSize
#define VALIDATION_LOG
Definition: validation.h:73

◆ IPLR_GUARDED_BY()

size_t current_state_ impeller::GPUTracerVK::IPLR_GUARDED_BY ( trace_state_mutex_  )
privatepure virtual

◆ IsEnabled()

bool impeller::GPUTracerVK::IsEnabled ( ) const

Definition at line 74 of file gpu_tracer_vk.cc.

74 {
75 return enabled_;
76}

◆ MarkFrameEnd()

void impeller::GPUTracerVK::MarkFrameEnd ( )

Signal the end of a frame workload.

Definition at line 87 of file gpu_tracer_vk.cc.

87 {
88 in_frame_ = false;
89
90 if (!enabled_) {
91 return;
92 }
93
94 Lock lock(trace_state_mutex_);
95 current_state_ = (current_state_ + 1) % kTraceStatesSize;
96
97 auto& state = trace_states_[current_state_];
98 // If there are still pending buffers on the trace state we're switching to,
99 // that means that a cmd buffer we were relying on to signal this likely
100 // never finished. This shouldn't happen unless there is a bug in the
101 // encoder logic. We set it to zero anyway to prevent a validation error
102 // from becoming a memory leak.
103 FML_DCHECK(state.pending_buffers == 0u);
104 state.pending_buffers = 0;
105 state.current_index = 0;
106}
AtkStateType state
#define FML_DCHECK(condition)
Definition: logging.h:103

◆ MarkFrameStart()

void impeller::GPUTracerVK::MarkFrameStart ( )

Signal the start of a frame workload.

   Any cmd buffers that are created after this call and before
   [MarkFrameEnd] will be attributed to the current frame. 

Definition at line 78 of file gpu_tracer_vk.cc.

78 {
79 if (!enabled_) {
80 return;
81 }
82 FML_DCHECK(!in_frame_);
83 in_frame_ = true;
84 raster_thread_id_ = std::this_thread::get_id();
85}

Friends And Related Function Documentation

◆ GPUProbe

friend class GPUProbe
friend

Definition at line 52 of file gpu_tracer_vk.h.


The documentation for this class was generated from the following files: