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

Generated by: LCOV version 2.0-1