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;
56 bpo::store(bpo::command_line_parser(argc, argv).options(desc).run(), vm);
59 catch (bpo::error
const & e) {
60 std::cerr <<
"Exception from command line processing in " << argv[0]
61 <<
": " << e.what() <<
"\n";
64 if (vm.count(
"help")) {
65 std::cout << desc << std::endl;
68 if (!vm.count(
"loops")) {
69 std::cerr <<
"Exception from command line processing in " << argv[0]
70 <<
": no loop count given.\n"
71 <<
"For usage and an options list, please do '"
72 << argv[0] <<
" --help"
76 size_t loops = vm[
"loops"].as<
size_t>();
81 std::cout <<
"Starting TRACEC test" << std::endl;
82 auto start = std::chrono::steady_clock::now();
83 for (
size_t l = 0; l < loops; ++l)
85 TRACE(TLVL_DEBUG,
"Test TRACEC with an int %i and a float %.1f", 42, 5.56);
87 auto time = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::steady_clock::now() - start).count();
88 std::cout <<
"TRACEC test took " << formatTime(time) <<
", avg: " << formatTime(time / loops) << std::endl;
92 std::cout <<
"Starting TRACES test" << std::endl;
93 auto start = std::chrono::steady_clock::now();
94 for (
size_t l = 0; l < loops; ++l)
96 TRACE(TLVL_DEBUG,
"Test TRACE with an int " + std::to_string(42) +
" and a float %.1f", 5.56);
98 auto time = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::steady_clock::now() - start).count();
99 std::cout <<
"TRACES test took " << formatTime(time) <<
", avg: " << formatTime(time / loops) << std::endl;
103 std::cout <<
"Starting TRACE_ test" << std::endl;
104 auto start = std::chrono::steady_clock::now();
105 for (
size_t l = 0; l < loops; ++l)
107 TRACE_(TLVL_DEBUG,
"Test TRACE_ with an int " << 42 <<
" and a float %.1f", 5.56);
109 auto time = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::steady_clock::now() - start).count();
110 std::cout <<
"TRACE_ test took " << formatTime(time) <<
", avg: " << formatTime(time / loops) << std::endl;
114 std::cout <<
"Starting TRACE_STREAMER test" << std::endl;
115 auto start = std::chrono::steady_clock::now();
116 for (
size_t l = 0; l < loops; ++l)
118 TRACE_STREAMER(TLVL_DEBUG,
"tracemf", 0) <<
"Test TRACE_STREAMER with an int " << 42 <<
" and a float " << std::fixed << std::setprecision(1) << 5.56 << TRACE_ENDL;
120 auto time = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::steady_clock::now() - start).count();
121 std::cout <<
"TRACE_STREAMER test took " << formatTime(time) <<
", avg: " << formatTime(time / loops) << std::endl;
125 std::cout <<
"Starting TLOG_DEBUG test" << std::endl;
126 auto start = std::chrono::steady_clock::now();
127 for (
size_t l = 0; l < loops; ++l)
129 TLOG_DEBUG(
"tracemf") <<
"Test TLOG_DEBUG with an int " << 42 <<
" and a float " << std::fixed << std::setprecision(1) << 5.56 << TRACE_ENDL;
131 auto time = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::steady_clock::now() - start).count();
132 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::fixed << std::setprecision(1) << 5.56 << 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;
void configureMessageFacility(char const *progname, bool useConsole=true)
Configure and start the message facility. Provide the program name so that messages will be appropria...