LCOV - code coverage report
Current view: top level - datadog - metrics.cpp (source / functions) Hit Total Coverage
Test: filtered.info Lines: 26 26 100.0 %
Date: 2024-01-03 20:30:12 Functions: 16 16 100.0 %

          Line data    Source code
       1             : #include "metrics.h"
       2             : 
       3             : #include "json.hpp"
       4             : 
       5             : namespace datadog {
       6             : namespace tracing {
       7             : 
       8        8500 : Metric::Metric(std::string name, std::string type,
       9        8500 :                std::vector<std::string> tags, bool common)
      10        8500 :     : name_(name), type_(type), tags_(tags), common_(common) {}
      11          36 : std::string Metric::name() { return name_; }
      12          72 : std::string Metric::type() { return type_; }
      13          36 : std::vector<std::string> Metric::tags() { return tags_; }
      14          36 : bool Metric::common() { return common_; }
      15           7 : uint64_t Metric::value() { return value_; }
      16         536 : uint64_t Metric::capture_and_reset_value() { return value_.exchange(0); }
      17             : 
      18        8499 : CounterMetric::CounterMetric(std::string name, std::vector<std::string> tags,
      19        8499 :                              bool common)
      20        8499 :     : Metric(name, "count", tags, common) {}
      21      332419 : void CounterMetric::inc() { add(1); }
      22      332420 : void CounterMetric::add(uint64_t amount) { value_ += amount; }
      23             : 
      24           1 : GaugeMetric::GaugeMetric(std::string name, std::vector<std::string> tags,
      25           1 :                          bool common)
      26           1 :     : Metric(name, "gauge", tags, common) {}
      27           1 : void GaugeMetric::set(uint64_t value) { value_ = value; }
      28           1 : void GaugeMetric::inc() { add(1); }
      29           3 : void GaugeMetric::add(uint64_t amount) { value_ += amount; }
      30           1 : void GaugeMetric::dec() { sub(1); }
      31           3 : void GaugeMetric::sub(uint64_t amount) {
      32           3 :   if (amount > value_) {
      33           1 :     value_ = 0;
      34             :   } else {
      35           2 :     value_ -= amount;
      36             :   }
      37           3 : }
      38             : 
      39             : }  // namespace tracing
      40             : }  // namespace datadog

Generated by: LCOV version 1.16