From 5d52c24c280610df053f07dfe7819ead315306a9 Mon Sep 17 00:00:00 2001 From: Andrej Babic Date: Mon, 27 Apr 2020 17:24:47 +0200 Subject: [PATCH] Most basic possible writer test --- core-buffer/test/perf_SFWriter.cpp | 84 ++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 core-buffer/test/perf_SFWriter.cpp diff --git a/core-buffer/test/perf_SFWriter.cpp b/core-buffer/test/perf_SFWriter.cpp new file mode 100644 index 0000000..a17001d --- /dev/null +++ b/core-buffer/test/perf_SFWriter.cpp @@ -0,0 +1,84 @@ +#include +#include +#include "buffer_config.hpp" +#include "zmq.h" +#include +#include +#include +#include +#include +#include "SFWriter.hpp" +#include + +using namespace std; +using namespace core_buffer; + + +int main (int argc, char *argv[]) +{ + if (argc != 4) { + cout << endl; + cout << "Usage: sf_writer "; + cout << " [output_file] [start_pulse_id] [stop_pulse_id]"; + cout << endl; + cout << "\toutput_file: Complete path to the output file." << endl; + cout << "\tstart_pulse_id: Start pulse_id of retrieval." << endl; + cout << "\tstop_pulse_id: Stop pulse_id of retrieval." << endl; + cout << endl; + + exit(-1); + } + + string output_file = string(argv[1]); + uint64_t start_pulse_id = (uint64_t) atoll(argv[2]); + uint64_t stop_pulse_id = (uint64_t) atoll(argv[3]); + + size_t n_modules = 32; + + size_t n_frames = stop_pulse_id - start_pulse_id; + SFWriter writer(output_file, n_frames, n_modules); + + // TODO: Remove stats trash. + int i_write = 0; + size_t total_ms = 0; + size_t max_ms = 0; + + auto start_time = chrono::steady_clock::now(); + + auto metadata = make_shared(); + auto data = make_unique(MODULE_N_BYTES*n_modules); + + auto current_pulse_id = start_pulse_id; + while (current_pulse_id <= stop_pulse_id) { + + writer.write(metadata, data.get()); + current_pulse_id++; + + i_write++; + + auto end_time = chrono::steady_clock::now(); + + // TODO: Some poor statistics. + + auto ms_duration = chrono::duration_cast( + end_time-start_time).count(); + total_ms += ms_duration; + if (ms_duration > max_ms) { + max_ms = ms_duration; + } + + if (i_write==100) { + cout << "assembly_ms " << total_ms / 100; + cout << " max_ms " << max_ms << endl; + i_write = 0; + total_ms = 0; + max_ms = 0; + } + + start_time = chrono::steady_clock::now(); + } + + writer.close_file(); + + return 0; +}