• 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 FRAMEWORKS_VSYNC_INCLUDE_VSYNC_LOG_H
17 #define FRAMEWORKS_VSYNC_INCLUDE_VSYNC_LOG_H
18 
19 #include <hilog/log.h>
20 
21 namespace OHOS {
22 namespace {
23 // The "0xD001400" is the domain ID for graphic module that alloted by the OS.
24 constexpr ::OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0xD001400, "Vsync" };
25 }
26 
27 #ifdef __aarch64__
28 #define VPUBI64  "%{public}ld"
29 #define VPUBSize "%{public}lu"
30 #define VPUBU64  "%{public}lu"
31 #else
32 #define VPUBI64  "%{public}lld"
33 #define VPUBSize "%{public}u"
34 #define VPUBU64  "%{public}llu"
35 #endif
36 
37 #define VLOG_BASE(func, fmt, ...) \
38     func(LABEL, "%{public}s: " fmt, __func__, ##__VA_ARGS__)
39 
40 #ifdef DEBUG
41 #define VLOGD(fmt, ...) VLOG_BASE(::OHOS::HiviewDFX::HiLog::Debug, fmt, ##__VA_ARGS__)
42 #else
43 #define VLOGD(fmt, ...)
44 #endif
45 #define VLOGI(fmt, ...) VLOG_BASE(::OHOS::HiviewDFX::HiLog::Info, fmt, ##__VA_ARGS__)
46 #define VLOGW(fmt, ...) VLOG_BASE(::OHOS::HiviewDFX::HiLog::Warn, fmt, ##__VA_ARGS__)
47 #define VLOGE(fmt, ...) VLOG_BASE(::OHOS::HiviewDFX::HiLog::Error, fmt, ##__VA_ARGS__)
48 
49 #define VLOG_SUCCESS(fmt, ...) VLOGI("Success, Way: " fmt, ##__VA_ARGS__)
50 #define VLOG_FAILURE(fmt, ...) VLOGE("Failure, Reason: " fmt, ##__VA_ARGS__)
51 #define VLOG_FAILURE_NO(vsync_error) VLOG_FAILURE("%{public}s", GSErrorStr(vsync_error).c_str())
52 #define VLOG_FAILURE_RET(vsync_error) \
53     do {                              \
54         VLOG_FAILURE_NO(vsync_error); \
55         return vsync_error;           \
56     } while (0)
57 #define VLOG_FAILURE_API(api, ret) VLOG_FAILURE(#api " failed with %{public}s", GSErrorStr(ret).c_str())
58 
59 #define VLOG_ERROR(errno, fmt, ...) \
60     VLOGE(fmt ", means %{public}s", ##__VA_ARGS__, strerror(errno))
61 
62 #define VLOG_ERROR_API(ret, api) \
63     VLOG_ERROR(ret, #api " failed with %{public}d", ret)
64 } // namespace OHOS
65 
66 #endif // FRAMEWORKS_VSYNC_INCLUDE_VSYNC_LOG_H