LCOV - code coverage report
Current view: top level - /opt/artdaq/srcs/artdaq-utilities/test/Plugins - MetricManager_t.cc (source / functions) Coverage Total Hit
Test: artdaq.info.cleaned Lines: 98.2 % 336 330
Test Date: 2025-09-04 00:45:34 Functions: 57.3 % 274 157

            Line data    Source code
       1              : 
       2              : #define TRACE_NAME "MetricManager_t"
       3              : #include "trace.h"
       4              : 
       5              : #include "artdaq-utilities/Plugins/MetricManager.hh"
       6              : #include "artdaq-utilities/Plugins/TestMetric.hh"
       7              : 
       8              : #define BOOST_TEST_MODULE MetricManager_t
       9              : #include "cetlib/quiet_unit_test.hpp"
      10              : #include "cetlib_except/exception.h"
      11              : 
      12              : BOOST_AUTO_TEST_SUITE(MetricManager_test)
      13              : 
      14              : #define TRACE_REQUIRE_EQUAL(l, r)                                                                                                    \
      15              :         do                                                                                                                               \
      16              :         {                                                                                                                                \
      17              :                 if ((l) == (r))                                                                                                              \
      18              :                 {                                                                                                                            \
      19              :                         TLOG(TLVL_DEBUG) << __LINE__ << ": Checking if " << #l << " (" << (l) << ") equals " << #r << " (" << (r) << ")...YES!"; \
      20              :                 }                                                                                                                            \
      21              :                 else                                                                                                                         \
      22              :                 {                                                                                                                            \
      23              :                         TLOG(TLVL_ERROR) << __LINE__ << ": Checking if " << #l << " (" << (l) << ") equals " << #r << " (" << (r) << ")...NO!";  \
      24              :                 }                                                                                                                            \
      25              :                 BOOST_REQUIRE_EQUAL((l), (r));                                                                                               \
      26              :         } while (0)
      27              : 
      28              : using seconds = std::chrono::duration<double, std::ratio<1>>;
      29              : 
      30            6 : constexpr double GetElapsedTime(std::chrono::steady_clock::time_point then,
      31              :                                 std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now())
      32              : {
      33            6 :         return std::chrono::duration_cast<seconds>(now - then).count();
      34              : }
      35              : 
      36            2 : BOOST_AUTO_TEST_CASE(Construct)
      37              : {
      38            3 :         TLOG_DEBUG("MetricManager_t") << "BEGIN TEST Construct" << TLOG_ENDL;
      39            1 :         artdaq::MetricManager mm;
      40            4 :         TRACE_REQUIRE_EQUAL(mm.Initialized(), false);
      41            4 :         TRACE_REQUIRE_EQUAL(mm.Running(), false);
      42            4 :         TRACE_REQUIRE_EQUAL(mm.Active(), false);
      43            4 :         TRACE_REQUIRE_EQUAL(mm.metricQueueEmpty(), true);
      44            8 :         TRACE_REQUIRE_EQUAL(mm.metricQueueSize(), 0);
      45            3 :         TLOG_DEBUG("MetricManager_t") << "END TEST Construct" << TLOG_ENDL;
      46            1 : }
      47              : 
      48            2 : BOOST_AUTO_TEST_CASE(Initialize)
      49              : {
      50            3 :         TLOG_DEBUG("MetricManager_t") << "BEGIN TEST Initialize" << TLOG_ENDL;
      51            1 :         artdaq::MetricManager mm;
      52            4 :         TRACE_REQUIRE_EQUAL(mm.Initialized(), false);
      53            4 :         TRACE_REQUIRE_EQUAL(mm.Running(), false);
      54            4 :         TRACE_REQUIRE_EQUAL(mm.Active(), false);
      55            4 :         TRACE_REQUIRE_EQUAL(mm.metricQueueEmpty(), true);
      56            8 :         TRACE_REQUIRE_EQUAL(mm.metricQueueSize(), 0);
      57              : 
      58            1 :         std::string testConfig = "msgFac: { level: 5 metricPluginType: test reporting_interval: 1.0}";
      59            1 :         fhicl::ParameterSet pset = fhicl::ParameterSet::make(testConfig);
      60              : 
      61            1 :         mm.initialize(pset, "MetricManager_t");
      62            4 :         TRACE_REQUIRE_EQUAL(mm.Initialized(), true);
      63            4 :         TRACE_REQUIRE_EQUAL(mm.Running(), false);
      64            4 :         TRACE_REQUIRE_EQUAL(mm.Active(), false);
      65              : 
      66            1 :         mm.do_start();
      67            4 :         TRACE_REQUIRE_EQUAL(mm.Running(), true);
      68            4 :         TRACE_REQUIRE_EQUAL(mm.Active(), true);
      69            3 :         TLOG_DEBUG("MetricManager_t") << "END TEST Initialize" << TLOG_ENDL;
      70            1 : }
      71              : 
      72            2 : BOOST_AUTO_TEST_CASE(Initialize_WithError)
      73              : {
      74            3 :         TLOG_DEBUG("MetricManager_t") << "BEGIN TEST Initialize_WithError" << TLOG_ENDL;
      75            1 :         artdaq::MetricManager mm;
      76            4 :         TRACE_REQUIRE_EQUAL(mm.Initialized(), false);
      77            4 :         TRACE_REQUIRE_EQUAL(mm.Running(), false);
      78            4 :         TRACE_REQUIRE_EQUAL(mm.Active(), false);
      79            4 :         TRACE_REQUIRE_EQUAL(mm.metricQueueEmpty(), true);
      80            8 :         TRACE_REQUIRE_EQUAL(mm.metricQueueSize(), 0);
      81              : 
      82            1 :         std::string testConfig = "err: { level: 5 metricPluginType: nonExistentPluginType reporting_interval: 1.0}";
      83            1 :         fhicl::ParameterSet pset = fhicl::ParameterSet::make(testConfig);
      84              : 
      85            1 :         mm.initialize(pset, "MetricManager_t");
      86            4 :         TRACE_REQUIRE_EQUAL(mm.Initialized(), true);
      87            4 :         TRACE_REQUIRE_EQUAL(mm.Running(), false);
      88              : 
      89            1 :         mm.do_start();
      90            4 :         TRACE_REQUIRE_EQUAL(mm.Running(), true);
      91            4 :         TRACE_REQUIRE_EQUAL(mm.Active(), false);
      92            3 :         TLOG_DEBUG("MetricManager_t") << "END TEST Initialize_WithError" << TLOG_ENDL;
      93            1 : }
      94              : 
      95            2 : BOOST_AUTO_TEST_CASE(Shutdown)
      96              : {
      97            3 :         TLOG_DEBUG("MetricManager_t") << "BEGIN TEST Shutdown" << TLOG_ENDL;
      98            1 :         artdaq::MetricManager mm;
      99            4 :         TRACE_REQUIRE_EQUAL(mm.Initialized(), false);
     100            4 :         TRACE_REQUIRE_EQUAL(mm.Running(), false);
     101            4 :         TRACE_REQUIRE_EQUAL(mm.Active(), false);
     102            4 :         TRACE_REQUIRE_EQUAL(mm.metricQueueEmpty(), true);
     103            8 :         TRACE_REQUIRE_EQUAL(mm.metricQueueSize(), 0);
     104              : 
     105            1 :         std::string testConfig = "msgFac: { level: 5 metricPluginType: test reporting_interval: 1.0}";
     106            1 :         fhicl::ParameterSet pset = fhicl::ParameterSet::make(testConfig);
     107              : 
     108            1 :         mm.initialize(pset, "MetricManager_t");
     109            4 :         TRACE_REQUIRE_EQUAL(mm.Initialized(), true);
     110            4 :         TRACE_REQUIRE_EQUAL(mm.Running(), false);
     111            4 :         TRACE_REQUIRE_EQUAL(mm.Active(), false);
     112              : 
     113            1 :         mm.do_start();
     114            4 :         TRACE_REQUIRE_EQUAL(mm.Running(), true);
     115            4 :         TRACE_REQUIRE_EQUAL(mm.Active(), true);
     116              : 
     117            1 :         mm.do_stop();
     118            4 :         TRACE_REQUIRE_EQUAL(mm.Running(), false);
     119            4 :         TRACE_REQUIRE_EQUAL(mm.Initialized(), true);
     120              : 
     121            1 :         mm.shutdown();
     122            4 :         TRACE_REQUIRE_EQUAL(mm.Initialized(), false);
     123            3 :         TLOG_DEBUG("MetricManager_t") << "END TEST Shutdown" << TLOG_ENDL;
     124            1 : }
     125              : 
     126            2 : BOOST_AUTO_TEST_CASE(SendMetric_String)
     127              : {
     128            3 :         TLOG_DEBUG("MetricManager_t") << "BEGIN TEST SendMetric_String" << TLOG_ENDL;
     129            1 :         artdaq::MetricManager mm;
     130            4 :         TRACE_REQUIRE_EQUAL(mm.Initialized(), false);
     131            4 :         TRACE_REQUIRE_EQUAL(mm.Running(), false);
     132            4 :         TRACE_REQUIRE_EQUAL(mm.Active(), false);
     133            4 :         TRACE_REQUIRE_EQUAL(mm.metricQueueEmpty(), true);
     134            8 :         TRACE_REQUIRE_EQUAL(mm.metricQueueSize(), 0);
     135              : 
     136            1 :         std::string testConfig = "msgFac: { level: 5 metricPluginType: test reporting_interval: 1.0}";
     137            1 :         fhicl::ParameterSet pset = fhicl::ParameterSet::make(testConfig);
     138              : 
     139            1 :         mm.initialize(pset, "MetricManager_t");
     140            4 :         TRACE_REQUIRE_EQUAL(mm.Initialized(), true);
     141            4 :         TRACE_REQUIRE_EQUAL(mm.Running(), false);
     142            4 :         TRACE_REQUIRE_EQUAL(mm.Active(), false);
     143              : 
     144            1 :         mm.do_start();
     145            4 :         TRACE_REQUIRE_EQUAL(mm.Running(), true);
     146            4 :         TRACE_REQUIRE_EQUAL(mm.Active(), true);
     147              : 
     148            7 :         mm.sendMetric("Test Metric", "This is a test", "Units", 2, artdaq::MetricMode::LastPoint);
     149              : 
     150            1 :         mm.do_stop();
     151            4 :         TRACE_REQUIRE_EQUAL(mm.Running(), false);
     152            4 :         TRACE_REQUIRE_EQUAL(mm.Initialized(), true);
     153              : 
     154            1 :         mm.shutdown();
     155            4 :         TRACE_REQUIRE_EQUAL(mm.Initialized(), false);
     156            3 :         TLOG_DEBUG("MetricManager_t") << "END TEST SendMetric_String" << TLOG_ENDL;
     157            1 : }
     158              : 
     159            2 : BOOST_AUTO_TEST_CASE(SendMetrics)  // NOLINT(readability-function-size)
     160              : {
     161            3 :         TLOG_DEBUG("MetricManager_t") << "BEGIN TEST SendMetrics" << TLOG_ENDL;
     162            1 :         artdaq::MetricManager mm;
     163            4 :         TRACE_REQUIRE_EQUAL(mm.Initialized(), false);
     164            4 :         TRACE_REQUIRE_EQUAL(mm.Running(), false);
     165            4 :         TRACE_REQUIRE_EQUAL(mm.Active(), false);
     166            4 :         TRACE_REQUIRE_EQUAL(mm.metricQueueEmpty(), true);
     167            8 :         TRACE_REQUIRE_EQUAL(mm.metricQueueSize(), 0);
     168              : 
     169            1 :         std::string testConfig = "msgFac: { level: 5 metricPluginType: test reporting_interval: 0.5 send_zeros: false} metric_send_maximum_delay_ms: 100 metric_holdoff_us: 10000";
     170            1 :         fhicl::ParameterSet pset = fhicl::ParameterSet::make(testConfig);
     171              : 
     172            1 :         mm.initialize(pset, "MetricManager_t");
     173            4 :         TRACE_REQUIRE_EQUAL(mm.Initialized(), true);
     174            4 :         TRACE_REQUIRE_EQUAL(mm.Running(), false);
     175            4 :         TRACE_REQUIRE_EQUAL(mm.Active(), false);
     176              : 
     177            1 :         mm.do_start();
     178            4 :         TRACE_REQUIRE_EQUAL(mm.Running(), true);
     179            4 :         TRACE_REQUIRE_EQUAL(mm.Active(), true);
     180              : 
     181            6 :         mm.sendMetric("Test Metric LastPoint", 1, "Units", 2, artdaq::MetricMode::LastPoint, "", true);
     182            5 :         mm.sendMetric("Test Metric LastPoint", 5, "Units", 2, artdaq::MetricMode::LastPoint, "", true);
     183           11 :         while (mm.metricManagerBusy())
     184              :         {
     185           10 :                 usleep(1000);
     186              :         }
     187              : 
     188              :         {
     189            1 :                 auto points = artdaq::TestMetric::get_received_metrics();
     190            1 :                 bool present = false;
     191           32 :                 for (auto& point : points)
     192              :                 {
     193           93 :                         TLOG(TLVL_DEBUG) << "Metric: " << point.metric << ", Value: " << point.value << ", Units: " << point.unit;
     194           31 :                         if (point.metric == "Test Metric LastPoint")
     195              :                         {
     196            4 :                                 TRACE_REQUIRE_EQUAL(point.value, "5");
     197            4 :                                 TRACE_REQUIRE_EQUAL(point.unit, "Units");
     198            1 :                                 present = true;
     199              :                         }
     200              :                 }
     201            1 :                 BOOST_REQUIRE(present);
     202            1 :         }
     203              : 
     204            6 :         mm.sendMetric("Test Metric Accumulate", 4, "Units", 2, artdaq::MetricMode::Accumulate, "", true);
     205            5 :         mm.sendMetric("Test Metric Accumulate", 5, "Units", 2, artdaq::MetricMode::Accumulate, "", true);
     206          491 :         while (mm.metricManagerBusy())
     207              :         {
     208          490 :                 usleep(1000);
     209              :         }
     210              : 
     211              :         {
     212            1 :                 auto points = artdaq::TestMetric::get_received_metrics();
     213            1 :                 bool present = false;
     214            6 :                 for (auto& point : points)
     215              :                 {
     216            5 :                         if (point.metric == "Test Metric Accumulate")
     217              :                         {
     218            4 :                                 TRACE_REQUIRE_EQUAL(point.value, "9");
     219            4 :                                 TRACE_REQUIRE_EQUAL(point.unit, "Units");
     220            1 :                                 present = true;
     221              :                         }
     222              :                 }
     223            1 :                 BOOST_REQUIRE(present);
     224            1 :         }
     225              : 
     226            6 :         mm.sendMetric("Test Metric Average", 1, "Units", 2, artdaq::MetricMode::Average, "", true);
     227            5 :         mm.sendMetric("Test Metric Average", 3, "Units", 2, artdaq::MetricMode::Average, "", true);
     228          492 :         while (mm.metricManagerBusy())
     229              :         {
     230          491 :                 usleep(1000);
     231              :         }
     232              : 
     233              :         {
     234            1 :                 auto points = artdaq::TestMetric::get_received_metrics();
     235            1 :                 bool present = false;
     236            6 :                 for (auto& point : points)
     237              :                 {
     238            5 :                         if (point.metric == "Test Metric Average")
     239              :                         {
     240            4 :                                 TRACE_REQUIRE_EQUAL(std::stof(point.value), 2);
     241            4 :                                 TRACE_REQUIRE_EQUAL(point.unit, "Units");
     242            1 :                                 present = true;
     243              :                         }
     244              :                 }
     245            1 :                 BOOST_REQUIRE(present);
     246            1 :         }
     247              : 
     248            6 :         mm.sendMetric("Test Metric Rate", 4, "Units", 2, artdaq::MetricMode::Rate, "", true);
     249            5 :         mm.sendMetric("Test Metric Rate", 5, "Units", 2, artdaq::MetricMode::Rate, "", true);
     250          492 :         while (mm.metricManagerBusy())
     251              :         {
     252          491 :                 usleep(1000);
     253              :         }
     254              : 
     255              :         {
     256            1 :                 auto points = artdaq::TestMetric::get_received_metrics();
     257            1 :                 bool present = false;
     258            6 :                 for (auto& point : points)
     259              :                 {
     260            5 :                         if (point.metric == "Test Metric Rate")
     261              :                         {
     262            4 :                                 TRACE_REQUIRE_EQUAL(point.unit, "Units/s");
     263            1 :                                 present = true;
     264              :                         }
     265              :                 }
     266            1 :                 BOOST_REQUIRE(present);
     267            1 :         }
     268              : 
     269            6 :         mm.sendMetric("Test Metric AccumulateAndRate", 4, "Units", 2, artdaq::MetricMode::Accumulate | artdaq::MetricMode::Rate, "", true);
     270            5 :         mm.sendMetric("Test Metric AccumulateAndRate", 5, "Units", 2, artdaq::MetricMode::Accumulate | artdaq::MetricMode::Rate, "", true);
     271          491 :         while (mm.metricManagerBusy())
     272              :         {
     273          490 :                 usleep(1000);
     274              :         }
     275              : 
     276              :         {
     277            1 :                 auto points = artdaq::TestMetric::get_received_metrics();
     278            1 :                 int present = 0;
     279            7 :                 for (auto& point : points)
     280              :                 {
     281            6 :                         if (point.metric == "Test Metric AccumulateAndRate - Sum")
     282              :                         {
     283            4 :                                 TRACE_REQUIRE_EQUAL(point.value, "9");
     284            4 :                                 TRACE_REQUIRE_EQUAL(point.unit, "Units");
     285            1 :                                 present++;
     286              :                         }
     287            6 :                         if (point.metric == "Test Metric AccumulateAndRate - Rate")
     288              :                         {
     289            4 :                                 TRACE_REQUIRE_EQUAL(point.unit, "Units/s");
     290            1 :                                 present++;
     291              :                         }
     292              :                 }
     293            4 :                 TRACE_REQUIRE_EQUAL(present, 2);
     294            1 :         }
     295              : 
     296            1 :         mm.do_stop();
     297            4 :         TRACE_REQUIRE_EQUAL(mm.Running(), false);
     298            4 :         TRACE_REQUIRE_EQUAL(mm.Initialized(), true);
     299              : 
     300            1 :         mm.shutdown();
     301            4 :         TRACE_REQUIRE_EQUAL(mm.Initialized(), false);
     302            3 :         TLOG_DEBUG("MetricManager_t") << "END TEST SendMetrics" << TLOG_ENDL;
     303            1 : }
     304              : 
     305            2 : BOOST_AUTO_TEST_CASE(SendMetrics_Levels)  // NOLINT(readability-function-size)
     306              : {
     307            3 :         TLOG_DEBUG("MetricManager_t") << "BEGIN TEST SendMetrics_Levels" << TLOG_ENDL;
     308            1 :         artdaq::MetricManager mm;
     309            4 :         TRACE_REQUIRE_EQUAL(mm.Initialized(), false);
     310            4 :         TRACE_REQUIRE_EQUAL(mm.Running(), false);
     311            4 :         TRACE_REQUIRE_EQUAL(mm.Active(), false);
     312            4 :         TRACE_REQUIRE_EQUAL(mm.metricQueueEmpty(), true);
     313            8 :         TRACE_REQUIRE_EQUAL(mm.metricQueueSize(), 0);
     314              : 
     315            1 :         std::string testConfig = "msgFac: { level: 0 metric_levels: [ 1, 2 ] level_string: \"3-5,9,7\" metricPluginType: test reporting_interval: 0.1 send_zeros: false} metric_send_maximum_delay_ms: 100";
     316            1 :         fhicl::ParameterSet pset = fhicl::ParameterSet::make(testConfig);
     317              : 
     318            1 :         mm.initialize(pset, "MetricManager_t");
     319            4 :         TRACE_REQUIRE_EQUAL(mm.Initialized(), true);
     320            4 :         TRACE_REQUIRE_EQUAL(mm.Running(), false);
     321            4 :         TRACE_REQUIRE_EQUAL(mm.Active(), false);
     322              : 
     323            1 :         mm.do_start();
     324            4 :         TRACE_REQUIRE_EQUAL(mm.Running(), true);
     325            4 :         TRACE_REQUIRE_EQUAL(mm.Active(), true);
     326              : 
     327            6 :         mm.sendMetric("Test Metric 0", 0, "Units", 0, artdaq::MetricMode::LastPoint, "", true);
     328            6 :         mm.sendMetric("Test Metric 1", 1, "Units", 1, artdaq::MetricMode::LastPoint, "", true);
     329            6 :         mm.sendMetric("Test Metric 2", 2, "Units", 2, artdaq::MetricMode::LastPoint, "", true);
     330            6 :         mm.sendMetric("Test Metric 3", 3, "Units", 3, artdaq::MetricMode::LastPoint, "", true);
     331            6 :         mm.sendMetric("Test Metric 4", 4, "Units", 4, artdaq::MetricMode::LastPoint, "", true);
     332            6 :         mm.sendMetric("Test Metric 5", 5, "Units", 5, artdaq::MetricMode::LastPoint, "", true);
     333            6 :         mm.sendMetric("Test Metric 6", 6, "Units", 6, artdaq::MetricMode::LastPoint, "", true);
     334            6 :         mm.sendMetric("Test Metric 7", 7, "Units", 7, artdaq::MetricMode::LastPoint, "", true);
     335            6 :         mm.sendMetric("Test Metric 8", 8, "Units", 8, artdaq::MetricMode::LastPoint, "", true);
     336            6 :         mm.sendMetric("Test Metric 9", 9, "Units", 9, artdaq::MetricMode::LastPoint, "", true);
     337            5 :         mm.sendMetric("Test Metric 10", 10, "Units", 10, artdaq::MetricMode::LastPoint, "", true);
     338            1 :         std::bitset<11> received_metrics_;
     339              : 
     340            3 :         while (mm.metricManagerBusy())
     341              :         {
     342            2 :                 usleep(1000);
     343              :         }
     344              : 
     345              :         {
     346            1 :                 auto points = artdaq::TestMetric::get_received_metrics();
     347           15 :                 for (auto& point : points)
     348              :                 {
     349           14 :                         if (point.metric == "Test Metric 0")
     350              :                         {
     351            4 :                                 TRACE_REQUIRE_EQUAL(point.value, "0");
     352            4 :                                 TRACE_REQUIRE_EQUAL(point.unit, "Units");
     353            1 :                                 received_metrics_[0] = true;
     354              :                         }
     355           14 :                         if (point.metric == "Test Metric 1")
     356              :                         {
     357            4 :                                 TRACE_REQUIRE_EQUAL(point.value, "1");
     358            4 :                                 TRACE_REQUIRE_EQUAL(point.unit, "Units");
     359            1 :                                 received_metrics_[1] = true;
     360              :                         }
     361           14 :                         if (point.metric == "Test Metric 2")
     362              :                         {
     363            4 :                                 TRACE_REQUIRE_EQUAL(point.value, "2");
     364            4 :                                 TRACE_REQUIRE_EQUAL(point.unit, "Units");
     365            1 :                                 received_metrics_[2] = true;
     366              :                         }
     367           14 :                         if (point.metric == "Test Metric 3")
     368              :                         {
     369            4 :                                 TRACE_REQUIRE_EQUAL(point.value, "3");
     370            4 :                                 TRACE_REQUIRE_EQUAL(point.unit, "Units");
     371            1 :                                 received_metrics_[3] = true;
     372              :                         }
     373           14 :                         if (point.metric == "Test Metric 4")
     374              :                         {
     375            4 :                                 TRACE_REQUIRE_EQUAL(point.value, "4");
     376            4 :                                 TRACE_REQUIRE_EQUAL(point.unit, "Units");
     377            1 :                                 received_metrics_[4] = true;
     378              :                         }
     379           14 :                         if (point.metric == "Test Metric 5")
     380              :                         {
     381            4 :                                 TRACE_REQUIRE_EQUAL(point.value, "5");
     382            4 :                                 TRACE_REQUIRE_EQUAL(point.unit, "Units");
     383            1 :                                 received_metrics_[5] = true;
     384              :                         }
     385           14 :                         if (point.metric == "Test Metric 6")
     386              :                         {
     387            0 :                                 BOOST_TEST_FAIL("Metric level 6 should not have been sent!");
     388            0 :                                 received_metrics_[6] = true;
     389              :                         }
     390           14 :                         if (point.metric == "Test Metric 7")
     391              :                         {
     392            4 :                                 TRACE_REQUIRE_EQUAL(point.value, "7");
     393            4 :                                 TRACE_REQUIRE_EQUAL(point.unit, "Units");
     394            1 :                                 received_metrics_[7] = true;
     395              :                         }
     396           14 :                         if (point.metric == "Test Metric 8")
     397              :                         {
     398            0 :                                 BOOST_TEST_FAIL("Metric level 8 should not have been sent!");
     399            0 :                                 received_metrics_[8] = true;
     400              :                         }
     401           14 :                         if (point.metric == "Test Metric 9")
     402              :                         {
     403            4 :                                 TRACE_REQUIRE_EQUAL(point.value, "9");
     404            4 :                                 TRACE_REQUIRE_EQUAL(point.unit, "Units");
     405            1 :                                 received_metrics_[9] = true;
     406              :                         }
     407           14 :                         if (point.metric == "Test Metric 10")
     408              :                         {
     409            0 :                                 BOOST_TEST_FAIL("Metric level 10 should not have been sent!");
     410            0 :                                 received_metrics_[10] = true;
     411              :                         }
     412              :                 }
     413            4 :                 TRACE_REQUIRE_EQUAL(received_metrics_.to_ulong(), 0x2BF);
     414            1 :         }
     415              : 
     416            1 :         mm.do_stop();
     417            4 :         TRACE_REQUIRE_EQUAL(mm.Running(), false);
     418            4 :         TRACE_REQUIRE_EQUAL(mm.Initialized(), true);
     419              : 
     420            1 :         mm.shutdown();
     421            4 :         TRACE_REQUIRE_EQUAL(mm.Initialized(), false);
     422            3 :         TLOG_DEBUG("MetricManager_t") << "END TEST SendMetrics_Levels" << TLOG_ENDL;
     423            1 : }
     424              : 
     425            2 : BOOST_AUTO_TEST_CASE(MetricFlood)  // NOLINT(readability-function-size)
     426              : {
     427            3 :         TLOG_DEBUG("MetricManager_t") << "BEGIN TEST MetricFlood" << TLOG_ENDL;
     428            1 :         artdaq::MetricManager mm;
     429            4 :         TRACE_REQUIRE_EQUAL(mm.Initialized(), false);
     430            4 :         TRACE_REQUIRE_EQUAL(mm.Running(), false);
     431            4 :         TRACE_REQUIRE_EQUAL(mm.Active(), false);
     432            4 :         TRACE_REQUIRE_EQUAL(mm.metricQueueEmpty(), true);
     433            8 :         TRACE_REQUIRE_EQUAL(mm.metricQueueSize(), 0);
     434              : 
     435            1 :         std::string testConfig = "msgFac: { level: 5 metricPluginType: test reporting_interval: 0.1 send_zeros: false}  metric_send_maximum_delay_ms: 100";
     436            1 :         fhicl::ParameterSet pset = fhicl::ParameterSet::make(testConfig);
     437              : 
     438            1 :         mm.initialize(pset, "MetricManager_t");
     439            4 :         TRACE_REQUIRE_EQUAL(mm.Initialized(), true);
     440            4 :         TRACE_REQUIRE_EQUAL(mm.Running(), false);
     441            4 :         TRACE_REQUIRE_EQUAL(mm.Active(), false);
     442              : 
     443            1 :         mm.do_start();
     444            4 :         TRACE_REQUIRE_EQUAL(mm.Running(), true);
     445            4 :         TRACE_REQUIRE_EQUAL(mm.Active(), true);
     446              : 
     447            1 :         auto beforeOne = std::chrono::steady_clock::now();
     448            5 :         mm.sendMetric("Test Metric 1", 1, "Units", 2, artdaq::MetricMode::Accumulate, "", true);
     449            1 :         auto afterOne = std::chrono::steady_clock::now();
     450              : 
     451            3 :         while (mm.metricManagerBusy())
     452              :         {
     453            2 :                 usleep(1000);
     454              :         }
     455              : 
     456            1 :         auto beforeTen = std::chrono::steady_clock::now();
     457           11 :         for (auto ii = 1; ii <= 10; ++ii)
     458              :         {
     459           60 :                 mm.sendMetric("Test Metric 10", ii, "Units", 2, artdaq::MetricMode::Accumulate, "", true);
     460              :         }
     461            1 :         auto afterTen = std::chrono::steady_clock::now();
     462              : 
     463          114 :         while (mm.metricManagerBusy())
     464              :         {
     465          113 :                 usleep(1000);
     466              :         }
     467              : 
     468            1 :         auto beforeOneHundred = std::chrono::steady_clock::now();
     469          101 :         for (auto ii = 1; ii <= 100; ++ii)
     470              :         {
     471          600 :                 mm.sendMetric("Test Metric 100", ii, "Units", 2, artdaq::MetricMode::Accumulate, "", true);
     472              :         }
     473            1 :         auto afterOneHundred = std::chrono::steady_clock::now();
     474              : 
     475          106 :         while (mm.metricManagerBusy())
     476              :         {
     477          105 :                 usleep(1000);
     478              :         }
     479              : 
     480            1 :         auto beforeOneThousand = std::chrono::steady_clock::now();
     481         1001 :         for (auto ii = 1; ii <= 1000; ++ii)
     482              :         {
     483         6000 :                 mm.sendMetric("Test Metric 1000", ii, "Units", 2, artdaq::MetricMode::Accumulate, "", true);
     484              :         }
     485            1 :         auto afterOneThousand = std::chrono::steady_clock::now();
     486              : 
     487          105 :         while (mm.metricManagerBusy())
     488              :         {
     489          104 :                 usleep(1000);
     490              :         }
     491              : 
     492            1 :         auto beforeTenThousand = std::chrono::steady_clock::now();
     493        10001 :         for (auto ii = 1; ii <= 10000; ++ii)
     494              :         {
     495        60000 :                 mm.sendMetric("Test Metric 10000", ii, "Units", 2, artdaq::MetricMode::Accumulate, "", true);
     496              :         }
     497            1 :         auto afterTenThousand = std::chrono::steady_clock::now();
     498              : 
     499            1 :         auto beforeStop = std::chrono::steady_clock::now();
     500            1 :         mm.do_stop();
     501            4 :         TRACE_REQUIRE_EQUAL(mm.Running(), false);
     502            4 :         TRACE_REQUIRE_EQUAL(mm.Initialized(), true);
     503            1 :         auto afterStop = std::chrono::steady_clock::now();
     504              : 
     505            3 :         TLOG_INFO("MetricManager_t") << "Time for One Metric: " << GetElapsedTime(beforeOne, afterOne) << " s." << TLOG_ENDL;
     506            3 :         TLOG_INFO("MetricManager_t") << "Time for Ten Metrics: " << GetElapsedTime(beforeTen, afterTen) << " s." << TLOG_ENDL;
     507            3 :         TLOG_INFO("MetricManager_t") << "Time for One Hundred Metrics: " << GetElapsedTime(beforeOneHundred, afterOneHundred)
     508            2 :                                      << " s." << TLOG_ENDL;
     509            3 :         TLOG_INFO("MetricManager_t") << "Time for One Thousand Metrics: "
     510            2 :                                      << GetElapsedTime(beforeOneThousand, afterOneThousand) << " s." << TLOG_ENDL;
     511            3 :         TLOG_INFO("MetricManager_t") << "Time for Ten Thousand Metrics: "
     512            2 :                                      << GetElapsedTime(beforeTenThousand, afterTenThousand) << " s." << TLOG_ENDL;
     513            3 :         TLOG_INFO("MetricManager_t") << "Time for Stop Metrics: " << GetElapsedTime(beforeStop, afterStop) << " s."
     514            2 :                                      << TLOG_ENDL;
     515              : 
     516            1 :         mm.shutdown();
     517            4 :         TRACE_REQUIRE_EQUAL(mm.Initialized(), false);
     518            3 :         TLOG_DEBUG("MetricManager_t") << "END TEST MetricFlood" << TLOG_ENDL;
     519            1 : }
     520              : 
     521              : BOOST_AUTO_TEST_SUITE_END()
        

Generated by: LCOV version 2.0-1