From 53a2690567b5811318a78cdf3e093955579d8121 Mon Sep 17 00:00:00 2001 From: Andrej Babic Date: Mon, 21 Sep 2020 10:16:27 +0200 Subject: [PATCH] Improve statistics and logging for sf_stream --- sf-stream/src/main.cpp | 45 +++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/sf-stream/src/main.cpp b/sf-stream/src/main.cpp index 367f875..0c3d500 100644 --- a/sf-stream/src/main.cpp +++ b/sf-stream/src/main.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "buffer_config.hpp" #include "stream_config.hpp" @@ -32,9 +33,6 @@ int main (int argc, char *argv[]) auto config = read_json_config(string(argv[1])); string RECV_IPC_URL = BUFFER_LIVE_IPC_URL + config.DETECTOR_NAME + "-"; - ModuleFrameBuffer* meta = new ModuleFrameBuffer(); - char* data = new char[config.n_modules * MODULE_N_BYTES]; - auto ctx = zmq_ctx_new(); zmq_ctx_set (ctx, ZMQ_IO_THREADS, STREAM_ZMQ_IO_THREADS); @@ -45,30 +43,41 @@ int main (int argc, char *argv[]) } ZmqPulseReceiver receiver(ipc_urls, ctx); + RamBuffer ram_buffer(config.DETECTOR_NAME, config.n_modules); ZmqLiveSender sender(ctx, config); // TODO: Remove stats trash. - int stats_counter = 0; + uint64_t last_pulse_id = 0; + uint64_t last_pulse_id_range = 0; + uint16_t n_good_images = 0; + ImageMetadata meta; while (true) { - - auto n_lost_pulses = receiver.get_next_pulse_id(); - - if (n_lost_pulses > 0) { - cout << "sf_stream:sync_lost_pulses " << n_lost_pulses << endl; - } + auto pulse_id = receiver.get_next_pulse_id(); + char* data = ram_buffer.read_image(pulse_id, meta); sender.send(meta, data); - stats_counter++; - if (stats_counter == STATS_MODULO) { - cout << "sf_stream:read_us " << read_total_us / STATS_MODULO; - cout << " sf_stream:read_max_us " << read_max_us; - cout << " sf_stream:send_us " << send_total_us / STATS_MODULO; - cout << " sf_stream:send_max_us " << send_max_us; - cout << endl; + // TODO: This logic works only at 100Hz. Fix it systematically. + uint64_t sync_lost_pulses = pulse_id - last_pulse_id; + if (last_pulse_id > 0 && sync_lost_pulses > 1) { + cout << "sf_stream:sync_lost_pulses " << sync_lost_pulses << endl; + } + last_pulse_id = pulse_id; - stats_counter = 0; + uint64_t curr_pulse_id_range = pulse_id / 10000; + if (last_pulse_id_range != curr_pulse_id_range) { + if (last_pulse_id_range > 0) { + cout << "sf_stream:n_good_images " << n_good_images; + cout << endl; + } + + last_pulse_id_range = curr_pulse_id_range; + n_good_images = 0; + } + + if (meta.is_good_image) { + n_good_images++; } } }