• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1  /*
2  * Copyright (c) 2025 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 #ifndef __XPERF_TRACE_H__
16 #define __XPERF_TRACE_H__
17 
18 #include <cstdlib>
19 #include <cstdio>
20 #include <cstdint>
21 
22 #include "hitrace_meter.h"
23 
24 namespace OHOS {
25 namespace HiviewDFX {
26 constexpr int TRACE_BUF_LEN = 128;
27 void XperfStartTrace(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
28 void FormatTraceName(char *name, size_t size, const char *fmt, ...) __attribute__((format(printf, 3, 4)));
29 
30 #define XPERF_TRACE_SCOPED(fmt, ...) \
31     char traceName[TRACE_BUF_LEN] = {0}; \
32     FormatTraceName(traceName, TRACE_BUF_LEN, fmt, ##__VA_ARGS__); \
33     HitraceScoped trace(HITRACE_TAG_APP, traceName)
34 
35 void XperfAsyncTraceBegin(int32_t taskId, const char* name, bool isAnimationTrace = false);
36 void XperfAsyncTraceEnd(int32_t taskId, const char* name, bool isAnimationTrace = false);
37 }
38 }
39 #endif