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 16286 : DlProfFunction &DlProfFunction::GetInstance()
16 : {
17 16286 : static DlProfFunction hcclDlProfFunction;
18 16286 : 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 418 : HcclResult DlProfFunction::DlProfFunctionInit()
121 : {
122 418 : std::lock_guard<std::mutex> lock(handleMutex_);
123 418 : if (handle_ == nullptr) {
124 418 : handle_ = dlopen("libprofapi.so", RTLD_NOW);
125 : }
126 418 : if (handle_ != nullptr) {
127 0 : CHK_RET(DlProfFunctionInterInit());
128 : }
129 418 : return HCCL_SUCCESS;
130 418 : }
131 : }
|