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#include "base/log/ace_trace.h"
17
18#include "hitrace_meter.h"
19
20#include "base/utils/utils.h"
21
22namespace OHOS::Ace {
23namespace {
24static constexpr uint64_t ACE_TRACE_COMMERCIAL = HITRACE_TAG_ACE | HITRACE_TAG_COMMERCIAL;
25static constexpr uint64_t ANIMATION_TRACE_COMMERCIAL = HITRACE_TAG_ANIMATION | HITRACE_TAG_COMMERCIAL;
26}
27
28void AceTraceBegin(const char* name)
29{
30    CHECK_NULL_VOID(name);
31    std::string nameStr(name);
32    StartTrace(HITRACE_TAG_ACE, nameStr);
33}
34
35void AceTraceEnd()
36{
37    FinishTrace(HITRACE_TAG_ACE);
38}
39
40void AceTraceBeginCommercial(const char* name)
41{
42    StartTrace(ACE_TRACE_COMMERCIAL, name);
43}
44
45void AceTraceEndCommercial()
46{
47    FinishTrace(ACE_TRACE_COMMERCIAL);
48}
49
50void AceAsyncTraceBegin(int32_t taskId, const char* name, bool isAnimationTrace)
51{
52    CHECK_NULL_VOID(name);
53    std::string nameStr(name);
54    if (isAnimationTrace) {
55        StartAsyncTrace(HITRACE_TAG_ANIMATION, nameStr, taskId);
56    } else {
57        StartAsyncTrace(HITRACE_TAG_ACE, nameStr, taskId);
58    }
59}
60
61void AceAsyncTraceEnd(int32_t taskId, const char* name, bool isAnimationTrace)
62{
63    CHECK_NULL_VOID(name);
64    std::string nameStr(name);
65    if (isAnimationTrace) {
66        FinishAsyncTrace(HITRACE_TAG_ANIMATION, nameStr, taskId);
67    } else {
68        FinishAsyncTrace(HITRACE_TAG_ACE, nameStr, taskId);
69    }
70}
71
72void AceAsyncTraceBeginCommercial(int32_t taskId, const char* name, bool isAnimationTrace)
73{
74    CHECK_NULL_VOID(name);
75    std::string nameStr(name);
76    if (isAnimationTrace) {
77        StartAsyncTrace(ANIMATION_TRACE_COMMERCIAL, nameStr, taskId);
78    } else {
79        StartAsyncTrace(ACE_TRACE_COMMERCIAL, nameStr, taskId);
80    }
81}
82
83void AceAsyncTraceEndCommercial(int32_t taskId, const char* name, bool isAnimationTrace)
84{
85    CHECK_NULL_VOID(name);
86    std::string nameStr(name);
87    if (isAnimationTrace) {
88        FinishAsyncTrace(ANIMATION_TRACE_COMMERCIAL, nameStr, taskId);
89    } else {
90        FinishAsyncTrace(ACE_TRACE_COMMERCIAL, nameStr, taskId);
91    }
92}
93
94void AceCountTrace(const char *key, int32_t count)
95{
96    CHECK_NULL_VOID(key);
97    std::string keyStr(key);
98    CountTrace(HITRACE_TAG_ACE, keyStr, count);
99}
100} // namespace OHOS::Ace
101