LCOV - code coverage report
Current view: top level - legacy/ascend910/common/debug/config - config_log.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 87.2 % 39 34
Test Date: 2026-08-18 17:47:01 Functions: 100.0 % 4 4

            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 "config_log.h"
      12              : #include "mmpa_api.h"
      13              : 
      14              : namespace hccl {
      15              : 
      16              : static u64 g_debugConfig = 0ULL;
      17              : static bool g_debugConfigInited = false;
      18              : 
      19          405 : u64 GetDebugConfig() { return g_debugConfig; }
      20              : 
      21           70 : HcclResult InitDebugConfigByEnv()
      22              : {
      23           70 :     g_debugConfig = 0;
      24           70 :     char* env = nullptr; // 环境变量值
      25           70 :     MM_SYS_GET_ENV(MM_ENV_HCCL_DEBUG_CONFIG, env);
      26           70 :     if (env == nullptr) {
      27           56 :         HCCL_RUN_INFO("HCCL_DEBUG_CONFIG is not set, debugConfig set by default to 0x%llx", g_debugConfig);
      28           56 :         return HCCL_SUCCESS;
      29              :     }
      30              : 
      31           14 :     bool invert = (env[0] == '^');
      32           14 :     g_debugConfig = invert ? ~0ULL : 0ULL; // 第一个字符是'^', 使用取反模式, 用户配置的项关闭, 未配置的项打开
      33           14 :     char* configValue = (env[0] == '^') ? env + 1 : env; // 去掉'^'符号
      34           14 :     char* configDup = strdup(configValue);               // 需要使用strdup避免修改字符串常量
      35           14 :     CHK_PTR_NULL(configDup);
      36              : 
      37           14 :     char* left = nullptr;
      38           14 :     char* subConfig = strtok_r(configDup, ",", &left); // 按逗号分割
      39           28 :     while (subConfig != nullptr) {
      40           14 :         u64 mask = 0;
      41           14 :         if (strcasecmp(subConfig, "ALG") == 0) {
      42            7 :             mask = HCCL_ALG;
      43            7 :         } else if (strcasecmp(subConfig, "TASK") == 0) {
      44            0 :             mask = HCCL_TASK;
      45            7 :         } else if (strcasecmp(subConfig, "RESOURCE") == 0) {
      46            0 :             mask = HCCL_RES;
      47            7 :         } else if (strcasecmp(subConfig, "AIV_OPS_EXC") == 0) {
      48            7 :             HCCL_WARNING("HCCL_DEBUG_CONFIG:%s subConfig:%s is deprecated and ignored", env, subConfig);
      49              :         } else {
      50            0 :             HCCL_ERROR("HCCL_DEBUG_CONFIG:%s is invalid, subConfig:%s is not supported", env, subConfig);
      51            0 :             free(configDup);
      52            0 :             return HCCL_E_PARA;
      53              :         }
      54           14 :         g_debugConfig = invert ? (g_debugConfig & (~mask)) : (g_debugConfig | mask);
      55           14 :         subConfig = strtok_r(nullptr, ",", &left);
      56              :     }
      57           14 :     free(configDup);
      58           14 :     HCCL_RUN_INFO("HCCL_DEBUG_CONFIG[%s], set debugConfig[0x%llx]", env, g_debugConfig);
      59           14 :     g_debugConfigInited = true;
      60           14 :     return HCCL_SUCCESS;
      61              : }
      62              : 
      63            7 : bool GetDebugConfigInited() { return g_debugConfigInited; }
      64              : 
      65           11 : void InitDebugConfigByValue(u64 config)
      66              : {
      67           11 :     g_debugConfig = config;
      68           11 :     HCCL_INFO("set debugConfig[0x%llx] by value", g_debugConfig);
      69           11 : }
      70              : 
      71              : } // namespace hccl
        

Generated by: LCOV version 2.0-1