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 "command_handle.h"
12 : #include "profiling_manager.h"
13 : #include "prof_common.h"
14 :
15 : namespace hccl {
16 8 : rtError_t CommandHandle(uint32_t rtType, void* data, uint32_t len)
17 : {
18 : (void)len;
19 8 : if (data == nullptr) {
20 0 : HCCL_ERROR("[Profiling][CommandHandle] CommandHandle's data is NULL.");
21 0 : return FAILED;
22 : }
23 8 : auto& profilingManager = hccl::ProfilingManager::Instance();
24 8 : if (rtType == RT_PROF_CTRL_REPORTER) { // 创建 reporter
25 1 : HCCL_INFO("[Profiling][CommandHandle] CommandHandle's rtType is %u.", rtType);
26 1 : profilingManager.SetMsprofReporterCallback(reinterpret_cast<MsprofReporterCallback>(data));
27 7 : } else if (rtType == RT_PROF_CTRL_SWITCH) {
28 7 : rtProfCommandHandle_t* profConfigParam = reinterpret_cast<rtProfCommandHandle_t*>(data);
29 7 : auto type = profConfigParam->type;
30 7 : auto profconfig = profConfigParam->profSwitch;
31 7 : HCCL_RUN_INFO(
32 : "[Profiling][CommandHandle] CommandHandle's rtType is %u. CommandHandle_switch type[%u], "
33 : "profconfig[%llu], deviceLogicId[%u]",
34 : rtType, type, profconfig, profConfigParam->devIdList[0]);
35 7 : switch (type) {
36 1 : case PROF_COMMANDHANDLE_TYPE_INIT:
37 1 : profilingManager.PluginInit();
38 1 : break;
39 1 : case PROF_COMMANDHANDLE_TYPE_START:
40 1 : profilingManager.PluginInit();
41 1 : profilingManager.StartSubscribe(profconfig);
42 1 : break;
43 1 : case PROF_COMMANDHANDLE_TYPE_STOP:
44 1 : profilingManager.StopSubscribe(profconfig);
45 1 : break;
46 1 : case PROF_COMMANDHANDLE_TYPE_FINALIZE:
47 1 : profilingManager.PluginUnInit();
48 1 : break;
49 1 : case PROF_COMMANDHANDLE_TYPE_MODEL_SUBSCRIBE:
50 1 : profilingManager.PluginInit();
51 1 : profilingManager.StartSubscribe(profconfig);
52 1 : break;
53 1 : case PROF_COMMANDHANDLE_TYPE_MODEL_UNSUBSCRIBE:
54 1 : profilingManager.StopSubscribe(profconfig);
55 1 : profilingManager.PluginUnInit();
56 1 : break;
57 1 : default:
58 1 : HCCL_RUN_INFO("[Profiling][CommandHandle] Unexpected behaviour.");
59 : }
60 : }
61 :
62 8 : return SUCCESS;
63 : }
64 :
65 7 : rtError_t EsCommandHandle(uint32_t rtType, void* data, uint32_t len)
66 : {
67 : (void)len;
68 7 : if (data == nullptr) {
69 0 : HCCL_ERROR("[Profiling][EsCommandHandle] EsCommandHandle's data is NULL.");
70 0 : return FAILED;
71 : }
72 :
73 7 : HCCL_INFO("[Profiling][EsCommandHandle] EsCommandHandle's rtType is %u.", rtType);
74 7 : if (rtType == RT_PROF_CTRL_REPORTER) { // 创建 reporter
75 1 : HCCL_INFO("rtType[%u] == RT_PROF_CTRL_REPORTER", rtType);
76 1 : return SUCCESS;
77 : }
78 :
79 6 : auto& profilingManager = hccl::ProfilingManager::Instance();
80 6 : rtProfCommandHandle_t* profConfigParam = static_cast<rtProfCommandHandle_t*>(data);
81 6 : auto type = profConfigParam->type;
82 6 : auto profconfig = profConfigParam->profSwitch;
83 :
84 6 : HCCL_INFO("[Profiling][EsCommandHandle] EsCommandHandle_switch type[%u], profconfig[%llu]", type, profconfig);
85 6 : switch (type) {
86 2 : case PROF_COMMANDHANDLE_TYPE_START:
87 : case PROF_COMMANDHANDLE_TYPE_MODEL_SUBSCRIBE:
88 2 : profilingManager.EsStartSubscribe(profconfig);
89 2 : break;
90 2 : case PROF_COMMANDHANDLE_TYPE_STOP:
91 : case PROF_COMMANDHANDLE_TYPE_MODEL_UNSUBSCRIBE:
92 2 : profilingManager.EsStopSubscribe(profconfig);
93 2 : break;
94 1 : case PROF_COMMANDHANDLE_TYPE_INIT:
95 : case PROF_COMMANDHANDLE_TYPE_FINALIZE:
96 1 : break;
97 1 : default:
98 1 : HCCL_ERROR("[Profiling][EsCommandHandle] Unexpected behaviour.");
99 : }
100 :
101 6 : return SUCCESS;
102 : }
103 :
104 : } // namespace hccl
|