7 #include "artdaq/DAQdata/Globals.hh"
9 #include <boost/program_options.hpp>
12 namespace bpo = boost::program_options;
14 std::string formatTime(
double time)
17 o << std::fixed << std::setprecision(3);
20 o << static_cast<int>(time / 60) <<
" m " << time - 60 * static_cast<int>(time / 60) <<
" s";
51 int main(
int argc,
char *argv[])
try
53 std::ostringstream descstr;
55 <<
" <-l test loops> [csutdi]";
56 bpo::options_description desc(descstr.str());
57 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");
58 bpo::variables_map vm;
61 bpo::store(bpo::command_line_parser(argc, argv).options(desc).run(), vm);
64 catch (bpo::error
const &e)
66 std::cerr <<
"Exception from command line processing in " << *argv
67 <<
": " << e.what() <<
"\n";
70 if (vm.count(
"help") != 0u)
72 std::cout << desc << std::endl;
75 if (vm.count(
"loops") == 0u)
77 std::cerr <<
"Exception from command line processing in " << *argv
78 <<
": no loop count given.\n"
79 <<
"For usage and an options list, please do '"
84 size_t loops = vm[
"loops"].as<
size_t>();
86 artdaq::configureMessageFacility(
"tracemf", vm.count(
"console") != 0u);
88 if (vm.count(
"C") != 0u)
90 std::cout <<
"Starting TRACEC test" << std::endl;
91 auto start = std::chrono::steady_clock::now();
92 for (
size_t l = 0; l < loops; ++l)
94 TRACE(TLVL_DEBUG,
"Test TRACEC with an int %i and a float %.1f", 42, 5.56);
96 auto time = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::steady_clock::now() - start).count();
97 std::cout <<
"TRACEC test took " << formatTime(time) <<
", avg: " << formatTime(time / loops) << std::endl;
100 if (vm.count(
"S") != 0u)
102 std::cout <<
"Starting TRACES test" << std::endl;
103 auto start = std::chrono::steady_clock::now();
104 for (
size_t l = 0; l < loops; ++l)
106 std::string test =
"Test TRACE with an int %d";
107 std::string test2 =
" and a float %.1f";
108 TRACE(TLVL_DEBUG, test + test2, 42, 5.56);
110 auto time = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::steady_clock::now() - start).count();
111 std::cout <<
"TRACES test took " << formatTime(time) <<
", avg: " << formatTime(time / loops) << std::endl;
114 if (vm.count(
"U") != 0u)
116 std::cout <<
"Starting TRACE_ test" << std::endl;
117 auto start = std::chrono::steady_clock::now();
118 for (
size_t l = 0; l < loops; ++l)
120 TRACEN_(
"tracemf", TLVL_DEBUG,
"Test TRACE_ with an int " << 42 <<
" and a float %.1f", 5.56);
122 auto time = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::steady_clock::now() - start).count();
123 std::cout <<
"TRACE_ test took " << formatTime(time) <<
", avg: " << formatTime(time / loops) << std::endl;
126 if (vm.count(
"D") != 0u)
128 std::cout <<
"Starting TLOG_DEBUG test" << std::endl;
129 auto start = std::chrono::steady_clock::now();
130 for (
size_t l = 0; l < loops; ++l)
132 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;
134 auto time = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::steady_clock::now() - start).count();
135 std::cout <<
"TLOG_DEBUG test took " << formatTime(time) <<
", avg: " << formatTime(time / loops) << std::endl;
138 if (vm.count(
"I") != 0u)
140 std::cout <<
"Starting TLOG_INFO test" << std::endl;
141 auto start = std::chrono::steady_clock::now();
142 for (
size_t l = 0; l < loops; ++l)
144 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;
146 auto time = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::steady_clock::now() - start).count();
147 std::cout <<
"TLOG_INFO test took " << formatTime(time) <<
", avg: " << formatTime(time / loops) << std::endl;