From 67698c27bb4afc7923a15ae16bf7d817b3705072 Mon Sep 17 00:00:00 2001 From: blocksmith314 Date: Sun, 15 Nov 2026 15:23:55 +0800 Subject: [PATCH] feat(ui): add optional performance log panel Add a View > Performance log toggle (persisted with QSettings) that shows a bottom dock with a read-only, monospace QPlainTextEdit capped at 2000 lines, plus Clear/Copy buttons. Instrumentation stays behind a single boolean: open file (probe/demux/ analyze/total), seek and step (seek/decode/display), and NAL selection (analyze/render). Nothing is timed or formatted while the panel is hidden. Fixes #17 --- README.md | 1 + README_CN.md | 1 + mainwindow.cpp | 114 ++++++++++++++++++++++++++++++++++++++++++++++ mainwindow.h | 9 ++++ test/test_gui.cpp | 48 +++++++++++++++++++ 5 files changed, 173 insertions(+) diff --git a/README.md b/README.md index 7151c5b..155d056 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,7 @@ the player jumps to the frame that contains it. - Detailed view for SPS/PPS/VPS fields, SEI payloads and slice information - Frame-type colour coding and linked highlighting between table and player - Player position shown as frame number or time (switchable, persisted) +- Optional performance log (View -> Performance log) with per-interaction timings ### Playback diff --git a/README_CN.md b/README_CN.md index 7fae7e4..accc1bf 100644 --- a/README_CN.md +++ b/README_CN.md @@ -27,6 +27,7 @@ Digital Image Analyzer 是一款免费开源的 **H.264/AVC 与 H.265/HEVC 码 - **分析容器文件**(MP4/MOV/MKV/TS),无需转成 Annex B - **逐帧播放**,把码流结构和画面直接对应起来 - 播放进度可在**帧号与时间**之间切换(选择会被记住) +- 可选的**性能日志**(查看 → Performance log),记录每次交互耗时 ## 适合谁用? diff --git a/mainwindow.cpp b/mainwindow.cpp index 1c60b0c..53bb63d 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -1,8 +1,10 @@ #include "mainwindow.h" #include +#include #include #include +#include #include #include #include @@ -10,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -21,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -30,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -316,6 +321,15 @@ void MainWindow::SetupUi() { connect(bottomSplit, &QSplitter::splitterMoved, this, [this](int, int) { SyncSplitterWidths(false); }); + QMenu* viewMenu = menuBar()->addMenu("View"); + perf_action_ = viewMenu->addAction("Performance log"); + perf_action_->setCheckable(true); + perf_action_->setChecked(QSettings().value("perfLogVisible", false).toBool()); + connect(perf_action_, &QAction::toggled, this, + &MainWindow::SetPerfLogVisible); + + SetupPerfLog(); + QMenu* helpMenu = menuBar()->addMenu("Help"); QAction* shortcutsAct = helpMenu->addAction("Keyboard Shortcuts"); connect(shortcutsAct, &QAction::triggered, this, &MainWindow::ShowShortcuts); @@ -360,6 +374,58 @@ void MainWindow::OpenFile() { } } +void MainWindow::SetupPerfLog() { + perf_dock_ = new QDockWidget("Performance log", this); + perf_dock_->setObjectName("perfLogDock"); + perf_dock_->setAllowedAreas(Qt::BottomDockWidgetArea); + + auto* panel = new QWidget(perf_dock_); + auto* layout = new QVBoxLayout(panel); + layout->setContentsMargins(4, 4, 4, 4); + layout->setSpacing(4); + + perf_log_ = new QPlainTextEdit(panel); + perf_log_->setObjectName("perfLog"); + perf_log_->setReadOnly(true); + perf_log_->setMaximumBlockCount(2000); + perf_log_->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont)); + layout->addWidget(perf_log_, 1); + + auto* buttons = new QHBoxLayout(); + auto* clear_button = new QPushButton("Clear", panel); + auto* copy_button = new QPushButton("Copy", panel); + connect(clear_button, &QPushButton::clicked, perf_log_, + &QPlainTextEdit::clear); + connect(copy_button, &QPushButton::clicked, this, [this]() { + QGuiApplication::clipboard()->setText(perf_log_->toPlainText()); + }); + buttons->addWidget(clear_button); + buttons->addWidget(copy_button); + buttons->addStretch(1); + layout->addLayout(buttons); + + perf_dock_->setWidget(panel); + addDockWidget(Qt::BottomDockWidgetArea, perf_dock_); + perf_log_enabled_ = perf_action_ && perf_action_->isChecked(); + perf_dock_->setVisible(perf_log_enabled_); +} + +void MainWindow::SetPerfLogVisible(bool visible) { + perf_log_enabled_ = visible; + if (perf_dock_) { + perf_dock_->setVisible(visible); + } + QSettings().setValue("perfLogVisible", visible); +} + +void MainWindow::AppendPerf(const QString& line) { + if (!perf_log_enabled_ || !perf_log_) { + return; + } + perf_log_->appendPlainText(QString("%1 %2").arg( + QTime::currentTime().toString("HH:mm:ss.zzz"), line)); +} + void MainWindow::ShowShortcuts() { const auto key = [](QKeySequence::StandardKey standard) { return QKeySequence(standard).toString(QKeySequence::NativeText); @@ -505,6 +571,15 @@ bool MainWindow::LoadFile(const QString& path) { } const qint64 total_ms = probeMs + demuxMs + analyze_ms + timer.restart(); + if (perf_log_enabled_) { + AppendPerf( + QString("open %1 probe=%2ms demux=%3ms analyze=%4ms total=%5ms") + .arg(QFileInfo(path).fileName()) + .arg(probeMs) + .arg(demuxMs) + .arg(analyze_ms) + .arg(total_ms)); + } if (time_info_label_) { time_info_label_->setText( QString("Loaded in %1 s (probe %2 s, read %3 s, analyze %4 s) ") @@ -765,6 +840,14 @@ void MainWindow::ShowFrameAt(int idx) { return; } + const bool perf = perf_log_enabled_; + QElapsedTimer perf_timer; + qint64 seek_ms = 0; + qint64 decode_ms = 0; + if (perf) { + perf_timer.start(); + } + // Decode sequentially when moving forward by one; otherwise seek. const bool jump = (idx < current_frame_index_ || idx > current_frame_index_ + 1); @@ -772,6 +855,9 @@ void MainWindow::ShowFrameAt(int idx) { if (!player_decoder_.SeekToFrame(idx)) { return; } + if (perf) { + seek_ms = perf_timer.restart(); + } } DecodedFrame frame; @@ -782,9 +868,24 @@ void MainWindow::ShowFrameAt(int idx) { play_btn_->setText("Play"); return; } + if (perf) { + decode_ms = perf_timer.restart(); + } current_frame_index_ = idx; current_pts_ = frame.pts_sec; ShowFrame(frame.image, idx); + if (perf) { + const qint64 display_ms = perf_timer.elapsed(); + AppendPerf( + QString("%1 %2 frame=%3 total=%4ms seek=%5 decode=%6 display=%7") + .arg(jump ? "seek " : "step ") + .arg(QFileInfo(QString::fromStdString(current_path_)).fileName()) + .arg(idx) + .arg(seek_ms + decode_ms + display_ms) + .arg(seek_ms) + .arg(decode_ms) + .arg(display_ms)); + } if (jump) { has_pending_ = false; @@ -972,9 +1073,22 @@ void MainWindow::OnNalSelected(int idx) { return; } + const bool perf = perf_log_enabled_; + QElapsedTimer perf_timer; + if (perf) { + perf_timer.start(); + } NALAnalysis analysis = analyzer_.AnalyzeOne( nals[(size_t)idx], parser_.NalData(nals[(size_t)idx])); details_->setPlainText(QString::fromStdString(analysis.details)); + if (perf) { + AppendPerf( + QString("nal %1 row=%2 analyze=%3ms render=%4ms") + .arg(QFileInfo(QString::fromStdString(current_path_)).fileName()) + .arg(idx) + .arg(perf_timer.restart()) + .arg(perf_timer.elapsed())); + } const int f_idx = nals[(size_t)idx].frame_index; if (f_idx >= 0 && f_idx < total_frames_) { diff --git a/mainwindow.h b/mainwindow.h index b337708..3e217a6 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -24,6 +24,8 @@ class AudioPlayer; class NalListModel; +class QDockWidget; +class QPlainTextEdit; class QSplitter; class MainWindow : public QMainWindow { @@ -55,6 +57,7 @@ class MainWindow : public QMainWindow { void ShowAbout(); void ShowShortcuts(); void UpdatePositionLabel(); + void SetPerfLogVisible(bool visible); private: enum class ProgressMode { kFrames, kTime }; @@ -65,6 +68,8 @@ class MainWindow : public QMainWindow { void BuildNalList(); void UpdateStats(); double SpsFrameRate() const; + void SetupPerfLog(); + void AppendPerf(const QString& line); void DecodeThumbnails(); void LoadRecentFiles(); void SaveRecentFiles(); @@ -115,6 +120,10 @@ class MainWindow : public QMainWindow { QComboBox* speed_combo_ = nullptr; QSpinBox* step_spin_ = nullptr; QComboBox* progress_mode_combo_ = nullptr; + QDockWidget* perf_dock_ = nullptr; + QPlainTextEdit* perf_log_ = nullptr; + QAction* perf_action_ = nullptr; + bool perf_log_enabled_ = false; ProgressMode progress_mode_ = ProgressMode::kFrames; bool is_playing_ = false; diff --git a/test/test_gui.cpp b/test/test_gui.cpp index b8a3244..1c79f58 100644 --- a/test/test_gui.cpp +++ b/test/test_gui.cpp @@ -2,12 +2,14 @@ #include #include +#include #include #include #include #include #include #include +#include #include #include #include @@ -214,6 +216,52 @@ TEST(MainWindowTest, HelpMenuHasEntries) { EXPECT_TRUE(entries.contains("Report an Issue")); } +TEST(MainWindowTest, PerformanceLogTogglesAndRecords) { + if (!exists(data_path("output.h264"))) { + GTEST_SKIP() << "H.264 fixture missing"; + } + + QSettings().setValue("perfLogVisible", false); + MainWindow window; + window.show(); + QApplication::processEvents(); + + auto* dock = window.findChild("perfLogDock"); + ASSERT_NE(dock, nullptr); + EXPECT_FALSE(dock->isVisible()); + + QAction* action = nullptr; + for (QAction* menu_action : window.menuBar()->actions()) { + if (menu_action->menu() == nullptr) { + continue; + } + for (QAction* entry : menu_action->menu()->actions()) { + if (entry->text().contains("Performance log")) { + action = entry; + } + } + } + ASSERT_NE(action, nullptr); + action->setChecked(true); + QApplication::processEvents(); + EXPECT_TRUE(dock->isVisible()); + + ASSERT_TRUE( + window.LoadFile(QString::fromStdString(data_path("output.h264")))); + QApplication::processEvents(); + + auto* log = window.findChild("perfLog"); + ASSERT_NE(log, nullptr); + EXPECT_TRUE(log->toPlainText().contains("open")) + << log->toPlainText().toStdString(); + EXPECT_TRUE(log->toPlainText().contains("total=")); + + action->setChecked(false); + QApplication::processEvents(); + EXPECT_FALSE(dock->isVisible()); + QSettings().setValue("perfLogVisible", false); +} + TEST(MainWindowTest, ProgressModeSwitchesToTime) { if (!exists(data_path("sample_720p.mp4"))) { GTEST_SKIP() << "MP4 fixture missing";