LCOV - code coverage report
Current view: top level - src/platform - platform_log.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 6 6
Test Date: 2026-07-28 10:52:27 Functions: 100.0 % 2 2

            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 __PLATFORM_LOG_H__
      12              : #define __PLATFORM_LOG_H__
      13              : 
      14              : #include <sys/syscall.h>
      15              : #include <unistd.h>
      16              : #include <string>
      17              : #include "err_msg.h"
      18              : #ifndef COMPILE_PLATFORM_STATIC
      19              : #include "dlog_pub.h"
      20              : #endif
      21              : using char_t = char;
      22              : /** Assigned FE name in log */
      23              : constexpr const char_t* const PF_MODULE_NAME = "FE";
      24              : 
      25           73 : inline pid_t PltGetTid()
      26              : {
      27            2 :     thread_local static pid_t tid = []() {
      28            1 :         const auto ret = syscall(__NR_gettid);
      29            1 :         return (ret == -1) ? getpid() : static_cast<pid_t>(ret); // 失败时降级为 PID
      30           73 :     }();
      31           73 :     return tid;
      32              : }
      33              : 
      34              : #ifdef COMPILE_PLATFORM_STATIC
      35              : #define D_PF_LOGD(MOD_NAME, fmt, ...) \
      36              :     do {                              \
      37              :         (void)MOD_NAME;               \
      38              :         (void)fmt;                    \
      39              :     } while (0)
      40              : 
      41              : #define D_PF_LOGI(MOD_NAME, fmt, ...) \
      42              :     do {                              \
      43              :         (void)MOD_NAME;               \
      44              :         (void)fmt;                    \
      45              :     } while (0)
      46              : 
      47              : #define D_PF_LOGW(MOD_NAME, fmt, ...) \
      48              :     do {                              \
      49              :         (void)MOD_NAME;               \
      50              :         (void)fmt;                    \
      51              :     } while (0)
      52              : 
      53              : #define D_PF_LOGE(MOD_NAME, fmt, ...) \
      54              :     do {                              \
      55              :         (void)MOD_NAME;               \
      56              :         (void)fmt;                    \
      57              :     } while (0)
      58              : #endif
      59              : 
      60              : #ifndef COMPILE_PLATFORM_STATIC
      61              : #define D_PF_LOGD(MOD_NAME, fmt, ...) dlog_debug(FE, "%lu %s:" fmt "\n", PltGetTid(), __FUNCTION__, ##__VA_ARGS__)
      62              : #define D_PF_LOGI(MOD_NAME, fmt, ...) dlog_info(FE, "%lu %s:" fmt "\n", PltGetTid(), __FUNCTION__, ##__VA_ARGS__)
      63              : #define D_PF_LOGW(MOD_NAME, fmt, ...) dlog_warn(FE, "%lu %s:" fmt "\n", PltGetTid(), __FUNCTION__, ##__VA_ARGS__)
      64              : #define D_PF_LOGE(MOD_NAME, fmt, ...) dlog_error(FE, "%lu %s:" fmt "\n", PltGetTid(), __FUNCTION__, ##__VA_ARGS__)
      65              : #endif
      66              : 
      67              : #define PF_LOGD(...) D_PF_LOGD(PF_MODULE_NAME, __VA_ARGS__)
      68              : #define PF_LOGI(...) D_PF_LOGI(PF_MODULE_NAME, __VA_ARGS__)
      69              : #define PF_LOGW(...) D_PF_LOGW(PF_MODULE_NAME, __VA_ARGS__)
      70              : #define PF_LOGE(...) D_PF_LOGE(PF_MODULE_NAME, __VA_ARGS__)
      71              : 
      72              : #define PF_MAKE_SHARED(exec_expr0, exec_expr1) \
      73              :     do {                                       \
      74              :         try {                                  \
      75              :             exec_expr0;                        \
      76              :         } catch (...) {                        \
      77              :             PF_LOGE("Make shared failed.");    \
      78              :             exec_expr1;                        \
      79              :         }                                      \
      80              :     } while (0)
      81              : 
      82              : #endif // __PLATFORM_LOG_H__
        

Generated by: LCOV version 2.0-1