LCOV - code coverage report
Current view: top level - root/contrail/src/contrail-common/base - task_monitor.h (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 5 8 62.5 %
Date: 2026-08-03 02:19:58 Functions: 5 8 62.5 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2017 Juniper Networks, Inc. All rights reserved.
       3             :  */
       4             : 
       5             : #ifndef __BASE_TASK_MONITOR_H__
       6             : #define __BASE_TASK_MONITOR_H__
       7             : 
       8             : /****************************************************************************
       9             :  * Monitor module for TBB.
      10             :  * It is observed that TBB randomly goes into a state where no tasks are
      11             :  * scheduled. The monitor here tracks the tasks enqueued and executed.
      12             :  *
      13             :  * If the monitor identifes that TBB is in a lockup state, then it will
      14             :  * assert the process
      15             :  ****************************************************************************/
      16             : #include <boost/asio/placeholders.hpp>
      17             : #include <boost/system/error_code.hpp>
      18             : 
      19             : #include "util.h"
      20             : 
      21             : class TaskScheduler;
      22             : class TimerImpl;
      23             : class EventManager;
      24             : 
      25             : class TaskMonitor {
      26             : public:
      27             :     TaskMonitor(TaskScheduler *scheduler, uint64_t tbb_keepawake_time_msec,
      28             :                 uint64_t inactivity_time_msec, uint64_t poll_interval_msec);
      29             :     ~TaskMonitor();
      30             : 
      31             :     void Start(EventManager *evm);
      32             :     void Terminate();
      33             :     void Run(const boost::system::error_code &ec);
      34             : 
      35          30 :     uint64_t last_activity() const { return last_activity_; }
      36          30 :     uint64_t last_enqueue_count() const { return last_enqueue_count_; }
      37          30 :     uint64_t last_done_count() const { return last_done_count_; }
      38             : 
      39           0 :     uint64_t inactivity_time_usec() const { return inactivity_time_usec_; }
      40          10 :     uint64_t inactivity_time_msec() const { return inactivity_time_usec_/1000; }
      41          10 :     uint64_t poll_interval_msec() const { return poll_interval_msec_; }
      42           0 :     uint64_t tbb_keepawake_time_msec() const { return tbb_keepawake_time_msec_;}
      43           0 :     uint64_t poll_count() const { return poll_count_; }
      44             : private:
      45             :     friend class TaskMonitorTest;
      46             : 
      47             :     void UpdateTimers();
      48             :     void Restart();
      49             :     bool Monitor(uint64_t t, uint64_t enqueue_count, uint64_t done_count);
      50             : 
      51             :     TaskScheduler *scheduler_;
      52             :     // Monitor terminated
      53             :     bool cancelled_;
      54             :     // ASIO Timer implementation class
      55             :     std::unique_ptr<TimerImpl> timer_impl_;
      56             : 
      57             :     // inactivity in usec after which monitor must invoke assert()
      58             :     uint64_t inactivity_time_usec_;
      59             :     // interval at which tbb must be monitored
      60             :     uint64_t poll_interval_msec_;
      61             :     // TBB keepawake time
      62             :     uint64_t tbb_keepawake_time_msec_;
      63             :     // time of last activity seen
      64             :     uint64_t last_activity_;
      65             :     // TaskScheduler->enqueue_count() at last_change_
      66             :     uint64_t last_enqueue_count_;
      67             :     // TaskScheduler->done_count() at last_change_
      68             :     uint64_t last_done_count_;
      69             :     // Number of times monitor is run
      70             :     uint64_t poll_count_;
      71             :     DISALLOW_COPY_AND_ASSIGN(TaskMonitor);
      72             : };
      73             : 
      74             : #endif  //  __BASE_TASK_MONITOR_H__

Generated by: LCOV version 1.14