* @brief Measures raw FrameReader extraction throughput (the driver pipeline, no parse). */
| 498 | * @brief Measures raw FrameReader extraction throughput (the driver pipeline, no parse). |
| 499 | */ |
| 500 | HotpathBenchmark::Result HotpathBenchmark::runDataPipeline(quint64 targetFrames, |
| 501 | double minFps, |
| 502 | double minSeconds) |
| 503 | { |
| 504 | Q_ASSERT(targetFrames > 0); |
| 505 | Q_ASSERT(minFps > 0.0); |
| 506 | Q_ASSERT(minSeconds >= 0.0); |
| 507 | |
| 508 | constexpr int kChannels = 8; |
| 509 | constexpr int kFramesPerChunk = 1000; |
| 510 | |
| 511 | const QByteArray chunk = buildChunk(kFramesPerChunk, kChannels); |
| 512 | |
| 513 | IO::FrameReader reader; |
| 514 | reader.setOperationMode(SerialStudio::QuickPlot); |
| 515 | reader.setFinishSequences({QByteArrayLiteral("\n")}); |
| 516 | |
| 517 | auto& queue = reader.queue(); |
| 518 | IO::CapturedDataPtr drained; |
| 519 | |
| 520 | using Clock = std::chrono::steady_clock; |
| 521 | const quint64 maxFrames = targetFrames + static_cast<quint64>(minSeconds * 1.0e9); |
| 522 | const quint64 maxChunks = maxFrames / kFramesPerChunk + 1; |
| 523 | |
| 524 | quint64 extracted = 0; |
| 525 | quint64 fed = 0; |
| 526 | double seconds = 0.0; |
| 527 | double spentSpin = 0.0; |
| 528 | double lastSpin = 0.0; |
| 529 | const auto start = Clock::now(); |
| 530 | for (quint64 c = 0; c < maxChunks && (fed < targetFrames || seconds < minSeconds); ++c) { |
| 531 | reader.processData(IO::makeCapturedData(chunk)); |
| 532 | |
| 533 | // code-verify off |
| 534 | while (queue.try_dequeue(drained)) |
| 535 | ++extracted; |
| 536 | // code-verify on |
| 537 | |
| 538 | fed += kFramesPerChunk; |
| 539 | seconds = std::chrono::duration<double>(Clock::now() - start).count() - spentSpin; |
| 540 | |
| 541 | if (seconds - lastSpin >= kSpinIntervalSec) { |
| 542 | spentSpin += spinEventLoop(); |
| 543 | lastSpin = seconds; |
| 544 | } |
| 545 | } |
| 546 | |
| 547 | const double fps = seconds > 0.0 ? static_cast<double>(extracted) / seconds : 0.0; |
| 548 | |
| 549 | Result result; |
| 550 | result.passed = fps >= minFps; |
| 551 | result.language = -1; |
| 552 | result.minFps = minFps; |
| 553 | result.framesPerSecond = fps; |
| 554 | result.elapsedSeconds = seconds; |
| 555 | result.framesParsed = extracted; |
| 556 | result.framesSkipped = 0; |
| 557 | return result; |
nothing calls this directly
no test coverage detected