artdaq  v2_03_00
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
tracemf.cc
1 /* This file (just.cc) was created by Ron Rechenmacher <ron@fnal.gov> on
2 // Feb 19, 2014. "TERMS AND CONDITIONS" governing this file are in the README
3 // or COPYING file. If you do not have such a file, one can be obtained by
4 // contacting Ron or Fermi Lab in Batavia IL, 60510, phone: 630-840-3000.
5 // $RCSfile: just_user.cc,v $
6 */
7 
8 #include "artdaq/DAQdata/Globals.hh"
9 #include "boost/program_options.hpp"
10 #include <iomanip>
11 namespace bpo = boost::program_options;
12 
13 std::string formatTime(double time)
14 {
15  std::ostringstream o;
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";
19  else
20  {
21  time *= 1000;
22  if (time > 1) o << time << " ms";
23  else
24  {
25  time *= 1000;
26  if (time > 1) o << time << " us";
27  else
28  {
29  time *= 1000;
30  o << time << " ns";
31  }
32  }
33  }
34 
35  return o.str();
36 }
37 
38 int main(int argc, char *argv[])
39 {
40  std::ostringstream descstr;
41  descstr << argv[0]
42  << " <-l test loops> [csutdi]";
43  bpo::options_description desc(descstr.str());
44  desc.add_options()
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;
55  try {
56  bpo::store(bpo::command_line_parser(argc, argv).options(desc).run(), vm);
57  bpo::notify(vm);
58  }
59  catch (bpo::error const & e) {
60  std::cerr << "Exception from command line processing in " << argv[0]
61  << ": " << e.what() << "\n";
62  return -1;
63  }
64  if (vm.count("help")) {
65  std::cout << desc << std::endl;
66  return 1;
67  }
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"
73  << "'.\n";
74  return 2;
75  }
76  size_t loops = vm["loops"].as<size_t>();
77 
78  artdaq::configureMessageFacility("tracemf",vm.count("console"));
79 
80  if (vm.count("C")) {
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)
84  {
85  TRACE(TLVL_DEBUG, "Test TRACEC with an int %i and a float %.1f", 42, 5.56);
86  }
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;
89  }
90 
91  if (vm.count("S")) {
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)
95  {
96  TRACE(TLVL_DEBUG, "Test TRACE with an int " + std::to_string(42) + " and a float %.1f", 5.56);
97  }
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;
100  }
101 
102  if (vm.count("U")) {
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)
106  {
107  TRACE_(TLVL_DEBUG, "Test TRACE_ with an int " << 42 << " and a float %.1f", 5.56);
108  }
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;
111  }
112 
113  if (vm.count("T")) {
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)
117  {
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;
119  }
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;
122  }
123 
124  if (vm.count("D")) {
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)
128  {
129  TLOG_DEBUG("tracemf") << "Test TLOG_DEBUG with an int " << 42 << " and a float " << std::fixed << std::setprecision(1) << 5.56 << TRACE_ENDL;
130  }
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;
133  }
134 
135  if (vm.count("I")) {
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)
139  {
140  TLOG_INFO("tracemf") << "Test TLOG_INFO with an int " << 42 << " and a float " << std::fixed << std::setprecision(1) << 5.56 << TRACE_ENDL;
141  }
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;
144  }
145 
146  return (0);
147 } /* main */
void configureMessageFacility(char const *progname, bool useConsole=true)
Configure and start the message facility. Provide the program name so that messages will be appropria...