$treeview $search $mathjax $extrastylesheet
artdaq
v3_04_00
$projectbrief
|
$projectbrief
|
$searchbox |
00001 /* This file (just.cc) was created by Ron Rechenmacher <ron@fnal.gov> on 00002 // Feb 19, 2014. "TERMS AND CONDITIONS" governing this file are in the README 00003 // or COPYING file. If you do not have such a file, one can be obtained by 00004 // contacting Ron or Fermi Lab in Batavia IL, 60510, phone: 630-840-3000. 00005 // $RCSfile: just_user.cc,v $ 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 { 00057 bpo::store(bpo::command_line_parser(argc, argv).options(desc).run(), vm); 00058 bpo::notify(vm); 00059 } 00060 catch (bpo::error const & e) 00061 { 00062 std::cerr << "Exception from command line processing in " << argv[0] 00063 << ": " << e.what() << "\n"; 00064 return -1; 00065 } 00066 if (vm.count("help")) 00067 { 00068 std::cout << desc << std::endl; 00069 return 1; 00070 } 00071 if (!vm.count("loops")) 00072 { 00073 std::cerr << "Exception from command line processing in " << argv[0] 00074 << ": no loop count given.\n" 00075 << "For usage and an options list, please do '" 00076 << argv[0] << " --help" 00077 << "'.\n"; 00078 return 2; 00079 } 00080 size_t loops = vm["loops"].as<size_t>(); 00081 00082 artdaq::configureMessageFacility("tracemf", vm.count("console")); 00083 00084 if (vm.count("C")) 00085 { 00086 std::cout << "Starting TRACEC test" << std::endl; 00087 auto start = std::chrono::steady_clock::now(); 00088 for (size_t l = 0; l < loops; ++l) 00089 { 00090 TRACE(TLVL_DEBUG, "Test TRACEC with an int %i and a float %.1f", 42, 5.56); 00091 } 00092 auto time = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::steady_clock::now() - start).count(); 00093 std::cout << "TRACEC test took " << formatTime(time) << ", avg: " << formatTime(time / loops) << std::endl; 00094 } 00095 00096 if (vm.count("S")) 00097 { 00098 std::cout << "Starting TRACES test" << std::endl; 00099 auto start = std::chrono::steady_clock::now(); 00100 for (size_t l = 0; l < loops; ++l) 00101 { 00102 std::string test = "Test TRACE with an int %d"; 00103 std::string test2 = " and a float %.1f"; 00104 TRACE(TLVL_DEBUG, test + test2, 42, 5.56); 00105 } 00106 auto time = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::steady_clock::now() - start).count(); 00107 std::cout << "TRACES test took " << formatTime(time) << ", avg: " << formatTime(time / loops) << std::endl; 00108 } 00109 00110 if (vm.count("U")) 00111 { 00112 std::cout << "Starting TRACE_ test" << std::endl; 00113 auto start = std::chrono::steady_clock::now(); 00114 for (size_t l = 0; l < loops; ++l) 00115 { 00116 TRACEN_( "tracemf", TLVL_DEBUG, "Test TRACE_ with an int " << 42 << " and a float %.1f", 5.56); 00117 } 00118 auto time = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::steady_clock::now() - start).count(); 00119 std::cout << "TRACE_ test took " << formatTime(time) << ", avg: " << formatTime(time / loops) << std::endl; 00120 } 00121 00122 if (vm.count("D")) 00123 { 00124 std::cout << "Starting TLOG_DEBUG test" << std::endl; 00125 auto start = std::chrono::steady_clock::now(); 00126 for (size_t l = 0; l < loops; ++l) 00127 { 00128 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; 00129 } 00130 auto time = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::steady_clock::now() - start).count(); 00131 std::cout << "TLOG_DEBUG test took " << formatTime(time) << ", avg: " << formatTime(time / loops) << std::endl; 00132 } 00133 00134 if (vm.count("I")) 00135 { 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::setprecision(1) << 5.56 << ", and another float " << std::fixed << 7.3 << 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 } /* main */