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 : #include "dfx_profiling_command_handle_lite.h"
11 : #include "log.h"
12 : #include "prof_common.h"
13 : #include "dfx_profiling_handler_lite.h"
14 :
15 : namespace Hccl {
16 :
17 3 : HcclResult DfxRegisterProfCallBack()
18 : {
19 3 : if (MsprofRegisterCallback != nullptr) {
20 3 : HCCL_INFO("RegisterProfCallBack not null");
21 3 : int32_t ret = MsprofRegisterCallback(AICPU, &DfxDeviceCommandHandle);
22 3 : CHK_PRT_RET((ret != 0), HCCL_ERROR("[%s] failed. ret = [%d]", __func__, ret), HCCL_E_PARA);
23 : } else {
24 0 : HCCL_INFO("RegisterProfCallBack is null");
25 : }
26 3 : return HCCL_SUCCESS;
27 : }
28 :
29 4 : int32_t DfxDeviceCommandHandle(uint32_t profType, void* data, uint32_t len)
30 : {
31 4 : HCCL_INFO("[%s] start", __func__);
32 : (void)len;
33 4 : if (data == nullptr) {
34 1 : HCCL_ERROR("[%s] CommandHandle's data is NULL.", __func__);
35 1 : return PROF_FAILED;
36 : }
37 3 : MsprofCommandHandle* command = reinterpret_cast<MsprofCommandHandle*>(data);
38 3 : auto type = command->type;
39 3 : HCCL_INFO("[%s] type = [%u]. CommandHandle_switch = [%llu]", __func__, type, command->profSwitch);
40 3 : if (type == PROF_COMMANDHANDLE_TYPE_START) {
41 2 : if ((ADPROF_TASK_TIME_L0 & command->profSwitch) != 0) {
42 1 : DfxProfilingHandlerLite::GetInstance().SetProL0On(true);
43 : }
44 2 : if ((ADPROF_TASK_TIME_L1 & command->profSwitch) != 0) {
45 1 : DfxProfilingHandlerLite::GetInstance().SetProL1On(true);
46 : }
47 1 : } else if (type == PROF_COMMANDHANDLE_TYPE_STOP) {
48 1 : DfxProfilingHandlerLite::GetInstance().SetProL0On(false);
49 1 : DfxProfilingHandlerLite::GetInstance().SetProL1On(false);
50 : }
51 3 : return PROF_SUCCESS;
52 : }
53 :
54 : } // namespace Hccl
|