LCOV - code coverage report
Current view: top level - datahandlinglibs/test/apps - test_bufferedfilewriter_app.cxx (source / functions) Coverage Total Hit
Test: code.result Lines: 0.0 % 41 0
Test Date: 2025-12-21 13:07:08 Functions: 0.0 % 7 0

            Line data    Source code
       1              : /**
       2              :  * @file test_bufferedfilewriter_app.cxx Test application for
       3              :  * BufferedFileWriter 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/BufferedFileWriter.hpp"
      10              : #include "datahandlinglibs/utils/RateLimiter.hpp"
      11              : 
      12              : #include "logging/Logging.hpp"
      13              : #include "datahandlinglibs/ReadoutTypes.hpp"
      14              : 
      15              : #include <atomic>
      16              : #include <chrono>
      17              : #include <memory>
      18              : #include <string>
      19              : 
      20              : using namespace dunedaq::datahandlinglibs;
      21              : 
      22              : int
      23            0 : main(int argc, char* argv[])
      24              : {
      25            0 :   if (argc < 2 || argc > 4 || argc==3 || (argc == 4 && strcmp(argv[2], "-L") != 0)) {
      26            0 :     TLOG() << "usage: datahandlinglibs_test_bufferedfilewriter filename <-L rate_limiter_frequency>" << std::endl;
      27            0 :     TLOG() << "-L frequency parameter is optional. Limiter will be disable" << std::endl;    
      28            0 :     exit(1);
      29              :   }
      30            0 :   remove(argv[1]); // NOLINT
      31            0 :   std::string filename(argv[1]);
      32            0 :   types::DUMMY_FRAME_STRUCT chunk;
      33            0 :   BufferedFileWriter writer(filename, 8388608);
      34            0 :   for (uint i = 0; i < sizeof(chunk); ++i) {
      35            0 :     (reinterpret_cast<char*>(&chunk))[i] = static_cast<char>(i); // NOLINT
      36              :   }
      37              : 
      38            0 :   std::atomic<int64_t> bytes_written_total = 0;
      39            0 :   std::atomic<int64_t> bytes_written_since_last_statistics = 0;
      40            0 :   std::chrono::steady_clock::time_point time_point_last_statistics = std::chrono::steady_clock::now();
      41              : 
      42            0 :   auto statistics_thread = std::thread([&]() {
      43            0 :     while (true) {
      44            0 :       std::this_thread::sleep_for(std::chrono::milliseconds(100));
      45            0 :       double time_diff = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::steady_clock::now() -
      46            0 :                                                                                    time_point_last_statistics)
      47            0 :                            .count();
      48            0 :       TLOG() << "Bytes written: " << bytes_written_total << ", Throughput: "
      49            0 :              << static_cast<double>(bytes_written_since_last_statistics) / ((int64_t)1 << 20) / time_diff << " MiB/s"
      50            0 :              << std::endl;
      51            0 :       time_point_last_statistics = std::chrono::steady_clock::now();
      52            0 :       bytes_written_since_last_statistics = 0;
      53            0 :     }
      54            0 :   });
      55              : 
      56              :   // Initializing limiter
      57            0 :   double limiter_freq = 0;
      58            0 :   if (argc == 4) limiter_freq = std::stod(argv[3]);
      59            0 :   auto limiter = RateLimiter(limiter_freq);
      60              : 
      61            0 :   if (argc == 4) {
      62            0 :     TLOG() << "Starting with ratelimiter at " << limiter_freq << "kHz";
      63            0 :     limiter.init();
      64              :   }
      65              :   
      66              : 
      67            0 :   while (true) {
      68            0 :     if (!writer.write(reinterpret_cast<char*>(&chunk), sizeof(chunk))) {
      69            0 :       TLOG() << "Could not write to file" << std::endl;
      70            0 :       exit(1);
      71              :     }
      72            0 :     bytes_written_total += sizeof(chunk);
      73            0 :     bytes_written_since_last_statistics += sizeof(chunk);
      74            0 :     if (argc == 4) limiter.limit();
      75              :   }
      76            0 : }
        

Generated by: LCOV version 2.0-1