LCOV - code coverage report
Current view: top level - pkg_inc/base - dlog_pub.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 83.3 % 6 5
Test Date: 2026-07-28 10:52:34 Functions: 100.0 % 1 1

            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              : /*
      12              :  * 本文件中的接口为非SDK接口,仅用于系统内部交互,其内容更改不会发布预告或记录,非CANN内部模块请勿直接引用
      13              :  */
      14              : 
      15              : #ifndef DLOG_PUB_H_
      16              : #define DLOG_PUB_H_
      17              : 
      18              : #include <string.h>
      19              : #include <stdint.h>
      20              : #include <stdarg.h>
      21              : #include "log_types.h"
      22              : 
      23           25 : static inline const char *DlogGetFileName(const char *filePath) {
      24           25 :     const char *result = filePath;
      25          425 :     for (size_t i = 0; filePath[i] != '\0'; i++) {
      26          400 :         if (filePath[i] == '/') {
      27            0 :             result = &filePath[i + 1U];
      28              :         }
      29              :     }
      30           25 :     return result;
      31              : }
      32              : 
      33              : #define DLOG_FILE_NAME (DlogGetFileName(__FILE__))
      34              : #define __FILENAME__ DLOG_FILE_NAME
      35              : 
      36              : #ifdef __cplusplus
      37              : #ifndef LOG_CPP
      38              : extern "C" {
      39              : #endif
      40              : #endif // __cplusplus
      41              : 
      42              : /**
      43              :  * @brief           get module debug loglevel and enableEvent
      44              :  * @param [in]      moduleId       moudule id(see log_types.h, eg: CCE), others: invalid
      45              :  * @param [out]     enableEvent    1: enable; 0: disable
      46              :  * @return          module level   0: debug, 1: info, 2: warning, 3: error, 4: null output
      47              :  */
      48              : LOG_FUNC_VISIBILITY int32_t dlog_getlevel(int32_t moduleId, int32_t *enableEvent);
      49              : 
      50              : /**
      51              :  * @brief           set module loglevel and enableEvent
      52              :  * @param [in]      moduleId       moudule id(see log_types.h, eg: CCE), -1: all modules, others: invalid
      53              :  * @param [in]      level          log level, eg: DLOG_ERROR/DLOG_WARN/DLOG_INFO/DLOG_DEBUG
      54              :  * @param [in]      enableEvent    1: enable; 0: disable, others:invalid
      55              :  * @return          0: SUCCEED, others: FAILED
      56              :  */
      57              : LOG_FUNC_VISIBILITY int32_t dlog_setlevel(int32_t moduleId, int32_t level, int32_t enableEvent);
      58              : 
      59              : /**
      60              :  * @brief           check module level enable or not
      61              :  * @param [in]      moduleId       module id, eg: CCE
      62              :  * @param [in]      logLevel       log level, eg: DLOG_ERROR/DLOG_WARN/DLOG_INFO/DLOG_DEBUG
      63              :  * @return          1:enable, 0:disable
      64              :  */
      65              : LOG_FUNC_VISIBILITY int32_t CheckLogLevel(int32_t moduleId, int32_t logLevel);
      66              : 
      67              : /**
      68              :  * @brief           set log attr, default pid is 0, default device id is 0, default process type is APPLICATION
      69              :  * @param [in]      logAttrInfo    attr info, include pid(must be larger than 0), process type and device id(chip ID)
      70              :  * @return          0: SUCCEED, others: FAILED
      71              :  */
      72              : LOG_FUNC_VISIBILITY int32_t DlogSetAttr(LogAttr logAttrInfo);
      73              : 
      74              : /**
      75              :  * @brief           print log, need va_list variable, exec CheckLogLevel() before call this function
      76              :  * @param[in]       moduleId      module id, eg: CCE
      77              :  * @param[in]       level         log level, eg: DLOG_ERROR/DLOG_WARN/DLOG_INFO/DLOG_DEBUG
      78              :  * @param[in]       fmt           log content
      79              :  * @param[in]       list          variable list of log content
      80              :  * @return          NA
      81              :  */
      82              : LOG_FUNC_VISIBILITY void DlogVaList(int32_t moduleId, int32_t level, const char *fmt, va_list list);
      83              : 
      84              : /**
      85              :  * @brief           flush log buffer to file
      86              :  * @return          NA
      87              :  */
      88              : LOG_FUNC_VISIBILITY void DlogFlush(void);
      89              : 
      90              : /**
      91              :  * @brief           print error log
      92              :  * @param [in]      moduleId      module id, eg: CCE
      93              :  * @param [in]      fmt           log content
      94              :  * @return          NA
      95              :  */
      96              : #define dlog_error(moduleId, fmt, ...)                                          \
      97              :     do {                                                                          \
      98              :         DlogRecord(moduleId, DLOG_ERROR, "[%s:%d]" fmt, DLOG_FILE_NAME, __LINE__, ##__VA_ARGS__); \
      99              :     } while (0)
     100              : 
     101              : /**
     102              :  * @brief           print warning log
     103              :  * call CheckLogLevel in advance to optimize performance, call interface with fmt input take time
     104              :  * @param [in]      moduleId      module id, eg: CCE
     105              :  * @param [in]      fmt           log content
     106              :  * @return          NA
     107              :  */
     108              : #define dlog_warn(moduleId, fmt, ...)                                               \
     109              :     do {                                                                              \
     110              :         if (CheckLogLevel(moduleId, DLOG_WARN) == 1) {                                   \
     111              :             DlogRecord(moduleId, DLOG_WARN, "[%s:%d]" fmt, DLOG_FILE_NAME, __LINE__, ##__VA_ARGS__);  \
     112              :         }                                                                               \
     113              :     } while (0)
     114              : 
     115              : /**
     116              :  * @brief           print info log
     117              :  * call CheckLogLevel in advance to optimize performance, call interface with fmt input take time
     118              :  * @param [in]      moduleId      module id, eg: CCE
     119              :  * @param [in]      fmt           log content
     120              :  * @return          NA
     121              :  */
     122              : #define dlog_info(moduleId, fmt, ...)                                               \
     123              :     do {                                                                              \
     124              :         if (CheckLogLevel(moduleId, DLOG_INFO) == 1) {                                   \
     125              :             DlogRecord(moduleId, DLOG_INFO, "[%s:%d]" fmt, DLOG_FILE_NAME, __LINE__, ##__VA_ARGS__);  \
     126              :         }                                                                               \
     127              :     } while (0)
     128              : 
     129              : /**
     130              :  * @brief           print debug log
     131              :  * call CheckLogLevel in advance to optimize performance, call interface with fmt input take time
     132              :  * @param [in]      moduleId      module id, eg: CCE
     133              :  * @param [in]      fmt           log content
     134              :  * @return          NA
     135              :  */
     136              : #define dlog_debug(moduleId, fmt, ...)                                              \
     137              :     do {                                                                              \
     138              :         if (CheckLogLevel(moduleId, DLOG_DEBUG) == 1) {                                  \
     139              :             DlogRecord(moduleId, DLOG_DEBUG, "[%s:%d]" fmt, DLOG_FILE_NAME, __LINE__, ##__VA_ARGS__); \
     140              :         }                                                                               \
     141              :     } while (0)
     142              : 
     143              : /**
     144              :  * @brief           print log, need caller to specify level
     145              :  * call CheckLogLevel in advance to optimize performance, call interface with fmt input take time
     146              :  * @param [in]      moduleId      module id, eg: CCE
     147              :  * @param [in]      level         log level, eg: DLOG_ERROR/DLOG_WARN/DLOG_INFO/DLOG_DEBUG
     148              :  * @param [in]      fmt           log content
     149              :  * @return          NA
     150              :  */
     151              : #define Dlog(moduleId, level, fmt, ...)                                                 \
     152              :     do {                                                                                  \
     153              :         if (CheckLogLevel(moduleId, level) == 1) {                                           \
     154              :             DlogRecord(moduleId, level, "[%s:%d]" fmt, DLOG_FILE_NAME, __LINE__, ##__VA_ARGS__);   \
     155              :         }                                                                                  \
     156              :     } while (0)
     157              : 
     158              : /**
     159              :  * @brief           print log, need caller to specify level and submodule
     160              :  * call CheckLogLevel in advance to optimize performance, call interface with fmt input take time
     161              :  * @param [in]      moduleId      module id, eg: CCE
     162              :  * @param [in]      submodule     eg: engine
     163              :  * @param [in]      level         log level, eg: DLOG_ERROR/DLOG_WARN/DLOG_INFO/DLOG_DEBUG
     164              :  * @param [in]      fmt           log content
     165              :  * @return          NA
     166              :  */
     167              : #define DlogSub(moduleId, submodule, level, fmt, ...)                                                   \
     168              :     do {                                                                                                  \
     169              :         if (CheckLogLevel(moduleId, level) == 1) {                                                           \
     170              :             DlogRecord(moduleId, level, "[%s:%d][%s]" fmt, DLOG_FILE_NAME, __LINE__, submodule, ##__VA_ARGS__);    \
     171              :         }                                                                                                   \
     172              :     } while (0)
     173              : 
     174              : /**
     175              :  * @brief           record log
     176              :  * @param [in]      moduleId   module id, eg: SLOG
     177              :  * @param [in]      level      log level, eg: DLOG_ERROR/DLOG_WARN/DLOG_INFO/DLOG_DEBUG
     178              :  * @param [in]      fmt        log content
     179              :  * @return:         NA
     180              :  */
     181              : LOG_FUNC_VISIBILITY void DlogRecord(int32_t moduleId, int32_t level, const char *fmt, ...) __attribute((weak));
     182              : 
     183              : #ifdef __cplusplus
     184              : #ifndef LOG_CPP
     185              : }
     186              : #endif // LOG_CPP
     187              : #endif // __cplusplus
     188              : 
     189              : #endif // DLOG_PUB_H_
        

Generated by: LCOV version 2.0-1