LCOV - code coverage report
Current view: top level - atrace/utrace/stacktrace - stacktrace_logger.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 9 9
Test Date: 2026-08-31 10:07:06 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              : #ifndef STACKTRACE_LOGGER_H
      12              : #define STACKTRACE_LOGGER_H
      13              : 
      14              : #include <stdarg.h>
      15              : #include <sys/syscall.h>
      16              : #include "securec.h"
      17              : #include "slog.h"
      18              : #include "atrace_types.h"
      19              : #include "stacktrace_common.h"
      20              : #include "adiag_utils.h"
      21              : 
      22              : #if defined _ADIAG_LLT_
      23              : #define STATIC
      24              : #define INLINE
      25              : #else
      26              : #define STATIC static
      27              : #define INLINE inline
      28              : #endif
      29              : 
      30              : #ifdef __cplusplus
      31              : extern "C" {
      32              : #endif // __cplusplus
      33              : 
      34              : #if defined _ADIAG_LLT_
      35              : #define DLOG_LEVEL DLOG_ERROR
      36              : #else
      37              : #define DLOG_LEVEL (DLOG_EVENT + 1)
      38              : #endif
      39              : #define LOG_BUFFER_SIZE 4096
      40        16122 : static inline void TraceDlogInner(int level, const char* extendStr, const char* format, ...)
      41              : {
      42        16122 :     if (level < DLOG_LEVEL) {
      43         7094 :         return;
      44              :     }
      45              :     va_list args;
      46         9028 :     char buffer[LOG_BUFFER_SIZE] = {0};
      47         9028 :     va_start(args, format);
      48         9028 :     if (vsnprintf_s(buffer, sizeof(buffer), sizeof(buffer), format, args) != -1) {
      49         8441 :         (void)printf("%s%s\n", extendStr, buffer);
      50         8441 :         (void)fflush(stdout);
      51              :     }
      52         9028 :     va_end(args);
      53              : }
      54              : 
      55              : #define LOGI(format, ...)                                           \
      56              :     do {                                                            \
      57              :         TraceDlogInner(DLOG_INFO, "[INFO]", format, ##__VA_ARGS__); \
      58              :     } while (0)
      59              : 
      60              : #define LOGR(format, ...)                                           \
      61              :     do {                                                            \
      62              :         TraceDlogInner(DLOG_EVENT, "[RUN]", format, ##__VA_ARGS__); \
      63              :     } while (0)
      64              : 
      65              : #define LOGW(format, ...)                                            \
      66              :     do {                                                             \
      67              :         TraceDlogInner(DLOG_WARN, "[WARN] ", format, ##__VA_ARGS__); \
      68              :     } while (0)
      69              : 
      70              : #define LOGE(format, ...)                                              \
      71              :     do {                                                               \
      72              :         TraceDlogInner(DLOG_ERROR, "[ERROR] ", format, ##__VA_ARGS__); \
      73              :     } while (0)
      74              : 
      75              : #define STACK_CHK_EXPR_ACTION(expr, ACTION, msg, ...) \
      76              :     do {                                              \
      77              :         if (expr) {                                   \
      78              :             LOGE(msg, ##__VA_ARGS__);                 \
      79              :             ACTION;                                   \
      80              :         }                                             \
      81              :     } while (0)
      82              : 
      83              : #define STACKTRACE_LOG_TITLE_MAIN "[main logcat]"
      84              : #define STACKTRACE_LOG_TITLE_SUB "[sub logcat]"
      85              : 
      86              : void StacktraceLogSetPath(const char* path, const char* name);
      87              : void StacktraceLogSetPathSuffix(const char* path, const char* name, const char* suffix);
      88              : void StackcoreLogSaveWithFlag(uint32_t flag);
      89              : void StackcoreLogSave(void);
      90              : void StacktraceLogInner(const char* format, ...);
      91              : 
      92              : TraStatus StacktraceLogInit(const char* title);
      93              : void StackcoreLogExit(void);
      94              : 
      95              : #define STACKTRACE_LOG_RUN(fmt, ...)                                                                   \
      96              :     do {                                                                                               \
      97              :         StacktraceLogInner("%lu(%ld): " fmt "\n", GetRealTime(), syscall(__NR_gettid), ##__VA_ARGS__); \
      98              :     } while (0)
      99              : 
     100              : #define STACKTRACE_LOG_ERR(fmt, ...)                                                                         \
     101              :     do {                                                                                                     \
     102              :         StacktraceLogInner("%lu(%ld): [FAIL]" fmt "\n", GetRealTime(), syscall(__NR_gettid), ##__VA_ARGS__); \
     103              :     } while (0)
     104              : 
     105              : #ifdef __cplusplus
     106              : }
     107              : #endif // __cplusplus
     108              : 
     109              : #endif
        

Generated by: LCOV version 2.0-1