5 #include <Metal/Metal.h>
6 #include "fml/trace_event.h"
17 if (@available(ios 10.3, tvos 10.2, macos 10.15, macCatalyst 13.0, *)) {
18 Lock lock(trace_state_mutex_);
19 current_state_ = (current_state_ + 1) % 16;
24 if (@available(ios 10.3, tvos 10.2, macos 10.15, macCatalyst 13.0, *)) {
25 Lock lock(trace_state_mutex_);
26 auto current_state = current_state_;
27 trace_states_[current_state].pending_buffers += 1;
29 auto weak_self = weak_from_this();
30 [buffer addCompletedHandler:^(id<MTLCommandBuffer> buffer) {
31 auto self = weak_self.lock();
35 Lock lock(self->trace_state_mutex_);
36 auto& state =
self->trace_states_[current_state];
37 state.pending_buffers--;
38 state.smallest_timestamp = std::min(
39 state.smallest_timestamp,
static_cast<Scalar>(buffer.GPUStartTime));
40 state.largest_timestamp = std::max(
41 state.largest_timestamp,
static_cast<Scalar>(buffer.GPUEndTime));
43 if (state.pending_buffers == 0) {
45 (state.largest_timestamp - state.smallest_timestamp) * 1000;
46 state.smallest_timestamp = std::numeric_limits<float>::max();
47 state.largest_timestamp = 0;
48 FML_TRACE_COUNTER(
"flutter",
"GPUTracer",
49 reinterpret_cast<int64_t
>(
this),
50 "FrameTimeMS", gpu_ms);