Line data Source code
1 : /**
2 : * @file test_bufferedfilereader_app.cxx Test application for
3 : * BufferedFileReader implementation
4 : *
5 : * This is part of the DUNE DAQ Application Framework, copyright 2020.
6 : * Licensing/copyright details are in the COPYING file that you should have
7 : * received with this code.
8 : */
9 : #include "datahandlinglibs/utils/BufferedFileReader.hpp"
10 :
11 : #include "logging/Logging.hpp"
12 : #include "datahandlinglibs/ReadoutTypes.hpp"
13 :
14 : #include <atomic>
15 : #include <chrono>
16 : #include <memory>
17 : #include <string>
18 :
19 : using namespace dunedaq::datahandlinglibs;
20 :
21 : int
22 0 : main(int argc, char* argv[])
23 : {
24 0 : if (argc != 2) {
25 0 : TLOG() << "usage: datahandlinglibs_test_bufferedfilereader filename" << std::endl;
26 0 : exit(1);
27 : }
28 0 : std::string filename(argv[1]);
29 0 : BufferedFileReader<types::DUMMY_FRAME_STRUCT> reader(filename, 8388608);
30 0 : types::DUMMY_FRAME_STRUCT chunk;
31 0 : for (uint i = 0; i < sizeof(chunk); ++i) {
32 0 : (reinterpret_cast<char*>(&chunk))[i] = static_cast<char>(i); // NOLINT
33 : }
34 :
35 0 : std::atomic<int64_t> bytes_read_total = 0;
36 0 : std::atomic<int64_t> bytes_read_since_last_statistics = 0;
37 0 : std::chrono::steady_clock::time_point time_point_last_statistics = std::chrono::steady_clock::now();
38 :
39 0 : auto statistics_thread = std::thread([&]() {
40 0 : while (true) {
41 0 : std::this_thread::sleep_for(std::chrono::milliseconds(100));
42 0 : double time_diff = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::steady_clock::now() -
43 0 : time_point_last_statistics)
44 0 : .count();
45 0 : TLOG() << "Bytes read: " << bytes_read_total << ", Throughput: "
46 0 : << static_cast<double>(bytes_read_since_last_statistics) / ((int64_t)1 << 20) / time_diff << " MiB/s"
47 0 : << std::endl;
48 0 : time_point_last_statistics = std::chrono::steady_clock::now();
49 0 : bytes_read_since_last_statistics = 0;
50 0 : }
51 0 : });
52 :
53 0 : while (true) {
54 0 : if (!reader.read(chunk)) {
55 0 : TLOG() << "Finished reading from file" << std::endl;
56 0 : exit(0);
57 : }
58 0 : bytes_read_total += sizeof(chunk);
59 0 : bytes_read_since_last_statistics += sizeof(chunk);
60 0 : }
61 0 : }
|