1 /** 2 * Copyright 2021 Huawei Technologies Co., Ltd 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef MINDSPORE_CORE_MINDRT_RUNTIME_THREADPOOL_LOG_H_ 18 #define MINDSPORE_CORE_MINDRT_RUNTIME_THREADPOOL_LOG_H_ 19 #ifdef MS_COMPILE_OHOS 20 #include "hilog/log.h" 21 #endif 22 namespace mindspore { 23 #ifdef THREAD_POOL_DEBUG 24 #include <stdio.h> 25 #define THREAD_DEBUG(content, args...) \ 26 { printf("[DEBUG] %s|%d: " #content "\r\n", __func__, __LINE__, ##args); } 27 #define THREAD_INFO(content, args...) \ 28 { printf("[INFO] %s|%d: " #content "\r\n", __func__, __LINE__, ##args); } 29 #define THREAD_ERROR(content, args...) \ 30 { printf("[ERROR] %s|%d: " #content "\r\n", __func__, __LINE__, ##args); } 31 #define THREAD_TEST_TRUE(flag) \ 32 if (flag) { \ 33 printf("[ERROR] %s|%d: " #flag "\r\n", __func__, __LINE__); \ 34 } 35 #else 36 #define THREAD_DEBUG(content, ...) 37 #define THREAD_TEST_TRUE(flag) 38 39 #if defined(__ANDROID__) 40 #define THREAD_INFO(content, ...) 41 #include <android/log.h> 42 #define THREAD_ERROR(content, args...) \ 43 { __android_log_print(ANDROID_LOG_ERROR, "MS_LITE", "%s|%d: " #content "\r\n", __func__, __LINE__, ##args); } 44 45 #elif defined(MS_COMPILE_OHOS) // For OHOS, use hilog. 46 47 #define MINDRT_OHOS_LOG_DOMAIN 0x2102 48 #define MINDRT_OHOS_LOG_TAG "MS_LITE" 49 50 #ifdef MS_COMPILE_WITH_OHOS_NDK 51 // When build with OHOS NDK, use public api of hilog module. 52 #define THREAD_INFO(content, args...) \ 53 { OH_LOG_Print(LOG_APP, LOG_INFO, MINDRT_OHOS_LOG_DOMAIN, MINDRT_OHOS_LOG_TAG, "%s:%d " #content, __func__, __LINE__, ##args); } 54 #define THREAD_ERROR(content, args...) \ 55 { OH_LOG_Print(LOG_APP, LOG_ERROR, MINDRT_OHOS_LOG_DOMAIN, MINDRT_OHOS_LOG_TAG, "%s:%d " #content, __func__, __LINE__, ##args); } 56 #else 57 // When build in OHOS repo, use inner api of hilog module. 58 #define THREAD_INFO(content, args...) \ 59 { HiLogPrint(LOG_APP, LOG_INFO, MINDRT_OHOS_LOG_DOMAIN, MINDRT_OHOS_LOG_TAG, "%s:%d " #content, __func__, __LINE__, ##args); } 60 #define THREAD_ERROR(content, args...) \ 61 { HiLogPrint(LOG_APP, LOG_ERROR, MINDRT_OHOS_LOG_DOMAIN, MINDRT_OHOS_LOG_TAG, "%s:%d " #content, __func__, __LINE__, ##args); } 62 #endif 63 64 #else 65 #define THREAD_INFO(content, ...) 66 #define THREAD_ERROR(content, ...) 67 #endif 68 #endif 69 70 #define THREAD_ERROR_IF_NULL(ptr) \ 71 do { \ 72 if ((ptr) == nullptr) { \ 73 return THREAD_ERROR; \ 74 } \ 75 } while (0) 76 77 #define THREAD_RETURN_IF_NULL(ptr) \ 78 do { \ 79 if ((ptr) == nullptr) { \ 80 return; \ 81 } \ 82 } while (0) 83 84 /* Thread return code */ 85 constexpr int THREAD_OK = 0; 86 constexpr int THREAD_ERROR = 1; 87 } // namespace mindspore 88 #endif // MINDSPORE_CORE_MINDRT_RUNTIME_THREADPOOL_LOG_H_ 89