xref: /aosp_15_r20/frameworks/native/include/android/trace.h (revision 38e8c45f13ce32b0dcecb25141ffecaf386fa17f)
1*38e8c45fSAndroid Build Coastguard Worker /*
2*38e8c45fSAndroid Build Coastguard Worker  * Copyright (C) 2015 The Android Open Source Project
3*38e8c45fSAndroid Build Coastguard Worker  *
4*38e8c45fSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*38e8c45fSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*38e8c45fSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*38e8c45fSAndroid Build Coastguard Worker  *
8*38e8c45fSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*38e8c45fSAndroid Build Coastguard Worker  *
10*38e8c45fSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*38e8c45fSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*38e8c45fSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*38e8c45fSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*38e8c45fSAndroid Build Coastguard Worker  * limitations under the License.
15*38e8c45fSAndroid Build Coastguard Worker  */
16*38e8c45fSAndroid Build Coastguard Worker 
17*38e8c45fSAndroid Build Coastguard Worker /**
18*38e8c45fSAndroid Build Coastguard Worker  * @addtogroup Tracing
19*38e8c45fSAndroid Build Coastguard Worker  * @{
20*38e8c45fSAndroid Build Coastguard Worker  */
21*38e8c45fSAndroid Build Coastguard Worker 
22*38e8c45fSAndroid Build Coastguard Worker /**
23*38e8c45fSAndroid Build Coastguard Worker  * @file trace.h
24*38e8c45fSAndroid Build Coastguard Worker  * @brief Writes trace events to the system trace buffer.
25*38e8c45fSAndroid Build Coastguard Worker  *
26*38e8c45fSAndroid Build Coastguard Worker  * These trace events can be collected and visualized using the Systrace tool.
27*38e8c45fSAndroid Build Coastguard Worker  * For information about using the Systrace tool, read <a href="https://developer.android.com/studio/profile/systrace.html">Analyzing UI Performance with Systrace</a>.
28*38e8c45fSAndroid Build Coastguard Worker  *
29*38e8c45fSAndroid Build Coastguard Worker  * Available since API level 23.
30*38e8c45fSAndroid Build Coastguard Worker  */
31*38e8c45fSAndroid Build Coastguard Worker 
32*38e8c45fSAndroid Build Coastguard Worker #ifndef ANDROID_NATIVE_TRACE_H
33*38e8c45fSAndroid Build Coastguard Worker #define ANDROID_NATIVE_TRACE_H
34*38e8c45fSAndroid Build Coastguard Worker 
35*38e8c45fSAndroid Build Coastguard Worker #include <stdbool.h>
36*38e8c45fSAndroid Build Coastguard Worker #include <stdint.h>
37*38e8c45fSAndroid Build Coastguard Worker #include <sys/cdefs.h>
38*38e8c45fSAndroid Build Coastguard Worker 
39*38e8c45fSAndroid Build Coastguard Worker #ifdef __cplusplus
40*38e8c45fSAndroid Build Coastguard Worker extern "C" {
41*38e8c45fSAndroid Build Coastguard Worker #endif
42*38e8c45fSAndroid Build Coastguard Worker 
43*38e8c45fSAndroid Build Coastguard Worker /**
44*38e8c45fSAndroid Build Coastguard Worker  * Returns true if tracing is enabled. Use this to avoid expensive computation only necessary
45*38e8c45fSAndroid Build Coastguard Worker  * when tracing is enabled.
46*38e8c45fSAndroid Build Coastguard Worker  *
47*38e8c45fSAndroid Build Coastguard Worker  * Available since API level 23.
48*38e8c45fSAndroid Build Coastguard Worker  */
49*38e8c45fSAndroid Build Coastguard Worker bool ATrace_isEnabled() __INTRODUCED_IN(23);
50*38e8c45fSAndroid Build Coastguard Worker 
51*38e8c45fSAndroid Build Coastguard Worker /**
52*38e8c45fSAndroid Build Coastguard Worker  * Writes a tracing message to indicate that the given section of code has begun. This call must be
53*38e8c45fSAndroid Build Coastguard Worker  * followed by a corresponding call to {@link ATrace_endSection} on the same thread.
54*38e8c45fSAndroid Build Coastguard Worker  *
55*38e8c45fSAndroid Build Coastguard Worker  * Note: At this time the vertical bar character '|' and newline character '\\n' are used internally
56*38e8c45fSAndroid Build Coastguard Worker  * by the tracing mechanism. If \p sectionName contains these characters they will be replaced with a
57*38e8c45fSAndroid Build Coastguard Worker  * space character in the trace.
58*38e8c45fSAndroid Build Coastguard Worker  *
59*38e8c45fSAndroid Build Coastguard Worker  * Available since API level 23.
60*38e8c45fSAndroid Build Coastguard Worker  */
61*38e8c45fSAndroid Build Coastguard Worker void ATrace_beginSection(const char* sectionName) __INTRODUCED_IN(23);
62*38e8c45fSAndroid Build Coastguard Worker 
63*38e8c45fSAndroid Build Coastguard Worker /**
64*38e8c45fSAndroid Build Coastguard Worker  * Writes a tracing message to indicate that a given section of code has ended. This call must be
65*38e8c45fSAndroid Build Coastguard Worker  * preceeded by a corresponding call to {@link ATrace_beginSection} on the same thread. Calling this method
66*38e8c45fSAndroid Build Coastguard Worker  * will mark the end of the most recently begun section of code, so care must be taken to ensure
67*38e8c45fSAndroid Build Coastguard Worker  * that {@link ATrace_beginSection}/{@link ATrace_endSection} pairs are properly nested and called from the same thread.
68*38e8c45fSAndroid Build Coastguard Worker  *
69*38e8c45fSAndroid Build Coastguard Worker  * Available since API level 23.
70*38e8c45fSAndroid Build Coastguard Worker  */
71*38e8c45fSAndroid Build Coastguard Worker void ATrace_endSection() __INTRODUCED_IN(23);
72*38e8c45fSAndroid Build Coastguard Worker 
73*38e8c45fSAndroid Build Coastguard Worker /**
74*38e8c45fSAndroid Build Coastguard Worker  * Writes a trace message to indicate that a given section of code has
75*38e8c45fSAndroid Build Coastguard Worker  * begun. Must be followed by a call to {@link ATrace_endAsyncSection} with the same
76*38e8c45fSAndroid Build Coastguard Worker  * methodName and cookie. Unlike {@link ATrace_beginSection} and {@link ATrace_endSection},
77*38e8c45fSAndroid Build Coastguard Worker  * asynchronous events do not need to be nested. The name and cookie used to
78*38e8c45fSAndroid Build Coastguard Worker  * begin an event must be used to end it.
79*38e8c45fSAndroid Build Coastguard Worker  *
80*38e8c45fSAndroid Build Coastguard Worker  * Available since API level 29.
81*38e8c45fSAndroid Build Coastguard Worker  *
82*38e8c45fSAndroid Build Coastguard Worker  * \param sectionName The method name to appear in the trace.
83*38e8c45fSAndroid Build Coastguard Worker  * \param cookie Unique identifier for distinguishing simultaneous events
84*38e8c45fSAndroid Build Coastguard Worker  */
85*38e8c45fSAndroid Build Coastguard Worker void ATrace_beginAsyncSection(const char* sectionName, int32_t cookie) __INTRODUCED_IN(29);
86*38e8c45fSAndroid Build Coastguard Worker 
87*38e8c45fSAndroid Build Coastguard Worker /**
88*38e8c45fSAndroid Build Coastguard Worker  * Writes a trace message to indicate that the current method has ended.
89*38e8c45fSAndroid Build Coastguard Worker  * Must be called exactly once for each call to {@link ATrace_beginAsyncSection}
90*38e8c45fSAndroid Build Coastguard Worker  * using the same name and cookie.
91*38e8c45fSAndroid Build Coastguard Worker  *
92*38e8c45fSAndroid Build Coastguard Worker  * Available since API level 29.
93*38e8c45fSAndroid Build Coastguard Worker  *
94*38e8c45fSAndroid Build Coastguard Worker  * \param sectionName The method name to appear in the trace.
95*38e8c45fSAndroid Build Coastguard Worker  * \param cookie Unique identifier for distinguishing simultaneous events
96*38e8c45fSAndroid Build Coastguard Worker  */
97*38e8c45fSAndroid Build Coastguard Worker void ATrace_endAsyncSection(const char* sectionName, int32_t cookie) __INTRODUCED_IN(29);
98*38e8c45fSAndroid Build Coastguard Worker 
99*38e8c45fSAndroid Build Coastguard Worker /**
100*38e8c45fSAndroid Build Coastguard Worker  * Writes trace message to indicate the value of a given counter.
101*38e8c45fSAndroid Build Coastguard Worker  *
102*38e8c45fSAndroid Build Coastguard Worker  * Available since API level 29.
103*38e8c45fSAndroid Build Coastguard Worker  *
104*38e8c45fSAndroid Build Coastguard Worker  * \param counterName The counter name to appear in the trace.
105*38e8c45fSAndroid Build Coastguard Worker  * \param counterValue The counter value.
106*38e8c45fSAndroid Build Coastguard Worker  */
107*38e8c45fSAndroid Build Coastguard Worker void ATrace_setCounter(const char* counterName, int64_t counterValue) __INTRODUCED_IN(29);
108*38e8c45fSAndroid Build Coastguard Worker 
109*38e8c45fSAndroid Build Coastguard Worker #ifdef __cplusplus
110*38e8c45fSAndroid Build Coastguard Worker }
111*38e8c45fSAndroid Build Coastguard Worker #endif
112*38e8c45fSAndroid Build Coastguard Worker 
113*38e8c45fSAndroid Build Coastguard Worker #endif // ANDROID_NATIVE_TRACE_H
114*38e8c45fSAndroid Build Coastguard Worker 
115*38e8c45fSAndroid Build Coastguard Worker /** @} */
116