LCOV - code coverage report
Current view: top level - aicpu_schedule/core - aicpusd_mpi_mgr.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 96.7 % 30 29
Test Date: 2026-07-28 10:54:05 Functions: 87.5 % 8 7

            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              : #include "aicpusd_mpi_mgr.h"
      11              : #include <chrono>
      12              : #include <cmath>
      13              : #include "aicpusd_status.h"
      14              : #include "aicpusd_common.h"
      15              : #include "aicpu_pulse.h"
      16              : 
      17              : namespace AicpuSchedule {
      18              : namespace mpi {
      19              : namespace {
      20              : // time interval of print mpi dvpp event
      21              : constexpr uint32_t PRINT_MPI_DVPP_RECORD_IN_SECOND = 5U;
      22              : }
      23              : 
      24           19 : MpiDvppStatisticManager &MpiDvppStatisticManager::Instance()
      25              : {
      26           19 :     static MpiDvppStatisticManager statisticManagerInstance;
      27           19 :     return statisticManagerInstance;
      28              : }
      29              : 
      30            2 : MpiDvppStatisticManager::~MpiDvppStatisticManager()
      31              : {
      32            2 :     (void)PrintStatisticInfo();
      33            2 : }
      34              : 
      35            1 : void MpiDvppStatisticManager::OnPulse(const MpiDvppTimePoint &nowTimePoint)
      36              : {
      37            1 :     const float64_t duration = std::chrono::duration<float64_t>(nowTimePoint - lastTimePoint_).count();
      38            1 :     if (round(duration) < static_cast<float64_t>(PRINT_MPI_DVPP_RECORD_IN_SECOND)) {
      39            0 :         return;
      40              :     }
      41            1 :     (void)PrintStatisticInfo();
      42            1 :     lastTimePoint_ = nowTimePoint;
      43              : }
      44              : 
      45           18 : int32_t MpiDvppStatisticManager::PrintStatisticInfo() const
      46              : {
      47           36 :     aicpusd_run_info("Mpi Dvpp event statistics: [%lld]", mpiEventStatistic_.load());
      48           18 :     return AicpuSchedule::AICPU_SCHEDULE_OK;
      49              : }
      50              : 
      51            1 : void MpiDvppStatisticManager::Record()
      52              : {
      53            1 :     mpiEventStatistic_++;
      54            1 : }
      55              : 
      56            1 : void MpiDvppStatisticManager::InitMpiDvpp()
      57              : {
      58            1 :     if (!registerFlag_.load()) {
      59            1 :         const std::lock_guard<std::mutex> lk(registerFlagMutex_);
      60            1 :         if (!registerFlag_.load()) {
      61            1 :             (void)RegisterPulseNotifyFunc("MpiDvppKernel", &AicpuSchedule::mpi::MpiDvppPulse::MpiDvppPulseNotify);
      62            1 :             registerFlag_.store(true);
      63              :         }
      64            1 :     }
      65            1 : }
      66              : MpiDvppPulseListener *MpiDvppPulse::pulseListener_ = &MpiDvppStatisticManager::Instance();
      67              : 
      68            1 : void MpiDvppPulse::MpiDvppPulseNotify()
      69              : {
      70            1 :     const auto nowTime = std::chrono::high_resolution_clock::now();
      71            1 :     pulseListener_->OnPulse(nowTime);
      72            1 : }
      73              : } // namespace mpi
      74              : }
        

Generated by: LCOV version 2.0-1