X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=print_latency.cpp;fp=print_latency.cpp;h=9b5be9ea0be3f0457f430e16118ea90f1bd51241;hb=a52521ba8935fcf02e37d01767c3013c39e8dce2;hp=7101f39671101738b3c5388c55cdc1f68e021b2c;hpb=da648fc65da0b5f8e96ff39ce52bdd00fa29b5dc;p=nageru 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());