QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
GstHwPathTelemetry.cc
Go to the documentation of this file.
2
3#include <array>
4#include <atomic>
5
7
8namespace {
9
10constexpr size_t kCounterCount = size_t(Counter::Count);
11std::array<std::array<std::atomic<quint64>, kCounterCount>, GstHw::kPathCount> s_counters{};
12
13std::array<std::atomic<quint64>, GstHw::kPathCount> s_mapDurationUsEwma{};
14
15constexpr size_t kReasonCount = size_t(HwFallbackReason::Count);
16std::array<std::array<std::atomic<quint64>, kReasonCount>, GstHw::kPathCount> s_fallbackReasons{};
17
18} // namespace
19
20void record(HwVideoBufferPath path, Counter counter) noexcept
21{
22 s_counters[size_t(path)][size_t(counter)].fetch_add(1, std::memory_order_relaxed);
23}
24
25void recordMapDuration(HwVideoBufferPath path, qint64 nsecs) noexcept
26{
27 if (nsecs < 0) {
28 return;
29 }
30 // EWMA in microseconds (alpha = 1/8); seed on the first sample so the average tracks immediately.
31 const quint64 sampleUs = static_cast<quint64>(nsecs) / 1000;
32 auto& ewma = s_mapDurationUsEwma[size_t(path)];
33 quint64 prev = ewma.load(std::memory_order_relaxed);
34 quint64 next;
35 do {
36 next = (prev == 0) ? sampleUs : prev - (prev >> 3) + (sampleUs >> 3);
37 } while (!ewma.compare_exchange_weak(prev, next, std::memory_order_relaxed));
38}
39
41{
42 return s_mapDurationUsEwma[size_t(path)].load(std::memory_order_relaxed);
43}
44
45void recordFallbackReason(HwVideoBufferPath attemptedPath, HwFallbackReason reason) noexcept
46{
47 s_fallbackReasons[size_t(attemptedPath)][size_t(reason)].fetch_add(1, std::memory_order_relaxed);
48}
49
51{
52 Snapshot out;
53 for (size_t path = 0; path < GstHw::kPathCount; ++path) {
54 for (size_t counter = 0; counter < kCounterCount; ++counter) {
55 out.counters[path][counter] = s_counters[path][counter].load(std::memory_order_relaxed);
56 }
57 for (size_t reason = 0; reason < kReasonCount; ++reason) {
58 out.fallbackReasons[path][reason] = s_fallbackReasons[path][reason].load(std::memory_order_relaxed);
59 }
60 }
61 return out;
62}
63
64} // namespace GstHwPathTelemetry
HwVideoBufferPath
GPU zero-copy path a frame is imported through; None means the frame takes the CPU path.
Definition GstHwTypes.h:7
Counter
Per-path event counts.
void recordFallbackReason(HwVideoBufferPath attemptedPath, HwFallbackReason reason) noexcept
Per-(path,reason) fallback accounting; lets a bug report show why a path demoted to CPU.
void recordMapDuration(HwVideoBufferPath path, qint64 nsecs) noexcept
Per-path mapTextures() wall-time, fed into an EWMA; peek returns the smoothed value in microseconds.
void record(HwVideoBufferPath path, Counter counter) noexcept
quint64 peekMapDurationUsEwma(HwVideoBufferPath path) noexcept
Snapshot snapshot() noexcept
HwFallbackReason
Specific cause a GPU path was rejected for a sample; surfaced as a per-(path,reason) breakdown.
constexpr std::size_t kPathCount
Definition GstHwTypes.h:33
Every counter and fallback reason at one instant; a reader's baseline for counts since then.
std::array< std::array< quint64, std::size_t(HwFallbackReason::Count)>, GstHw::kPathCount > fallbackReasons
std::array< std::array< quint64, std::size_t(Counter::Count)>, GstHw::kPathCount > counters