1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef HIPERF_HILOG 17 #define HIPERF_HILOG 18 19 #ifndef CONFIG_NO_HILOG 20 #define HILOG_PUBLIC "{public}" 21 #define HILOG_NEWLINE "" 22 #else 23 #define HILOG_PUBLIC "" 24 #define HILOG_NEWLINE "\n" 25 #endif 26 27 #define FILENAME \ 28 (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__) 29 30 #define FORMATTED(fmt, ...) \ 31 "[%" HILOG_PUBLIC "s:%" HILOG_PUBLIC "d] %" HILOG_PUBLIC "s# " fmt HILOG_NEWLINE, FILENAME, \ 32 __LINE__, __FUNCTION__, ##__VA_ARGS__ 33 34 #ifndef CONFIG_NO_HILOG 35 #include "hilog/log.h" 36 37 #ifdef HIPERF_HILOGF 38 #undef HIPERF_HILOGF 39 #endif 40 41 #ifdef HIPERF_HILOGE 42 #undef HIPERF_HILOGE 43 #endif 44 45 #ifdef HIPERF_HILOGW 46 #undef HIPERF_HILOGW 47 #endif 48 49 #ifdef HIPERF_HILOGI 50 #undef HIPERF_HILOGI 51 #endif 52 53 #ifdef HIPERF_HILOGD 54 #undef HIPERF_HILOGD 55 #endif 56 57 // param of log interface, such as HIPERF_HILOGF. 58 enum HiperfModule { 59 MODULE_DEFAULT = 0, 60 MODULE_JS_NAPI, 61 MODULE_CPP_API, 62 }; 63 64 static constexpr unsigned int BASE_HIPERF_DOMAIN_ID = 0xD002D0D; 65 static constexpr OHOS::HiviewDFX::HiLogLabel HIPERF_HILOG_LABLE[] = { 66 {LOG_CORE, BASE_HIPERF_DOMAIN_ID, "hiperf"}, 67 {LOG_CORE, BASE_HIPERF_DOMAIN_ID, "HiperfJSNAPI"}, 68 {LOG_CORE, BASE_HIPERF_DOMAIN_ID, "HiperfCPPAPI"}, 69 }; 70 71 #ifdef LOG_DOMAIN 72 #undef LOG_DOMAIN 73 #endif 74 #define LOG_DOMAIN 0xD002D0D 75 76 #ifdef LOG_TAG 77 #undef LOG_TAG 78 #endif 79 #define LOG_TAG "hiperf" 80 81 // In order to improve performance, do not check the module range 82 83 #define HIPERF_HILOGF(module, ...) \ 84 HILOG_FATAL(LOG_CORE, __VA_ARGS__) 85 #define HIPERF_HILOGE(module, ...) \ 86 HILOG_ERROR(LOG_CORE, __VA_ARGS__) 87 #define HIPERF_HILOGW(module, ...) \ 88 HILOG_WARN(LOG_CORE, __VA_ARGS__) 89 #define HIPERF_HILOGI(module, ...) \ 90 HILOG_INFO(LOG_CORE, __VA_ARGS__) 91 #define HIPERF_HILOGD(module, ...) \ 92 HILOG_DEBUG(LOG_CORE, __VA_ARGS__) 93 #else 94 95 #define HIPERF_HILOGF(module, ...) printf(FORMATTED(__VA_ARGS__)) 96 #define HIPERF_HILOGE(module, ...) printf(FORMATTED(__VA_ARGS__)) 97 #define HIPERF_HILOGW(module, ...) printf(FORMATTED(__VA_ARGS__)) 98 #define HIPERF_HILOGI(module, ...) printf(FORMATTED(__VA_ARGS__)) 99 #define HIPERF_HILOGD(module, ...) printf(FORMATTED(__VA_ARGS__)) 100 101 #endif // CONFIG_NO_HILOG 102 103 #endif // HIPERF_HILOG 104