LCOV - code coverage report
Current view: top level - server - statistic_manager.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 93.3 % 240 224
Test Date: 2026-08-12 11:05:07 Functions: 94.9 % 79 75

            Line data    Source code
       1              : /**
       2              :  * Copyright (c) 2025 Huawei Technologies Co., Ltd.
       3              :  * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
       4              :  * CANN Open Software License Agreement Version 2.0 (the "License").
       5              :  * Please refer to the License for details. You may not use this file except in compliance with the License.
       6              :  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
       7              :  * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
       8              :  * See LICENSE in the root of the software repository for the full text of the License.
       9              :  */
      10              : 
      11              : #include "statistic_manager.h"
      12              : #include <thread>
      13              : #include "common/bqs_log.h"
      14              : #include "server/hccl_process.h"
      15              : #include "server/qs_interface_process.h"
      16              : 
      17              : namespace bqs {
      18              : namespace {
      19              : // statistic period in seconds
      20              : constexpr const float64_t STATISTIC_PERIOD = 80.0;
      21              : // entity statistic period in seconds
      22              : constexpr const uint64_t ENTITY_STATISTIC_PERIOD = 30UL;
      23              : // supply event period in seconds
      24              : constexpr const uint64_t SUPPLY_EVENT_PERIOD = 1UL;
      25              : // wake up statistic thread in milliseconds (100ms)
      26              : constexpr const uint64_t WAKEUP_PERIOD_IN_MS = 100UL;
      27              : // 1s = 1000ms
      28              : constexpr const uint64_t MS_IN_ONE_SECOND = 1000UL;
      29              : constexpr const char_t* STATISTIC_THREAD_NAME_PREFIX = "statistic";
      30              : // proc mem stat period 10s
      31              : constexpr const uint64_t PROC_MEM_STAT_PERIOD = 10UL;
      32              : } // namespace
      33              : 
      34         2013 : StatisticManager& StatisticManager::GetInstance()
      35              : {
      36         2013 :     static StatisticManager instance;
      37         2013 :     return instance;
      38              : }
      39              : 
      40            2 : uint64_t StatisticManager::EventScheduleStat(const uint32_t scheduleNum)
      41              : {
      42            2 :     totalStat_.eventScheduleTimes += static_cast<uint64_t>(scheduleNum);
      43            2 :     periodStat_.eventScheduleTimes += static_cast<uint64_t>(scheduleNum);
      44            2 :     return totalStat_.eventScheduleTimes;
      45              : }
      46              : 
      47            1 : void StatisticManager::EnqueueEventFalseAwakenStat() { ++totalStat_.enqueueFalseAwakenTimes; }
      48              : 
      49            0 : uint64_t StatisticManager::GetEventScheduleStat() const { return totalStat_.eventScheduleTimes; }
      50              : 
      51            1 : void StatisticManager::DaemonEventScheduleStat() { ++totalStat_.daemonEventScheduleTimes; }
      52              : 
      53          111 : void StatisticManager::AwakenAdd() { ++totalStat_.awakenTimes; }
      54              : 
      55            0 : uint64_t StatisticManager::GetAwakenTimes() const { return totalStat_.awakenTimes; }
      56              : 
      57           15 : void StatisticManager::AddScheduleEmpty() { ++totalStat_.scheduleEmptyTimes; }
      58              : 
      59           26 : void StatisticManager::DataScheduleFailedStat(const uint64_t failedNum)
      60              : {
      61           26 :     totalStat_.dataScheduleFailedTimes += failedNum;
      62           26 : }
      63              : 
      64            3 : void StatisticManager::RelationEnqueueStat() { ++totalStat_.relationEnqueueTimes; }
      65              : 
      66            4 : void StatisticManager::RelationDequeueStat() { ++totalStat_.relationDequeueTimes; }
      67              : 
      68            2 : uint64_t StatisticManager::GetRelationEnqueCnt() const { return totalStat_.relationEnqueueTimes; }
      69              : 
      70            2 : uint64_t StatisticManager::GetRelationDequeCnt() const { return totalStat_.relationDequeueTimes; }
      71              : 
      72            2 : void StatisticManager::AsynMemEnqueueStat() { ++totalStat_.asynMemEnqueueTimes; }
      73              : 
      74            1 : void StatisticManager::AsynMemDequeueStat() { ++totalStat_.asynMemDequeueTimes; }
      75              : 
      76            0 : uint64_t StatisticManager::GetAsynMemEnqueCnt() const { return totalStat_.asynMemEnqueueTimes; }
      77              : 
      78            0 : uint64_t StatisticManager::GetAsynMemDequeCnt() const { return totalStat_.asynMemDequeueTimes; }
      79              : 
      80            2 : void StatisticManager::F2nfEnqueueStat() { ++totalStat_.f2nfEnqueueTimes; }
      81              : 
      82            5 : void StatisticManager::F2nfDequeueStat() { ++totalStat_.f2nfDequeueTimes; }
      83              : 
      84            2 : uint64_t StatisticManager::HcclMpiRecvRequestEventStat() { return ++totalStat_.hcclMpiRecvRequestEventTimes; }
      85              : 
      86            1 : void StatisticManager::HcclMpiRecvReqFalseAwakenStat() { ++totalStat_.hcclMpiRecvReqFalseAwakenTimes; }
      87              : 
      88            2 : void StatisticManager::HcclMpiRecvReqEmptySchedStat() { ++totalStat_.hcclMpiRecvReqEmptySchedTimes; }
      89              : 
      90            2 : void StatisticManager::HcclMpiRecvReqCallbackStat() { ++totalStat_.hcclMpiRecvReqCallbackTimes; }
      91              : 
      92            3 : uint64_t StatisticManager::HcclMpiSendCompEventStat() { return ++totalStat_.hcclMpiSendCompEventTimes; }
      93              : 
      94            1 : void StatisticManager::HcclMpiSendCompFalseAwakenStat() { ++totalStat_.hcclMpiSendCompFalseAwakenTimes; }
      95              : 
      96            4 : void StatisticManager::HcclMpiSendCompEmptySchedStat() { ++totalStat_.hcclMpiSendCompEmptySchedTimes; }
      97              : 
      98            3 : void StatisticManager::HcclMpiSendCompCallbackStat() { ++totalStat_.hcclMpiSendCompCallbackTimes; }
      99              : 
     100            5 : uint64_t StatisticManager::HcclMpiRecvCompEventStat() { return ++totalStat_.hcclMpiRecvCompEventTimes; }
     101              : 
     102            1 : void StatisticManager::HcclMpiRecvCompFalseAwakenStat() { ++totalStat_.hcclMpiRecvCompFalseAwakenTimes; }
     103              : 
     104            3 : void StatisticManager::HcclMpiRecvCompEmptySchedStat() { ++totalStat_.hcclMpiRecvCompEmptySchedTimes; }
     105              : 
     106            5 : void StatisticManager::HcclMpiRecvCompCallbackStat() { ++totalStat_.hcclMpiRecvCompCallbackTimes; }
     107              : 
     108            1 : void StatisticManager::F2nfEventStat() { ++totalStat_.f2nfEventTimes; }
     109              : 
     110            1 : void StatisticManager::F2nfEventFalseAwakenStat() { ++totalStat_.f2nfFalseAwakenTimes; }
     111              : 
     112           17 : void StatisticManager::HcclMpiRecvSuccStat() { ++totalStat_.hcclMpiRecvSuccTimes; }
     113              : 
     114            4 : void StatisticManager::HcclMpiRecvFailStat() { ++totalStat_.hcclMpiRecvFailTimes; }
     115              : 
     116           36 : void StatisticManager::HcclMpiSendSuccStat() { ++totalStat_.hcclMpiSendSuccTimes; }
     117              : 
     118            5 : void StatisticManager::HcclMpiSendFailStat() { ++totalStat_.hcclMpiSendFailTimes; }
     119              : 
     120            3 : void StatisticManager::HcclMpiSendFullStat() { ++totalStat_.hcclMpiSendFullTimes; }
     121              : 
     122            1 : void StatisticManager::HcclMpiF2nfEventStat() { ++totalStat_.hcclMpiF2nfEventTimes; }
     123              : 
     124           12 : void StatisticManager::MbufAllocStat(const uint64_t size)
     125              : {
     126           12 :     ++totalStat_.mbufAllocTimes;
     127           12 :     totalStat_.mbufAllocSize += size;
     128           12 : }
     129              : 
     130            4 : void StatisticManager::MbufFreeStat(const uint64_t size)
     131              : {
     132            4 :     ++totalStat_.mbufFreeTimes;
     133            4 :     totalStat_.mbufFreeSize += size;
     134            4 : }
     135              : 
     136            2 : void StatisticManager::RecvReqEventSupplyStat() { ++totalStat_.supplyRecvReqEventTimes; }
     137              : 
     138           15 : void StatisticManager::DataDequeueStat() { ++totalStat_.dataDequeueTimes; }
     139              : 
     140            7 : void StatisticManager::DataQueueEnqueueSuccStat()
     141              : {
     142            7 :     ++totalStat_.dataEnqueueSuccTimes;
     143            7 :     ++periodStat_.dataEnqueueSuccTimes;
     144            7 : }
     145              : 
     146           17 : void StatisticManager::DataQueueEnqueueFailStat() { ++totalStat_.dataEnqueueFailTimes; }
     147              : 
     148            4 : void StatisticManager::DataQueueEnqueueFullStat() { ++totalStat_.dataEnqueueFullTimes; }
     149              : 
     150            4 : void StatisticManager::BindStat() { ++totalStat_.bindTimes; }
     151              : 
     152            2 : void StatisticManager::UnbindStat() { ++totalStat_.unbindTimes; }
     153              : 
     154           10 : void StatisticManager::GetBindStat() { ++totalStat_.getBindTimes; }
     155              : 
     156            2 : void StatisticManager::GetAllBindStat() { ++totalStat_.getAllBindTimes; }
     157              : 
     158            9 : void StatisticManager::ResponseStat() { ++totalStat_.responseTimes; }
     159              : 
     160          137 : void StatisticManager::BindNum(const uint32_t bindNum) { bindNum_.store(bindNum); }
     161              : 
     162          136 : void StatisticManager::AbnormalBindNum(const uint32_t bindNum) { abnormalBindNum_.store(bindNum); }
     163              : 
     164          137 : void StatisticManager::SubscribeNum(const uint32_t subscribeNum) { subscribeNum_.store(subscribeNum); }
     165              : 
     166           13 : void StatisticManager::PauseSubscribe() { ++pauseSubscribeNum_; }
     167              : 
     168            9 : void StatisticManager::ResumeSubscribe() { --pauseSubscribeNum_; }
     169              : 
     170          128 : void StatisticManager::RefreshEnqueHeartBeat() { ++enqueThreadHearBeat_; }
     171              : 
     172           18 : void StatisticManager::StartStatisticManager(
     173              :     const uint32_t abnormalInterval, const uint32_t hostPid, const bool numaFlag, const uint32_t deviceIdExtra,
     174              :     const uint32_t enqueGroupIdExtra)
     175              : {
     176           18 :     runFlag_ = true;
     177           18 :     abnormalInterval_ = abnormalInterval;
     178           18 :     numaFlag_ = numaFlag;
     179           18 :     deviceIdExtra_ = deviceIdExtra;
     180           18 :     enqueGroupIdExtra_ = enqueGroupIdExtra;
     181           18 :     procMemStat_.InitProcMemStatistic();
     182           18 :     hostPid_ = hostPid;
     183           18 :     BQS_LOG_RUN_INFO("StartStatisticManager, abnormalInterval: %u, numaFlag: %d", abnormalInterval, numaFlag);
     184           18 :     timerThread_ = std::thread(&StatisticManager::ThreadFunc, this);
     185           18 : }
     186              : 
     187            3 : StatisticManager::~StatisticManager()
     188              : {
     189            3 :     DumpStatistic();
     190            3 :     StopStatisticManager();
     191            3 : }
     192              : 
     193          313 : void StatisticManager::StopStatisticManager()
     194              : {
     195          313 :     runFlag_ = false;
     196              : 
     197          313 :     const std::unique_lock<std::mutex> waitLock(timerMutex_);
     198          313 :     if (timerThread_.joinable()) {
     199           18 :         timerThread_.join();
     200              :     }
     201          313 : }
     202              : 
     203           11 : void StatisticManager::DumpStatistic()
     204              : {
     205           11 :     const uint64_t awakenTimes = totalStat_.awakenTimes;
     206           11 :     const uint64_t eventScheduleTimes = totalStat_.eventScheduleTimes;
     207           11 :     const uint64_t enqueueFlaseAwakenTimes = totalStat_.enqueueFalseAwakenTimes;
     208           11 :     const uint64_t daemonEventScheduleTimes = totalStat_.daemonEventScheduleTimes;
     209           11 :     const uint64_t periodEventScheduleTimes = periodStat_.eventScheduleTimes.exchange(0UL);
     210           11 :     const uint64_t dataEnqueueTimes = totalStat_.dataEnqueueSuccTimes;
     211           11 :     const uint64_t dataDequeueTimes = totalStat_.dataDequeueTimes;
     212           11 :     const uint64_t scheduleEmptyTimes = totalStat_.scheduleEmptyTimes;
     213           11 :     const uint64_t dataScheduleFailedTimes = totalStat_.dataScheduleFailedTimes;
     214           11 :     const uint64_t relationEnqueueTimes = totalStat_.relationEnqueueTimes;
     215           11 :     const uint64_t relationDequeueTimes = totalStat_.relationDequeueTimes;
     216           11 :     const uint64_t asynMemEnqueueTimes = totalStat_.asynMemEnqueueTimes;
     217           11 :     const uint64_t asynMemDequeueTimes = totalStat_.asynMemDequeueTimes;
     218           11 :     const uint64_t periodDataEnqueueTimes = periodStat_.dataEnqueueSuccTimes.exchange(0UL);
     219           11 :     const uint64_t dataEnqueueSuccTimes = totalStat_.dataEnqueueSuccTimes;
     220           11 :     const uint64_t dataEnqueueFailTimes = totalStat_.dataEnqueueFailTimes;
     221           11 :     const uint64_t dataEnqueueFullTimes = totalStat_.dataEnqueueFullTimes;
     222           11 :     const uint64_t mpiRecvSuccTimes = totalStat_.hcclMpiRecvSuccTimes;
     223           11 :     const uint64_t mpiRecvFailTimes = totalStat_.hcclMpiRecvFailTimes;
     224           11 :     const uint64_t mpiSendSuccTimes = totalStat_.hcclMpiSendSuccTimes;
     225           11 :     const uint64_t mpiSendFailTimes = totalStat_.hcclMpiSendFailTimes;
     226           11 :     const uint64_t mpiSendFullTimes = totalStat_.hcclMpiSendFullTimes;
     227           11 :     const uint64_t supplyRecvReqEventTimes = totalStat_.supplyRecvReqEventTimes;
     228           11 :     const uint64_t f2nfEventTimes = totalStat_.f2nfEventTimes;
     229           11 :     const uint64_t f2nfFalseAwakenTimes = totalStat_.f2nfFalseAwakenTimes;
     230           11 :     const uint64_t f2nfEnqueueTimes = totalStat_.f2nfEnqueueTimes;
     231           11 :     const uint64_t f2nfDequeueTimes = totalStat_.f2nfDequeueTimes;
     232           11 :     const float64_t maxProcessCostUs = scheduleStatistic_.GetMaxProcessCost();
     233           11 :     const float64_t maxScheduleDelayUs = scheduleStatistic_.GetMaxScheduleDelay();
     234           11 :     const float64_t secProcessCostUs = scheduleStatistic_.GetSecondProcessCost();
     235           11 :     const float64_t avgProcessCostUs = scheduleStatistic_.GetAvgProcessCost();
     236           11 :     scheduleStatistic_.Reset();
     237              : 
     238           55 :     BQS_LOG_RUN_INFO(
     239              :         "Statistic info: queue={bind:%u, abnormal_bind:%u, subscribe:%u, pause:%u},"
     240              :         "event={awaken:%lu, aicpu schedule:%lu, "
     241              :         "incorrect waken:%lu, control schedule:%lu, period:%lu, %.2f/s}, data={total enqueue:%lu, total dequeue:%lu, "
     242              :         "total sched empty:%lu, total n-success:%lu, period:%lu, %.2f/s}, relation queue={enqueue:%lu, dequeue:%lu}, "
     243              :         "AsynMem queue={enqueue:%lu, dequeue:%lu}, dst queue={success:%lu, n-success:%lu, full:%lu}, "
     244              :         "queue f2nf=[success:%lu, incorrect awaken:%lu, enqueue:%lu, dequeue:%lu], "
     245              :         "hcclImrecv=[success:%lu, n-success:%lu], hcclIsend=[success:%lu, full:%lu, n-success:%lu], "
     246              :         "supply recv request event times=%lu}, maxProcessCostUs[%.2f/%.2f], maxSchedDelayUs[%.2f], avgCostUs[%.2f].",
     247              :         bindNum_.load(), abnormalBindNum_.load(), subscribeNum_.load(), pauseSubscribeNum_.load(), awakenTimes,
     248              :         eventScheduleTimes, enqueueFlaseAwakenTimes, daemonEventScheduleTimes, periodEventScheduleTimes,
     249              :         static_cast<float64_t>(static_cast<float64_t>(periodEventScheduleTimes) / STATISTIC_PERIOD), dataEnqueueTimes,
     250              :         dataDequeueTimes, scheduleEmptyTimes, dataScheduleFailedTimes, periodDataEnqueueTimes,
     251              :         static_cast<float64_t>(static_cast<float64_t>(periodDataEnqueueTimes) / STATISTIC_PERIOD), relationEnqueueTimes,
     252              :         relationDequeueTimes, asynMemEnqueueTimes, asynMemDequeueTimes, dataEnqueueSuccTimes, dataEnqueueFailTimes,
     253              :         dataEnqueueFullTimes, f2nfEventTimes, f2nfFalseAwakenTimes, f2nfEnqueueTimes, f2nfDequeueTimes,
     254              :         mpiRecvSuccTimes, mpiRecvFailTimes, mpiSendSuccTimes, mpiSendFullTimes, mpiSendFailTimes,
     255              :         supplyRecvReqEventTimes, maxProcessCostUs, secProcessCostUs, maxScheduleDelayUs, avgProcessCostUs);
     256           11 : }
     257              : 
     258            6 : void StatisticManager::ResetStatistic()
     259              : {
     260            6 :     DumpStatistic();
     261              :     // clear old statistic info
     262            6 :     totalStat_.Reset();
     263            6 :     periodStat_.Reset();
     264            6 : }
     265              : 
     266            2 : void StatisticManager::DumpChannelStatistic()
     267              : {
     268              :     // dump src entity statistic info
     269            2 :     dgw::CommChannels& srcChannels = dgw::EntityManager::Instance(0U).GetCommChannels(true);
     270            2 :     (void)pthread_rwlock_rdlock(&srcChannels.lock);
     271            2 :     for (auto& entity : srcChannels.entities) {
     272            0 :         entity->Dump();
     273              :     }
     274            2 :     (void)pthread_rwlock_unlock(&srcChannels.lock);
     275              : 
     276              :     // dump dst entity statistic info
     277            2 :     dgw::CommChannels& dstChannels = dgw::EntityManager::Instance(0U).GetCommChannels(false);
     278            2 :     (void)pthread_rwlock_rdlock(&dstChannels.lock);
     279            2 :     for (auto& entity : dstChannels.entities) {
     280            0 :         entity->Dump();
     281              :     }
     282            2 :     (void)pthread_rwlock_unlock(&dstChannels.lock);
     283              : 
     284            2 :     if (numaFlag_) {
     285              :         // dump src entity statistic info
     286            1 :         dgw::CommChannels& srcChannelsExtra = dgw::EntityManager::Instance(1U).GetCommChannels(true);
     287            1 :         BQS_LOG_INFO("EntityManager[1]'s srcChannelsExtra size is %zu", srcChannelsExtra.entities.size());
     288            1 :         (void)pthread_rwlock_rdlock(&srcChannelsExtra.lock);
     289            1 :         for (auto& entity : srcChannelsExtra.entities) {
     290            0 :             entity->Dump();
     291              :         }
     292            1 :         (void)pthread_rwlock_unlock(&srcChannelsExtra.lock);
     293              : 
     294              :         // dump dst entity statistic info
     295            1 :         dgw::CommChannels& dstChannelsExtra = dgw::EntityManager::Instance(1U).GetCommChannels(false);
     296            1 :         BQS_LOG_INFO("EntityManager[1]'s dstChannelsExtra size is %zu", dstChannelsExtra.entities.size());
     297            1 :         (void)pthread_rwlock_rdlock(&dstChannelsExtra.lock);
     298            1 :         for (auto& entity : dstChannelsExtra.entities) {
     299            0 :             entity->Dump();
     300              :         }
     301            1 :         (void)pthread_rwlock_unlock(&dstChannelsExtra.lock);
     302              :     }
     303            2 : }
     304              : 
     305           18 : void StatisticManager::ThreadFunc()
     306              : {
     307              :     static uint64_t count = 0UL;
     308              :     static uint64_t countForSupplyEvent = 0UL;
     309              : 
     310              :     static uint64_t statisticPeriod = static_cast<uint64_t>(STATISTIC_PERIOD) * MS_IN_ONE_SECOND / WAKEUP_PERIOD_IN_MS;
     311              :     static uint64_t channelStatisticPeriod = ENTITY_STATISTIC_PERIOD * MS_IN_ONE_SECOND / WAKEUP_PERIOD_IN_MS;
     312              :     static uint64_t supplyEventPeriod = SUPPLY_EVENT_PERIOD * MS_IN_ONE_SECOND / WAKEUP_PERIOD_IN_MS;
     313              :     static uint64_t procMemPeriod = PROC_MEM_STAT_PERIOD * MS_IN_ONE_SECOND / WAKEUP_PERIOD_IN_MS;
     314           18 :     const uint64_t abnormalCheckPeriod = abnormalInterval_ * MS_IN_ONE_SECOND / WAKEUP_PERIOD_IN_MS;
     315           18 :     BQS_LOG_INFO(
     316              :         "statistic thread start, statisticPeriod [%lu], channelStatisticPeriod[%lu], "
     317              :         "supplyEventPeriod[%lu]",
     318              :         statisticPeriod, channelStatisticPeriod, supplyEventPeriod);
     319           18 :     (void)pthread_setname_np(pthread_self(), STATISTIC_THREAD_NAME_PREFIX);
     320           18 :     uint64_t enqueThreadHeartBeat = 0UL;
     321           53 :     while (runFlag_) {
     322              :         // only supply event when exist entity
     323           35 :         if (existEntityFlag_.load()) {
     324           60 :             if ((unLinkTagNum_.load() > 0U) ||
     325           22 :                 ((countForSupplyEvent % supplyEventPeriod == 0UL) && (totalTagNum_.load() > 0U))) {
     326            0 :                 (void)dgw::HcclProcess::GetInstance().SupplyEvents(0U);
     327            0 :                 if (numaFlag_) {
     328            0 :                     (void)dgw::HcclProcess::GetInstance().SupplyEvents(1U);
     329              :                 }
     330              :             }
     331           20 :             countForSupplyEvent++;
     332              :         } else {
     333           15 :             countForSupplyEvent = 0UL;
     334              :         }
     335              :         // dump total statistic and channel statistic
     336           35 :         if (count % statisticPeriod == 0UL) {
     337            1 :             DumpStatistic();
     338              :         }
     339           35 :         if (count % channelStatisticPeriod == 0UL) {
     340            1 :             DumpChannelStatistic();
     341              :         }
     342           35 :         if ((count + 1) % abnormalCheckPeriod == 0UL) {
     343            0 :             const auto currentEnqueHeartBeat = enqueThreadHearBeat_.load();
     344            0 :             if (enqueThreadHeartBeat == currentEnqueHeartBeat) {
     345            0 :                 QueueScheduleInterface::GetInstance().ReportAbnormal();
     346              :             } else {
     347            0 :                 enqueThreadHeartBeat = currentEnqueHeartBeat;
     348              :             }
     349              :         }
     350           35 :         if (count % procMemPeriod == 0) {
     351            1 :             RecordProcMemInfo();
     352              :         }
     353              : 
     354           35 :         count++;
     355           35 :         usleep(WAKEUP_PERIOD_IN_MS * 1000U);
     356              :     }
     357           18 :     BQS_LOG_INFO("statistic thread end.");
     358           18 : }
     359              : 
     360          377 : void StatisticManager::SetExistEntityFlag(const bool flag) { existEntityFlag_.store(flag); }
     361              : 
     362           31 : const uint32_t StatisticManager::AddUnlinkCount()
     363              : {
     364           31 :     ++unLinkTagNum_;
     365           62 :     return unLinkTagNum_.load();
     366              : }
     367              : 
     368            4 : const uint32_t StatisticManager::ReduceUnlinkCount()
     369              : {
     370            4 :     --unLinkTagNum_;
     371            8 :     return unLinkTagNum_.load();
     372              : }
     373              : 
     374           31 : void StatisticManager::AddTagCount() { ++totalTagNum_; }
     375              : 
     376           32 : void StatisticManager::ReduceTagCount() { --totalTagNum_; }
     377              : 
     378            1 : void StatisticManager::UpdateScheuleStatistic(const float64_t delay, const float64_t cost)
     379              : {
     380            1 :     scheduleStatistic_.UpdateScheduleDelay(delay);
     381            1 :     scheduleStatistic_.UpdateProcessCost(cost);
     382            1 : }
     383              : 
     384          308 : void StatisticManager::DumpOutProcMemStatInfo() { procMemStat_.PrintOutProcMemInfo(hostPid_); }
     385              : 
     386            1 : void StatisticManager::RecordProcMemInfo() { procMemStat_.StatisticProcMemInfo(); }
     387              : 
     388           14 : void ScheduleStatistic::Reset()
     389              : {
     390           14 :     std::unique_lock<std::mutex> lock(mutex_);
     391           14 :     maxProcessCostUs_ = 0.0;
     392           14 :     maxScheduleDelayUs_ = 0.0;
     393           14 :     secondMaxProcessUs_ = 0.0;
     394           14 :     totalProcessCostUs_ = 0.0;
     395           14 :     totalProcessCount_ = 0U;
     396           14 : }
     397              : 
     398            1 : void ScheduleStatistic::UpdateProcessCost(const float64_t cost)
     399              : {
     400            1 :     std::unique_lock<std::mutex> lock(mutex_);
     401            1 :     if (cost > maxProcessCostUs_) {
     402            1 :         secondMaxProcessUs_ = maxProcessCostUs_;
     403            1 :         maxProcessCostUs_ = cost;
     404              :     }
     405            1 :     totalProcessCostUs_ += cost;
     406            1 :     ++totalProcessCount_;
     407            1 : }
     408              : 
     409            1 : void ScheduleStatistic::UpdateScheduleDelay(const float64_t delay)
     410              : {
     411            1 :     std::unique_lock<std::mutex> lock(mutex_);
     412            1 :     if (delay > maxScheduleDelayUs_) {
     413            0 :         maxScheduleDelayUs_ = delay;
     414              :     }
     415            1 : }
     416              : 
     417           11 : float64_t ScheduleStatistic::GetMaxProcessCost()
     418              : {
     419           11 :     std::unique_lock<std::mutex> lock(mutex_);
     420           11 :     return maxProcessCostUs_;
     421           11 : }
     422              : 
     423           11 : float64_t ScheduleStatistic::GetSecondProcessCost()
     424              : {
     425           11 :     std::unique_lock<std::mutex> lock(mutex_);
     426           11 :     return secondMaxProcessUs_;
     427           11 : }
     428              : 
     429           11 : float64_t ScheduleStatistic::GetMaxScheduleDelay()
     430              : {
     431           11 :     std::unique_lock<std::mutex> lock(mutex_);
     432           11 :     return maxScheduleDelayUs_;
     433           11 : }
     434              : 
     435           11 : float64_t ScheduleStatistic::GetAvgProcessCost()
     436              : {
     437           11 :     std::unique_lock<std::mutex> lock(mutex_);
     438           22 :     return totalProcessCount_ > 0U ? totalProcessCostUs_ / totalProcessCount_ : totalProcessCostUs_;
     439           11 : }
     440              : 
     441              : } // namespace bqs
        

Generated by: LCOV version 2.0-1