LCOV - code coverage report
Current view: top level - aicpu_prof - aicpu_prof.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 89.3 % 28 25
Test Date: 2026-08-12 11:05:02 Functions: 84.6 % 13 11

            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 AICPU_PROF_H
      11              : #define AICPU_PROF_H
      12              : #include "aicpu_prof/profiling_adp.h"
      13              : namespace aicpu {
      14              : #ifdef __cplusplus
      15              : extern "C" {
      16              : #endif
      17              : void InitProfilingDataInfo(const uint32_t deviceId, const pid_t hostPid, const uint32_t channelId);
      18              : void SetProfilingFlagForKFC(const uint32_t flag);
      19              : void LoadProfilingLib();
      20              : #ifdef __cplusplus
      21              : }
      22              : #endif
      23              : 
      24              : enum AicpumiMessageIndex {
      25              :     QUEUE_SIZE = 1,
      26              :     RUN_START_TIME,
      27              :     RUN_END_TIME,
      28              :     TOTAL_LEN,
      29              : };
      30              : 
      31              : class ProfMessageCount {
      32              : public:
      33            1 :     static ProfMessageCount& getInstance()
      34              :     {
      35            9 :         static ProfMessageCount instance;
      36            1 :         return instance;
      37              :     }
      38              : 
      39            2 :     void AicpuMesCountInc() { aicpuMesCount++; }
      40              : 
      41            1 :     void DpMesCountInc() { dpMesCount++; }
      42              : 
      43            4 :     void ModelMesCountInc() { modelMesCount++; }
      44              : 
      45            3 :     void MiMesCountInc() { miMesCount++; }
      46              : 
      47              : private:
      48              :     uint64_t aicpuMesCount;
      49              :     uint64_t dpMesCount;
      50              :     uint64_t modelMesCount;
      51              :     uint64_t miMesCount;
      52              : 
      53            1 :     ProfMessageCount() : aicpuMesCount(0U), dpMesCount(0U), modelMesCount(0U), miMesCount(0U) {}
      54              : 
      55            1 :     ~ProfMessageCount()
      56              :     {
      57            1 :         AICPU_LOG_INFO(
      58              :             "The total data is: aicpu[%llu], dp[%llu], model[%llu], aicpumi[%llu]", aicpuMesCount, dpMesCount,
      59              :             modelMesCount, miMesCount);
      60            1 :     }
      61              : };
      62              : 
      63              : class ProfilingAdp {
      64              :     friend ProfModelMessage;
      65              : 
      66              : public:
      67              :     /**
      68              :      * it is a constructor function.
      69              :      */
      70            1 :     ProfilingAdp()
      71            1 :         : reportCallback_(nullptr),
      72            1 :           deviceId_(0U),
      73            1 :           hostPid_(0),
      74            1 :           initFlag_(false),
      75            1 :           channelId_(0U),
      76            1 :           profilingFlag_(0U),
      77            1 :           isProfApiSo_(false)
      78            1 :     {}
      79              :     /**
      80              :      * it is a Destructor function.
      81              :      */
      82            1 :     virtual ~ProfilingAdp() {}
      83              :     /**
      84              :      * it is a Singleton mode,get a global and unique instance of class ProfilingAdp.
      85              :      * @return a global and unique instance of class ProfilingAdp
      86              :      */
      87           79 :     static ProfilingAdp& GetInstance()
      88              :     {
      89           79 :         static ProfilingAdp instance;
      90           79 :         return instance;
      91              :     }
      92              :     /**
      93              :      * it is used to initialize the ProfilingAdp object.
      94              :      * @param [in]deviceId real device ID
      95              :      * @param [in]hostPid real host process ID
      96              :      * @return status whether this operation success
      97              :      */
      98              :     int32_t InitAicpuProfiling(const uint32_t deviceId, const pid_t hostPid, const uint32_t channelId);
      99              :     /**
     100              :      * it is used to provide interface to DP module which can send data to profiling.
     101              :      * @param [in]sendData the data ptr which it is need send to profiling
     102              :      * @param [in]mark the mark of dataset
     103              :      * @return status whether this operation success
     104              :      */
     105              :     int32_t Send(const char_t* const sendData, std::string mark);
     106              :     /**
     107              :      * it is used to set report callback function valid.
     108              :      * @param [in]flag report flag
     109              :      * @param [in]reportCallback report callback function
     110              :      */
     111              :     void SetReportCallbackValid(bool flag, MsprofReporterCallback profReportCallback);
     112              :     /**
     113              :      * it is used to know the data whether can send to profiling.
     114              :      * @return status whether the data can send to profiling
     115              :      */
     116              :     bool GetReportValid(void);
     117              :     /**
     118              :      * it is used to update mode.
     119              :      * @return status whether the data can send to profiling
     120              :      */
     121              :     void UpdateModeProcess(const bool mode);
     122              :     /**
     123              :      * it is used to uninit profiling.
     124              :      * @return NA
     125              :      */
     126              :     int32_t UninitProcess();
     127              :     /**
     128              :      * it is used to initialize the ProfilingAdp object data info.
     129              :      * @param [in]deviceId real device ID
     130              :      * @param [in]hostPid real host process ID
     131              :      * @return NA
     132              :      */
     133              :     void InitAicpuProfilingDataInfo(const uint32_t deviceId, const pid_t hostPid, const uint32_t channelId);
     134              :     /**
     135              :      * it is used to set the kfc op profiling switch.
     136              :      * @param [in]flag
     137              :      * @return NA
     138              :      */
     139              :     void SetAicpuProfilingFlagForKFC(const uint32_t flag);
     140              :     MsprofReporterCallback GetMsprofReporterCallback(void);
     141              : 
     142              :     /**
     143              :      * it is used to update mode open process.
     144              :      * @param NA
     145              :      * @param NA
     146              :      * @return status whether this operation success
     147              :      */
     148              :     int32_t ProfilingModeOpenProcess();
     149            2 :     bool IsProfApiSo() const { return isProfApiSo_; }
     150            0 :     void SetNewSoFlag(bool flag)
     151              :     {
     152            0 :         isProfApiSo_ = flag;
     153            0 :         return;
     154              :     }
     155              : 
     156              : protected:
     157              :     /**
     158              :      * it is used to send data to profiling.
     159              :      * @param [in]data the data which it is need send to profiling
     160              :      * @return status whether this operation success
     161              :      */
     162              :     int32_t SendProcess(ReporterData& data);
     163              : 
     164              :     /**
     165              :      * it is used to send data to profiling with MsprofAdditionalInfo.
     166              :      * @param [in]data the data which it is need send to profiling
     167              :      * @return status whether this operation success
     168              :      */
     169              :     int32_t SendAdditionalProcess(MsprofAdditionalInfo& additionalReportData);
     170              : 
     171              : private:
     172              :     /**
     173              :      * it is used to new memory to store data.
     174              :      * @param [in]sendSize the size of data
     175              :      * @param [in]sendData the source data
     176              :      * @param [in]reportData the data which need to send
     177              :      * @return status whether this operation success
     178              :      */
     179              :     bool NewMemoryToStoreData(int32_t sendSize, const std::string& sendData, ReporterData& reportData) const;
     180              :     /**
     181              :      * it is used to create the content.
     182              :      * @param [in]sendData the source data
     183              :      * @param [in]mark the mark of dataset
     184              :      * @param [in]buffer it is used to store data
     185              :      * @param [in]bufferlen the size of buffer
     186              :      * @param [in]newflag if it is true,it means new memory to store data
     187              :      * @param [in]reportData it is struct of profiling data package
     188              :      * @return status whether this operation success
     189              :      */
     190              :     bool BuildSendContent(
     191              :         const std::string& sendData, const std::string& mark, char_t buffer[], const int32_t bufferlen, bool& newflag,
     192              :         ReporterData& reportData) const;
     193              :     /**
     194              :      * it is used to create the content.
     195              :      * @param [in]sendData the source data
     196              :      * @param [in]mark the mark of dataset
     197              :      * @param [in]reportData it is struct of profiling data package
     198              :      */
     199              :     template <typename T>
     200              :     void BuildProfData(const T& sendData, const std::string& mark, ReporterData& reportData) const;
     201              : 
     202              :     void BuildProfAicpuAdditionalData(const MsprofAicpuProfData& sendData, MsprofAdditionalInfo& reportData) const;
     203              : 
     204              :     void BuildProfDpAdditionalData(const MsprofDpProfData& sendData, MsprofAdditionalInfo& reportData) const;
     205              : 
     206              :     void BuildProfMiAdditionalData(const std::string& sendData, MsprofAdditionalInfo& reportData) const;
     207              : 
     208              :     int32_t SendProfDataWithNewChannel(const char_t* const sendData, std::string mark);
     209              : 
     210              :     int32_t SendProfDataWithOldChannel(const char_t* const sendData, std::string mark);
     211              : 
     212              : private:
     213              :     // the send callBack function of profiling
     214              :     MsprofReporterCallback reportCallback_;
     215              : 
     216              :     // real device ID.
     217              :     uint32_t deviceId_;
     218              : 
     219              :     // host pid
     220              :     pid_t hostPid_;
     221              : 
     222              :     // profiling init flag
     223              :     bool initFlag_;
     224              : 
     225              :     uint32_t channelId_;
     226              :     uint32_t profilingFlag_;
     227              :     bool isProfApiSo_;
     228              :     ProfMessageCount& counter = ProfMessageCount::getInstance();
     229              : };
     230              : } // namespace aicpu
     231              : #endif
        

Generated by: LCOV version 2.0-1