LCOV - code coverage report
Current view: top level - atrace/utrace - trace_core.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 96.0 % 50 48
Test Date: 2026-08-31 10:07:06 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              : #include "adiag_print.h"
      12              : #include "trace_attr.h"
      13              : #include "trace_driver_api.h"
      14              : #include "tracer_core.h"
      15              : #include "trace_event.h"
      16              : #include "stacktrace_dumper.h"
      17              : #include "stacktrace_signal.h"
      18              : #include "trace_recorder.h"
      19              : 
      20              : #ifdef ATRACE_HOST
      21              : #include "atrace_client_core.h"
      22              : /**
      23              :  * @brief       : initialize dynamic library
      24              :  * @return      : NA
      25              :  */
      26          995 : STATIC CONSTRUCTOR void TraceInit(void)
      27              : {
      28          995 :     TraStatus ret = TraceAttrInit();
      29          995 :     ADIAG_CHK_EXPR_ACTION(ret != TRACE_SUCCESS, return, "init attr failed, ret=%d.", ret);
      30          995 :     if (!AtraceCheckSupported()) {
      31           22 :         ADIAG_INF("atrace is not supported, init nothing.");
      32           22 :         return;
      33              :     }
      34          973 :     ret = TraceRecorderInit();
      35          973 :     ADIAG_CHK_EXPR_ACTION(ret != TRACE_SUCCESS, return, "init recorder failed, ret=%d.", ret);
      36              : 
      37          973 :     ret = TraceEventInit();
      38          973 :     ADIAG_CHK_EXPR_ACTION(ret != TRACE_SUCCESS, return, "init event failed, ret=%d.", ret);
      39              : 
      40          973 :     ret = TracerInit();
      41          973 :     ADIAG_CHK_EXPR_ACTION(ret != TRACE_SUCCESS, return, "init tracer failed, ret=%d.", ret);
      42              : 
      43          973 :     ret = AtraceClientInit();
      44          973 :     ADIAG_CHK_EXPR_ACTION(ret != TRACE_SUCCESS, return, "init trace client failed, ret=%d.", ret);
      45              : 
      46          973 :     ret = TraceDumperInit();
      47          973 :     ADIAG_CHK_EXPR_ACTION(ret != TRACE_SUCCESS, return, "init stacktrace dumper failed, ret=%d.", ret);
      48              : 
      49          973 :     ret = TraceSignalInit();
      50          973 :     ADIAG_CHK_EXPR_ACTION(ret != TRACE_SUCCESS, return, "init signal failed, ret=%d.", ret);
      51          973 :     ADIAG_INF("init trace successfully.");
      52              : }
      53              : 
      54              : /**
      55              :  * @brief       : finalize dynamic library
      56              :  * @return      : NA
      57              :  */
      58         1051 : STATIC DESTRUCTOR void TraceExit(void)
      59              : {
      60         1051 :     if (AtraceCheckSupported()) {
      61         1029 :         TraceSignalExit();
      62         1029 :         TraceDumperExit();
      63         1029 :         AtraceClientExit();
      64         1029 :         TracerExit();
      65         1029 :         TraceEventExit();
      66         1029 :         TraceRecorderExit();
      67              :     }
      68         1051 :     TraceAttrExit();
      69         1051 : }
      70              : 
      71              : #else
      72              : #include "utrace_socket.h"
      73              : /**
      74              :  * @brief       : initialize dynamic library
      75              :  * @return      : NA
      76              :  */
      77            9 : STATIC CONSTRUCTOR void TraceInit(void)
      78              : {
      79            9 :     TraStatus ret = TraceAttrInit();
      80            9 :     ADIAG_CHK_EXPR_ACTION(ret != TRACE_SUCCESS, return, "init attr failed, ret=%d.", ret);
      81            9 :     if (!AtraceCheckSupported()) {
      82            0 :         ADIAG_INF("atrace is not supported, init nothing.");
      83            0 :         return;
      84              :     }
      85            9 :     ret = TraceRecorderInit();
      86            9 :     ADIAG_CHK_EXPR_ACTION(ret != TRACE_SUCCESS, return, "init recorder failed, ret=%d.", ret);
      87              : 
      88            9 :     ret = TraceEventInit();
      89            9 :     ADIAG_CHK_EXPR_ACTION(ret != TRACE_SUCCESS, return, "init event failed, ret=%d.", ret);
      90              : 
      91            9 :     ret = TracerInit();
      92            9 :     ADIAG_CHK_EXPR_ACTION(ret != TRACE_SUCCESS, return, "init tracer failed, ret=%d.", ret);
      93              : 
      94            9 :     ADIAG_INF("init trace successfully.");
      95              : }
      96              : 
      97              : /**
      98              :  * @brief       : finalize dynamic library
      99              :  * @return      : NA
     100              :  */
     101            9 : STATIC DESTRUCTOR void TraceExit(void)
     102              : {
     103            9 :     if (AtraceCheckSupported()) {
     104            9 :         TracerExit();
     105            9 :         TraceEventExit();
     106            9 :         TraceRecorderExit();
     107            9 :         UtraceCloseSocket();
     108              :     }
     109            9 :     TraceAttrExit();
     110            9 : }
     111              : #endif
        

Generated by: LCOV version 2.0-1