From a52521ba8935fcf02e37d01767c3013c39e8dce2 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Thu, 15 Jun 2017 18:28:24 +0200 Subject: [PATCH] Unbreak the min/max latency stdout display; it did not ignore non-timestamps properly. --- print_latency.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/print_latency.cpp b/print_latency.cpp index 7101f39..9b5be9e 100644 --- a/print_latency.cpp +++ b/print_latency.cpp @@ -71,8 +71,6 @@ void print_latency(const string &header, const ReceivedTimestamps &received_ts, return; const steady_clock::time_point now = steady_clock::now(); - duration lowest_latency = now - *max_element(received_ts.ts.begin(), received_ts.ts.end()); - duration highest_latency = now - *min_element(received_ts.ts.begin(), received_ts.ts.end()); unsigned num_cards = global_mixer->get_num_cards(); assert(received_ts.ts.size() == num_cards * FRAME_HISTORY_LENGTH); @@ -89,6 +87,17 @@ void print_latency(const string &header, const ReceivedTimestamps &received_ts, // 101 is chosen so that it's prime, which is unlikely to get the same frame type every time. if (global_flags.print_video_latency && (++*frameno % 101) == 0) { + // Find min and max timestamp of all input frames that have a timestamp. + steady_clock::time_point min_ts = steady_clock::time_point::max(), max_ts = steady_clock::time_point::min(); + for (const auto &ts : received_ts.ts) { + if (ts > steady_clock::time_point::min()) { + min_ts = min(min_ts, ts); + max_ts = max(max_ts, ts); + } + } + duration lowest_latency = now - max_ts; + duration highest_latency = now - min_ts; + printf("%-60s %4.0f ms (lowest-latency input), %4.0f ms (highest-latency input)", header.c_str(), 1e3 * lowest_latency.count(), 1e3 * highest_latency.count()); -- 2.39.2