# PerfettoSdkTrace

# 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)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/tracing/perfetto/PerfettoSdkTrace "View this page in Java")

<br />

```
object PerfettoSdkTrace
```

<br />

*** ** * ** ***

Allows for emitting trace events using Perfetto SDK.

## Summary

|                             ### Public functions                              |
|-------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [beginSection](https://developer.android.com/reference/kotlin/androidx/tracing/perfetto/PerfettoSdkTrace#beginSection(kotlin.String))`(sectionName: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`)` Writes a trace message to indicate that a given section of code has begun. |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [endSection](https://developer.android.com/reference/kotlin/androidx/tracing/perfetto/PerfettoSdkTrace#endSection())`()` Writes a trace message to indicate that a given section of code has ended.                                                                                                                  |

|                                ### Public properties                                |
|-------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | [isEnabled](https://developer.android.com/reference/kotlin/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 functions

### beginSection

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

```
fun beginSection(sectionName: String): Unit
```

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

|                                            Parameters                                            |
|--------------------------------------------------------------------------------------------------|------------------------------------------------------|
| `sectionName: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) | 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)  

```
fun endSection(): Unit
```

Writes a trace message to indicate that a given section of code has ended. This call must be preceded by a corresponding call to[beginSection](https://developer.android.com/reference/kotlin/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[beginSection](https://developer.android.com/reference/kotlin/androidx/tracing/perfetto/PerfettoSdkTrace#beginSection(kotlin.String))/[endSection](https://developer.android.com/reference/kotlin/androidx/tracing/perfetto/PerfettoSdkTrace#endSection())pairs are properly nested and called from the same thread.  

## Public properties

### isEnabled

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

```
val isEnabled: Boolean
```

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](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | true if tracing is currently enabled, false otherwise |