artdaq_utilities  v1_05_00
test_metric.cc
1 // test_metric.cc: Test Metric Plugin
2 // Author: Eric Flumerfelt
3 // Last Modified: 4/10/2019
4 //
5 // An implementation of the MetricPlugin that writes to the TestMetric static storage
6 
7 #include "artdaq-utilities/Plugins/MetricMacros.hh"
8 #include "artdaq-utilities/Plugins/TestMetric.hh"
9 #include "fhiclcpp/ParameterSet.h"
10 
11 #include <sys/types.h>
12 #include <unistd.h>
13 #include <ctime>
14 #include <string>
15 
16 namespace artdaq {
21 {
22 public:
28  explicit TestMetricImpl(fhicl::ParameterSet const& config, std::string const& app_name)
29  : MetricPlugin(config, app_name)
30  {
31  startMetrics();
32  }
33 
37  virtual ~TestMetricImpl()
38  {
39  stopMetrics();
40  }
41 
46  std::string getLibName() const override { return "test"; }
47 
54  void sendMetric_(const std::string& name, const std::string& value, const std::string& unit) override
55  {
56  if (!inhibit_)
57  {
58  std::lock_guard<std::mutex> lk(TestMetric::received_metrics_mutex);
59  TestMetric::received_metrics.emplace_back(TestMetric::MetricPoint{std::chrono::steady_clock::now(), name, value, unit});
60  }
61  }
62 
69  void sendMetric_(const std::string& name, const int& value, const std::string& unit) override
70  {
71  sendMetric_(name, std::to_string(value), unit);
72  }
73 
80  void sendMetric_(const std::string& name, const double& value, const std::string& unit) override
81  {
82  sendMetric_(name, std::to_string(value), unit);
83  }
84 
91  void sendMetric_(const std::string& name, const float& value, const std::string& unit) override
92  {
93  sendMetric_(name, std::to_string(value), unit);
94  }
95 
102  void sendMetric_(const std::string& name, const unsigned long int& value, const std::string& unit) override
103  {
104  sendMetric_(name, std::to_string(value), unit);
105  }
106 
110  void startMetrics_() override
111  {
112  }
113 
117  void stopMetrics_() override
118  {
119  }
120 };
121 
122 } // End namespace artdaq
123 
124 DEFINE_ARTDAQ_METRIC(artdaq::TestMetricImpl)
TestMetricImpl(fhicl::ParameterSet const &config, std::string const &app_name)
TestMetric Constructor.
Definition: test_metric.cc:28
void startMetrics_() override
Perform startup actions.
Definition: test_metric.cc:110
void sendMetric_(const std::string &name, const double &value, const std::string &unit) override
Write metric data to memory.
Definition: test_metric.cc:80
The MetricPlugin class defines the interface that MetricManager uses to send metric data to the vario...
Definition: MetricPlugin.hh:29
void startMetrics()
Perform startup actions. Simply calls the virtual startMetrics_ function.
virtual ~TestMetricImpl()
TestMetricImpl Destructor. Calls stopMetrics.
Definition: test_metric.cc:37
std::string getLibName() const override
Get the library name for the Test metric.
Definition: test_metric.cc:46
void stopMetrics()
Perform shutdown actions. Zeroes out all accumulators, and sends zeros for each metric. Calls stopMetrics_() for any plugin-defined shutdown actions.
TestMetric writes metric data to a statically-allocated memory block.
Definition: test_metric.cc:20
void sendMetric_(const std::string &name, const unsigned long int &value, const std::string &unit) override
Write metric data to memory.
Definition: test_metric.cc:102
void sendMetric_(const std::string &name, const int &value, const std::string &unit) override
Write metric data to memory.
Definition: test_metric.cc:69
void sendMetric_(const std::string &name, const std::string &value, const std::string &unit) override
Write metric data to memory.
Definition: test_metric.cc:54
void stopMetrics_() override
Perform shutdown actions.
Definition: test_metric.cc:117
void sendMetric_(const std::string &name, const float &value, const std::string &unit) override
Write metric data to memory.
Definition: test_metric.cc:91
bool inhibit_
Flag to indicate that the MetricPlugin is being stopped, and any metric back-ends which do not have a...