LCOV - code coverage report
Current view: top level - server - statistic_manager.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 94.2 % 343 323
Test Date: 2026-07-28 10:54:05 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()
      48              : {
      49            1 :     ++totalStat_.enqueueFalseAwakenTimes;
      50            1 : }
      51              : 
      52            0 : uint64_t StatisticManager::GetEventScheduleStat() const
      53              : {
      54            0 :     return totalStat_.eventScheduleTimes;
      55              : }
      56              : 
      57            1 : void StatisticManager::DaemonEventScheduleStat()
      58              : {
      59            1 :     ++totalStat_.daemonEventScheduleTimes;
      60            1 : }
      61              : 
      62          111 : void StatisticManager::AwakenAdd()
      63              : {
      64          111 :     ++totalStat_.awakenTimes;
      65          111 : }
      66              : 
      67            0 : uint64_t StatisticManager::GetAwakenTimes() const
      68              : {
      69            0 :     return totalStat_.awakenTimes;
      70              : }
      71              : 
      72           15 : void StatisticManager::AddScheduleEmpty()
      73              : {
      74           15 :     ++totalStat_.scheduleEmptyTimes;
      75           15 : }
      76              : 
      77           26 : void StatisticManager::DataScheduleFailedStat(const uint64_t failedNum)
      78              : {
      79           26 :     totalStat_.dataScheduleFailedTimes += failedNum;
      80           26 : }
      81              : 
      82            3 : void StatisticManager::RelationEnqueueStat()
      83              : {
      84            3 :     ++totalStat_.relationEnqueueTimes;
      85            3 : }
      86              : 
      87            4 : void StatisticManager::RelationDequeueStat()
      88              : {
      89            4 :     ++totalStat_.relationDequeueTimes;
      90            4 : }
      91              : 
      92            2 : uint64_t StatisticManager::GetRelationEnqueCnt() const
      93              : {
      94            2 :     return totalStat_.relationEnqueueTimes;
      95              : }
      96              : 
      97            2 : uint64_t StatisticManager::GetRelationDequeCnt() const
      98              : {
      99            2 :     return totalStat_.relationDequeueTimes;
     100              : }
     101              : 
     102            2 : void StatisticManager::AsynMemEnqueueStat()
     103              : {
     104            2 :     ++totalStat_.asynMemEnqueueTimes;
     105            2 : }
     106              : 
     107            1 : void StatisticManager::AsynMemDequeueStat()
     108              : {
     109            1 :     ++totalStat_.asynMemDequeueTimes;
     110            1 : }
     111              : 
     112            0 : uint64_t StatisticManager::GetAsynMemEnqueCnt() const
     113              : {
     114            0 :     return totalStat_.asynMemEnqueueTimes;
     115              : }
     116              : 
     117            0 : uint64_t StatisticManager::GetAsynMemDequeCnt() const
     118              : {
     119            0 :     return totalStat_.asynMemDequeueTimes;
     120              : }
     121              : 
     122            2 : void StatisticManager::F2nfEnqueueStat()
     123              : {
     124            2 :     ++totalStat_.f2nfEnqueueTimes;
     125            2 : }
     126              : 
     127            5 : void StatisticManager::F2nfDequeueStat()
     128              : {
     129            5 :     ++totalStat_.f2nfDequeueTimes;
     130            5 : }
     131              : 
     132            2 : uint64_t StatisticManager::HcclMpiRecvRequestEventStat()
     133              : {
     134            2 :     return ++totalStat_.hcclMpiRecvRequestEventTimes;
     135              : }
     136              : 
     137            1 : void StatisticManager::HcclMpiRecvReqFalseAwakenStat()
     138              : {
     139            1 :     ++totalStat_.hcclMpiRecvReqFalseAwakenTimes;
     140            1 : }
     141              : 
     142            2 : void StatisticManager::HcclMpiRecvReqEmptySchedStat()
     143              : {
     144            2 :     ++totalStat_.hcclMpiRecvReqEmptySchedTimes;
     145            2 : }
     146              : 
     147            2 : void StatisticManager::HcclMpiRecvReqCallbackStat()
     148              : {
     149            2 :     ++totalStat_.hcclMpiRecvReqCallbackTimes;
     150            2 : }
     151              : 
     152            3 : uint64_t StatisticManager::HcclMpiSendCompEventStat()
     153              : {
     154            3 :     return ++totalStat_.hcclMpiSendCompEventTimes;
     155              : }
     156              : 
     157            1 : void StatisticManager::HcclMpiSendCompFalseAwakenStat()
     158              : {
     159            1 :     ++totalStat_.hcclMpiSendCompFalseAwakenTimes;
     160            1 : }
     161              : 
     162            4 : void StatisticManager::HcclMpiSendCompEmptySchedStat()
     163              : {
     164            4 :     ++totalStat_.hcclMpiSendCompEmptySchedTimes;
     165            4 : }
     166              : 
     167            3 : void StatisticManager::HcclMpiSendCompCallbackStat()
     168              : {
     169            3 :     ++totalStat_.hcclMpiSendCompCallbackTimes;
     170            3 : }
     171              : 
     172            5 : uint64_t StatisticManager::HcclMpiRecvCompEventStat()
     173              : {
     174            5 :     return ++totalStat_.hcclMpiRecvCompEventTimes;
     175              : }
     176              : 
     177            1 : void StatisticManager::HcclMpiRecvCompFalseAwakenStat()
     178              : {
     179            1 :     ++totalStat_.hcclMpiRecvCompFalseAwakenTimes;
     180            1 : }
     181              : 
     182            3 : void StatisticManager::HcclMpiRecvCompEmptySchedStat()
     183              : {
     184            3 :     ++totalStat_.hcclMpiRecvCompEmptySchedTimes;
     185            3 : }
     186              : 
     187            5 : void StatisticManager::HcclMpiRecvCompCallbackStat()
     188              : {
     189            5 :     ++totalStat_.hcclMpiRecvCompCallbackTimes;
     190            5 : }
     191              : 
     192            1 : void StatisticManager::F2nfEventStat()
     193              : {
     194            1 :     ++totalStat_.f2nfEventTimes;
     195            1 : }
     196              : 
     197            1 : void StatisticManager::F2nfEventFalseAwakenStat()
     198              : {
     199            1 :     ++totalStat_.f2nfFalseAwakenTimes;
     200            1 : }
     201              : 
     202           17 : void StatisticManager::HcclMpiRecvSuccStat()
     203              : {
     204           17 :     ++totalStat_.hcclMpiRecvSuccTimes;
     205           17 : }
     206              : 
     207            4 : void StatisticManager::HcclMpiRecvFailStat()
     208              : {
     209            4 :     ++totalStat_.hcclMpiRecvFailTimes;
     210            4 : }
     211              : 
     212           36 : void StatisticManager::HcclMpiSendSuccStat()
     213              : {
     214           36 :     ++totalStat_.hcclMpiSendSuccTimes;
     215           36 : }
     216              : 
     217            5 : void StatisticManager::HcclMpiSendFailStat()
     218              : {
     219            5 :     ++totalStat_.hcclMpiSendFailTimes;
     220            5 : }
     221              : 
     222            3 : void StatisticManager::HcclMpiSendFullStat()
     223              : {
     224            3 :     ++totalStat_.hcclMpiSendFullTimes;
     225            3 : }
     226              : 
     227            1 : void StatisticManager::HcclMpiF2nfEventStat()
     228              : {
     229            1 :     ++totalStat_.hcclMpiF2nfEventTimes;
     230            1 : }
     231              : 
     232           12 : void StatisticManager::MbufAllocStat(const uint64_t size)
     233              : {
     234           12 :     ++totalStat_.mbufAllocTimes;
     235           12 :     totalStat_.mbufAllocSize += size;
     236           12 : }
     237              : 
     238            4 : void StatisticManager::MbufFreeStat(const uint64_t size)
     239              : {
     240            4 :     ++totalStat_.mbufFreeTimes;
     241            4 :     totalStat_.mbufFreeSize += size;
     242            4 : }
     243              : 
     244            2 : void StatisticManager::RecvReqEventSupplyStat()
     245              : {
     246            2 :     ++totalStat_.supplyRecvReqEventTimes;
     247            2 : }
     248              : 
     249           15 : void StatisticManager::DataDequeueStat()
     250              : {
     251           15 :     ++totalStat_.dataDequeueTimes;
     252           15 : }
     253              : 
     254            7 : void StatisticManager::DataQueueEnqueueSuccStat()
     255              : {
     256            7 :     ++totalStat_.dataEnqueueSuccTimes;
     257            7 :     ++periodStat_.dataEnqueueSuccTimes;
     258            7 : }
     259              : 
     260           17 : void StatisticManager::DataQueueEnqueueFailStat()
     261              : {
     262           17 :     ++totalStat_.dataEnqueueFailTimes;
     263           17 : }
     264              : 
     265            4 : void StatisticManager::DataQueueEnqueueFullStat()
     266              : {
     267            4 :     ++totalStat_.dataEnqueueFullTimes;
     268            4 : }
     269              : 
     270            4 : void StatisticManager::BindStat()
     271              : {
     272            4 :     ++totalStat_.bindTimes;
     273            4 : }
     274              : 
     275            2 : void StatisticManager::UnbindStat()
     276              : {
     277            2 :     ++totalStat_.unbindTimes;
     278            2 : }
     279              : 
     280           10 : void StatisticManager::GetBindStat()
     281              : {
     282           10 :     ++totalStat_.getBindTimes;
     283           10 : }
     284              : 
     285            2 : void StatisticManager::GetAllBindStat()
     286              : {
     287            2 :     ++totalStat_.getAllBindTimes;
     288            2 : }
     289              : 
     290            9 : void StatisticManager::ResponseStat()
     291              : {
     292            9 :     ++totalStat_.responseTimes;
     293            9 : }
     294              : 
     295          137 : void StatisticManager::BindNum(const uint32_t bindNum)
     296              : {
     297          137 :     bindNum_.store(bindNum);
     298          137 : }
     299              : 
     300          136 : void StatisticManager::AbnormalBindNum(const uint32_t bindNum)
     301              : {
     302          136 :     abnormalBindNum_.store(bindNum);
     303          136 : }
     304              : 
     305          137 : void StatisticManager::SubscribeNum(const uint32_t subscribeNum)
     306              : {
     307          137 :     subscribeNum_.store(subscribeNum);
     308          137 : }
     309              : 
     310           13 : void StatisticManager::PauseSubscribe()
     311              : {
     312           13 :     ++pauseSubscribeNum_;
     313           13 : }
     314              : 
     315            9 : void StatisticManager::ResumeSubscribe()
     316              : {
     317            9 :     --pauseSubscribeNum_;
     318            9 : }
     319              : 
     320          128 : void StatisticManager::RefreshEnqueHeartBeat()
     321              : {
     322          128 :     ++enqueThreadHearBeat_;
     323          129 : }
     324              : 
     325           18 : void StatisticManager::StartStatisticManager(const uint32_t abnormalInterval, const uint32_t hostPid,
     326              :                                              const bool numaFlag, const uint32_t deviceIdExtra,
     327              :                                              const uint32_t enqueGroupIdExtra)
     328              : {
     329           18 :     runFlag_ = true;
     330           18 :     abnormalInterval_ = abnormalInterval;
     331           18 :     numaFlag_ = numaFlag;
     332           18 :     deviceIdExtra_ = deviceIdExtra;
     333           18 :     enqueGroupIdExtra_ = enqueGroupIdExtra;
     334           18 :     procMemStat_.InitProcMemStatistic();
     335           18 :     hostPid_ = hostPid;
     336           18 :     BQS_LOG_RUN_INFO("StartStatisticManager, abnormalInterval: %u, numaFlag: %d", abnormalInterval, numaFlag);
     337           18 :     timerThread_ = std::thread(&StatisticManager::ThreadFunc, this);
     338           18 : }
     339              : 
     340            3 : StatisticManager::~StatisticManager()
     341              : {
     342            3 :     DumpStatistic();
     343            3 :     StopStatisticManager();
     344            3 : }
     345              : 
     346          313 : void StatisticManager::StopStatisticManager()
     347              : {
     348          313 :     runFlag_ = false;
     349              : 
     350          313 :     const std::unique_lock<std::mutex> waitLock(timerMutex_);
     351          313 :     if (timerThread_.joinable()) {
     352           18 :         timerThread_.join();
     353              :     }
     354          313 : }
     355              : 
     356           11 : void StatisticManager::DumpStatistic()
     357              : {
     358           11 :     const uint64_t awakenTimes = totalStat_.awakenTimes;
     359           11 :     const uint64_t eventScheduleTimes = totalStat_.eventScheduleTimes;
     360           11 :     const uint64_t enqueueFlaseAwakenTimes = totalStat_.enqueueFalseAwakenTimes;
     361           11 :     const uint64_t daemonEventScheduleTimes = totalStat_.daemonEventScheduleTimes;
     362           11 :     const uint64_t periodEventScheduleTimes = periodStat_.eventScheduleTimes.exchange(0UL);
     363           11 :     const uint64_t dataEnqueueTimes = totalStat_.dataEnqueueSuccTimes;
     364           11 :     const uint64_t dataDequeueTimes = totalStat_.dataDequeueTimes;
     365           11 :     const uint64_t scheduleEmptyTimes = totalStat_.scheduleEmptyTimes;
     366           11 :     const uint64_t dataScheduleFailedTimes = totalStat_.dataScheduleFailedTimes;
     367           11 :     const uint64_t relationEnqueueTimes = totalStat_.relationEnqueueTimes;
     368           11 :     const uint64_t relationDequeueTimes = totalStat_.relationDequeueTimes;
     369           11 :     const uint64_t asynMemEnqueueTimes = totalStat_.asynMemEnqueueTimes;
     370           11 :     const uint64_t asynMemDequeueTimes = totalStat_.asynMemDequeueTimes;
     371           11 :     const uint64_t periodDataEnqueueTimes = periodStat_.dataEnqueueSuccTimes.exchange(0UL);
     372           11 :     const uint64_t dataEnqueueSuccTimes = totalStat_.dataEnqueueSuccTimes;
     373           11 :     const uint64_t dataEnqueueFailTimes = totalStat_.dataEnqueueFailTimes;
     374           11 :     const uint64_t dataEnqueueFullTimes = totalStat_.dataEnqueueFullTimes;
     375           11 :     const uint64_t mpiRecvSuccTimes = totalStat_.hcclMpiRecvSuccTimes;
     376           11 :     const uint64_t mpiRecvFailTimes = totalStat_.hcclMpiRecvFailTimes;
     377           11 :     const uint64_t mpiSendSuccTimes = totalStat_.hcclMpiSendSuccTimes;
     378           11 :     const uint64_t mpiSendFailTimes = totalStat_.hcclMpiSendFailTimes;
     379           11 :     const uint64_t mpiSendFullTimes = totalStat_.hcclMpiSendFullTimes;
     380           11 :     const uint64_t supplyRecvReqEventTimes = totalStat_.supplyRecvReqEventTimes;
     381           11 :     const uint64_t f2nfEventTimes = totalStat_.f2nfEventTimes;
     382           11 :     const uint64_t f2nfFalseAwakenTimes = totalStat_.f2nfFalseAwakenTimes;
     383           11 :     const uint64_t f2nfEnqueueTimes = totalStat_.f2nfEnqueueTimes;
     384           11 :     const uint64_t f2nfDequeueTimes = totalStat_.f2nfDequeueTimes;
     385           11 :     const float64_t maxProcessCostUs = scheduleStatistic_.GetMaxProcessCost();
     386           11 :     const float64_t maxScheduleDelayUs = scheduleStatistic_.GetMaxScheduleDelay();
     387           11 :     const float64_t secProcessCostUs = scheduleStatistic_.GetSecondProcessCost();
     388           11 :     const float64_t avgProcessCostUs = scheduleStatistic_.GetAvgProcessCost();
     389           11 :     scheduleStatistic_.Reset();
     390              : 
     391           55 :     BQS_LOG_RUN_INFO("Statistic info: queue={bind:%u, abnormal_bind:%u, subscribe:%u, pause:%u},"
     392              :         "event={awaken:%lu, aicpu schedule:%lu, "
     393              :         "incorrect waken:%lu, control schedule:%lu, period:%lu, %.2f/s}, data={total enqueue:%lu, total dequeue:%lu, "
     394              :         "total sched empty:%lu, total n-success:%lu, period:%lu, %.2f/s}, relation queue={enqueue:%lu, dequeue:%lu}, "
     395              :         "AsynMem queue={enqueue:%lu, dequeue:%lu}, dst queue={success:%lu, n-success:%lu, full:%lu}, "
     396              :         "queue f2nf=[success:%lu, incorrect awaken:%lu, enqueue:%lu, dequeue:%lu], "
     397              :         "hcclImrecv=[success:%lu, n-success:%lu], hcclIsend=[success:%lu, full:%lu, n-success:%lu], "
     398              :         "supply recv request event times=%lu}, maxProcessCostUs[%.2f/%.2f], maxSchedDelayUs[%.2f], avgCostUs[%.2f].",
     399              :         bindNum_.load(), abnormalBindNum_.load(), subscribeNum_.load(), pauseSubscribeNum_.load(),
     400              :         awakenTimes, eventScheduleTimes,
     401              :         enqueueFlaseAwakenTimes, daemonEventScheduleTimes, periodEventScheduleTimes,
     402              :         static_cast<float64_t>(static_cast<float64_t>(periodEventScheduleTimes) / STATISTIC_PERIOD), dataEnqueueTimes,
     403              :         dataDequeueTimes, scheduleEmptyTimes, dataScheduleFailedTimes, periodDataEnqueueTimes,
     404              :         static_cast<float64_t>(static_cast<float64_t>(periodDataEnqueueTimes) / STATISTIC_PERIOD), relationEnqueueTimes,
     405              :         relationDequeueTimes, asynMemEnqueueTimes, asynMemDequeueTimes,
     406              :         dataEnqueueSuccTimes, dataEnqueueFailTimes, dataEnqueueFullTimes,
     407              :         f2nfEventTimes, f2nfFalseAwakenTimes, f2nfEnqueueTimes, f2nfDequeueTimes,
     408              :         mpiRecvSuccTimes, mpiRecvFailTimes, mpiSendSuccTimes, mpiSendFullTimes, mpiSendFailTimes,
     409              :         supplyRecvReqEventTimes, maxProcessCostUs, secProcessCostUs, maxScheduleDelayUs, avgProcessCostUs);
     410           11 : }
     411              : 
     412            6 : void StatisticManager::ResetStatistic()
     413              : {
     414            6 :     DumpStatistic();
     415              :     // clear old statistic info
     416            6 :     totalStat_.Reset();
     417            6 :     periodStat_.Reset();
     418            6 : }
     419              : 
     420            2 : void StatisticManager::DumpChannelStatistic()
     421              : {
     422              :     // dump src entity statistic info
     423            2 :     dgw::CommChannels &srcChannels = dgw::EntityManager::Instance(0U).GetCommChannels(true);
     424            2 :     (void)pthread_rwlock_rdlock(&srcChannels.lock);
     425            2 :     for (auto &entity : srcChannels.entities) {
     426            0 :         entity->Dump();
     427              :     }
     428            2 :     (void)pthread_rwlock_unlock(&srcChannels.lock);
     429              : 
     430              :     // dump dst entity statistic info
     431            2 :     dgw::CommChannels &dstChannels = dgw::EntityManager::Instance(0U).GetCommChannels(false);
     432            2 :     (void)pthread_rwlock_rdlock(&dstChannels.lock);
     433            2 :     for (auto &entity : dstChannels.entities) {
     434            0 :         entity->Dump();
     435              :     }
     436            2 :     (void)pthread_rwlock_unlock(&dstChannels.lock);
     437              : 
     438            2 :     if (numaFlag_) {
     439              :         // dump src entity statistic info
     440            1 :         dgw::CommChannels &srcChannelsExtra = dgw::EntityManager::Instance(1U).GetCommChannels(true);
     441            1 :         BQS_LOG_INFO("EntityManager[1]'s srcChannelsExtra size is %zu", srcChannelsExtra.entities.size());
     442            1 :         (void)pthread_rwlock_rdlock(&srcChannelsExtra.lock);
     443            1 :         for (auto &entity : srcChannelsExtra.entities) {
     444            0 :             entity->Dump();
     445              :         }
     446            1 :         (void)pthread_rwlock_unlock(&srcChannelsExtra.lock);
     447              : 
     448              :         // dump dst entity statistic info
     449            1 :         dgw::CommChannels &dstChannelsExtra = dgw::EntityManager::Instance(1U).GetCommChannels(false);
     450            1 :         BQS_LOG_INFO("EntityManager[1]'s dstChannelsExtra size is %zu", dstChannelsExtra.entities.size());
     451            1 :         (void)pthread_rwlock_rdlock(&dstChannelsExtra.lock);
     452            1 :         for (auto &entity : dstChannelsExtra.entities) {
     453            0 :             entity->Dump();
     454              :         }
     455            1 :         (void)pthread_rwlock_unlock(&dstChannelsExtra.lock);
     456              :     }
     457            2 : }
     458              : 
     459           18 : void StatisticManager::ThreadFunc()
     460              : {
     461              :     static uint64_t count = 0UL;
     462              :     static uint64_t countForSupplyEvent = 0UL;
     463              : 
     464              :     static uint64_t statisticPeriod = static_cast<uint64_t>(STATISTIC_PERIOD) * MS_IN_ONE_SECOND / WAKEUP_PERIOD_IN_MS;
     465              :     static uint64_t channelStatisticPeriod = ENTITY_STATISTIC_PERIOD * MS_IN_ONE_SECOND / WAKEUP_PERIOD_IN_MS;
     466              :     static uint64_t supplyEventPeriod = SUPPLY_EVENT_PERIOD * MS_IN_ONE_SECOND / WAKEUP_PERIOD_IN_MS;
     467              :     static uint64_t procMemPeriod = PROC_MEM_STAT_PERIOD * MS_IN_ONE_SECOND / WAKEUP_PERIOD_IN_MS;
     468           18 :     const uint64_t abnormalCheckPeriod = abnormalInterval_ * MS_IN_ONE_SECOND / WAKEUP_PERIOD_IN_MS;
     469           18 :     BQS_LOG_INFO("statistic thread start, statisticPeriod [%lu], channelStatisticPeriod[%lu], "
     470              :         "supplyEventPeriod[%lu]", statisticPeriod, channelStatisticPeriod, supplyEventPeriod);
     471           18 :     (void)pthread_setname_np(pthread_self(), STATISTIC_THREAD_NAME_PREFIX);
     472           18 :     uint64_t enqueThreadHeartBeat = 0UL;
     473           53 :     while (runFlag_) {
     474              :         // only supply event when exist entity
     475           35 :         if (existEntityFlag_.load()) {
     476           60 :             if ((unLinkTagNum_.load() > 0U) ||
     477           22 :                 ((countForSupplyEvent % supplyEventPeriod == 0UL) && (totalTagNum_.load() > 0U))) {
     478            0 :                 (void)dgw::HcclProcess::GetInstance().SupplyEvents(0U);
     479            0 :                 if (numaFlag_) {
     480            0 :                     (void)dgw::HcclProcess::GetInstance().SupplyEvents(1U);
     481              :                 }
     482              :             }
     483           20 :             countForSupplyEvent++;
     484              :         } else {
     485           15 :             countForSupplyEvent = 0UL;
     486              :         }
     487              :         // dump total statistic and channel statistic
     488           35 :         if (count % statisticPeriod == 0UL) {
     489            1 :             DumpStatistic();
     490              :         }
     491           35 :         if (count % channelStatisticPeriod == 0UL) {
     492            1 :             DumpChannelStatistic();
     493              :         }
     494           35 :         if ((count + 1) % abnormalCheckPeriod == 0UL) {
     495            0 :             const auto currentEnqueHeartBeat = enqueThreadHearBeat_.load();
     496            0 :             if (enqueThreadHeartBeat == currentEnqueHeartBeat) {
     497            0 :                 QueueScheduleInterface::GetInstance().ReportAbnormal();
     498              :             } else {
     499            0 :                 enqueThreadHeartBeat = currentEnqueHeartBeat;
     500              :             }
     501              :         }
     502           35 :         if (count % procMemPeriod == 0) {
     503            1 :             RecordProcMemInfo();
     504              :         }
     505              : 
     506           35 :         count++;
     507           35 :         usleep(WAKEUP_PERIOD_IN_MS * 1000U);
     508              :     }
     509           18 :     BQS_LOG_INFO("statistic thread end.");
     510           18 : }
     511              : 
     512          377 : void StatisticManager::SetExistEntityFlag(const bool flag)
     513              : {
     514          377 :     existEntityFlag_.store(flag);
     515          377 : }
     516              : 
     517           31 : const uint32_t StatisticManager::AddUnlinkCount()
     518              : {
     519           31 :     ++unLinkTagNum_;
     520           62 :     return unLinkTagNum_.load();
     521              : }
     522              : 
     523            4 : const uint32_t StatisticManager::ReduceUnlinkCount()
     524              : {
     525            4 :     --unLinkTagNum_;
     526            8 :     return unLinkTagNum_.load();
     527              : }
     528              : 
     529           31 : void StatisticManager::AddTagCount()
     530              : {
     531           31 :     ++totalTagNum_;
     532           31 : }
     533              : 
     534           32 : void StatisticManager::ReduceTagCount()
     535              : {
     536           32 :     --totalTagNum_;
     537           32 : }
     538              : 
     539            1 : void StatisticManager::UpdateScheuleStatistic(const float64_t delay, const float64_t cost)
     540              : {
     541            1 :     scheduleStatistic_.UpdateScheduleDelay(delay);
     542            1 :     scheduleStatistic_.UpdateProcessCost(cost);
     543            1 : }
     544              : 
     545          308 : void StatisticManager::DumpOutProcMemStatInfo()
     546              : {
     547          308 :     procMemStat_.PrintOutProcMemInfo(hostPid_);
     548          308 : }
     549              : 
     550            1 : void StatisticManager::RecordProcMemInfo()
     551              : {
     552            1 :     procMemStat_.StatisticProcMemInfo();
     553            1 : }
     554              : 
     555           14 : void ScheduleStatistic::Reset()
     556              : {
     557           14 :     std::unique_lock<std::mutex> lock(mutex_);
     558           14 :     maxProcessCostUs_ = 0.0;
     559           14 :     maxScheduleDelayUs_ = 0.0;
     560           14 :     secondMaxProcessUs_ = 0.0;
     561           14 :     totalProcessCostUs_ = 0.0;
     562           14 :     totalProcessCount_ = 0U;
     563           14 : }
     564              : 
     565            1 : void ScheduleStatistic::UpdateProcessCost(const float64_t cost)
     566              : {
     567            1 :     std::unique_lock<std::mutex> lock(mutex_);
     568            1 :     if (cost > maxProcessCostUs_) {
     569            1 :         secondMaxProcessUs_ = maxProcessCostUs_;
     570            1 :         maxProcessCostUs_ = cost;
     571              :     }
     572            1 :     totalProcessCostUs_ += cost;
     573            1 :     ++totalProcessCount_;
     574            1 : }
     575              : 
     576            1 : void ScheduleStatistic::UpdateScheduleDelay(const float64_t delay)
     577              : {
     578            1 :     std::unique_lock<std::mutex> lock(mutex_);
     579            1 :     if (delay > maxScheduleDelayUs_) {
     580            0 :         maxScheduleDelayUs_ = delay;
     581              :     }
     582            1 : }
     583              : 
     584           11 : float64_t ScheduleStatistic::GetMaxProcessCost()
     585              : {
     586           11 :     std::unique_lock<std::mutex> lock(mutex_);
     587           11 :     return maxProcessCostUs_;
     588           11 : }
     589              : 
     590           11 : float64_t ScheduleStatistic::GetSecondProcessCost()
     591              : {
     592           11 :     std::unique_lock<std::mutex> lock(mutex_);
     593           11 :     return secondMaxProcessUs_;
     594           11 : }
     595              : 
     596           11 : float64_t ScheduleStatistic::GetMaxScheduleDelay()
     597              : {
     598           11 :     std::unique_lock<std::mutex> lock(mutex_);
     599           11 :     return maxScheduleDelayUs_;
     600           11 : }
     601              : 
     602           11 : float64_t ScheduleStatistic::GetAvgProcessCost()
     603              : {
     604           11 :     std::unique_lock<std::mutex> lock(mutex_);
     605           22 :     return totalProcessCount_ > 0U ? totalProcessCostUs_ / totalProcessCount_ : totalProcessCostUs_;
     606           11 : }
     607              : 
     608              : }  // namespace bqs
        

Generated by: LCOV version 2.0-1