artdaq  v3_04_01
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  {
57  bpo::store(bpo::command_line_parser(argc, argv).options(desc).run(), vm);
58  bpo::notify(vm);
59  }
60  catch (bpo::error const & e)
61  {
62  std::cerr << "Exception from command line processing in " << argv[0]
63  << ": " << e.what() << "\n";
64  return -1;
65  }
66  if (vm.count("help"))
67  {
68  std::cout << desc << std::endl;
69  return 1;
70  }
71  if (!vm.count("loops"))
72  {
73  std::cerr << "Exception from command line processing in " << argv[0]
74  << ": no loop count given.\n"
75  << "For usage and an options list, please do '"
76  << argv[0] << " --help"
77  << "'.\n";
78  return 2;
79  }
80  size_t loops = vm["loops"].as<size_t>();
81 
82  artdaq::configureMessageFacility("tracemf", vm.count("console"));
83 
84  if (vm.count("C"))
85  {
86  std::cout << "Starting TRACEC test" << std::endl;
87  auto start = std::chrono::steady_clock::now();
88  for (size_t l = 0; l < loops; ++l)
89  {
90  TRACE(TLVL_DEBUG, "Test TRACEC with an int %i and a float %.1f", 42, 5.56);
91  }
92  auto time = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::steady_clock::now() - start).count();
93  std::cout << "TRACEC test took " << formatTime(time) << ", avg: " << formatTime(time / loops) << std::endl;
94  }
95 
96  if (vm.count("S"))
97  {
98  std::cout << "Starting TRACES test" << std::endl;
99  auto start = std::chrono::steady_clock::now();
100  for (size_t l = 0; l < loops; ++l)
101  {
102  std::string test = "Test TRACE with an int %d";
103  std::string test2 = " and a float %.1f";
104  TRACE(TLVL_DEBUG, test + test2, 42, 5.56);
105  }
106  auto time = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::steady_clock::now() - start).count();
107  std::cout << "TRACES test took " << formatTime(time) << ", avg: " << formatTime(time / loops) << std::endl;
108  }
109 
110  if (vm.count("U"))
111  {
112  std::cout << "Starting TRACE_ test" << std::endl;
113  auto start = std::chrono::steady_clock::now();
114  for (size_t l = 0; l < loops; ++l)
115  {
116  TRACEN_( "tracemf", TLVL_DEBUG, "Test TRACE_ with an int " << 42 << " and a float %.1f", 5.56);
117  }
118  auto time = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::steady_clock::now() - start).count();
119  std::cout << "TRACE_ test took " << formatTime(time) << ", avg: " << formatTime(time / loops) << std::endl;
120  }
121 
122  if (vm.count("D"))
123  {
124  std::cout << "Starting TLOG_DEBUG test" << std::endl;
125  auto start = std::chrono::steady_clock::now();
126  for (size_t l = 0; l < loops; ++l)
127  {
128  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;
129  }
130  auto time = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::steady_clock::now() - start).count();
131  std::cout << "TLOG_DEBUG test took " << formatTime(time) << ", avg: " << formatTime(time / loops) << std::endl;
132  }
133 
134  if (vm.count("I"))
135  {
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::setprecision(1) << 5.56 << ", and another float " << std::fixed << 7.3 << 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 */