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

Generated by: LCOV version 2.0-1