From 3ed5bcb33021573f0c8e820de0376dab3f8cdbc8 Mon Sep 17 00:00:00 2001 From: Andrej Babic Date: Fri, 15 Jan 2021 11:07:31 +0100 Subject: [PATCH] Statistics for sf-stream --- sf-stream/src/main.cpp | 42 +++++++++++------------------------------- 1 file changed, 11 insertions(+), 31 deletions(-) diff --git a/sf-stream/src/main.cpp b/sf-stream/src/main.cpp index dbd588f..9ebb111 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" @@ -15,57 +16,36 @@ using namespace stream_config; int main (int argc, char *argv[]) { - if (argc != 2) { + if (argc != 3) { cout << endl; - cout << "Usage: sf_stream [detector_json_filename]" << endl; + cout << "Usage: sf_stream [detector_json_filename]" + " [stream_name]" << endl; cout << "\tdetector_json_filename: detector config file path." << endl; cout << endl; exit(-1); } + const auto stream_name = string(argv[2]); + // TODO: Add stream_name to config reading - multiple stream definitions. auto config = BufferUtils::read_json_config(string(argv[1])); - string RECV_IPC_URL = BUFFER_LIVE_IPC_URL + config.detector_name + "-"; + string RECV_IPC_URL = BUFFER_LIVE_IPC_URL + config.detector_name + "-"; auto ctx = zmq_ctx_new(); zmq_ctx_set(ctx, ZMQ_IO_THREADS, STREAM_ZMQ_IO_THREADS); ZmqPulseSyncReceiver receiver(ctx, config.detector_name, config.n_modules); RamBuffer ram_buffer(config.detector_name, config.n_modules); + StreamStats stats(config.detector_name, stream_name, STREAM_STATS_MODULO); ZmqLiveSender sender(ctx, config); - // TODO: Remove stats trash. - uint64_t last_pulse_id = 0; - uint64_t last_pulse_id_range = 0; - uint16_t n_good_images = 0; - ImageMetadata meta; while (true) { - auto pulse_id = receiver.get_next_pulse_id(); - char* data = ram_buffer.read_image(pulse_id, meta); + auto pulse_and_sync = receiver.get_next_pulse_id(); + char* data = ram_buffer.read_image(pulse_and_sync.pulse_id, meta); sender.send(meta, data); - // 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; - - 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++; - } + stats.record_stats(meta, pulse_and_sync.n_lost_pulses); } }