Files
Jungfraujoch/receiver/RugnuxLiveStatus.cpp
T
leonarski_fandClaude Opus 5.5 7349832309 Live rugnux timing: from the puller's receive time, and from the first image
The live panel showed ~80 Hz on a 100 Hz collection. Its clock started when
the receiver had applied and forwarded the START message, so the START ->
first image gap counted as collection time; the images were stamped when a
forward thread dequeued them, and the last image only after END and the
thread joins; and N images were divided by a span holding N-1 intervals.

- ImagePullerOutput carries `received`, a steady_clock time set by the TCP
  and ZeroMQ pullers as the message comes off the socket, before it is
  queued or deserialised (TestImagePuller stamps it on Put when unset).
- RugnuxLiveStatus takes those times: START's for its origin, each image's
  for the first and last image (min/max, as forward threads report out of
  order). last_image_s is the last data image's puller time.
- Zero of every reported time (elapsed_s, steps' started_s, probe_s,
  last_image_s, cut_s) is now the FIRST IMAGE, as the frontend already
  said; before the first image arrives "now" is 0 and earlier steps are
  negative. The START -> first image time is recorded on its own as
  start_to_first_image_s (snapshot, OpenAPI rugnux_live_status, regenerated
  C++ model and frontend client, OpenAPIConvert).
- The frontend rate is (images_received - 1) / (last - first image); the
  panel headers show "START -> first image X.X s".
- The broker logs "rugnux live: START -> first image ..., N images in T s
  from the first to the last (R Hz)"; "done X s after the last image" and
  last_image_to_written_s run from the puller time of the last image.

The deadline timer is unchanged (it still starts once the forward threads
have joined). No analysis result changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PXc1zD1yxHqaR1DGdCTHL4
2026-10-19 19:35:54 +02:00

126 lines
3.9 KiB
C++

// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
// SPDX-License-Identifier: GPL-3.0-only
#include "RugnuxLiveStatus.h"
double RugnuxLiveStatus::Since(std::chrono::steady_clock::time_point t) const {
return std::chrono::duration<double>(t - start).count();
}
double RugnuxLiveStatus::Now() const {
return Since(std::chrono::steady_clock::now());
}
void RugnuxLiveStatus::CloseStep() {
if (!s.steps.empty() && !s.steps.back().duration_s)
s.steps.back().duration_s = Now() - s.steps.back().started_s;
}
void RugnuxLiveStatus::Start(int64_t images_expected, std::chrono::steady_clock::time_point start_received) {
std::unique_lock ul(m);
s = RugnuxLiveSnapshot{};
s.state = RugnuxLiveState::Running;
s.images_expected = images_expected;
start = start_received;
last_image.reset();
}
void RugnuxLiveStatus::ImageReceived(std::chrono::steady_clock::time_point received) {
std::unique_lock ul(m);
++s.images_received;
// Several forward threads report, so the images need not come here in the order they arrived.
const double t = Since(received);
if (!s.start_to_first_image_s || t < s.start_to_first_image_s.value())
s.start_to_first_image_s = t;
if (!last_image || received > last_image.value())
last_image = received;
}
void RugnuxLiveStatus::Step(const std::string &title) {
std::unique_lock ul(m);
CloseStep();
s.steps.push_back(RugnuxLiveStep{.title = title, .started_s = Now()});
s.step_progress.reset();
}
void RugnuxLiveStatus::Note(const std::string &text) {
std::unique_lock ul(m);
if (s.steps.empty())
s.steps.push_back(RugnuxLiveStep{.title = "", .started_s = Now()});
s.steps.back().notes.push_back(text);
}
void RugnuxLiveStatus::Progress(uint64_t done, uint64_t total) {
std::unique_lock ul(m);
if (total > 0)
s.step_progress = static_cast<float>(done) / static_cast<float>(total);
}
void RugnuxLiveStatus::Finish(RugnuxLiveState state, const std::string &message) {
std::unique_lock ul(m);
CloseStep();
s.elapsed_s = Now();
s.state = state;
s.message = message;
s.step_progress.reset();
}
void RugnuxLiveStatus::Result(const std::string &verdict, const std::string &verdict_text,
const std::vector<std::pair<std::string, std::string>> &summary,
const std::vector<std::string> &warnings) {
std::unique_lock ul(m);
s.verdict = verdict;
s.verdict_text = verdict_text;
s.summary = summary;
s.warnings = warnings;
}
void RugnuxLiveStatus::Latency(double last_image_to_written_s) {
std::unique_lock ul(m);
s.last_image_to_written_s = last_image_to_written_s;
}
std::optional<std::chrono::steady_clock::time_point> RugnuxLiveStatus::LastImage() {
std::unique_lock ul(m);
if (last_image)
s.last_image_s = Since(last_image.value());
return last_image;
}
void RugnuxLiveStatus::Cut(const std::string &reason) {
std::unique_lock ul(m);
s.cut = reason;
s.cut_s = Now();
}
void RugnuxLiveStatus::Probe(const std::string &text) {
std::unique_lock ul(m);
s.probe = text;
s.probe_s = Now();
}
void RugnuxLiveStatus::Warning(const std::string &text) {
std::unique_lock ul(m);
s.warnings.push_back(text);
}
RugnuxLiveSnapshot RugnuxLiveStatus::Get() const {
std::unique_lock ul(m);
RugnuxLiveSnapshot ret = s;
if (s.state == RugnuxLiveState::Running)
ret.elapsed_s = Now();
// Held since START, reported since the first image - or, before it has come, since now.
const double zero = s.start_to_first_image_s.value_or(s.state == RugnuxLiveState::Running ? ret.elapsed_s : 0.0);
ret.elapsed_s -= zero;
for (auto &step: ret.steps)
step.started_s -= zero;
if (ret.probe_s)
*ret.probe_s -= zero;
if (ret.last_image_s)
*ret.last_image_s -= zero;
if (ret.cut_s)
*ret.cut_s -= zero;
return ret;
}