LCOV - code coverage report
Current view: top level - legacy/ascend950/framework/env_config - plf_debug_config.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 91.7 % 36 33
Test Date: 2026-08-17 10:19:35 Functions: 100.0 % 4 4

            Line data    Source code
       1              : /**
       2              :  * Copyright (c) 2026 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              : #include "plf_debug_config.h"
      11              : #include "env_config_v2.h"
      12              : #include "config_plf_log.h"
      13              : #include <sstream>
      14              : 
      15              : namespace Hccl {
      16              : 
      17           22 : static u64 ParseDebugConfig(const char* envName, u64 domainMask)
      18              : {
      19           22 :     char* env = getenv(envName);
      20           22 :     if (env == nullptr) {
      21           15 :         return 0;
      22              :     }
      23            7 :     std::string configDup(env);
      24              : 
      25            7 :     bool invert = (!configDup.empty() && configDup.front() == '^');
      26              :     // 第一个字符是'^', 使用取反模式,用户配置的项关闭,未配置的项打开
      27            7 :     u64 result = invert ? domainMask : 0ULL;
      28            7 :     if (invert) {
      29            1 :         configDup.erase(configDup.begin()); // 去掉'^'符号
      30              :     }
      31              : 
      32            7 :     std::istringstream stream(configDup);
      33            7 :     std::string subConfig;
      34           13 :     while (std::getline(stream, subConfig, ',')) {
      35            7 :         if (subConfig.empty()) {
      36            0 :             continue;
      37              :         }
      38            7 :         u64 mask = 0;
      39            7 :         if (((domainMask & PLF_TASK) != 0) && strcasecmp(subConfig.c_str(), "TASK") == 0) {
      40            4 :             mask = PLF_TASK;
      41            3 :         } else if (((domainMask & PLF_ALG) != 0) && strcasecmp(subConfig.c_str(), "ALG") == 0) {
      42            0 :             mask = PLF_ALG;
      43            3 :         } else if (((domainMask & PLF_RES) != 0) && strcasecmp(subConfig.c_str(), "RESOURCE") == 0) {
      44            0 :             mask = PLF_RES;
      45            3 :         } else if (((domainMask & PLF_DATA_OP) != 0) && strcasecmp(subConfig.c_str(), "DATA_OP") == 0) {
      46            2 :             mask = PLF_DATA_OP;
      47              :         } else {
      48            3 :             HCCL_ERROR("%s:%s subConfig:%s is not supported", envName, env, subConfig.c_str());
      49            1 :             return 0;
      50              :         }
      51            6 :         result = invert ? (result & ~mask) : (result | mask);
      52              :     }
      53           18 :     HCCL_RUN_INFO("[HCCL_ENV] %s set by [%s] to [0x%llx]", envName, env, result);
      54            6 :     return result;
      55            7 : }
      56              : 
      57           11 : void EnvPlfDebugConfig::Parse()
      58              : {
      59           11 :     plfDebugConfig_ = ParseDebugConfig("HCCL_DEBUG_CONFIG", PLF_TASK | PLF_ALG | PLF_RES);
      60           11 :     plfDebugConfig_ |= ParseDebugConfig("HCOMM_DEBUG_CONFIG", PLF_TASK | PLF_DATA_OP);
      61           33 :     HCCL_RUN_INFO("[HCCL_ENV] plfDebugConfig set to [0x%llx]", plfDebugConfig_);
      62           11 : }
      63              : 
      64           30 : u64 EnvPlfDebugConfig::GetConfigValue() const { return plfDebugConfig_; }
      65              : 
      66           24 : u64 GetPlfDebugConfigValue() { return EnvConfig::GetInstance().GetPlfDebugConfig().GetConfigValue(); }
      67              : 
      68              : } // namespace Hccl
        

Generated by: LCOV version 2.0-1