00001
00002
00003
00004
00005
00006
00007
00008 #include "artdaq/DAQdata/Globals.hh"
00009 #include <boost/program_options.hpp>
00010 #include <iomanip>
00011 namespace bpo = boost::program_options;
00012
00013 std::string formatTime(double time)
00014 {
00015 std::ostringstream o;
00016 o << std::fixed << std::setprecision(3);
00017 if (time > 60) o << static_cast<int>(time / 60) << " m " << time - 60 * static_cast<int>(time / 60) << " s";
00018 else if (time > 1) o << time << " s";
00019 else
00020 {
00021 time *= 1000;
00022 if (time > 1) o << time << " ms";
00023 else
00024 {
00025 time *= 1000;
00026 if (time > 1) o << time << " us";
00027 else
00028 {
00029 time *= 1000;
00030 o << time << " ns";
00031 }
00032 }
00033 }
00034
00035 return o.str();
00036 }
00037
00038 int main(int argc, char *argv[])
00039 {
00040 std::ostringstream descstr;
00041 descstr << argv[0]
00042 << " <-l test loops> [csutdi]";
00043 bpo::options_description desc(descstr.str());
00044 desc.add_options()
00045 ("loops,l", bpo::value<size_t>(), "Number of times to run each test")
00046 ("C,c", "Run TRACEC test")
00047 ("S,s", "Run TRACES test")
00048 ("U,u", "Run TRACE_ test")
00049 ("T,t", "Run TRACE_STREAMER test")
00050 ("D,d", "Run TLOG_DEBUG test")
00051 ("I,i", "Run TLOG_INFO test")
00052 ("console,x", "Enable MessageFacility output to console")
00053 ("help,h", "produce help message");
00054 bpo::variables_map vm;
00055 try {
00056 bpo::store(bpo::command_line_parser(argc, argv).options(desc).run(), vm);
00057 bpo::notify(vm);
00058 }
00059 catch (bpo::error const & e) {
00060 std::cerr << "Exception from command line processing in " << argv[0]
00061 << ": " << e.what() << "\n";
00062 return -1;
00063 }
00064 if (vm.count("help")) {
00065 std::cout << desc << std::endl;
00066 return 1;
00067 }
00068 if (!vm.count("loops")) {
00069 std::cerr << "Exception from command line processing in " << argv[0]
00070 << ": no loop count given.\n"
00071 << "For usage and an options list, please do '"
00072 << argv[0] << " --help"
00073 << "'.\n";
00074 return 2;
00075 }
00076 size_t loops = vm["loops"].as<size_t>();
00077
00078 artdaq::configureMessageFacility("tracemf",vm.count("console"));
00079
00080 if (vm.count("C")) {
00081 std::cout << "Starting TRACEC test" << std::endl;
00082 auto start = std::chrono::steady_clock::now();
00083 for (size_t l = 0; l < loops; ++l)
00084 {
00085 TRACE(TLVL_DEBUG, "Test TRACEC with an int %i and a float %.1f", 42, 5.56);
00086 }
00087 auto time = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::steady_clock::now() - start).count();
00088 std::cout << "TRACEC test took " << formatTime(time) << ", avg: " << formatTime(time / loops) << std::endl;
00089 }
00090
00091 if (vm.count("S")) {
00092 std::cout << "Starting TRACES test" << std::endl;
00093 auto start = std::chrono::steady_clock::now();
00094 for (size_t l = 0; l < loops; ++l)
00095 {
00096 TRACE(TLVL_DEBUG, "Test TRACE with an int " + std::to_string(42) + " and a float %.1f", 5.56);
00097 }
00098 auto time = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::steady_clock::now() - start).count();
00099 std::cout << "TRACES test took " << formatTime(time) << ", avg: " << formatTime(time / loops) << std::endl;
00100 }
00101
00102 if (vm.count("U")) {
00103 std::cout << "Starting TRACE_ test" << std::endl;
00104 auto start = std::chrono::steady_clock::now();
00105 for (size_t l = 0; l < loops; ++l)
00106 {
00107 TRACE_(TLVL_DEBUG, "Test TRACE_ with an int " << 42 << " and a float %.1f", 5.56);
00108 }
00109 auto time = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::steady_clock::now() - start).count();
00110 std::cout << "TRACE_ test took " << formatTime(time) << ", avg: " << formatTime(time / loops) << std::endl;
00111 }
00112
00113 if (vm.count("T")) {
00114 std::cout << "Starting TRACE_STREAMER test" << std::endl;
00115 auto start = std::chrono::steady_clock::now();
00116 for (size_t l = 0; l < loops; ++l)
00117 {
00118 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;
00119 }
00120 auto time = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::steady_clock::now() - start).count();
00121 std::cout << "TRACE_STREAMER test took " << formatTime(time) << ", avg: " << formatTime(time / loops) << std::endl;
00122 }
00123
00124 if (vm.count("D")) {
00125 std::cout << "Starting TLOG_DEBUG test" << std::endl;
00126 auto start = std::chrono::steady_clock::now();
00127 for (size_t l = 0; l < loops; ++l)
00128 {
00129 TLOG_DEBUG("tracemf") << "Test TLOG_DEBUG with an int " << 42 << " and a float " << std::fixed << std::setprecision(1) << 5.56 << TRACE_ENDL;
00130 }
00131 auto time = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::steady_clock::now() - start).count();
00132 std::cout << "TLOG_DEBUG test took " << formatTime(time) << ", avg: " << formatTime(time / loops) << std::endl;
00133 }
00134
00135 if (vm.count("I")) {
00136 std::cout << "Starting TLOG_INFO test" << std::endl;
00137 auto start = std::chrono::steady_clock::now();
00138 for (size_t l = 0; l < loops; ++l)
00139 {
00140 TLOG_INFO("tracemf") << "Test TLOG_INFO with an int " << 42 << " and a float " << std::fixed << std::setprecision(1) << 5.56 << TRACE_ENDL;
00141 }
00142 auto time = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::steady_clock::now() - start).count();
00143 std::cout << "TLOG_INFO test took " << formatTime(time) << ", avg: " << formatTime(time/loops) << std::endl;
00144 }
00145
00146 return (0);
00147 }