Separate internal Sample diagnostics
Compared with 83be436:
- move private backend, DMA, delivery, startup, and frame timing diagnostics into a dedicated InternalDiagnostics module
- keep the capture controller independent from gvfg_debug.h and private backend baseline structures
- compile the diagnostics module and diagnostic signal path only for Debug builds
- keep Release builds free of diagnostic collection and aligned with the customer-facing capture flow
Validation: git diff --check passed. MSVC Release and Debug clean builds completed successfully, and the updated Sample behavior was tested on hardware.
This commit is contained in:
@@ -93,6 +93,11 @@ set(GVFG_QT_PREVIEW_SOURCES
|
|||||||
previewwindow.ui
|
previewwindow.ui
|
||||||
)
|
)
|
||||||
|
|
||||||
|
list(APPEND GVFG_QT_PREVIEW_SOURCES
|
||||||
|
$<$<CONFIG:Debug>:${CMAKE_CURRENT_SOURCE_DIR}/internal_diagnostics.cpp>
|
||||||
|
$<$<CONFIG:Debug>:${CMAKE_CURRENT_SOURCE_DIR}/internal_diagnostics.h>
|
||||||
|
)
|
||||||
|
|
||||||
if (QT_VERSION_MAJOR GREATER_EQUAL 6)
|
if (QT_VERSION_MAJOR GREATER_EQUAL 6)
|
||||||
qt_add_executable(gvfg_qt_preview ${GVFG_QT_PREVIEW_SOURCES})
|
qt_add_executable(gvfg_qt_preview ${GVFG_QT_PREVIEW_SOURCES})
|
||||||
else()
|
else()
|
||||||
|
|||||||
@@ -7,7 +7,6 @@
|
|||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
@@ -24,11 +23,6 @@ namespace
|
|||||||
constexpr int kAudioSampleRate = 48000;
|
constexpr int kAudioSampleRate = 48000;
|
||||||
constexpr int kAudioChannelCount = 2;
|
constexpr int kAudioChannelCount = 2;
|
||||||
|
|
||||||
#if GVFG_INTERNAL_DIAGNOSTICS
|
|
||||||
QString boolText(int value) { return value ? QStringLiteral("yes") : QStringLiteral("no"); }
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
QString frameText(bool valid, int width, int height, const char *pixelFormat, int bitDepth)
|
QString frameText(bool valid, int width, int height, const char *pixelFormat, int bitDepth)
|
||||||
{
|
{
|
||||||
if (!valid || width <= 0 || height <= 0) return QStringLiteral("--");
|
if (!valid || width <= 0 || height <= 0) return QStringLiteral("--");
|
||||||
@@ -372,13 +366,13 @@ void CaptureController::startCapture(int channelIndex)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
channel.startupStartTime = std::chrono::steady_clock::now();
|
#if GVFG_INTERNAL_DIAGNOSTICS
|
||||||
|
internalDiagnostics_.beginStart(channelIndex);
|
||||||
|
#endif
|
||||||
const gvfg_status_t st = gvfg_start_channel(handle_, channelIndex);
|
const gvfg_status_t st = gvfg_start_channel(handle_, channelIndex);
|
||||||
const auto startupStartCallEnd = std::chrono::steady_clock::now();
|
#if GVFG_INTERNAL_DIAGNOSTICS
|
||||||
channel.startupStartCallMs =
|
internalDiagnostics_.finishStartCall(channelIndex);
|
||||||
std::chrono::duration<double, std::milli>(
|
#endif
|
||||||
startupStartCallEnd - channel.startupStartTime)
|
|
||||||
.count();
|
|
||||||
if (st != GVFG_OK)
|
if (st != GVFG_OK)
|
||||||
{
|
{
|
||||||
reportError(QStringLiteral("gvfg_start_channel"), st, channelIndex);
|
reportError(QStringLiteral("gvfg_start_channel"), st, channelIndex);
|
||||||
@@ -436,19 +430,16 @@ void CaptureController::startCapture(int channelIndex)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
channel.previewFailureCount = 0;
|
channel.previewFailureCount = 0;
|
||||||
channel.getFrameAverageMs.store(0.0, std::memory_order_relaxed);
|
|
||||||
channel.getFrameMaximumMs.store(0.0, std::memory_order_relaxed);
|
|
||||||
channel.getFrameWindowMaximumMs.store(0.0, std::memory_order_relaxed);
|
|
||||||
channel.getFrameSamples.store(0, std::memory_order_relaxed);
|
|
||||||
channel.audioEnabled = audioEnabled;
|
channel.audioEnabled = audioEnabled;
|
||||||
channel.videoReceived = 0; channel.videoFailed = 0;
|
channel.videoFailed = 0;
|
||||||
channel.lastLoggedPreviewFailures = 0;
|
channel.lastLoggedPreviewFailures = 0;
|
||||||
channel.lastLoggedAudioReleaseFailures = channel.lastLoggedAudioOutputFailures = 0;
|
channel.lastLoggedAudioReleaseFailures = channel.lastLoggedAudioOutputFailures = 0;
|
||||||
channel.lastDeliveryLogMs = 0;
|
channel.lastDeliveryLogMs = 0;
|
||||||
channel.previewBaseline = {};
|
channel.previewBaseline = {};
|
||||||
gvfg_preview_get_delivery_stats(channel.previewHandle, &channel.previewBaseline);
|
gvfg_preview_get_delivery_stats(channel.previewHandle, &channel.previewBaseline);
|
||||||
channel.backendBaseline = {};
|
#if GVFG_INTERNAL_DIAGNOSTICS
|
||||||
gvfg_debug_get_channel_backend_stats(handle_, channelIndex, &channel.backendBaseline);
|
internalDiagnostics_.resetChannel(handle_, channelIndex);
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(channel.audioQueueMutex);
|
std::lock_guard<std::mutex> lock(channel.audioQueueMutex);
|
||||||
channel.audioQueue.clear();
|
channel.audioQueue.clear();
|
||||||
@@ -708,54 +699,17 @@ void CaptureController::updateSignalStatus(bool queryHardware)
|
|||||||
.arg(channel.audioFormat.bits_per_sample)
|
.arg(channel.audioFormat.bits_per_sample)
|
||||||
.arg(static_cast<qulonglong>(receivedFrames));
|
.arg(static_cast<qulonglong>(receivedFrames));
|
||||||
#if GVFG_INTERNAL_DIAGNOSTICS
|
#if GVFG_INTERNAL_DIAGNOSTICS
|
||||||
gvfg_debug_backend_stats_t audioStats{};
|
internalDiagnostics_.appendAudioStatusLine(
|
||||||
if (gvfg_debug_get_channel_backend_stats(handle_, channelIndex, &audioStats) == GVFG_OK)
|
statusLines, handle_, channelIndex, receivedFrames);
|
||||||
{
|
|
||||||
statusLines << QStringLiteral("CH%1 Audio Debug | LIB events DMA=%2 Extra=%3 | LIB->SDK %4 frames | SDK->APP %5 frames")
|
|
||||||
.arg(channelIndex)
|
|
||||||
.arg(static_cast<qulonglong>(audioStats.audio_dma_event_wakes - channel.backendBaseline.audio_dma_event_wakes))
|
|
||||||
.arg(static_cast<qulonglong>(audioStats.extra_audio_event_wakes - channel.backendBaseline.extra_audio_event_wakes))
|
|
||||||
.arg(static_cast<qulonglong>(audioStats.audio_frames_from_lib - channel.backendBaseline.audio_frames_from_lib))
|
|
||||||
.arg(static_cast<qulonglong>(receivedFrames));
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
statusLines << QStringLiteral("CH%1 Preview | %2 FPS | %3")
|
statusLines << QStringLiteral("CH%1 Preview | %2 FPS | %3")
|
||||||
.arg(channelIndex)
|
.arg(channelIndex)
|
||||||
.arg(previewFps, previewFrame);
|
.arg(previewFps, previewFrame);
|
||||||
logDeliveryStatus(channelIndex);
|
logDeliveryStatus(channelIndex);
|
||||||
const uint64_t readSamples = channel.getFrameSamples.load(std::memory_order_relaxed);
|
|
||||||
statusLines << (readSamples >= 300
|
|
||||||
? QStringLiteral("CH%1 Read | avg=%2 max300=%3 max=%4 ms samples=%5")
|
|
||||||
.arg(channelIndex)
|
|
||||||
.arg(channel.getFrameAverageMs.load(std::memory_order_relaxed), 0, 'f', 3)
|
|
||||||
.arg(channel.getFrameWindowMaximumMs.load(std::memory_order_relaxed), 0, 'f', 3)
|
|
||||||
.arg(channel.getFrameMaximumMs.load(std::memory_order_relaxed), 0, 'f', 3)
|
|
||||||
.arg(static_cast<qulonglong>(readSamples))
|
|
||||||
: QStringLiteral("CH%1 Read | measuring").arg(channelIndex));
|
|
||||||
|
|
||||||
#if GVFG_INTERNAL_DIAGNOSTICS
|
#if GVFG_INTERNAL_DIAGNOSTICS
|
||||||
gvfg_debug_backend_stats_t channelStats{};
|
internalDiagnostics_.appendVideoStatusLines(
|
||||||
if (gvfg_debug_get_channel_backend_stats(handle_, channelIndex, &channelStats) == GVFG_OK)
|
statusLines, handle_, channelIndex, channel.zeroCopy);
|
||||||
{
|
|
||||||
statusLines << (channelStats.get_frame_timing_samples >= 300
|
|
||||||
? QStringLiteral("CH%1 %2 | avg=%3 max300=%4 max=%5 us samples=%6")
|
|
||||||
.arg(channelIndex)
|
|
||||||
.arg(channel.zeroCopy
|
|
||||||
? QStringLiteral("[LIB] GvfgGetVideoFrameZeroCopy")
|
|
||||||
: QStringLiteral("[LIB] GvfgGetVideoFrame"))
|
|
||||||
.arg(channelStats.get_frame_timing_average_us, 0, 'f', 3)
|
|
||||||
.arg(channelStats.get_frame_timing_max300_us, 0, 'f', 3)
|
|
||||||
.arg(channelStats.get_frame_timing_max_us, 0, 'f', 3)
|
|
||||||
.arg(static_cast<qulonglong>(channelStats.get_frame_timing_samples))
|
|
||||||
: QStringLiteral("CH%1 [LIB] GetVideoFrame | measuring").arg(channelIndex));
|
|
||||||
statusLines << QStringLiteral("CH%1 Video Debug | LIB events DMA=%2 Extra=%3 | LIB->SDK %4 frames | SDK->APP %5 frames")
|
|
||||||
.arg(channelIndex)
|
|
||||||
.arg(static_cast<qulonglong>(channelStats.video_dma_event_wakes - channel.backendBaseline.video_dma_event_wakes))
|
|
||||||
.arg(static_cast<qulonglong>(channelStats.extra_video_event_wakes - channel.backendBaseline.extra_video_event_wakes))
|
|
||||||
.arg(static_cast<qulonglong>(channelStats.video_frames_from_lib - channel.backendBaseline.video_frames_from_lib))
|
|
||||||
.arg(static_cast<qulonglong>(channel.videoReceived.load()));
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -852,16 +806,9 @@ void CaptureController::logDeliveryStatus(int channelIndex, bool finalSnapshot)
|
|||||||
|
|
||||||
void CaptureController::captureReadLoop(int channelIndex)
|
void CaptureController::captureReadLoop(int channelIndex)
|
||||||
{
|
{
|
||||||
constexpr uint64_t kTimingWarmupFrames = 30;
|
|
||||||
constexpr uint64_t kGetFrameTimingSampleFrames = 300;
|
|
||||||
|
|
||||||
std::chrono::steady_clock::time_point noFrameSince{};
|
std::chrono::steady_clock::time_point noFrameSince{};
|
||||||
std::chrono::steady_clock::time_point nextNoFrameReport{};
|
std::chrono::steady_clock::time_point nextNoFrameReport{};
|
||||||
bool captureStalledLogged = false;
|
bool captureStalledLogged = false;
|
||||||
bool startupLatencyLogged = false;
|
|
||||||
uint64_t successfulFrameCount = 0;
|
|
||||||
uint64_t getFrameTimingSampleCount = 0;
|
|
||||||
double getFrameTimingMaximumMs = 0.0;
|
|
||||||
ChannelRuntime &channel = channels_[channelIndex];
|
ChannelRuntime &channel = channels_[channelIndex];
|
||||||
while (!channel.stopRequested.load(std::memory_order_acquire))
|
while (!channel.stopRequested.load(std::memory_order_acquire))
|
||||||
{
|
{
|
||||||
@@ -876,40 +823,21 @@ void CaptureController::captureReadLoop(int channelIndex)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
gvfg_frame_t frame{};
|
gvfg_frame_t frame{};
|
||||||
|
#if GVFG_INTERNAL_DIAGNOSTICS
|
||||||
const auto getFrameStart = std::chrono::steady_clock::now();
|
const auto getFrameStart = std::chrono::steady_clock::now();
|
||||||
|
#endif
|
||||||
const gvfg_status_t st = gvfg_read_channel_frame(handle_, channelIndex, &frame, 200);
|
const gvfg_status_t st = gvfg_read_channel_frame(handle_, channelIndex, &frame, 200);
|
||||||
|
#if GVFG_INTERNAL_DIAGNOSTICS
|
||||||
const double getFrameElapsedMs =
|
const double getFrameElapsedMs =
|
||||||
std::chrono::duration<double, std::milli>(
|
std::chrono::duration<double, std::milli>(
|
||||||
std::chrono::steady_clock::now() - getFrameStart)
|
std::chrono::steady_clock::now() - getFrameStart)
|
||||||
.count();
|
.count();
|
||||||
|
#endif
|
||||||
if (st == GVFG_OK)
|
if (st == GVFG_OK)
|
||||||
{
|
{
|
||||||
channel.videoReceived.fetch_add(1);
|
#if GVFG_INTERNAL_DIAGNOSTICS
|
||||||
const bool timingWarmupComplete = ++successfulFrameCount > kTimingWarmupFrames;
|
internalDiagnostics_.recordVideoRead(channelIndex, getFrameElapsedMs);
|
||||||
if (timingWarmupComplete)
|
#endif
|
||||||
{
|
|
||||||
++getFrameTimingSampleCount;
|
|
||||||
getFrameTimingMaximumMs = (std::max)(getFrameTimingMaximumMs, getFrameElapsedMs);
|
|
||||||
const uint64_t totalSamples = channel.getFrameSamples.fetch_add(1, std::memory_order_relaxed) + 1;
|
|
||||||
const double previousAverage = channel.getFrameAverageMs.load(std::memory_order_relaxed);
|
|
||||||
channel.getFrameAverageMs.store(
|
|
||||||
previousAverage + (getFrameElapsedMs - previousAverage) / static_cast<double>(totalSamples),
|
|
||||||
std::memory_order_relaxed);
|
|
||||||
double observedMaximum = channel.getFrameMaximumMs.load(std::memory_order_relaxed);
|
|
||||||
while (getFrameElapsedMs > observedMaximum &&
|
|
||||||
!channel.getFrameMaximumMs.compare_exchange_weak(
|
|
||||||
observedMaximum, getFrameElapsedMs, std::memory_order_relaxed))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
if (totalSamples <= kGetFrameTimingSampleFrames)
|
|
||||||
channel.getFrameWindowMaximumMs.store(getFrameTimingMaximumMs, std::memory_order_relaxed);
|
|
||||||
if (getFrameTimingSampleCount >= kGetFrameTimingSampleFrames)
|
|
||||||
{
|
|
||||||
channel.getFrameWindowMaximumMs.store(getFrameTimingMaximumMs, std::memory_order_relaxed);
|
|
||||||
getFrameTimingSampleCount = 0;
|
|
||||||
getFrameTimingMaximumMs = 0.0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
noFrameSince = {};
|
noFrameSince = {};
|
||||||
nextNoFrameReport = {};
|
nextNoFrameReport = {};
|
||||||
if (!channel.frameAvailable.exchange(true, std::memory_order_acq_rel))
|
if (!channel.frameAvailable.exchange(true, std::memory_order_acq_rel))
|
||||||
@@ -950,12 +878,17 @@ void CaptureController::captureReadLoop(int channelIndex)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if GVFG_INTERNAL_DIAGNOSTICS
|
||||||
const auto previewStart = std::chrono::steady_clock::now();
|
const auto previewStart = std::chrono::steady_clock::now();
|
||||||
|
#endif
|
||||||
const gvfg_preview_status_t previewStatus =
|
const gvfg_preview_status_t previewStatus =
|
||||||
gvfg_preview_render_frame(channel.previewHandle, &previewFrame);
|
gvfg_preview_render_frame(channel.previewHandle, &previewFrame);
|
||||||
const auto previewEnd = std::chrono::steady_clock::now();
|
#if GVFG_INTERNAL_DIAGNOSTICS
|
||||||
const double previewElapsedMs =
|
const double previewElapsedMs =
|
||||||
std::chrono::duration<double, std::milli>(previewEnd - previewStart).count();
|
std::chrono::duration<double, std::milli>(
|
||||||
|
std::chrono::steady_clock::now() - previewStart)
|
||||||
|
.count();
|
||||||
|
#endif
|
||||||
if (previewStatus != GVFG_PREVIEW_OK)
|
if (previewStatus != GVFG_PREVIEW_OK)
|
||||||
{
|
{
|
||||||
++channel.videoFailed;
|
++channel.videoFailed;
|
||||||
@@ -971,35 +904,17 @@ void CaptureController::captureReadLoop(int channelIndex)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!startupLatencyLogged)
|
#if GVFG_INTERNAL_DIAGNOSTICS
|
||||||
|
const QString startupLine = internalDiagnostics_.takeStartupLatencyLine(
|
||||||
|
channelIndex, getFrameElapsedMs, previewElapsedMs, frame.frame_id);
|
||||||
|
if (!startupLine.isEmpty())
|
||||||
{
|
{
|
||||||
startupLatencyLogged = true;
|
|
||||||
const double startupLatencyMs =
|
|
||||||
std::chrono::duration<double, std::milli>(
|
|
||||||
previewEnd - channel.startupStartTime)
|
|
||||||
.count();
|
|
||||||
const double startCallMs = channel.startupStartCallMs;
|
|
||||||
const double firstReadMs = getFrameElapsedMs;
|
|
||||||
const double firstRenderFrameMs = previewElapsedMs;
|
|
||||||
const uint64_t startupFrameId = frame.frame_id;
|
|
||||||
QMetaObject::invokeMethod(
|
QMetaObject::invokeMethod(
|
||||||
this,
|
this,
|
||||||
[this, channelIndex, startCallMs, firstReadMs,
|
[this, startupLine]() { appendLog(startupLine); },
|
||||||
firstRenderFrameMs, startupLatencyMs, startupFrameId]()
|
|
||||||
{
|
|
||||||
appendLog(QStringLiteral("CH%1 Startup latency | Start -> start_channel return=%2 ms | "
|
|
||||||
"first read_frame call -> return=%3 ms | "
|
|
||||||
"first render_frame call -> return=%4 ms | "
|
|
||||||
"Start -> first render_frame return=%5 ms | SDK_frame_id=%6")
|
|
||||||
.arg(channelIndex)
|
|
||||||
.arg(startCallMs, 0, 'f', 3)
|
|
||||||
.arg(firstReadMs, 0, 'f', 3)
|
|
||||||
.arg(firstRenderFrameMs, 0, 'f', 3)
|
|
||||||
.arg(startupLatencyMs, 0, 'f', 3)
|
|
||||||
.arg(static_cast<qulonglong>(startupFrameId)));
|
|
||||||
},
|
|
||||||
Qt::QueuedConnection);
|
Qt::QueuedConnection);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
if (channel.previewFailureCount != 0)
|
if (channel.previewFailureCount != 0)
|
||||||
{
|
{
|
||||||
const uint64_t failures = channel.previewFailureCount;
|
const uint64_t failures = channel.previewFailureCount;
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#if GVFG_INTERNAL_DIAGNOSTICS
|
||||||
|
#include "internal_diagnostics.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <gvfg_capture.h>
|
#include <gvfg_capture.h>
|
||||||
#include <gvfg_debug.h>
|
|
||||||
#include <gvfg_preview.h>
|
#include <gvfg_preview.h>
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
@@ -56,7 +59,9 @@ signals:
|
|||||||
void statusChanged(const QString &text);
|
void statusChanged(const QString &text);
|
||||||
void sdiInfoChanged(const QString &text);
|
void sdiInfoChanged(const QString &text);
|
||||||
void logMessage(const QString &message);
|
void logMessage(const QString &message);
|
||||||
|
#if GVFG_INTERNAL_DIAGNOSTICS
|
||||||
void diagnosticMessage(const QString &message);
|
void diagnosticMessage(const QString &message);
|
||||||
|
#endif
|
||||||
void previewSourceSizeChanged(int channel, int width, int height);
|
void previewSourceSizeChanged(int channel, int width, int height);
|
||||||
void previewShowRequested(int channel);
|
void previewShowRequested(int channel);
|
||||||
void previewCloseRequested(int channel);
|
void previewCloseRequested(int channel);
|
||||||
@@ -88,16 +93,11 @@ private:
|
|||||||
gvfg_audio_format_t audioFormat{};
|
gvfg_audio_format_t audioFormat{};
|
||||||
uint64_t audioReceivedFrames = 0;
|
uint64_t audioReceivedFrames = 0;
|
||||||
uint64_t audioReleaseFailedFrames = 0, audioOutputFailedFrames = 0;
|
uint64_t audioReleaseFailedFrames = 0, audioOutputFailedFrames = 0;
|
||||||
std::atomic<uint64_t> videoReceived{0}, videoFailed{0};
|
std::atomic<uint64_t> videoFailed{0};
|
||||||
gvfg_preview_delivery_stats_t previewBaseline{};
|
gvfg_preview_delivery_stats_t previewBaseline{};
|
||||||
gvfg_debug_backend_stats_t backendBaseline{};
|
|
||||||
std::chrono::steady_clock::time_point startupStartTime{};
|
|
||||||
double startupStartCallMs = 0.0;
|
|
||||||
uint64_t lastLoggedPreviewFailures = 0;
|
uint64_t lastLoggedPreviewFailures = 0;
|
||||||
uint64_t lastLoggedAudioReleaseFailures = 0, lastLoggedAudioOutputFailures = 0;
|
uint64_t lastLoggedAudioReleaseFailures = 0, lastLoggedAudioOutputFailures = 0;
|
||||||
qint64 lastDeliveryLogMs = 0;
|
qint64 lastDeliveryLogMs = 0;
|
||||||
std::atomic<double> getFrameAverageMs{0.0}, getFrameMaximumMs{0.0}, getFrameWindowMaximumMs{0.0};
|
|
||||||
std::atomic<uint64_t> getFrameSamples{0};
|
|
||||||
uint64_t previewFailureCount = 0;
|
uint64_t previewFailureCount = 0;
|
||||||
gvfg_signal_status_t cachedSignalStatus{};
|
gvfg_signal_status_t cachedSignalStatus{};
|
||||||
bool haveCachedSignalStatus = false;
|
bool haveCachedSignalStatus = false;
|
||||||
@@ -124,6 +124,9 @@ private:
|
|||||||
gvfg_handle handle_ = nullptr;
|
gvfg_handle handle_ = nullptr;
|
||||||
int selectedDeviceIndex_ = -1;
|
int selectedDeviceIndex_ = -1;
|
||||||
std::array<ChannelRuntime, 2> channels_{};
|
std::array<ChannelRuntime, 2> channels_{};
|
||||||
|
#if GVFG_INTERNAL_DIAGNOSTICS
|
||||||
|
InternalDiagnostics internalDiagnostics_;
|
||||||
|
#endif
|
||||||
std::array<bool, 2> channelStatusVisible_{{true, true}};
|
std::array<bool, 2> channelStatusVisible_{{true, true}};
|
||||||
QTimer *runtimeStatusTimer_ = nullptr;
|
QTimer *runtimeStatusTimer_ = nullptr;
|
||||||
QString lastSignalStatusText_;
|
QString lastSignalStatusText_;
|
||||||
|
|||||||
@@ -0,0 +1,202 @@
|
|||||||
|
#include "internal_diagnostics.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
#if GVFG_INTERNAL_DIAGNOSTICS
|
||||||
|
#include <gvfg_debug.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void InternalDiagnostics::beginStart(int channel)
|
||||||
|
{
|
||||||
|
if (channel < 0 || channel >= static_cast<int>(metrics_.size()))
|
||||||
|
return;
|
||||||
|
metrics_[channel].startTime = std::chrono::steady_clock::now();
|
||||||
|
}
|
||||||
|
|
||||||
|
void InternalDiagnostics::finishStartCall(int channel)
|
||||||
|
{
|
||||||
|
if (channel < 0 || channel >= static_cast<int>(metrics_.size()))
|
||||||
|
return;
|
||||||
|
ChannelMetrics &metrics = metrics_[channel];
|
||||||
|
metrics.startCallMs = std::chrono::duration<double, std::milli>(
|
||||||
|
std::chrono::steady_clock::now() - metrics.startTime)
|
||||||
|
.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
void InternalDiagnostics::resetChannel(gvfg_handle handle, int channel)
|
||||||
|
{
|
||||||
|
if (channel < 0 || channel >= static_cast<int>(baselines_.size()))
|
||||||
|
return;
|
||||||
|
|
||||||
|
baselines_[channel] = {};
|
||||||
|
ChannelMetrics &metrics = metrics_[channel];
|
||||||
|
metrics.successfulFrames = 0;
|
||||||
|
metrics.windowSamples = 0;
|
||||||
|
metrics.windowMaximumMs = 0.0;
|
||||||
|
metrics.startupLatencyReported = false;
|
||||||
|
metrics.videoReceived.store(0, std::memory_order_relaxed);
|
||||||
|
metrics.readSamples.store(0, std::memory_order_relaxed);
|
||||||
|
metrics.readAverageMs.store(0.0, std::memory_order_relaxed);
|
||||||
|
metrics.readMaximumMs.store(0.0, std::memory_order_relaxed);
|
||||||
|
metrics.readWindowMaximumMs.store(0.0, std::memory_order_relaxed);
|
||||||
|
|
||||||
|
#if GVFG_INTERNAL_DIAGNOSTICS
|
||||||
|
gvfg_debug_backend_stats_t stats{};
|
||||||
|
if (handle != nullptr &&
|
||||||
|
gvfg_debug_get_channel_backend_stats(handle, channel, &stats) == GVFG_OK)
|
||||||
|
{
|
||||||
|
baselines_[channel] = {
|
||||||
|
stats.video_dma_event_wakes,
|
||||||
|
stats.extra_video_event_wakes,
|
||||||
|
stats.video_frames_from_lib,
|
||||||
|
stats.audio_dma_event_wakes,
|
||||||
|
stats.extra_audio_event_wakes,
|
||||||
|
stats.audio_frames_from_lib};
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
(void)handle;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void InternalDiagnostics::recordVideoRead(int channel, double elapsedMs)
|
||||||
|
{
|
||||||
|
constexpr uint64_t kTimingWarmupFrames = 30;
|
||||||
|
constexpr uint64_t kTimingWindowFrames = 300;
|
||||||
|
|
||||||
|
if (channel < 0 || channel >= static_cast<int>(metrics_.size()))
|
||||||
|
return;
|
||||||
|
|
||||||
|
ChannelMetrics &metrics = metrics_[channel];
|
||||||
|
metrics.videoReceived.fetch_add(1, std::memory_order_relaxed);
|
||||||
|
if (++metrics.successfulFrames <= kTimingWarmupFrames)
|
||||||
|
return;
|
||||||
|
|
||||||
|
++metrics.windowSamples;
|
||||||
|
metrics.windowMaximumMs = (std::max)(metrics.windowMaximumMs, elapsedMs);
|
||||||
|
const uint64_t totalSamples = metrics.readSamples.fetch_add(1, std::memory_order_relaxed) + 1;
|
||||||
|
const double previousAverage = metrics.readAverageMs.load(std::memory_order_relaxed);
|
||||||
|
metrics.readAverageMs.store(
|
||||||
|
previousAverage + (elapsedMs - previousAverage) / static_cast<double>(totalSamples),
|
||||||
|
std::memory_order_relaxed);
|
||||||
|
double observedMaximum = metrics.readMaximumMs.load(std::memory_order_relaxed);
|
||||||
|
while (elapsedMs > observedMaximum &&
|
||||||
|
!metrics.readMaximumMs.compare_exchange_weak(
|
||||||
|
observedMaximum, elapsedMs, std::memory_order_relaxed))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
if (totalSamples <= kTimingWindowFrames)
|
||||||
|
metrics.readWindowMaximumMs.store(metrics.windowMaximumMs, std::memory_order_relaxed);
|
||||||
|
if (metrics.windowSamples >= kTimingWindowFrames)
|
||||||
|
{
|
||||||
|
metrics.readWindowMaximumMs.store(metrics.windowMaximumMs, std::memory_order_relaxed);
|
||||||
|
metrics.windowSamples = 0;
|
||||||
|
metrics.windowMaximumMs = 0.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QString InternalDiagnostics::takeStartupLatencyLine(int channel,
|
||||||
|
double firstReadMs,
|
||||||
|
double firstRenderMs,
|
||||||
|
uint64_t frameId)
|
||||||
|
{
|
||||||
|
if (channel < 0 || channel >= static_cast<int>(metrics_.size()))
|
||||||
|
return {};
|
||||||
|
|
||||||
|
ChannelMetrics &metrics = metrics_[channel];
|
||||||
|
if (metrics.startupLatencyReported)
|
||||||
|
return {};
|
||||||
|
metrics.startupLatencyReported = true;
|
||||||
|
|
||||||
|
const double totalMs = std::chrono::duration<double, std::milli>(
|
||||||
|
std::chrono::steady_clock::now() - metrics.startTime)
|
||||||
|
.count();
|
||||||
|
return QStringLiteral("CH%1 Startup latency | Start -> start_channel return=%2 ms | "
|
||||||
|
"first read_frame call -> return=%3 ms | "
|
||||||
|
"first render_frame call -> return=%4 ms | "
|
||||||
|
"Start -> first render_frame return=%5 ms | SDK_frame_id=%6")
|
||||||
|
.arg(channel)
|
||||||
|
.arg(metrics.startCallMs, 0, 'f', 3)
|
||||||
|
.arg(firstReadMs, 0, 'f', 3)
|
||||||
|
.arg(firstRenderMs, 0, 'f', 3)
|
||||||
|
.arg(totalMs, 0, 'f', 3)
|
||||||
|
.arg(static_cast<qulonglong>(frameId));
|
||||||
|
}
|
||||||
|
|
||||||
|
void InternalDiagnostics::appendAudioStatusLine(QStringList &lines,
|
||||||
|
gvfg_handle handle,
|
||||||
|
int channel,
|
||||||
|
uint64_t audioReceived) const
|
||||||
|
{
|
||||||
|
#if GVFG_INTERNAL_DIAGNOSTICS
|
||||||
|
if (handle == nullptr || channel < 0 || channel >= static_cast<int>(baselines_.size()))
|
||||||
|
return;
|
||||||
|
|
||||||
|
gvfg_debug_backend_stats_t stats{};
|
||||||
|
if (gvfg_debug_get_channel_backend_stats(handle, channel, &stats) != GVFG_OK)
|
||||||
|
return;
|
||||||
|
|
||||||
|
const BackendBaseline &baseline = baselines_[channel];
|
||||||
|
lines << QStringLiteral("CH%1 Audio Debug | LIB events DMA=%2 Extra=%3 | LIB->SDK %4 frames | SDK->APP %5 frames")
|
||||||
|
.arg(channel)
|
||||||
|
.arg(static_cast<qulonglong>(stats.audio_dma_event_wakes - baseline.audioDmaEventWakes))
|
||||||
|
.arg(static_cast<qulonglong>(stats.extra_audio_event_wakes - baseline.extraAudioEventWakes))
|
||||||
|
.arg(static_cast<qulonglong>(stats.audio_frames_from_lib - baseline.audioFramesFromLibrary))
|
||||||
|
.arg(static_cast<qulonglong>(audioReceived));
|
||||||
|
#else
|
||||||
|
(void)lines;
|
||||||
|
(void)handle;
|
||||||
|
(void)channel;
|
||||||
|
(void)audioReceived;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void InternalDiagnostics::appendVideoStatusLines(QStringList &lines,
|
||||||
|
gvfg_handle handle,
|
||||||
|
int channel,
|
||||||
|
bool zeroCopy) const
|
||||||
|
{
|
||||||
|
#if GVFG_INTERNAL_DIAGNOSTICS
|
||||||
|
if (handle == nullptr || channel < 0 || channel >= static_cast<int>(baselines_.size()))
|
||||||
|
return;
|
||||||
|
|
||||||
|
const ChannelMetrics &metrics = metrics_[channel];
|
||||||
|
const uint64_t readSamples = metrics.readSamples.load(std::memory_order_relaxed);
|
||||||
|
lines << (readSamples >= 300
|
||||||
|
? QStringLiteral("CH%1 Read | avg=%2 max300=%3 max=%4 ms samples=%5")
|
||||||
|
.arg(channel)
|
||||||
|
.arg(metrics.readAverageMs.load(std::memory_order_relaxed), 0, 'f', 3)
|
||||||
|
.arg(metrics.readWindowMaximumMs.load(std::memory_order_relaxed), 0, 'f', 3)
|
||||||
|
.arg(metrics.readMaximumMs.load(std::memory_order_relaxed), 0, 'f', 3)
|
||||||
|
.arg(static_cast<qulonglong>(readSamples))
|
||||||
|
: QStringLiteral("CH%1 Read | measuring").arg(channel));
|
||||||
|
|
||||||
|
gvfg_debug_backend_stats_t stats{};
|
||||||
|
if (gvfg_debug_get_channel_backend_stats(handle, channel, &stats) != GVFG_OK)
|
||||||
|
return;
|
||||||
|
|
||||||
|
const BackendBaseline &baseline = baselines_[channel];
|
||||||
|
|
||||||
|
lines << (stats.get_frame_timing_samples >= 300
|
||||||
|
? QStringLiteral("CH%1 %2 | avg=%3 max300=%4 max=%5 us samples=%6")
|
||||||
|
.arg(channel)
|
||||||
|
.arg(zeroCopy
|
||||||
|
? QStringLiteral("[LIB] GvfgGetVideoFrameZeroCopy")
|
||||||
|
: QStringLiteral("[LIB] GvfgGetVideoFrame"))
|
||||||
|
.arg(stats.get_frame_timing_average_us, 0, 'f', 3)
|
||||||
|
.arg(stats.get_frame_timing_max300_us, 0, 'f', 3)
|
||||||
|
.arg(stats.get_frame_timing_max_us, 0, 'f', 3)
|
||||||
|
.arg(static_cast<qulonglong>(stats.get_frame_timing_samples))
|
||||||
|
: QStringLiteral("CH%1 [LIB] GetVideoFrame | measuring").arg(channel));
|
||||||
|
lines << QStringLiteral("CH%1 Video Debug | LIB events DMA=%2 Extra=%3 | LIB->SDK %4 frames | SDK->APP %5 frames")
|
||||||
|
.arg(channel)
|
||||||
|
.arg(static_cast<qulonglong>(stats.video_dma_event_wakes - baseline.videoDmaEventWakes))
|
||||||
|
.arg(static_cast<qulonglong>(stats.extra_video_event_wakes - baseline.extraVideoEventWakes))
|
||||||
|
.arg(static_cast<qulonglong>(stats.video_frames_from_lib - baseline.videoFramesFromLibrary))
|
||||||
|
.arg(static_cast<qulonglong>(metrics.videoReceived.load(std::memory_order_relaxed)));
|
||||||
|
#else
|
||||||
|
(void)lines;
|
||||||
|
(void)handle;
|
||||||
|
(void)channel;
|
||||||
|
(void)zeroCopy;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <gvfg_capture.h>
|
||||||
|
|
||||||
|
#include <QStringList>
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
#include <atomic>
|
||||||
|
#include <chrono>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
class InternalDiagnostics final
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void beginStart(int channel);
|
||||||
|
void finishStartCall(int channel);
|
||||||
|
void resetChannel(gvfg_handle handle, int channel);
|
||||||
|
void recordVideoRead(int channel, double elapsedMs);
|
||||||
|
QString takeStartupLatencyLine(int channel,
|
||||||
|
double firstReadMs,
|
||||||
|
double firstRenderMs,
|
||||||
|
uint64_t frameId);
|
||||||
|
void appendAudioStatusLine(QStringList &lines,
|
||||||
|
gvfg_handle handle,
|
||||||
|
int channel,
|
||||||
|
uint64_t audioReceived) const;
|
||||||
|
void appendVideoStatusLines(QStringList &lines,
|
||||||
|
gvfg_handle handle,
|
||||||
|
int channel,
|
||||||
|
bool zeroCopy) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
struct BackendBaseline
|
||||||
|
{
|
||||||
|
uint64_t videoDmaEventWakes = 0;
|
||||||
|
uint64_t extraVideoEventWakes = 0;
|
||||||
|
uint64_t videoFramesFromLibrary = 0;
|
||||||
|
uint64_t audioDmaEventWakes = 0;
|
||||||
|
uint64_t extraAudioEventWakes = 0;
|
||||||
|
uint64_t audioFramesFromLibrary = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ChannelMetrics
|
||||||
|
{
|
||||||
|
std::chrono::steady_clock::time_point startTime{};
|
||||||
|
double startCallMs = 0.0;
|
||||||
|
uint64_t successfulFrames = 0;
|
||||||
|
uint64_t windowSamples = 0;
|
||||||
|
double windowMaximumMs = 0.0;
|
||||||
|
bool startupLatencyReported = false;
|
||||||
|
std::atomic<uint64_t> videoReceived{0};
|
||||||
|
std::atomic<uint64_t> readSamples{0};
|
||||||
|
std::atomic<double> readAverageMs{0.0};
|
||||||
|
std::atomic<double> readMaximumMs{0.0};
|
||||||
|
std::atomic<double> readWindowMaximumMs{0.0};
|
||||||
|
};
|
||||||
|
|
||||||
|
std::array<BackendBaseline, 2> baselines_{};
|
||||||
|
std::array<ChannelMetrics, 2> metrics_{};
|
||||||
|
};
|
||||||
@@ -76,8 +76,10 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
connect(controller_, &CaptureController::statusChanged, ui_->statusLabel, &QLabel::setText);
|
connect(controller_, &CaptureController::statusChanged, ui_->statusLabel, &QLabel::setText);
|
||||||
connect(controller_, &CaptureController::sdiInfoChanged, ui_->sdiInfoLabel, &QLabel::setText);
|
connect(controller_, &CaptureController::sdiInfoChanged, ui_->sdiInfoLabel, &QLabel::setText);
|
||||||
connect(controller_, &CaptureController::logMessage, log_, &SampleLog::append, Qt::QueuedConnection);
|
connect(controller_, &CaptureController::logMessage, log_, &SampleLog::append, Qt::QueuedConnection);
|
||||||
|
#if GVFG_INTERNAL_DIAGNOSTICS
|
||||||
connect(controller_, &CaptureController::diagnosticMessage, log_, &SampleLog::appendDiagnostic,
|
connect(controller_, &CaptureController::diagnosticMessage, log_, &SampleLog::appendDiagnostic,
|
||||||
Qt::QueuedConnection);
|
Qt::QueuedConnection);
|
||||||
|
#endif
|
||||||
connect(log_, &SampleLog::lineReady, this, &MainWindow::appendLogLine);
|
connect(log_, &SampleLog::lineReady, this, &MainWindow::appendLogLine);
|
||||||
connect(controller_, &CaptureController::previewSourceSizeChanged, this,
|
connect(controller_, &CaptureController::previewSourceSizeChanged, this,
|
||||||
[this](int channel, int width, int height) {
|
[this](int channel, int width, int height) {
|
||||||
|
|||||||
Reference in New Issue
Block a user