# TraceSectionMetric

Artifact: [androidx.benchmark:benchmark-macro](https://developer.android.com/jetpack/androidx/releases/benchmark) [View Source](https://cs.android.com/search?q=file:androidx/benchmark/macro/Metric.kt+class:androidx.benchmark.macro.TraceSectionMetric) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/benchmark#1.1.0)

*** ** * ** ***


```
@ExperimentalMetricApi
class TraceSectionMetric : Metric
```

<br />

|---|---|---|
| [kotlin.Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html) |||
| ↳ | [androidx.benchmark.macro.Metric](https://developer.android.com/reference/kotlin/androidx/benchmark/macro/Metric) ||
|   | ↳ | [androidx.benchmark.macro.TraceSectionMetric](https://developer.android.com/reference/kotlin/androidx/benchmark/macro/TraceSectionMetric) |

*** ** * ** ***

Captures the time taken by named trace section - a named begin / end pair matching the provided `https://developer.android.com/reference/kotlin/androidx/benchmark/macro/TraceSectionMetric#sectionNames()`.

Select how matching sections are resolved into a duration metric with `https://developer.android.com/reference/kotlin/androidx/benchmark/macro/TraceSectionMetric#mode()`, and configure if sections outside the target process are included with `https://developer.android.com/reference/kotlin/androidx/benchmark/macro/TraceSectionMetric#targetPackageOnly()`.

The following TraceSectionMetric counts the number of JIT method compilations that occur within a trace:

```kotlin
TraceSectionMetric(
    sectionName = "JIT Compiling %",
    mode = TraceSectionMetric.Mode.Sum
)
```

Note that non-terminating slices in the trace (where duration = -1) are always ignored by this metric.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/tracing/Trace#beginSection(kotlin.String)` |   |
| `https://developer.android.com/reference/kotlin/androidx/tracing/Trace#endSection()` |   |
| `https://developer.android.com/reference/kotlin/androidx/tracing/package-summary#trace(kotlin.String,kotlin.Function0)` |   |

## Summary

| ### Nested types |
|---|
| `sealed class https://developer.android.com/reference/kotlin/androidx/benchmark/macro/TraceSectionMetric.Mode` |
| `object https://developer.android.com/reference/kotlin/androidx/benchmark/macro/TraceSectionMetric.Mode.Average : https://developer.android.com/reference/kotlin/androidx/benchmark/macro/TraceSectionMetric.Mode` Average duration of trace sections matching `sectionName` in the trace. |
| `object https://developer.android.com/reference/kotlin/androidx/benchmark/macro/TraceSectionMetric.Mode.Count : https://developer.android.com/reference/kotlin/androidx/benchmark/macro/TraceSectionMetric.Mode` Counts the number of observed instances of a trace section matching `sectionName` in the trace. |
| `object https://developer.android.com/reference/kotlin/androidx/benchmark/macro/TraceSectionMetric.Mode.First : https://developer.android.com/reference/kotlin/androidx/benchmark/macro/TraceSectionMetric.Mode` Captures the duration of the first instance of `sectionName` in the trace. |
| `object https://developer.android.com/reference/kotlin/androidx/benchmark/macro/TraceSectionMetric.Mode.Max : https://developer.android.com/reference/kotlin/androidx/benchmark/macro/TraceSectionMetric.Mode` Reports the maximum observed duration for a trace section matching `sectionName` in the trace. |
| `object https://developer.android.com/reference/kotlin/androidx/benchmark/macro/TraceSectionMetric.Mode.Min : https://developer.android.com/reference/kotlin/androidx/benchmark/macro/TraceSectionMetric.Mode` Reports the maximum observed duration for a trace section matching `sectionName` in the trace. |
| `object https://developer.android.com/reference/kotlin/androidx/benchmark/macro/TraceSectionMetric.Mode.Sum : https://developer.android.com/reference/kotlin/androidx/benchmark/macro/TraceSectionMetric.Mode` Captures the sum of all instances of `sectionName` in the trace. |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/benchmark/macro/TraceSectionMetric#TraceSectionMetric(kotlin.String,androidx.benchmark.macro.TraceSectionMetric.Mode,kotlin.String,kotlin.Boolean)( sectionName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, mode: https://developer.android.com/reference/kotlin/androidx/benchmark/macro/TraceSectionMetric.Mode, label: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, targetPackageOnly: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html )` |
| `https://developer.android.com/reference/kotlin/androidx/benchmark/macro/TraceSectionMetric#TraceSectionMetric(kotlin.collections.List,kotlin.String,androidx.benchmark.macro.TraceSectionMetric.Mode,kotlin.Boolean)( sectionNames: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html>, label: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, mode: https://developer.android.com/reference/kotlin/androidx/benchmark/macro/TraceSectionMetric.Mode, targetPackageOnly: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html )` |

## Public constructors

### TraceSectionMetric

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

```
TraceSectionMetric(
    sectionName: String,
    mode: TraceSectionMetric.Mode = Mode.Sum,
    label: String = sectionName,
    targetPackageOnly: Boolean = true
)
```

### TraceSectionMetric

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

```
TraceSectionMetric(
    sectionNames: List<String>,
    label: String,
    mode: TraceSectionMetric.Mode = Mode.Sum,
    targetPackageOnly: Boolean = true
)
```