blob: dbad6f6f21e9895bb2b994c7bced53f7221ac641 [file] [log] [blame]
Chris Craik6a40d672015-06-09 17:28:05 -07001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Quddus Chong0e40c142017-02-23 14:51:09 -080017/**
Dan Alberta0a25952018-04-13 14:43:35 -070018 * @addtogroup Tracing
19 * @{
20 */
21
22/**
Quddus Chong0e40c142017-02-23 14:51:09 -080023 * @file trace.h
24 * @brief Writes trace events to the system trace buffer.
25 *
26 * These trace events can be collected and visualized using the Systrace tool.
27 * For information about using the Systrace tool, read <a href="https://developer.android.com/studio/profile/systrace.html">Analyzing UI Performance with Systrace</a>.
Elliott Hughes75249552018-07-27 15:28:29 -070028 *
29 * Available since API level 23.
Quddus Chong0e40c142017-02-23 14:51:09 -080030 */
Chris Craik6a40d672015-06-09 17:28:05 -070031
32#ifndef ANDROID_NATIVE_TRACE_H
33#define ANDROID_NATIVE_TRACE_H
34
35#include <stdbool.h>
John Reck73e5bf22018-12-05 18:18:53 -080036#include <stdint.h>
Dan Albert494ed552016-09-23 15:57:45 -070037#include <sys/cdefs.h>
Chris Craik6a40d672015-06-09 17:28:05 -070038
39#ifdef __cplusplus
40extern "C" {
41#endif
42
Ryan Prichard0277d0a2018-07-19 20:32:19 -070043#if __ANDROID_API__ >= 23
44
Chris Craik6a40d672015-06-09 17:28:05 -070045/**
Elliott Hughes8064fa72018-07-27 17:23:16 -070046 * Returns true if tracing is enabled. Use this to avoid expensive computation only necessary
Chris Craik6a40d672015-06-09 17:28:05 -070047 * when tracing is enabled.
Elliott Hughes75249552018-07-27 15:28:29 -070048 *
49 * Available since API level 23.
Chris Craik6a40d672015-06-09 17:28:05 -070050 */
Elliott Hughesc2fcafc2018-06-18 12:28:46 -070051bool ATrace_isEnabled() __INTRODUCED_IN(23);
Chris Craik6a40d672015-06-09 17:28:05 -070052
53/**
54 * Writes a tracing message to indicate that the given section of code has begun. This call must be
Elliott Hughes8064fa72018-07-27 17:23:16 -070055 * followed by a corresponding call to {@link ATrace_endSection} on the same thread.
Chris Craik6a40d672015-06-09 17:28:05 -070056 *
Elliott Hughes8064fa72018-07-27 17:23:16 -070057 * Note: At this time the vertical bar character '|' and newline character '\\n' are used internally
58 * by the tracing mechanism. If \p sectionName contains these characters they will be replaced with a
Chris Craik6a40d672015-06-09 17:28:05 -070059 * space character in the trace.
Elliott Hughes75249552018-07-27 15:28:29 -070060 *
61 * Available since API level 23.
Chris Craik6a40d672015-06-09 17:28:05 -070062 */
Elliott Hughesc2fcafc2018-06-18 12:28:46 -070063void ATrace_beginSection(const char* sectionName) __INTRODUCED_IN(23);
Chris Craik6a40d672015-06-09 17:28:05 -070064
65/**
66 * Writes a tracing message to indicate that a given section of code has ended. This call must be
Elliott Hughes8064fa72018-07-27 17:23:16 -070067 * preceeded by a corresponding call to {@link ATrace_beginSection} on the same thread. Calling this method
Chris Craik6a40d672015-06-09 17:28:05 -070068 * will mark the end of the most recently begun section of code, so care must be taken to ensure
Elliott Hughes8064fa72018-07-27 17:23:16 -070069 * that {@link ATrace_beginSection}/{@link ATrace_endSection} pairs are properly nested and called from the same thread.
Elliott Hughes75249552018-07-27 15:28:29 -070070 *
71 * Available since API level 23.
Chris Craik6a40d672015-06-09 17:28:05 -070072 */
Elliott Hughesc2fcafc2018-06-18 12:28:46 -070073void ATrace_endSection() __INTRODUCED_IN(23);
Dan Albert494ed552016-09-23 15:57:45 -070074
Ryan Prichard0277d0a2018-07-19 20:32:19 -070075#endif /* __ANDROID_API__ >= 23 */
76
Elliott Hughes05565472019-10-29 08:59:39 -070077#if __ANDROID_API__ >= 29
John Reck73e5bf22018-12-05 18:18:53 -080078
79/**
80 * Writes a trace message to indicate that a given section of code has
81 * begun. Must be followed by a call to {@link ATrace_endAsyncSection} with the same
82 * methodName and cookie. Unlike {@link ATrace_beginSection} and {@link ATrace_endSection},
83 * asynchronous events do not need to be nested. The name and cookie used to
84 * begin an event must be used to end it.
85 *
Elliott Hughes05565472019-10-29 08:59:39 -070086 * Available since API level 29.
87 *
John Reck73e5bf22018-12-05 18:18:53 -080088 * \param sectionName The method name to appear in the trace.
89 * \param cookie Unique identifier for distinguishing simultaneous events
90 */
91void ATrace_beginAsyncSection(const char* sectionName, int32_t cookie) __INTRODUCED_IN(29);
92
93/**
94 * Writes a trace message to indicate that the current method has ended.
95 * Must be called exactly once for each call to {@link ATrace_beginAsyncSection}
96 * using the same name and cookie.
97 *
Elliott Hughes05565472019-10-29 08:59:39 -070098 * Available since API level 29.
99 *
John Reck73e5bf22018-12-05 18:18:53 -0800100 * \param methodName The method name to appear in the trace.
101 * \param cookie Unique identifier for distinguishing simultaneous events
102 */
103void ATrace_endAsyncSection(const char* sectionName, int32_t cookie) __INTRODUCED_IN(29);
104
105/**
106 * Writes trace message to indicate the value of a given counter.
107 *
Elliott Hughes05565472019-10-29 08:59:39 -0700108 * Available since API level 29.
109 *
John Reck73e5bf22018-12-05 18:18:53 -0800110 * \param counterName The counter name to appear in the trace.
111 * \param counterValue The counter value.
112 */
113void ATrace_setCounter(const char* counterName, int64_t counterValue) __INTRODUCED_IN(29);
114
115#endif /* __ANDROID_API__ >= 29 */
116
Chris Craik6a40d672015-06-09 17:28:05 -0700117#ifdef __cplusplus
Devin Mooreb34bfce2020-04-29 11:51:26 -0700118}
Chris Craik6a40d672015-06-09 17:28:05 -0700119#endif
120
121#endif // ANDROID_NATIVE_TRACE_H
Dan Alberta0a25952018-04-13 14:43:35 -0700122
123/** @} */