LCOV - code coverage report
Current view: top level - legacy/ascend910/framework/device/debug/dfx/profiling - profiling_manager_device.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 34.8 % 247 86
Test Date: 2026-08-04 10:52:23 Functions: 54.5 % 22 12

            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 "profiling_manager_device.h"
      12              : #include "aicpu_schedule/aicpu_context.h"
      13              : #include "prof_common.h"
      14              : #include "log.h"
      15              : #include "sal_pub.h"
      16              : #include "common/aicpu_sqe_context.h"
      17              : #include "common/aicpu_hccl_common.h"
      18              : #include "dlprof_function.h"
      19              : 
      20              : namespace {
      21              : static constexpr u32 aging = 1;
      22              : }
      23              : namespace dfx {
      24              : 
      25              : std::mutex ProfilingManager::streamMutex_;
      26              : std::unordered_map<std::string, ProfCommInfo> ProfilingManager::tagOpInfoMap_;
      27              : std::unordered_map<s32, std::string> ProfilingManager::streamToTagMap_;
      28              : 
      29              : std::mutex ProfilingManager::startReportSqeIdxMutex_;
      30              : std::unordered_map<s32, u32> ProfilingManager::streamToSqeIdxMap_;
      31              : 
      32              : bool ProfilingManager::isL0Open_ = false;
      33              : bool ProfilingManager::isL1Open_ = false;
      34              : 
      35              : constexpr std::uint32_t HCCLINFO_REPORT_BATCH_NUM = 2;
      36              : 
      37           46 : bool ProfilingManager::IsProfOn(uint64_t feature)
      38              : {
      39           46 :     if (MsprofReportBatchAdditionalInfo == nullptr) {
      40           46 :         if (AdprofCheckFeatureIsOn == nullptr) {
      41            0 :             return false;
      42              :         }
      43           46 :         return AdprofCheckFeatureIsOn(feature) > 0;
      44              :     } else {
      45            0 :         if (feature == ADPROF_TASK_TIME_L1) {
      46            0 :             return isL1Open_;
      47            0 :         } else if (feature == ADPROF_TASK_TIME_L0) {
      48            0 :             return isL0Open_;
      49              :         }
      50              :     }
      51            0 :     return false;
      52              : }
      53              : 
      54            0 : bool ProfilingManager::IsL1fromOffToOn()
      55              : {
      56            0 :     if (((!GetProfL1State()) && ProfilingManager::IsProfL1On())) {
      57            0 :         HCCL_INFO("Profiling L1 switch from off to on.");
      58            0 :         return true;
      59              :     }
      60            0 :     return false;
      61              : }
      62              : 
      63           23 : bool ProfilingManager::IsProfL1On()
      64              : {
      65           23 :     if (IsProfOn(ADPROF_TASK_TIME_L1)) {
      66            8 :         isL1Open_ = true;
      67            8 :         return true;
      68              :     }
      69           15 :     isL1Open_ = false;
      70           15 :     return false;
      71              : }
      72              : 
      73           23 : bool ProfilingManager::IsProfL0On()
      74              : {
      75           23 :     if (IsProfOn(ADPROF_TASK_TIME_L0)) {
      76            8 :         isL0Open_ = true;
      77            8 :         return true;
      78              :     }
      79           15 :     isL0Open_ = false;
      80           15 :     return false;
      81              : }
      82              : 
      83            0 : void ProfilingManager::SetProL1On(bool val)
      84              : {
      85            0 :     HCCL_INFO("[%s] val = [%d]", __func__, val);
      86            0 :     isL1Open_ = val;
      87            0 : }
      88              : 
      89            0 : void ProfilingManager::SetProL0On(bool val)
      90              : {
      91            0 :     HCCL_INFO("[%s] val = [%d]", __func__, val);
      92            0 :     isL0Open_ = val;
      93            0 : }
      94              : 
      95          424 : bool ProfilingManager::GetProfL0State()
      96              : {
      97          424 :     if (!isL0Open_) {
      98          381 :         return false;
      99              :     }
     100           43 :     return true;
     101              : }
     102              : 
     103     29988622 : bool ProfilingManager::GetProfL1State()
     104              : {
     105     29988622 :     if (!isL1Open_) {
     106     29988499 :         return false;
     107              :     }
     108          123 :     return true;
     109              : }
     110              : 
     111         1161 : HcclResult ProfilingManager::CallMsprofReportAdditionInfo(uint32_t type, uint64_t timeStamp, const void *data, int len)
     112              : {
     113         1161 :     MsprofAdditionalInfo reporterData{};
     114         1161 :     reporterData.level = MSPROF_REPORT_AICPU_LEVEL;
     115         1161 :     reporterData.type = type;
     116         1161 :     reporterData.threadId = SalGetTid();
     117         1161 :     reporterData.dataLen = len;
     118         1161 :     reporterData.timeStamp = timeStamp;
     119         1161 :     s32 sret = memcpy_s(reporterData.data, sizeof(reporterData.data), data, len);
     120         1161 :     CHK_PRT_RET(sret != EOK, 
     121              :             HCCL_ERROR("memcpy failed. errorno:[%d] level:[%hu] type:[%u] threadId:[%u] sizeof_data[%zu] len:[%u] timeStamp:[%llu]",
     122              :                 sret, reporterData.level, type, reporterData.threadId, sizeof(reporterData.data), len, timeStamp), 
     123              :             HCCL_E_MEMORY);
     124         1161 :     HCCL_DEBUG("CallMsprofReportAdditionInfo, AdditionInfoType[%u]", type);
     125         1161 :         if (MsprofReportBatchAdditionalInfo == nullptr) {
     126         1161 :         CHK_PTR_NULL(AdprofReportAdditionalInfo);
     127         1161 :         int32_t ret = AdprofReportAdditionalInfo(aging, &reporterData, sizeof(MsprofAdditionalInfo));
     128         1161 :         CHK_PRT_RET(ret != 0,
     129              :             HCCL_ERROR("AdprofReportAdditionalInfo failed. ret = [%d]", ret),
     130              :             HCCL_E_INTERNAL);
     131              :     } else {
     132            0 :         CHK_PTR_NULL(MsprofReportAdditionalInfo);
     133            0 :         int32_t ret = MsprofReportAdditionalInfo(aging, &reporterData, sizeof(MsprofAdditionalInfo));
     134            0 :         CHK_PRT_RET(ret != 0,
     135              :             HCCL_ERROR("MsprofReportAdditionalInfo failed. ret = [%d]", ret),
     136              :             HCCL_E_INTERNAL);
     137              :     }
     138              : 
     139         1161 :     HCCL_DEBUG("CallMsprofReportAdditionInfo with additionInfoType[%u] successfully", type);
     140         1161 :     return HCCL_SUCCESS;
     141              : }
     142              : 
     143            0 : HcclResult ProfilingManager::TaskInfo2Addition(const void *data, int len, MsprofAdditionalInfo& reporterData)
     144              : {
     145            0 :     reporterData.level = MSPROF_REPORT_AICPU_LEVEL;
     146            0 :     reporterData.type = MSPROF_REPORT_AICPU_MC2_BATCH_HCCL_INFO;
     147            0 :     reporterData.threadId = SalGetTid();
     148            0 :     reporterData.dataLen = len;
     149            0 :     reporterData.timeStamp = 0;
     150            0 :     s32 sret = memcpy_s(reporterData.data, sizeof(reporterData.data), data, len);
     151            0 :     CHK_PRT_RET(sret != EOK, HCCL_ERROR("memcpy failed. errorno[%d]:", sret), HCCL_E_MEMORY);
     152            0 :     return HCCL_SUCCESS;
     153              : }
     154              : 
     155            8 : HcclResult ProfilingManager::ReportTaskInfo(s32 streamId, void* ctxPtr)
     156              : {
     157            8 :     if (!GetProfL1State()) {
     158            8 :         return HCCL_SUCCESS;
     159              :     }
     160            0 :     ProfCommInfo profInfo;
     161              :     // 通信域中获取rankId, groupHashId等信息
     162            0 :     CHK_RET(GetProfInfoByStreamId(streamId, profInfo));
     163            0 :     CHK_PTR_NULL(ctxPtr);
     164            0 :     hccl::HcclSqeContext *sqeContext = reinterpret_cast<hccl::HcclSqeContext*>(ctxPtr);
     165            0 :     hccl::SqeRingBuffer *sqeContextBuffer = &(sqeContext->buffer);
     166            0 :     CHK_PTR_NULL(sqeContextBuffer);
     167            0 :     u32 startSqeIdx = GetStartReportSqeIdx(streamId);
     168            0 :     HCCL_INFO("[ReportTaskInfo] Rank:%u, stream:%d, sqeNum:%u, startSqeIdx:%u, curSqeTailIdx: %u", profInfo.rankId, streamId,
     169              :         sqeContextBuffer->tailSqeIdx - startSqeIdx, startSqeIdx, sqeContextBuffer->tailSqeIdx);
     170            0 :     MsprofAicpuHcclTaskInfo taskInfos[HCCLINFO_REPORT_BATCH_NUM] = {};
     171            0 :     auto endIdx = static_cast<uint32_t>(sqeContextBuffer->tailSqeIdx);
     172            0 :     bool isSupportBatchReport = (AdprofReportBatchAdditionalInfo != nullptr || MsprofReportBatchAdditionalInfo != nullptr);
     173            0 :     HCCL_INFO("AdprofReportBatchAdditionalInfo != nullptr || MsprofReportBatchAdditionalInfo != nullptr: %s", isSupportBatchReport ? "true" : "false");
     174            0 :     constexpr int32_t MAX_BATCH_REPORT_NUM = 512; // 最大支持批量上报的MsprofAdditionalInfo个数, 需要与接口实现侧保持一致
     175            0 :     MsprofAdditionalInfo addInfoVec[MAX_BATCH_REPORT_NUM] = {};
     176            0 :     uint32_t addInfoIndx = 0;
     177            0 :     for (uint32_t idx = startSqeIdx, batchId = 0; idx < endIdx; ++idx) {
     178              :         // 获取SqeInfo
     179            0 :         SqeInfo sqeInfo{};
     180            0 :         SqeContextUtils::QuerySqeInfo(sqeContextBuffer->localBuff + idx * hccl::HCCL_SQE_SIZE,
     181            0 :             sqeContextBuffer->sqeType[idx], sqeContextBuffer->addInfo[idx], &sqeInfo);
     182            0 :         sqeInfo.remoteRank = sqeContextBuffer->dfxInfo[idx].remoteRank;
     183              :         // 转换为MsprofAicpuHcclTaskInfo
     184            0 :         auto& taskInfo = taskInfos[batchId++];
     185            0 :         dfx::ProfilingExtendInfoHelper::InitHcclInfo(taskInfo);
     186            0 :         CommInfo2HcclInfo(profInfo, taskInfo);
     187            0 :         dfx::ProfilingExtendInfoHelper::SqeInfo2MsprofAicpuMC2HcclInfo(sqeInfo, taskInfo);
     188            0 :         taskInfo.timeStamp = sqeContextBuffer->profTimestap[idx]; // 时间戳
     189            0 :         DumpHcclInfo(taskInfo, batchId, idx);
     190              :         // 上报信息
     191            0 :         if (batchId == HCCLINFO_REPORT_BATCH_NUM || idx == (endIdx - 1)) {
     192            0 :             if (!isSupportBatchReport) {
     193            0 :                 CHK_PRT(dfx::ProfilingManager::CallMsprofReportAdditionInfo(MSPROF_REPORT_AICPU_MC2_BATCH_HCCL_INFO,
     194              :                     0, taskInfos, sizeof(MsprofAicpuHcclTaskInfo) * batchId));
     195              :             } else {
     196            0 :                 CHK_PRT(TaskInfo2Addition(taskInfos, sizeof(MsprofAicpuHcclTaskInfo) * batchId, addInfoVec[addInfoIndx++]));
     197            0 :                 if (addInfoIndx == MAX_BATCH_REPORT_NUM || idx == (endIdx - 1)) {
     198            0 :                     if (MsprofReportBatchAdditionalInfo == nullptr) {
     199            0 :                         CHK_PRT_RET(AdprofReportBatchAdditionalInfo(aging, addInfoVec, addInfoIndx * sizeof(MsprofAdditionalInfo)),
     200              :                                 HCCL_ERROR("AdprofReportBatchAdditionalInfo failed"), HCCL_E_INTERNAL);
     201            0 :                         addInfoIndx = 0; // 后面直接覆盖就行不需要清零;
     202              :                     } else {
     203            0 :                         CHK_PRT_RET(MsprofReportBatchAdditionalInfo(aging, addInfoVec, addInfoIndx * sizeof(MsprofAdditionalInfo)),
     204              :                                 HCCL_ERROR("MsprofReportBatchAdditionalInfo failed"), HCCL_E_INTERNAL);
     205            0 :                         addInfoIndx = 0; // 后面直接覆盖就行不需要清零;
     206              :                     }
     207              :                 }
     208              :             }
     209            0 :             batchId = 0;
     210            0 :             memset_s(taskInfos, sizeof(taskInfos), 0, sizeof(taskInfos));
     211              :         }
     212              :     }
     213            0 :     CHK_RET(UpdateStartReportSqeIdx(streamId, sqeContextBuffer->tailSqeIdx));
     214            0 :     return HCCL_SUCCESS;
     215              : }
     216              : 
     217         2237 : void ProfilingManager::DumpHcclInfo(const MsprofAicpuHcclTaskInfo& taskInfo, u32 batchId, u32 idx)
     218              : {
     219         2237 :     HCCL_DEBUG("[ReportTaskInfo] batchId:%u, idx:%u, itemId:%llu, groupName:%llu, localRank:%u, remoteRank:%u, " \
     220              :             "rankSize:%u, timeStamp:%llu, srcAddr:0x%llx, dstAddr:0x%llx, dataSize:%llu, taskId:%u, streamId:%u, planeID:%u," \
     221              :             "opType:%u, dataType:%u, linkType:%u, transportType:%u, rdmaType:%u, role:%u",
     222              :             batchId, idx, taskInfo.itemId, taskInfo.groupName, taskInfo.localRank, taskInfo.remoteRank,taskInfo.rankSize,
     223              :             taskInfo.timeStamp, taskInfo.srcAddr, taskInfo.dstAddr, taskInfo.dataSize,taskInfo.taskId, taskInfo.streamId,
     224              :             taskInfo.planeID, taskInfo.opType, taskInfo.dataType, taskInfo.linkType, taskInfo.transportType,
     225              :             taskInfo.rdmaType, taskInfo.role);
     226         2237 : }
     227              : 
     228            0 : void ProfilingManager::CommInfo2HcclInfo(const dfx::ProfCommInfo &profInfo, MsprofAicpuHcclTaskInfo &taskInfo)
     229              : {
     230            0 :     taskInfo.groupName = profInfo.groupNameHashId;
     231            0 :     taskInfo.localRank = profInfo.rankId;
     232            0 :     taskInfo.rankSize = profInfo.rankNum;
     233            0 : }
     234              : 
     235            0 : HcclResult ProfilingManager::ReportHcclOpInfo(MsprofAicpuHCCLOPInfo& hcclOpInfo, std::string &algTypeStr)
     236              : {
     237            0 :     if (!GetProfL0State()) {
     238            0 :         return HCCL_SUCCESS;
     239              :     }
     240            0 :     CHK_PTR_NULL(aicpu::GetTaskAndStreamId);
     241            0 :     uint64_t taskId = 0U;
     242            0 :     uint32_t streamId = 0;
     243            0 :     if (AicpuGetStreamId == nullptr || AicpuGetTaskId == nullptr) {
     244            0 :         CHK_PTR_NULL(aicpu::GetTaskAndStreamId);
     245            0 :         CHK_PRT_RET(aicpu::GetTaskAndStreamId(taskId, streamId) != aicpu::status_t::AICPU_ERROR_NONE,
     246              :         HCCL_ERROR("Failed to get task id and stream id."), HCCL_E_PARA);
     247              :     } else {
     248            0 :         streamId = AicpuGetStreamId();
     249            0 :         taskId = AicpuGetTaskId();
     250              :     }
     251              : 
     252            0 :     HCCL_INFO("[ProfilingManager] ReportHcclOpInfo streamId = %u, taskId = %llu", streamId, taskId);
     253              : 
     254            0 :     hcclOpInfo.algType = GetProfHashId(algTypeStr.c_str(), algTypeStr.length());
     255            0 :     hcclOpInfo.taskId = taskId;
     256            0 :     hcclOpInfo.streamId = streamId;
     257            0 :     HCCL_INFO("[ReportHcclOpInfo] relay:%u, retry:%u, dataType:%u, algType:%llu, count:%llu, groupHashId:%llu",
     258              :         hcclOpInfo.relay, hcclOpInfo.retry, hcclOpInfo.dataType, hcclOpInfo.algType, hcclOpInfo.count,
     259              :         hcclOpInfo.groupName);
     260            0 :     CHK_PRT(dfx::ProfilingManager::CallMsprofReportAdditionInfo(MSPROF_REPORT_AICPU_HCCL_OP_INFO,
     261              :         ProfGetCurCpuTimestamp(), &hcclOpInfo, sizeof(MsprofAicpuHCCLOPInfo)));
     262            0 :     return HCCL_SUCCESS;
     263              : }
     264              : 
     265            0 : HcclResult ProfilingManager::ReportMainStreamTask(hccl::Stream& stream, uint16_t taskId, uint16_t type)
     266              : {
     267            0 :     if (!GetProfL0State()) {
     268            0 :         return HCCL_SUCCESS;
     269              :     }
     270            0 :     CHK_PTR_NULL(aicpu::GetTaskAndStreamId);
     271            0 :     uint64_t aicpuKernelTaskId = 0U;
     272            0 :     uint32_t aicpuKernelStreamId = 0;
     273            0 :     if (AicpuGetStreamId == nullptr || AicpuGetTaskId == nullptr) {
     274            0 :         CHK_PTR_NULL(aicpu::GetTaskAndStreamId);
     275            0 :         CHK_PRT_RET(aicpu::GetTaskAndStreamId(aicpuKernelTaskId, aicpuKernelStreamId) != aicpu::status_t::AICPU_ERROR_NONE,
     276              :         HCCL_ERROR("Failed to get task id and stream id."), HCCL_E_PARA);
     277              :     } else {
     278            0 :         aicpuKernelTaskId = AicpuGetTaskId();
     279            0 :         aicpuKernelStreamId = AicpuGetStreamId();
     280              :     }
     281            0 :     HCCL_INFO("[ReportMainStreamTask] aicpuKernelStreamId = %u, aicpuKernelTaskId = %llu", aicpuKernelStreamId, aicpuKernelTaskId);
     282            0 :     MsprofAicpuHcclMainStreamTask flagtask{};
     283            0 :     flagtask.streamId = stream.id();
     284            0 :     flagtask.taskId = taskId;
     285            0 :     flagtask.type = type;
     286            0 :     flagtask.aicpuStreamId = aicpuKernelStreamId;
     287            0 :     flagtask.aicpuTaskId = aicpuKernelTaskId;
     288            0 :     HCCL_INFO("[ReportMainStreamTask] streamId:%u, taskId:%u, type:%u", flagtask.streamId, flagtask.taskId, flagtask.type);
     289              : 
     290            0 :     CHK_PRT(dfx::ProfilingManager::CallMsprofReportAdditionInfo(MSPROF_REPORT_AICPU_HCCL_FLAG_TASK,
     291              :         ProfGetCurCpuTimestamp(), &flagtask, sizeof(MsprofAicpuHcclMainStreamTask)));
     292              : 
     293            0 :     return HCCL_SUCCESS;
     294              : }
     295              : 
     296          411 : HcclResult ProfilingManager::ReportFilpTask(s32 streamId, uint16_t taskId, uint32_t flipNum)
     297              : {
     298          411 :     if (!GetProfL0State()) {
     299          369 :         return HCCL_SUCCESS;
     300              :     }
     301           42 :     MsporfAicpuFlipTask flipTaskInfo{};
     302           42 :     flipTaskInfo.streamId = streamId;
     303           42 :     flipTaskInfo.taskId = taskId;
     304           42 :     flipTaskInfo.flipNum = flipNum;
     305           42 :     HCCL_INFO("[ReportFlipTask] streamId:%u, taskId:%u, flipNum:%u", flipTaskInfo.streamId, flipTaskInfo.taskId,
     306              :         flipTaskInfo.flipNum);
     307           42 :     CHK_PRT(dfx::ProfilingManager::CallMsprofReportAdditionInfo(MSPROF_REPORT_AICPU_FILP_TASK,
     308              :         ProfGetCurCpuTimestamp(), &flipTaskInfo, sizeof(MsporfAicpuFlipTask)));
     309              : 
     310           42 :     return HCCL_SUCCESS;
     311              : }
     312              : 
     313           11 : uint64_t ProfilingManager::GetProfHashId(const char *name, uint32_t len)
     314              : {
     315           11 :     if (name == nullptr || len == 0) {
     316            0 :         HCCL_WARNING("HashData is empty.");
     317            0 :         return INVALID_U64;
     318              :     }
     319           11 :     if (MsprofReportBatchAdditionalInfo == nullptr) {
     320           11 :         CHK_PRT_RET((AdprofGetHashId == nullptr), HCCL_WARNING("AdprofGetHashId is null, just return"), INVALID_U64);
     321           11 :         return AdprofGetHashId(name, len);
     322              :     } else {
     323            0 :         CHK_PRT_RET((MsprofStr2Id == nullptr), HCCL_WARNING("MsprofStr2Id is null, just return"), INVALID_U64);
     324            0 :         return MsprofStr2Id(name, len);
     325              :     }
     326              : }
     327              : 
     328            0 : uint32_t ProfilingManager::GetStartReportSqeIdx(s32 streamId)
     329              : {
     330            0 :     std::unique_lock<std::mutex> lock(startReportSqeIdxMutex_);
     331            0 :     u32 lastSqeTailIdx = 0;
     332            0 :     auto iter = streamToSqeIdxMap_.find(streamId);
     333            0 :     if (iter == streamToSqeIdxMap_.end()) {
     334            0 :         HCCL_INFO("[GetProfInfoByStreamId]streamId:%d is not found", streamId);
     335            0 :         streamToSqeIdxMap_.insert({streamId, 0});
     336              :     } else {
     337            0 :         lastSqeTailIdx = iter->second;
     338              :     }
     339            0 :     return lastSqeTailIdx;
     340            0 : }
     341              : 
     342            5 : HcclResult ProfilingManager::UpdateStartReportSqeIdx(s32 streamId, u32 newSqeTailIdx)
     343              : {
     344            5 :     std::unique_lock<std::mutex> lock(startReportSqeIdxMutex_);
     345            5 :     auto iter = streamToSqeIdxMap_.find(streamId);
     346            5 :     if (iter == streamToSqeIdxMap_.end()) {
     347            2 :         streamToSqeIdxMap_.insert({ streamId, newSqeTailIdx });
     348            2 :         HCCL_INFO("[UpdateStartReportSqeIdx]streamId:%d is not found, newSqeTailIdx:%u", streamId, newSqeTailIdx);
     349              :     } else {
     350              :         // 到2048时,更新成0;
     351            3 :         newSqeTailIdx = (newSqeTailIdx == hccl::HCCL_SQE_MAX_CNT) ? 0 : newSqeTailIdx;
     352            3 :         HCCL_INFO("[UpdateStartReportSqeIdx] streamId:%d, lastSqeTailIdx:%u, newSqeTailIdx:%u", streamId,
     353              :             iter->second, newSqeTailIdx);
     354            3 :         iter->second = newSqeTailIdx;
     355              :     }
     356            5 :     return HCCL_SUCCESS;
     357            5 : }
     358              : 
     359            0 : HcclResult ProfilingManager::GetProfInfoByStreamId(s32 streamId, ProfCommInfo& profInfo)
     360              : {
     361            0 :     std::string tag = "unknown";
     362            0 :     std::unique_lock<std::mutex> lock(streamMutex_);
     363            0 :     auto iter = streamToTagMap_.find(streamId);
     364            0 :     if (iter == streamToTagMap_.end()) {
     365            0 :         HCCL_INFO("[GetProfInfoByStreamId]streamId:%d is not found", streamId);
     366              :     } else {
     367            0 :         tag = iter->second;
     368            0 :         auto opInfoIter = tagOpInfoMap_.find(tag);
     369            0 :         if (opInfoIter == tagOpInfoMap_.end()) {
     370            0 :             HCCL_INFO("[GetProfInfoByStreamId]tag:%s is not found", tag.c_str());
     371              :         } else {
     372            0 :             profInfo = opInfoIter->second;
     373              :         }
     374              :     }
     375            0 :     return HCCL_SUCCESS;
     376            0 : }
     377              : 
     378          451 : HcclResult ProfilingManager::AddProfInfoByStreamId(s32 streamId, const std::string &tag, const ProfCommInfo& profInfo)
     379              : {
     380          451 :     std::unique_lock<std::mutex> lock(streamMutex_);
     381          451 :     auto tagMapIter = streamToTagMap_.find(streamId);
     382          451 :     if (tagMapIter == streamToTagMap_.end()) {
     383           41 :         streamToTagMap_.insert({streamId, tag});
     384              :     } else {
     385          410 :         tagMapIter->second = tag;
     386              :         // streamId之前存在说明流被销毁了,被其它通信域复用了, 上报一条信息告知profiling taskid发生翻转
     387          410 :         CHK_RET(ReportFilpTask(streamId, UINT16_MAX, UINT16_MAX));
     388          410 :         HCCL_INFO("[AddProfInfoByStreamId] streamId:%d content:%s update", streamId, tag.c_str());
     389              :     }
     390              : 
     391          451 :     auto opInfoMapIter = tagOpInfoMap_.find(tag);
     392          451 :     if (opInfoMapIter == tagOpInfoMap_.end()) {
     393           11 :         tagOpInfoMap_.insert(std::make_pair(tag, profInfo));
     394              :     } else {
     395          440 :         opInfoMapIter->second = profInfo;
     396              :     }
     397          451 :     return HCCL_SUCCESS;
     398          451 : }
     399              : 
     400            0 : void TaskProfilingCallBack(void *userPtr, void *param, u32 length)
     401              : {
     402            0 :     if (UNLIKELY(param == nullptr)) {
     403            0 :         HCCL_ERROR("[ProfilingManager][%s]param is nullptr.", __func__);
     404            0 :         return;
     405              :     }
     406            0 :     struct hccl::TaskPara *taskPara = (struct hccl::TaskPara *)param;
     407              : 
     408            0 :     if (UNLIKELY(sizeof(hccl::TaskPara) < length)) {
     409            0 :         return;
     410              :     }
     411            0 :     HCCL_INFO("[ProfilingManager][%s]Start handle task profiler, taskType[%d], profilerType[%d]", __func__,
     412              :         static_cast<int>(taskPara->type), static_cast<int>(taskPara->profilerType));
     413            0 :     switch (taskPara->type) {
     414            0 :         case hccl::TaskType::TASK_BATCH_REPORT:
     415            0 :             dfx::ProfilingManager::ReportTaskInfo(taskPara->streamTasks.streamID, taskPara->streamTasks.ctxPtr);
     416            0 :             break;
     417              : 
     418            0 :         case hccl::TaskType::TASK_FLIP:
     419            0 :             dfx::ProfilingManager::ReportFilpTask(
     420            0 :                     taskPara->flipTask.streamID, taskPara->flipTask.taskID, taskPara->flipTask.flipNum);
     421            0 :             break;
     422              : 
     423            0 :         default:
     424            0 :             return;
     425              :     }
     426            0 :     return;
     427              : }
     428              : }  // namespace dfx
        

Generated by: LCOV version 2.0-1