# PerfettoSdkTrace

Artifact: [androidx.tracing:tracing-perfetto](https://developer.android.com/jetpack/androidx/releases/tracing) [View Source](https://cs.android.com/search?q=file:androidx/tracing/perfetto/PerfettoSdkTrace.kt+class:androidx.tracing.perfetto.PerfettoSdkTrace) Added in [1.0.1](https://developer.android.com/jetpack/androidx/releases/tracing#1.0.1)

*** ** * ** ***


```
public static class PerfettoSdkTrace
```

<br />

*** ** * ** ***

Allows for emitting trace events using Perfetto SDK.

## Summary

| ### Public fields |
|---|---|
| `static @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/tracing/perfetto/PerfettoSdkTrace` | `https://developer.android.com/reference/androidx/tracing/perfetto/PerfettoSdkTrace#INSTANCE()` |

| ### Public methods |
|---|---|
| `final void` | `https://developer.android.com/reference/androidx/tracing/perfetto/PerfettoSdkTrace#beginSection(kotlin.String)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html sectionName)` Writes a trace message to indicate that a given section of code has begun. |
| `final void` | `https://developer.android.com/reference/androidx/tracing/perfetto/PerfettoSdkTrace#endSection()()` Writes a trace message to indicate that a given section of code has ended. |
| `final boolean` | `https://developer.android.com/reference/androidx/tracing/perfetto/PerfettoSdkTrace#isEnabled()()` Checks whether the tracing library has been loaded and the app has been registered with Perfetto SDK tracing server. |

## Public fields

### INSTANCE

Added in [1.0.1](https://developer.android.com/jetpack/androidx/releases/tracing#1.0.1)

```
public static @NonNull PerfettoSdkTrace INSTANCE
```

## Public methods

### beginSection

Added in [1.0.1](https://developer.android.com/jetpack/androidx/releases/tracing#1.0.1)

```
public final void beginSection(@NonNull String sectionName)
```

Writes a trace message to indicate that a given section of code has begun. This call must be followed by a corresponding call to `https://developer.android.com/reference/androidx/tracing/perfetto/PerfettoSdkTrace#endSection()` on the same thread.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html sectionName` | The name of the code section to appear in the trace. |

### endSection

Added in [1.0.1](https://developer.android.com/jetpack/androidx/releases/tracing#1.0.1)

```
public final void endSection()
```

Writes a trace message to indicate that a given section of code has ended. This call must be preceded by a corresponding call to `https://developer.android.com/reference/androidx/tracing/perfetto/PerfettoSdkTrace#beginSection(kotlin.String)`. Calling this method will mark the end of the most recently begun section of code, so care must be taken to ensure that `https://developer.android.com/reference/androidx/tracing/perfetto/PerfettoSdkTrace#beginSection(kotlin.String)` / `https://developer.android.com/reference/androidx/tracing/perfetto/PerfettoSdkTrace#endSection()` pairs are properly nested and called from the same thread.

### isEnabled

Added in [1.0.1](https://developer.android.com/jetpack/androidx/releases/tracing#1.0.1)

```
public final boolean isEnabled()
```

Checks whether the tracing library has been loaded and the app has been registered with Perfetto SDK tracing server. This is useful to avoid intermediate string creation for trace sections that require formatting. It is not necessary to guard all Trace method calls as they internally already check this. However it is recommended to use this to prevent creating any temporary objects that would then be passed to those methods to reduce runtime cost when tracing isn't enabled.

| Returns |
|---|---|
| `boolean` | true if tracing is currently enabled, false otherwise |