mirror of
https://github.com/paulscherrerinstitute/sf_daq_buffer.git
synced 2026-06-06 19:28:41 +02:00
Improve statistics and logging for sf_stream
This commit is contained in:
+27
-18
@@ -3,6 +3,7 @@
|
||||
#include <chrono>
|
||||
#include <cstring>
|
||||
#include <zmq.h>
|
||||
#include <RamBuffer.hpp>
|
||||
|
||||
#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++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user