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 : #include "log.h"
11 :
12 : thread_local bool g_hcclErrToWarn = false;
13 : constexpr int32_t HCCL_LOG_LEVEL_INVALID = -1;
14 : static int32_t g_logLevelCache = -1;
15 : int32_t dlog_getlevel(int32_t moduleId, int32_t* enableEvent) __attribute((weak));
16 :
17 2223621 : bool HcclCheckLogLevel(int logType, int moduleId)
18 : {
19 2223621 : if ((moduleId & RUN_LOG_MASK) != 0) {
20 95916 : return true;
21 : }
22 2127705 : if (UNLIKELY(g_logLevelCache == HCCL_LOG_LEVEL_INVALID)) {
23 46 : int32_t enableEvent = -1;
24 46 : g_logLevelCache = dlog_getlevel(moduleId, &enableEvent);
25 : }
26 2127705 : return (logType >= g_logLevelCache);
27 : }
28 :
29 6 : void SetErrToWarnSwitch(bool flag)
30 : {
31 6 : if (g_hcclErrToWarn != flag) {
32 6 : g_hcclErrToWarn = flag;
33 : }
34 6 : }
35 :
36 15150 : bool IsErrorToWarn() { return g_hcclErrToWarn; }
|