LCOV - code coverage report
Current view: top level - legacy/ascend910/common/debug/profiling - dlprof_function.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 65.1 % 63 41
Test Date: 2026-08-17 10:19:35 Functions: 78.6 % 14 11

            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_function.h"
      12              : #include "log.h"
      13              : 
      14              : namespace hccl {
      15        16492 : DlProfFunction& DlProfFunction::GetInstance()
      16              : {
      17        16492 :     static DlProfFunction hcclDlProfFunction;
      18        16492 :     return hcclDlProfFunction;
      19              : }
      20              : 
      21           12 : DlProfFunction::DlProfFunction() { DlProfFunctionStubInit(); }
      22              : 
      23           12 : DlProfFunction::~DlProfFunction()
      24              : {
      25           12 :     if (handle_ != nullptr) {
      26            0 :         (void)dlclose(handle_);
      27            0 :         handle_ = nullptr;
      28              :     }
      29           12 : }
      30              : 
      31            0 : int32_t MsprofRegisterCallbackStub(uint32_t moduleId, ProfCommandHandle handle)
      32              : {
      33            0 :     HCCL_WARNING("Entry MsprofRegisterCallbackStub");
      34            0 :     return 0;
      35              : }
      36              : 
      37           84 : int32_t MsprofRegTypeInfoStub(uint16_t level, uint32_t typeId, const char* typeName)
      38              : {
      39           84 :     HCCL_WARNING("Entry MsprofRegTypeInfoStub");
      40           84 :     return 0;
      41              : }
      42              : 
      43           53 : int32_t MsprofReportApiStub(uint32_t agingFlag, const MsprofApi* api)
      44              : {
      45           53 :     HCCL_WARNING("Entry MsprofReportApiStub");
      46           53 :     return 0;
      47              : }
      48              : 
      49            1 : int32_t MsprofReportCompactInfoStub(uint32_t agingFlag, const VOID_PTR data, uint32_t length)
      50              : {
      51            1 :     HCCL_WARNING("Entry MsprofReportCompactInfoStub");
      52            1 :     return 0;
      53              : }
      54              : 
      55           48 : int32_t MsprofReportAdditionalInfoStub(uint32_t agingFlag, const VOID_PTR data, uint32_t length)
      56              : {
      57           48 :     HCCL_WARNING("Entry MsprofReportAdditionalInfoStub");
      58           48 :     return 0;
      59              : }
      60              : 
      61        15734 : uint64_t MsprofStr2IdStub(const char* hashInfo, uint32_t length)
      62              : {
      63        15734 :     HCCL_WARNING("Entry MsprofStr2IdStub");
      64        15734 :     return 0;
      65              : }
      66              : 
      67           98 : uint64_t MsprofSysCycleTimeStub()
      68              : {
      69           98 :     HCCL_WARNING("Entry MsprofSysCycleTimeStub");
      70           98 :     return 0;
      71              : }
      72              : 
      73           12 : void DlProfFunction::DlProfFunctionStubInit()
      74              : {
      75           12 :     dlMsprofRegisterCallback = (s32(*)(uint32_t, ProfCommandHandle))MsprofRegisterCallbackStub;
      76           12 :     dlMsprofRegTypeInfo = (s32(*)(uint16_t, uint32_t, const char*))MsprofRegTypeInfoStub;
      77           12 :     dlMsprofReportApi = (s32(*)(uint32_t, const MsprofApi*))MsprofReportApiStub;
      78           12 :     dlMsprofReportCompactInfo = (s32(*)(uint32_t, const VOID_PTR, uint32_t))MsprofReportCompactInfoStub;
      79           12 :     dlMsprofReportAdditionalInfo = (s32(*)(uint32_t, const VOID_PTR, uint32_t))MsprofReportAdditionalInfoStub;
      80           12 :     dlMsprofStr2Id = (uint64_t(*)(const char*, uint32_t))MsprofStr2IdStub;
      81           12 :     dlMsprofSysCycleTime = (uint64_t(*)(void))MsprofSysCycleTimeStub;
      82           12 : }
      83              : 
      84            0 : HcclResult DlProfFunction::DlProfFunctionInterInit()
      85              : {
      86            0 :     dlMsprofRegisterCallback = (s32(*)(uint32_t, ProfCommandHandle))dlsym(handle_, "MsprofRegisterCallback");
      87            0 :     CHK_SMART_PTR_NULL(dlMsprofRegisterCallback);
      88              : 
      89            0 :     dlMsprofRegTypeInfo = (s32(*)(uint16_t, uint32_t, const char*))dlsym(handle_, "MsprofRegTypeInfo");
      90            0 :     CHK_SMART_PTR_NULL(dlMsprofRegTypeInfo);
      91              : 
      92            0 :     dlMsprofReportApi = (s32(*)(uint32_t, const MsprofApi*))dlsym(handle_, "MsprofReportApi");
      93            0 :     CHK_SMART_PTR_NULL(dlMsprofReportApi);
      94              : 
      95            0 :     dlMsprofReportCompactInfo = (s32(*)(uint32_t, const VOID_PTR, uint32_t))dlsym(handle_, "MsprofReportCompactInfo");
      96            0 :     CHK_SMART_PTR_NULL(dlMsprofReportCompactInfo);
      97              : 
      98              :     dlMsprofReportAdditionalInfo
      99            0 :         = (s32(*)(uint32_t, const VOID_PTR, uint32_t))dlsym(handle_, "MsprofReportAdditionalInfo");
     100            0 :     CHK_SMART_PTR_NULL(dlMsprofReportAdditionalInfo);
     101              : 
     102            0 :     dlMsprofStr2Id = (uint64_t(*)(const char*, uint32_t))dlsym(handle_, "MsprofStr2Id");
     103            0 :     CHK_SMART_PTR_NULL(dlMsprofStr2Id);
     104              : 
     105            0 :     dlMsprofSysCycleTime = (uint64_t(*)(void))dlsym(handle_, "MsprofSysCycleTime");
     106            0 :     CHK_SMART_PTR_NULL(dlMsprofSysCycleTime);
     107              : 
     108            0 :     return HCCL_SUCCESS;
     109              : }
     110              : 
     111          474 : HcclResult DlProfFunction::DlProfFunctionInit()
     112              : {
     113          474 :     std::lock_guard<std::mutex> lock(handleMutex_);
     114          474 :     if (handle_ == nullptr) {
     115          474 :         handle_ = dlopen("libprofapi.so", RTLD_NOW);
     116              :     }
     117          474 :     if (handle_ != nullptr) {
     118            0 :         CHK_RET(DlProfFunctionInterInit());
     119              :     }
     120          474 :     return HCCL_SUCCESS;
     121          474 : }
     122              : } // namespace hccl
        

Generated by: LCOV version 2.0-1