LCOV - code coverage report
Current view: top level - proto - tracemf.cc (source / functions) Coverage Total Hit
Test: artdaq.info.cleaned Lines: 0.0 % 80 0
Test Date: 2025-09-04 00:45:34 Functions: 0.0 % 4 0

            Line data    Source code
       1              : // This file (just.cc) was created by Ron Rechenmacher <ron@fnal.gov> on
       2              : // Feb 19, 2014. "TERMS AND CONDITIONS" governing this file are in the README
       3              : // or COPYING file. If you do not have such a file, one can be obtained by
       4              : // contacting Ron or Fermi Lab in Batavia IL, 60510, phone: 630-840-3000.
       5              : // $RCSfile: just_user.cc,v $
       6              : 
       7              : #include "artdaq-core/Utilities/configureMessageFacility.hh"
       8              : #include "artdaq/DAQdata/Globals.hh"
       9              : 
      10              : #include <boost/program_options.hpp>
      11              : 
      12              : #include <iomanip>
      13              : namespace bpo = boost::program_options;
      14              : 
      15            0 : std::string formatTime(double time)
      16              : {
      17            0 :         std::ostringstream o;
      18            0 :         o << std::fixed << std::setprecision(3);
      19            0 :         if (time > 60)
      20              :         {
      21            0 :                 o << static_cast<int>(time / 60) << " m " << time - 60 * static_cast<int>(time / 60) << " s";
      22              :         }
      23            0 :         else if (time > 1)
      24              :         {
      25            0 :                 o << time << " s";
      26              :         }
      27              :         else
      28              :         {
      29            0 :                 time *= 1000;
      30            0 :                 if (time > 1)
      31              :                 {
      32            0 :                         o << time << " ms";
      33              :                 }
      34              :                 else
      35              :                 {
      36            0 :                         time *= 1000;
      37            0 :                         if (time > 1)
      38              :                         {
      39            0 :                                 o << time << " us";
      40              :                         }
      41              :                         else
      42              :                         {
      43            0 :                                 time *= 1000;
      44            0 :                                 o << time << " ns";
      45              :                         }
      46              :                 }
      47              :         }
      48              : 
      49            0 :         return o.str();
      50            0 : }
      51              : 
      52            0 : int main(int argc, char *argv[])
      53              : try
      54              : {
      55            0 :         std::ostringstream descstr;
      56              :         descstr << *argv
      57            0 :                 << " <-l test loops> [csutdi]";
      58            0 :         bpo::options_description desc(descstr.str());
      59            0 :         desc.add_options()("loops,l", bpo::value<size_t>(), "Number of times to run each test")("C,c", "Run TRACEC test")("S,s", "Run TRACES test")("U,u", "Run TRACE_ test")("T,t", "Run TRACE_STREAMER test")("D,d", "Run TLOG_DEBUG test")("I,i", "Run TLOG_INFO test")("console,x", "Enable MessageFacility output to console")("help,h", "produce help message");
      60            0 :         bpo::variables_map vm;
      61              :         try
      62              :         {
      63            0 :                 bpo::store(bpo::command_line_parser(argc, argv).options(desc).run(), vm);
      64            0 :                 bpo::notify(vm);
      65              :         }
      66            0 :         catch (bpo::error const &e)
      67              :         {
      68              :                 std::cerr << "Exception from command line processing in " << *argv
      69            0 :                           << ": " << e.what() << "\n";
      70            0 :                 return -1;
      71            0 :         }
      72            0 :         if (vm.count("help") != 0u)
      73              :         {
      74            0 :                 std::cout << desc << std::endl;
      75            0 :                 return 1;
      76              :         }
      77            0 :         if (vm.count("loops") == 0u)
      78              :         {
      79              :                 std::cerr << "Exception from command line processing in " << *argv
      80              :                           << ": no loop count given.\n"
      81              :                           << "For usage and an options list, please do '"
      82              :                           << *argv << " --help"
      83            0 :                           << "'.\n";
      84            0 :                 return 2;
      85              :         }
      86            0 :         size_t loops = vm["loops"].as<size_t>();
      87              : 
      88            0 :         artdaq::configureMessageFacility("tracemf", vm.count("console") != 0u);
      89              : 
      90            0 :         if (vm.count("C") != 0u)
      91              :         {
      92            0 :                 std::cout << "Starting TRACEC test" << std::endl;
      93            0 :                 auto start = std::chrono::steady_clock::now();
      94            0 :                 for (size_t l = 0; l < loops; ++l)
      95              :                 {
      96            0 :                         TRACE(TLVL_DEBUG, "Test TRACEC with an int %i and a float %.1f", 42, 5.56);  // NOLINT
      97              :                 }
      98            0 :                 auto time = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::steady_clock::now() - start).count();
      99            0 :                 std::cout << "TRACEC test took " << formatTime(time) << ", avg: " << formatTime(time / loops) << std::endl;
     100              :         }
     101              : 
     102            0 :         if (vm.count("S") != 0u)
     103              :         {
     104            0 :                 std::cout << "Starting TRACES test" << std::endl;
     105            0 :                 auto start = std::chrono::steady_clock::now();
     106            0 :                 for (size_t l = 0; l < loops; ++l)
     107              :                 {
     108            0 :                         std::string test = "Test TRACE with an int %d";
     109            0 :                         std::string test2 = " and a float %.1f";
     110            0 :                         TRACE(TLVL_DEBUG, test + test2, 42, 5.56);  // NOLINT
     111            0 :                 }
     112            0 :                 auto time = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::steady_clock::now() - start).count();
     113            0 :                 std::cout << "TRACES test took " << formatTime(time) << ", avg: " << formatTime(time / loops) << std::endl;
     114              :         }
     115              : 
     116            0 :         if (vm.count("U") != 0u)
     117              :         {
     118            0 :                 std::cout << "Starting TRACE_ test" << std::endl;
     119            0 :                 auto start = std::chrono::steady_clock::now();
     120            0 :                 for (size_t l = 0; l < loops; ++l)
     121              :                 {
     122            0 :                         TRACEN_("tracemf", TLVL_DEBUG, "Test TRACE_ with an int " << 42 << " and a float %.1f", 5.56);  // NOLINT
     123              :                 }
     124            0 :                 auto time = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::steady_clock::now() - start).count();
     125            0 :                 std::cout << "TRACE_ test took " << formatTime(time) << ", avg: " << formatTime(time / loops) << std::endl;
     126              :         }
     127              : 
     128            0 :         if (vm.count("D") != 0u)
     129              :         {
     130            0 :                 std::cout << "Starting TLOG_DEBUG test" << std::endl;
     131            0 :                 auto start = std::chrono::steady_clock::now();
     132            0 :                 for (size_t l = 0; l < loops; ++l)
     133              :                 {
     134            0 :                         TLOG_DEBUG("tracemf") << "Test TLOG_DEBUG with an int " << 42 << " and a float " << std::setprecision(1) << 5.56 << ", and another float " << 7.3 << TRACE_ENDL;
     135              :                 }
     136            0 :                 auto time = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::steady_clock::now() - start).count();
     137            0 :                 std::cout << "TLOG_DEBUG test took " << formatTime(time) << ", avg: " << formatTime(time / loops) << std::endl;
     138              :         }
     139              : 
     140            0 :         if (vm.count("I") != 0u)
     141              :         {
     142            0 :                 std::cout << "Starting TLOG_INFO test" << std::endl;
     143            0 :                 auto start = std::chrono::steady_clock::now();
     144            0 :                 for (size_t l = 0; l < loops; ++l)
     145              :                 {
     146            0 :                         TLOG_INFO("tracemf") << "Test TLOG_INFO with an int " << 42 << " and a float " << std::setprecision(1) << 5.56 << ", and another float " << std::fixed << 7.3 << TRACE_ENDL;
     147              :                 }
     148            0 :                 auto time = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::steady_clock::now() - start).count();
     149            0 :                 std::cout << "TLOG_INFO test took " << formatTime(time) << ", avg: " << formatTime(time / loops) << std::endl;
     150              :         }
     151              : 
     152            0 :         return (0);
     153            0 : }
     154            0 : catch (...)
     155              : {
     156            0 :         return -1;
     157            0 : }
        

Generated by: LCOV version 2.0-1