# 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
public final class TraceSectionMetric extends Metric
```

<br />

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) |||
| ↳ | [androidx.benchmark.macro.Metric](https://developer.android.com/reference/androidx/benchmark/macro/Metric) ||
|   | ↳ | [androidx.benchmark.macro.TraceSectionMetric](https://developer.android.com/reference/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/androidx/benchmark/macro/TraceSectionMetric#sectionNames()`.

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

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

```
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/androidx/tracing/Trace#beginSection(kotlin.String)` |   |
| `https://developer.android.com/reference/androidx/tracing/Trace#endSection()` |   |
| `https://developer.android.com/reference/androidx/tracing/package-summary#trace(kotlin.String,kotlin.Function0)` |   |

## Summary

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

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/benchmark/macro/TraceSectionMetric#TraceSectionMetric(kotlin.String,androidx.benchmark.macro.TraceSectionMetric.Mode,kotlin.String,kotlin.Boolean)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html sectionName, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/benchmark/macro/TraceSectionMetric.Mode mode, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html label, boolean targetPackageOnly )` |
| `https://developer.android.com/reference/androidx/benchmark/macro/TraceSectionMetric#TraceSectionMetric(kotlin.collections.List,kotlin.String,androidx.benchmark.macro.TraceSectionMetric.Mode,kotlin.Boolean)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html> sectionNames, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html label, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/benchmark/macro/TraceSectionMetric.Mode mode, boolean targetPackageOnly )` |

## Public constructors

### TraceSectionMetric

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

```
public TraceSectionMetric(
    @NonNull String sectionName,
    @NonNull TraceSectionMetric.Mode mode,
    @NonNull String label,
    boolean targetPackageOnly
)
```

### TraceSectionMetric

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

```
public TraceSectionMetric(
    @NonNull List<@NonNull String> sectionNames,
    @NonNull String label,
    @NonNull TraceSectionMetric.Mode mode,
    boolean targetPackageOnly
)
```