8 #include "artdaq/DAQdata/Globals.hh"
9 #include <boost/program_options.hpp>
11 namespace bpo = boost::program_options;
13 std::string formatTime(
double time)
16 o << std::fixed << std::setprecision(3);
17 if (time > 60) o << static_cast<int>(time / 60) <<
" m " << time - 60 * static_cast<int>(time / 60) <<
" s";
18 else if (time > 1) o << time <<
" s";
22 if (time > 1) o << time <<
" ms";
26 if (time > 1) o << time <<
" us";
38 int main(
int argc,
char *argv[])
40 std::ostringstream descstr;
42 <<
" <-l test loops> [csutdi]";
43 bpo::options_description desc(descstr.str());
45 (
"loops,l", bpo::value<size_t>(),
"Number of times to run each test")
46 (
"C,c",
"Run TRACEC test")
47 (
"S,s",
"Run TRACES test")
48 (
"U,u",
"Run TRACE_ test")
49 (
"T,t",
"Run TRACE_STREAMER test")
50 (
"D,d",
"Run TLOG_DEBUG test")
51 (
"I,i",
"Run TLOG_INFO test")
52 (
"console,x",
"Enable MessageFacility output to console")
53 (
"help,h",
"produce help message");
54 bpo::variables_map vm;
57 bpo::store(bpo::command_line_parser(argc, argv).options(desc).run(), vm);
60 catch (bpo::error
const & e)
62 std::cerr <<
"Exception from command line processing in " << argv[0]
63 <<
": " << e.what() <<
"\n";
68 std::cout << desc << std::endl;
71 if (!vm.count(
"loops"))
73 std::cerr <<
"Exception from command line processing in " << argv[0]
74 <<
": no loop count given.\n"
75 <<
"For usage and an options list, please do '"
76 << argv[0] <<
" --help"
80 size_t loops = vm[
"loops"].as<
size_t>();
82 artdaq::configureMessageFacility(
"tracemf", vm.count(
"console"));
86 std::cout <<
"Starting TRACEC test" << std::endl;
87 auto start = std::chrono::steady_clock::now();
88 for (
size_t l = 0; l < loops; ++l)
90 TRACE(TLVL_DEBUG,
"Test TRACEC with an int %i and a float %.1f", 42, 5.56);
92 auto time = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::steady_clock::now() - start).count();
93 std::cout <<
"TRACEC test took " << formatTime(time) <<
", avg: " << formatTime(time / loops) << std::endl;
98 std::cout <<
"Starting TRACES test" << std::endl;
99 auto start = std::chrono::steady_clock::now();
100 for (
size_t l = 0; l < loops; ++l)
102 std::string test =
"Test TRACE with an int %d";
103 std::string test2 =
" and a float %.1f";
104 TRACE(TLVL_DEBUG, test + test2, 42, 5.56);
106 auto time = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::steady_clock::now() - start).count();
107 std::cout <<
"TRACES test took " << formatTime(time) <<
", avg: " << formatTime(time / loops) << std::endl;
112 std::cout <<
"Starting TRACE_ test" << std::endl;
113 auto start = std::chrono::steady_clock::now();
114 for (
size_t l = 0; l < loops; ++l)
116 TRACEN_(
"tracemf", TLVL_DEBUG,
"Test TRACE_ with an int " << 42 <<
" and a float %.1f", 5.56);
118 auto time = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::steady_clock::now() - start).count();
119 std::cout <<
"TRACE_ test took " << formatTime(time) <<
", avg: " << formatTime(time / loops) << std::endl;
124 std::cout <<
"Starting TLOG_DEBUG test" << std::endl;
125 auto start = std::chrono::steady_clock::now();
126 for (
size_t l = 0; l < loops; ++l)
128 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;
130 auto time = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::steady_clock::now() - start).count();
131 std::cout <<
"TLOG_DEBUG test took " << formatTime(time) <<
", avg: " << formatTime(time / loops) << std::endl;
136 std::cout <<
"Starting TLOG_INFO test" << std::endl;
137 auto start = std::chrono::steady_clock::now();
138 for (
size_t l = 0; l < loops; ++l)
140 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;
142 auto time = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::steady_clock::now() - start).count();
143 std::cout <<
"TLOG_INFO test took " << formatTime(time) <<
", avg: " << formatTime(time / loops) << std::endl;