LCOV - code coverage report
Current view: top level - legacy/ascend950/framework/dfx/aicpu/profiling - profiling_handler_lite.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 5 5
Test Date: 2026-07-28 12:11:00 Functions: 100.0 % 9 9

            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              : #ifndef HCCL_PROFILING_HANDLER_LITE_H
      11              : #define HCCL_PROFILING_HANDLER_LITE_H
      12              : 
      13              : #include <vector>
      14              : #include <unordered_map>
      15              : #include "hccl/hccl_types.h"
      16              : #include "prof_common.h"
      17              : #include "aprof_pub.h"
      18              : #include "task_info.h"
      19              : #include "profiling_common.h"
      20              : 
      21              : extern "C" {
      22              : __attribute__((weak)) int32_t MsprofReportBatchAdditionalInfo(uint32_t nonPersistantFlag, const VOID_PTR data, uint32_t length);
      23              : __attribute__((weak)) int32_t AdprofReportBatchAdditionalInfo(uint32_t nonPersistantFlag, const void *data, uint32_t length);
      24              : __attribute__((weak)) int32_t AdprofReportAdditionalInfo(uint32_t agingFlag, const void *data, uint32_t length);
      25              : __attribute__((weak)) int32_t MsprofReportAdditionalInfo(uint32_t nonPersistantFlag, const VOID_PTR data, uint32_t length);
      26              : __attribute__((weak)) int32_t AdprofCheckFeatureIsOn(uint64_t feature);
      27              : __attribute__((weak)) int32_t MsprofRegisterCallback(uint32_t moduleId, ProfCommandHandle handle);
      28              : __attribute__((weak)) uint64_t AdprofGetHashId(const char *hashInfo, size_t length);
      29              : __attribute__((weak)) uint64_t MsprofStr2Id(const char *hashInfo, size_t length);
      30              : };
      31              : 
      32              : namespace aicpu {
      33           10 : MAKE_ENUM (status_t, AICPU_ERROR_NONE = 0, AICPU_ERROR_FAILED = 1)
      34              : status_t __attribute__((weak)) GetTaskAndStreamId(uint64_t &taskId, uint32_t &streamId);
      35              : }
      36              :  
      37              : namespace Hccl {
      38           19 : MAKE_ENUM(MainStreamTaskType, HEAD = 0, TAIL = 1)
      39              : 
      40           45 : MAKE_ENUM(ProfilingLevel, L0, L1)
      41              : 
      42              : struct FlagTaskInfo {
      43              :     uint32_t           taskId;
      44              :     MainStreamTaskType type;
      45              : };
      46              : 
      47              : class ProfilingHandlerLite {
      48              : public:
      49              :     ~ProfilingHandlerLite();
      50              :     ProfilingHandlerLite(const ProfilingHandlerLite &that)                   = delete;
      51              :     ProfilingHandlerLite        &operator=(const ProfilingHandlerLite &that) = delete;
      52              :     static ProfilingHandlerLite &GetInstance();
      53              :     HcclResult                   Init();
      54              :     void                         ReportHcclOpInfo(const DfxOpInfo &opInfo) const;
      55              :     void                         ReportHcclTaskDetails(const std::vector<TaskInfo *> &taskInfo) const;
      56              :     void                         ReportMainStreamTask(const FlagTaskInfo &flagTaskInfo) const;
      57              :     void                         SetCachedCclTag();
      58              :     void                         SetCachedGroupName(const std::string &groupName, u32 rankSize);
      59              :     uint64_t                     GetCachedAlgTypeHashId() const { return cachedAlgTypeHashId_; }
      60              :     void                         UpdateProfSwitch();
      61              :     void                         SetProL0On(bool val);
      62              :     void                         SetProL1On(bool val);
      63           19 :     inline bool                  GetProfL0State() const { return enableHcclL0_; }
      64            8 :     inline bool                  GetProfL1State() const { return enableHcclL1_; }
      65              :     uint64_t                     GetProfHashId(const char *name, uint32_t len) const;
      66              : 
      67              : private:
      68              :     explicit ProfilingHandlerLite();
      69              :     void ReportAdditionInfo(const MsprofAdditionalInfo& reporterData) const;
      70              : 
      71              :     bool IsProfOn(uint64_t feature) const;
      72              :     bool IsProfSwitchOn(ProfilingLevel level);
      73              :     bool IsL1fromOffToOn();
      74              : 
      75              :     void DumpTaskDetails(const MsprofAicpuHcclTaskInfo& taskDetailsInfos, const TaskInfo *taskInfo) const;
      76              :     void GetTaskDetailInfos(const TaskInfo *it, MsprofAicpuHcclTaskInfo &taskDetailsInfos) const;
      77              :     void FillTaskParamDetails(const TaskInfo *it, MsprofAicpuHcclTaskInfo &taskDetailsInfos) const;
      78              :     bool FillBatchReporterData(uint32_t batchId, const MsprofAicpuHcclTaskInfo *taskInfos,
      79              :                                MsprofAdditionalInfo &addInfo) const;
      80              :     void ReportHcclTaskDetailsLog(const std::vector<TaskInfo *> &taskInfo) const;
      81              :     bool ReportBatchAddInfo(uint32_t batchId, const MsprofAicpuHcclTaskInfo *taskInfos,
      82              :                             MsprofAdditionalInfo *addInfoVec, uint32_t &addInfoIndx,
      83              :                             uint32_t maxBatchNum, bool isLastBatch) const;
      84              : 
      85              : private:
      86              :     static ProfilingHandlerLite instance_;
      87              :     bool                        enableHcclL0_{false};
      88              :     bool                        enableHcclL1_{false};
      89              :     bool                        initializedFlag_{false};
      90              :     uint64_t                    cachedGroupName_{INVALID_U64};
      91              :     uint64_t                    cachedAlgTypeHashId_{0};
      92              :     u32                         cachedRankSize_{0};
      93              :     uint32_t                    cachedTid_{0};
      94              :     std::unordered_map<uint32_t, uint64_t> taskTypeHashCache_;
      95              :     std::unordered_map<std::string, uint64_t> cachedCclTag_;
      96              :     using ReportAdditionalInfoHandle = int32_t (*)(uint32_t, const void*, uint32_t);
      97              :     ReportAdditionalInfoHandle reportAdditionalInfo_{nullptr};
      98              :     using ReportBatchAdditionalInfoHandle = int32_t (*)(uint32_t, const void*, uint32_t);
      99              :     ReportBatchAdditionalInfoHandle reportBatchAdditionalInfo_{nullptr};
     100              :     using GetProfHashIdHandle = uint64_t (*)(const char *, size_t);
     101              :     GetProfHashIdHandle getProfHashId_{nullptr};
     102              : };
     103              : } // namespace Hccl
     104              : 
     105              : #endif // HCCL_PROFILING_HANDLER_LITE_H
        

Generated by: LCOV version 2.0-1