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 "adapter_trace.h"
12 : #include "dltrace_function.h"
13 : #include "log.h"
14 : using namespace hccl;
15 :
16 525 : HcclResult hrtOpenTrace()
17 : {
18 525 : HcclResult ret = DlTraceFunction::GetInstance().DlTraceFunctionInit();
19 525 : HCCL_INFO("Call TraceCreate, return value[%d]", ret);
20 525 : CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("Call TraceCreate, return value[%d]", ret), HCCL_E_INTERNAL);
21 525 : return HCCL_SUCCESS;
22 : }
23 :
24 312 : void hrtTraceDestroy(TraHandle handle)
25 : {
26 312 : if (DlTraceFunction::GetInstance().dlAtraceDestroy != nullptr) {
27 312 : DlTraceFunction::GetInstance().dlAtraceDestroy(handle);
28 : } else {
29 0 : DlTraceFunction::GetInstance().dlUtraceDestroy(handle);
30 : }
31 312 : HCCL_INFO("Call TraceDestroy, Params:handle[%p]", handle);
32 312 : return;
33 : }
34 :
35 1 : HcclResult hrtTraceSubmit(TraHandle handle, const void* buffer, u32 bufSize)
36 : {
37 1 : HcclResult ret = HCCL_E_RESERVED;
38 1 : if (DlTraceFunction::GetInstance().dlAtraceSubmit != nullptr) {
39 1 : ret = DlTraceFunction::GetInstance().dlAtraceSubmit(handle, buffer, bufSize);
40 : } else {
41 0 : ret = DlTraceFunction::GetInstance().dlUtraceSubmit(handle, buffer, bufSize);
42 : }
43 1 : CHK_PRT_RET(
44 : ret != 0, HCCL_ERROR("Call TraceSubmit, return value[%d], Params:handle[%p]", ret, handle), HCCL_E_INTERNAL);
45 1 : return HCCL_SUCCESS;
46 : }
47 :
48 313 : HcclResult hrtTraceCreateWithAttr(const char* objName, TraHandle& handle)
49 : {
50 313 : CHK_PTR_NULL(objName);
51 313 : TraHandle ret = TRACE_INVALID_HANDLE;
52 313 : if (DlTraceFunction::GetInstance().dlAtraceCreateWithAttr != nullptr) {
53 313 : TraceAttr hcclAtraceAttr = {};
54 313 : hcclAtraceAttr.exitSave = true;
55 313 : hcclAtraceAttr.msgNum = DEFAULT_ATRACE_MSG_NUM;
56 313 : hcclAtraceAttr.msgSize = DEFAULT_ATRACE_MSG_SIZE;
57 313 : ret = DlTraceFunction::GetInstance().dlAtraceCreateWithAttr(TRACER_TYPE_SCHEDULE, objName, &hcclAtraceAttr);
58 : } else {
59 0 : TraceAttr hcclUtraceAttr = {};
60 0 : hcclUtraceAttr.exitSave = false;
61 0 : hcclUtraceAttr.msgNum = DEFAULT_ATRACE_MSG_NUM;
62 0 : hcclUtraceAttr.msgSize = DEFAULT_ATRACE_MSG_SIZE;
63 0 : ret = DlTraceFunction::GetInstance().dlUtraceCreateWithAttr(TRACER_TYPE_SCHEDULE, objName, &hcclUtraceAttr);
64 : }
65 313 : HCCL_INFO("Call TraceCreateWithAttr, return value[%p], Params: objName[%s]", ret, objName);
66 313 : CHK_PRT_RET(
67 : ret == TRACE_INVALID_HANDLE, HCCL_WARNING("Call TraceCreateWithAttr, return value[%lld]", ret),
68 : HCCL_E_INTERNAL);
69 313 : handle = ret;
70 313 : return HCCL_SUCCESS;
71 : }
72 :
73 0 : HcclResult hrtTraceSetGlobalAttr(const TraceGlobalAttr* attr)
74 : {
75 0 : TraHandle ret = TRACE_INVALID_HANDLE;
76 0 : if (DlTraceFunction::GetInstance().dlAtraceSetGlobalAttr != nullptr) {
77 0 : ret = DlTraceFunction::GetInstance().dlAtraceSetGlobalAttr(attr);
78 : } else {
79 0 : ret = DlTraceFunction::GetInstance().dlUtraceSetGlobalAttr(attr);
80 : }
81 0 : CHK_PRT_RET(ret != 0, HCCL_ERROR("Call TraceSetGlobalAttr, return value[%d]", ret), HCCL_E_INTERNAL);
82 0 : return HCCL_SUCCESS;
83 : }
84 :
85 0 : HcclResult hrtTraceSave(TracerType tracerType, bool syncFlag)
86 : {
87 0 : TraHandle ret = TRACE_INVALID_HANDLE;
88 0 : if (DlTraceFunction::GetInstance().dlAtraceSave != nullptr) {
89 0 : ret = DlTraceFunction::GetInstance().dlAtraceSave(tracerType, syncFlag);
90 : } else {
91 0 : ret = DlTraceFunction::GetInstance().dlUtraceSave(tracerType, syncFlag);
92 : }
93 0 : CHK_PRT_RET(ret != 0, HCCL_ERROR("Call traceSave, return value[%d]", ret), HCCL_E_INTERNAL);
94 0 : return HCCL_SUCCESS;
95 : }
|