• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 = 0xD000000;
65  static constexpr unsigned int BYTRACE_TAG = 0xd03301;
66  
67  static constexpr OHOS::HiviewDFX::HiLogLabel HIPERF_HILOG_LABLE[] = {
68      {LOG_CORE, BYTRACE_TAG, "hiperf"},
69      {LOG_CORE, BYTRACE_TAG, "HiperfJSNAPI"},
70      {LOG_CORE, BYTRACE_TAG, "HiperfCPPAPI"},
71  };
72  
73  // In order to improve performance, do not check the module range
74  
75  #define HIPERF_HILOGF(module, ...)                                                                 \
76      (void)OHOS::HiviewDFX::HiLog::Fatal(HIPERF_HILOG_LABLE[module], FORMATTED(__VA_ARGS__))
77  #define HIPERF_HILOGE(module, ...)                                                                 \
78      (void)OHOS::HiviewDFX::HiLog::Error(HIPERF_HILOG_LABLE[module], FORMATTED(__VA_ARGS__))
79  #define HIPERF_HILOGW(module, ...)                                                                 \
80      (void)OHOS::HiviewDFX::HiLog::Warn(HIPERF_HILOG_LABLE[module], FORMATTED(__VA_ARGS__))
81  #define HIPERF_HILOGI(module, ...)                                                                 \
82      (void)OHOS::HiviewDFX::HiLog::Info(HIPERF_HILOG_LABLE[module], FORMATTED(__VA_ARGS__))
83  #define HIPERF_HILOGD(module, ...)                                                                 \
84      (void)OHOS::HiviewDFX::HiLog::Debug(HIPERF_HILOG_LABLE[module], FORMATTED(__VA_ARGS__))
85  #else
86  
87  #define HIPERF_HILOGF(module, ...) printf(FORMATTED(__VA_ARGS__))
88  #define HIPERF_HILOGE(module, ...) printf(FORMATTED(__VA_ARGS__))
89  #define HIPERF_HILOGW(module, ...) printf(FORMATTED(__VA_ARGS__))
90  #define HIPERF_HILOGI(module, ...) printf(FORMATTED(__VA_ARGS__))
91  #define HIPERF_HILOGD(module, ...) printf(FORMATTED(__VA_ARGS__))
92  
93  #endif // CONFIG_NO_HILOG
94  
95  #endif // HIPERF_HILOG
96