LCOV - code coverage report
Current view: top level - legacy/ascend910/common/debug/profiling - dlrt_function.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 78.6 % 28 22
Test Date: 2026-08-18 17:47:01 Functions: 75.0 % 8 6

            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 "dlrt_function.h"
      12              : #include "log.h"
      13              : 
      14              : namespace hccl {
      15          313 : DlRtFunction& DlRtFunction::GetInstance()
      16              : {
      17          313 :     static DlRtFunction hcclDlRtFunction;
      18          313 :     return hcclDlRtFunction;
      19              : }
      20              : 
      21            8 : DlRtFunction::DlRtFunction() {}
      22              : 
      23            8 : DlRtFunction::~DlRtFunction()
      24              : {
      25            8 :     if (handle_ != nullptr) {
      26            0 :         (void)dlclose(handle_);
      27            0 :         handle_ = nullptr;
      28              :     }
      29            8 : }
      30              : 
      31            1 : rtError_t rtProfRegisterCtrlCallbackStub([[maybe_unused]] uint32_t modelid, [[maybe_unused]] rtProfCtrlHandle callback)
      32              : {
      33            1 :     HCCL_WARNING("Entry rtProfRegisterCtrlCallbackStub");
      34            1 :     return RT_ERROR_NONE;
      35              : }
      36              : 
      37          312 : HcclResult DlRtFunction::DlRtFunctionStubInit()
      38              : {
      39          312 :     dlrtProfRegisterCtrlCallback = (rtError_t(*)(uint32_t, rtProfCtrlHandle))rtProfRegisterCtrlCallbackStub;
      40          312 :     return HCCL_SUCCESS;
      41              : }
      42              : 
      43            0 : HcclResult DlRtFunction::DlRtFunctionInterInit()
      44              : {
      45              :     dlrtProfRegisterCtrlCallback
      46            0 :         = (rtError_t(*)(uint32_t, rtProfCtrlHandle))dlsym(handle_, "rtProfRegisterCtrlCallback");
      47            0 :     return HCCL_SUCCESS;
      48              : }
      49              : 
      50          312 : HcclResult DlRtFunction::DlRtFunctionInit()
      51              : {
      52          312 :     std::lock_guard<std::mutex> lock(handleMutex_);
      53          312 :     if (handle_ == nullptr) {
      54          312 :         handle_ = dlopen("libruntime.so", RTLD_NOW);
      55              :     }
      56          312 :     if (handle_ != nullptr) {
      57            0 :         CHK_RET(DlRtFunctionInterInit());
      58              :     } else {
      59          312 :         CHK_RET(DlRtFunctionStubInit());
      60          312 :         HCCL_WARNING("dlopen libruntime.so failed");
      61              :     }
      62          312 :     return HCCL_SUCCESS;
      63          312 : }
      64              : } // namespace hccl
        

Generated by: LCOV version 2.0-1