LCOV - code coverage report
Current view: top level - root/contrail/src/contrail-common/base - watermark.cc (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 47 52 90.4 %
Date: 2026-11-09 02:10:49 Functions: 12 13 92.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //
       2             : // Copyright (c) 2016 Juniper Networks, Inc. All rights reserved.
       3             : // Copyright Contributors to the OpenSDN project
       4             : //
       5             : 
       6             : #include "watermark.h"
       7             : 
       8      250365 : WaterMarkTuple::WaterMarkTuple() :
       9      250365 :     last_count_(0) {
      10      250364 : }
      11             : 
      12           1 : void WaterMarkTuple::SetHighWaterMark(const WaterMarkInfos &high_water) {
      13           1 :     high_water_ = high_water;
      14           1 : }
      15             : 
      16        1643 : void WaterMarkTuple::SetHighWaterMark(const WaterMarkInfo& hwm_info) {
      17        1643 :     high_water_.insert(hwm_info);
      18        1643 : }
      19             : 
      20      226418 : void WaterMarkTuple::ResetHighWaterMark() {
      21      226418 :     high_water_.clear();
      22      226418 : }
      23             : 
      24          11 : WaterMarkInfos WaterMarkTuple::GetHighWaterMark() const {
      25          11 :     return high_water_;
      26             : }
      27             : 
      28           4 : void WaterMarkTuple::SetLowWaterMark(const WaterMarkInfos &low_water) {
      29           4 :     low_water_ = low_water;
      30           4 : }
      31             : 
      32        1628 : void WaterMarkTuple::SetLowWaterMark(const WaterMarkInfo& lwm_info) {
      33        1628 :     low_water_.insert(lwm_info);
      34        1628 : }
      35             : 
      36      226417 : void WaterMarkTuple::ResetLowWaterMark() {
      37      226417 :     low_water_.clear();
      38      226417 : }
      39             : 
      40           1 : WaterMarkInfos WaterMarkTuple::GetLowWaterMark() const {
      41           1 :     return low_water_;
      42             : }
      43             : 
      44           0 : void WaterMarkTuple::ProcessWaterMarks(size_t in_count,
      45             :                                        size_t curr_count) {
      46           0 :     if (in_count < curr_count)
      47           0 :         ProcessLowWaterMarks(in_count);
      48             :     else
      49           0 :         ProcessHighWaterMarks(in_count);
      50           0 : }
      51             : 
      52    21785532 : bool WaterMarkTuple::AreWaterMarksSet() const {
      53    21785532 :     return high_water_.size() != 0 || low_water_.size() != 0;
      54             : }
      55             : 
      56     9643700 : void WaterMarkTuple::ProcessHighWaterMarks(size_t count) {
      57     9643700 :     if (high_water_.size() != 0) {
      58      113012 :         WaterMarkInfos::const_iterator ubound = high_water_.upper_bound(
      59      226024 :             WaterMarkInfo(count, NULL));
      60             : 
      61      113012 :         if (ubound != high_water_.begin()) {
      62             :             // ubound is the first one bigger than count,
      63             :             // so ubound-1 is the last one smaller or equal to count
      64       52663 :             --ubound;
      65       52663 :             assert(count >= ubound->count_);
      66             :             // we have to check if we actually crossed the watermark
      67       52663 :             if (last_count_ < ubound->count_) {
      68          65 :                 ubound->cb_(count);
      69             :             }
      70             :         }
      71             :     }
      72     9643527 :     last_count_ = count;
      73     9643527 : }
      74             : 
      75     9643062 : void WaterMarkTuple::ProcessLowWaterMarks(size_t count) {
      76     9643062 :     if (low_water_.size() != 0) {
      77      113010 :         WaterMarkInfos::const_iterator lbound = low_water_.lower_bound(
      78      226020 :             WaterMarkInfo(count, NULL));
      79             : 
      80      113010 :         if (lbound != low_water_.end()) {
      81             :             // we have to check if we actually crossed the watermark
      82      112996 :             if (last_count_ > lbound->count_) {
      83         163 :                 lbound->cb_(count);
      84             :             }
      85             :         }
      86             :     }
      87     9642742 :     last_count_ = count;
      88     9642742 : }

Generated by: LCOV version 1.14