# Tracing

## Summary

| ### Functions ||
|---|---|
| `https://developer.android.com/ndk/reference/group/tracing#group___tracing_1gac4becb4be939b590913adc7ebb5b8428(const char *sectionName, int32_t cookie)` | `void` Writes a trace message to indicate that a given section of code has begun. |
| `https://developer.android.com/ndk/reference/group/tracing#group___tracing_1ga13768bfdb5d90166ec50bc41235e2797(const char *sectionName)` | `void` Writes a tracing message to indicate that the given section of code has begun. |
| `https://developer.android.com/ndk/reference/group/tracing#group___tracing_1gabc6f8b943c0469a827abd8533b2ab4b6(const char *sectionName, int32_t cookie)` | `void` Writes a trace message to indicate that the current method has ended. |
| `https://developer.android.com/ndk/reference/group/tracing#group___tracing_1gacd849f3cdbe927673c0ad8740c369aed()` | `void` Writes a tracing message to indicate that a given section of code has ended. |
| `https://developer.android.com/ndk/reference/group/tracing#group___tracing_1gad839953d2c6d4189ec80f7b028f7f778()` | `bool` Returns true if tracing is enabled. |
| `https://developer.android.com/ndk/reference/group/tracing#group___tracing_1ga8a31ac945206b18a394d2fcb536c06fb(const char *counterName, int64_t counterValue)` | `void` Writes trace message to indicate the value of a given counter. |

## Functions

### ATrace_beginAsyncSection

Declared in `android/trace.h`

```gdscript
void ATrace_beginAsyncSection(
  const char *sectionName,
  int32_t cookie
)
```
Writes a trace message to indicate that a given section of code has begun.

Must be followed by a call to [ATrace_endAsyncSection](https://developer.android.com/ndk/reference/group/tracing#group___tracing_1gabc6f8b943c0469a827abd8533b2ab4b6) with the same methodName and cookie. Unlike [ATrace_beginSection](https://developer.android.com/ndk/reference/group/tracing#group___tracing_1ga13768bfdb5d90166ec50bc41235e2797) and [ATrace_endSection](https://developer.android.com/ndk/reference/group/tracing#group___tracing_1gacd849f3cdbe927673c0ad8740c369aed), asynchronous events do not need to be nested. The name and cookie used to begin an event must be used to end it.

Available since API level 29.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `sectionName` | The method name to appear in the trace. | | `cookie` | Unique identifier for distinguishing simultaneous events | |

### ATrace_beginSection

Declared in `android/trace.h`

```gdscript
void ATrace_beginSection(
  const char *sectionName
)
```
Writes a tracing message to indicate that the given section of code has begun.

This call must be followed by a corresponding call to [ATrace_endSection](https://developer.android.com/ndk/reference/group/tracing#group___tracing_1gacd849f3cdbe927673c0ad8740c369aed) on the same thread.

Note: At this time the vertical bar character '\|' and newline character '\\n' are used internally by the tracing mechanism. If `sectionName` contains these characters they will be replaced with a space character in the trace.

Available since API level 23.

### ATrace_endAsyncSection

Declared in `android/trace.h`

```gdscript
void ATrace_endAsyncSection(
  const char *sectionName,
  int32_t cookie
)
```
Writes a trace message to indicate that the current method has ended.

Must be called exactly once for each call to [ATrace_beginAsyncSection](https://developer.android.com/ndk/reference/group/tracing#group___tracing_1gac4becb4be939b590913adc7ebb5b8428) using the same name and cookie.

Available since API level 29.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `sectionName` | The method name to appear in the trace. | | `cookie` | Unique identifier for distinguishing simultaneous events | |

### ATrace_endSection

Declared in `android/trace.h`

```scdoc
void ATrace_endSection()
```
Writes a tracing message to indicate that a given section of code has ended.

This call must be preceeded by a corresponding call to [ATrace_beginSection](https://developer.android.com/ndk/reference/group/tracing#group___tracing_1ga13768bfdb5d90166ec50bc41235e2797) on the same thread. Calling this method will mark the end of the most recently begun section of code, so care must be taken to ensure that [ATrace_beginSection](https://developer.android.com/ndk/reference/group/tracing#group___tracing_1ga13768bfdb5d90166ec50bc41235e2797)/[ATrace_endSection](https://developer.android.com/ndk/reference/group/tracing#group___tracing_1gacd849f3cdbe927673c0ad8740c369aed) pairs are properly nested and called from the same thread.

Available since API level 23.

### ATrace_isEnabled

Declared in `android/trace.h`

```scdoc
bool ATrace_isEnabled()
```
Returns true if tracing is enabled.

Use this to avoid expensive computation only necessary when tracing is enabled.

Available since API level 23.

### ATrace_setCounter

Declared in `android/trace.h`

```gdscript
void ATrace_setCounter(
  const char *counterName,
  int64_t counterValue
)
```
Writes trace message to indicate the value of a given counter.

Available since API level 29.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `counterName` | The counter name to appear in the trace. | | `counterValue` | The counter value. | |