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-07-28 10:53:44 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        14162 : static inline void TraceDlogInner(int level, const char *extendStr, const char *format, ...)
      41              : {
      42        14162 :     if (level < DLOG_LEVEL) {
      43         6375 :         return;
      44              :     }
      45              :     va_list args;
      46         7787 :     char buffer[LOG_BUFFER_SIZE] = {0};
      47         7787 :     va_start(args, format);
      48         7787 :     if (vsnprintf_s(buffer, sizeof(buffer), sizeof(buffer), format, args) != -1) {
      49         7270 :         (void)printf("%s%s\n", extendStr, buffer);
      50         7270 :         (void)fflush(stdout);
      51              :     }
      52         7787 :     va_end(args);
      53              : }
      54              : 
      55              : #define LOGI(format, ...) do {                                                          \
      56              :     TraceDlogInner(DLOG_INFO, "[INFO]", format,  ##__VA_ARGS__);                        \
      57              : } while (0)
      58              : 
      59              : #define LOGR(format, ...) do {                                                          \
      60              :     TraceDlogInner(DLOG_EVENT, "[RUN]", format,  ##__VA_ARGS__);                        \
      61              : } while (0)
      62              :  
      63              : #define LOGW(format, ...) do {                                                          \
      64              :     TraceDlogInner(DLOG_WARN, "[WARN] ", format,  ##__VA_ARGS__);                       \
      65              : } while (0)
      66              :  
      67              : #define LOGE(format, ...) do {                                                          \
      68              :     TraceDlogInner(DLOG_ERROR, "[ERROR] ", format,  ##__VA_ARGS__);                     \
      69              : } while (0)
      70              : 
      71              : #define STACK_CHK_EXPR_ACTION(expr, ACTION, msg, ...) do { \
      72              :     if (expr) { \
      73              :         LOGE(msg, ##__VA_ARGS__); \
      74              :         ACTION; \
      75              :     } \
      76              : } while (0)
      77              : 
      78              : #define STACKTRACE_LOG_TITLE_MAIN   "[main logcat]"
      79              : #define STACKTRACE_LOG_TITLE_SUB    "[sub logcat]"
      80              : 
      81              : void StacktraceLogSetPath(const char *path, const char *name);
      82              : void StacktraceLogSetPathSuffix(const char *path, const char *name, const char *suffix);
      83              : void StackcoreLogSaveWithFlag(uint32_t flag);
      84              : void StackcoreLogSave(void);
      85              : void StacktraceLogInner(const char *format, ...);
      86              : 
      87              : TraStatus StacktraceLogInit(const char *title);
      88              : void StackcoreLogExit(void);
      89              : 
      90              : 
      91              : #define STACKTRACE_LOG_RUN(fmt, ...) do { \
      92              :     StacktraceLogInner("%lu(%ld): " fmt "\n", GetRealTime(), syscall(__NR_gettid), ##__VA_ARGS__);   \
      93              : } while (0)
      94              : 
      95              : #define STACKTRACE_LOG_ERR(fmt, ...) do { \
      96              :     StacktraceLogInner("%lu(%ld): [FAIL]" fmt "\n", GetRealTime(), syscall(__NR_gettid), ##__VA_ARGS__);   \
      97              : } while (0)
      98              : 
      99              : #ifdef __cplusplus
     100              : }
     101              : #endif // __cplusplus
     102              : 
     103              : #endif
        

Generated by: LCOV version 2.0-1