artdaq  v3_08_00
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 <boost/program_options.hpp>
9 #include <iomanip>
10 #include "artdaq/DAQdata/Globals.hh"
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)
18  o << static_cast<int>(time / 60) << " m " << time - 60 * static_cast<int>(time / 60) << " s";
19  else if (time > 1)
20  o << time << " s";
21  else
22  {
23  time *= 1000;
24  if (time > 1)
25  o << time << " ms";
26  else
27  {
28  time *= 1000;
29  if (time > 1)
30  o << time << " us";
31  else
32  {
33  time *= 1000;
34  o << time << " ns";
35  }
36  }
37  }
38 
39  return o.str();
40 }
41 
42 int main(int argc, char *argv[])
43 {
44  std::ostringstream descstr;
45  descstr << argv[0]
46  << " <-l test loops> [csutdi]";
47  bpo::options_description desc(descstr.str());
48  desc.add_options()("loops,l", bpo::value<size_t>(), "Number of times to run each test")("C,c", "Run TRACEC test")("S,s", "Run TRACES test")("U,u", "Run TRACE_ test")("T,t", "Run TRACE_STREAMER test")("D,d", "Run TLOG_DEBUG test")("I,i", "Run TLOG_INFO test")("console,x", "Enable MessageFacility output to console")("help,h", "produce help message");
49  bpo::variables_map vm;
50  try
51  {
52  bpo::store(bpo::command_line_parser(argc, argv).options(desc).run(), vm);
53  bpo::notify(vm);
54  }
55  catch (bpo::error const &e)
56  {
57  std::cerr << "Exception from command line processing in " << argv[0]
58  << ": " << e.what() << "\n";
59  return -1;
60  }
61  if (vm.count("help"))
62  {
63  std::cout << desc << std::endl;
64  return 1;
65  }
66  if (!vm.count("loops"))
67  {
68  std::cerr << "Exception from command line processing in " << argv[0]
69  << ": no loop count given.\n"
70  << "For usage and an options list, please do '"
71  << argv[0] << " --help"
72  << "'.\n";
73  return 2;
74  }
75  size_t loops = vm["loops"].as<size_t>();
76 
77  artdaq::configureMessageFacility("tracemf", vm.count("console"));
78 
79  if (vm.count("C"))
80  {
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  {
93  std::cout << "Starting TRACES test" << std::endl;
94  auto start = std::chrono::steady_clock::now();
95  for (size_t l = 0; l < loops; ++l)
96  {
97  std::string test = "Test TRACE with an int %d";
98  std::string test2 = " and a float %.1f";
99  TRACE(TLVL_DEBUG, test + test2, 42, 5.56);
100  }
101  auto time = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::steady_clock::now() - start).count();
102  std::cout << "TRACES test took " << formatTime(time) << ", avg: " << formatTime(time / loops) << std::endl;
103  }
104 
105  if (vm.count("U"))
106  {
107  std::cout << "Starting TRACE_ test" << std::endl;
108  auto start = std::chrono::steady_clock::now();
109  for (size_t l = 0; l < loops; ++l)
110  {
111  TRACEN_("tracemf", TLVL_DEBUG, "Test TRACE_ with an int " << 42 << " and a float %.1f", 5.56);
112  }
113  auto time = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::steady_clock::now() - start).count();
114  std::cout << "TRACE_ test took " << formatTime(time) << ", avg: " << formatTime(time / loops) << std::endl;
115  }
116 
117  if (vm.count("D"))
118  {
119  std::cout << "Starting TLOG_DEBUG test" << std::endl;
120  auto start = std::chrono::steady_clock::now();
121  for (size_t l = 0; l < loops; ++l)
122  {
123  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;
124  }
125  auto time = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::steady_clock::now() - start).count();
126  std::cout << "TLOG_DEBUG test took " << formatTime(time) << ", avg: " << formatTime(time / loops) << std::endl;
127  }
128 
129  if (vm.count("I"))
130  {
131  std::cout << "Starting TLOG_INFO test" << std::endl;
132  auto start = std::chrono::steady_clock::now();
133  for (size_t l = 0; l < loops; ++l)
134  {
135  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;
136  }
137  auto time = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::steady_clock::now() - start).count();
138  std::cout << "TLOG_INFO test took " << formatTime(time) << ", avg: " << formatTime(time / loops) << std::endl;
139  }
140 
141  return (0);
142 } /* main */