LCOV - code coverage report
Current view: top level - legacy/ascend950/unified_platform/common - dlprof_func.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 42.1 % 38 16
Test Date: 2026-08-04 10:52:23 Functions: 55.6 % 9 5

            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 "dlprof_func.h"
      12              : #include "log.h"
      13              : #include "exception_util.h"
      14              :  
      15              : namespace Hccl {
      16           17 : DlProfFunc &DlProfFunc::GetInstance()
      17              : {
      18           17 :     static DlProfFunc hcclDlProfFunction;
      19           17 :     return hcclDlProfFunction;
      20              : }
      21              :  
      22            0 : bool DlProfFunc::isStubMode()
      23              : {
      24            0 :     return false;
      25              : }
      26              :  
      27            1 : DlProfFunc::DlProfFunc()
      28              : {
      29            1 :     if (isStubMode()) {
      30            1 :         DlProfFunctionStubInit();
      31              :     } else {
      32            0 :         DlProfFunctionInit();
      33              :     }
      34            1 : }
      35              :  
      36            1 : DlProfFunc::~DlProfFunc()
      37              : {
      38            1 :     if (handle_ != nullptr) {
      39            0 :         (void)dlclose(handle_);
      40            0 :         handle_ = nullptr;
      41              :     }
      42            1 : }
      43              :  
      44           17 : static uint64_t HcclMsprofSysCycleTimeStub()
      45              : {
      46           51 :     HCCL_WARNING("Entry HcclMsprofSysCycleTimeStub");
      47           17 :     return 0;
      48              : }
      49              :  
      50            1 : void DlProfFunc::DlProfFunctionStubInit()
      51              : {
      52            1 :     dlMsprofSysCycleTime = (uint64_t(*)(void))HcclMsprofSysCycleTimeStub;
      53            1 : }
      54              :  
      55            0 : HcclResult DlProfFunc::DlProfFunctionInterInit()
      56              : {
      57            0 :     CHECK_NULLPTR(handle_, "[DlProfFunc::DlProfFunctionInterInit] handle_ is nullptr!");
      58            0 :     dlMsprofSysCycleTime = (uint64_t(*)(void))dlsym(handle_,
      59            0 :         "MsprofSysCycleTime");
      60            0 :     CHK_PTR_NULL(dlMsprofSysCycleTime);
      61              :  
      62            0 :     return HCCL_SUCCESS;
      63              : }
      64              :  
      65            0 : HcclResult DlProfFunc::DlProfFunctionInit()
      66              : {
      67            0 :     if (initializedFlag_) {
      68            0 :         return HCCL_SUCCESS;
      69              :     }
      70              :  
      71            0 :     std::lock_guard<std::mutex> lock(handleMutex_);
      72            0 :     if (handle_ == nullptr) {
      73            0 :         handle_ = dlopen("libprofapi.so", RTLD_NOW);
      74              :     }
      75            0 :     if (handle_ != nullptr) {
      76            0 :         CHK_RET(DlProfFunctionInterInit());
      77              :     }
      78            0 :     initializedFlag_ = true;
      79            0 :     return HCCL_SUCCESS;
      80            0 : }
      81              : }
        

Generated by: LCOV version 2.0-1