# HeapProfileRequestBuilder

Artifact: [androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/os/Profiling.kt+class:androidx.core.os.HeapProfileRequestBuilder) Added in [1.15.0](https://developer.android.com/jetpack/androidx/releases/core#1.15.0)

*** ** * ** ***


```
@RequiresApi(api = 35)
public final class HeapProfileRequestBuilder extends ProfilingRequestBuilder<@NonNull HeapProfileRequestBuilder>
```

<br />

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) |||
| ↳ | [androidx.core.os.ProfilingRequestBuilder](https://developer.android.com/reference/androidx/core/os/ProfilingRequestBuilder)\<@[NonNull](https://developer.android.com/reference/androidx/annotation/NonNull) [HeapProfileRequestBuilder](https://developer.android.com/reference/androidx/core/os/HeapProfileRequestBuilder)\> ||
|   | ↳ | [androidx.core.os.HeapProfileRequestBuilder](https://developer.android.com/reference/androidx/core/os/HeapProfileRequestBuilder) |

*** ** * ** ***

Request builder to create a request for a heap profile from `https://developer.android.com/reference/android/os/ProfilingManager.html`.

```kotlin
val listener =
    Consumer<ProfilingResult> { profilingResult ->
        if (profilingResult.errorCode == ProfilingResult.ERROR_NONE) {
            doSomethingWithMyFile(profilingResult.resultFilePath)
        } else {
            doSomethingWithFailure(profilingResult.errorCode, profilingResult.errorMessage)
        }
    }

val cancellationSignal = CancellationSignal()

requestProfiling(
    context,
    HeapProfileRequestBuilder()
        .setBufferSizeKb(1000 /* Requested buffer size in KB */)
        .setDurationMs(5 * 1000 /* Requested profiling duration in milliseconds */)
        .setTrackJavaAllocations(true)
        .setSamplingIntervalBytes(100 /* Requested sampling interval in bytes */)
        .setTag("tag" /* Caller supplied tag for identification */)
        .setCancellationSignal(cancellationSignal)
        .build(),
    Dispatchers.IO.asExecutor(), // Your choice of executor for the callback to occur on.
    listener,
)

// Optionally, wait for something interesting to happen and then stop the profiling to receive
// the result as is.
cancellationSignal.cancel()
```

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/core/os/HeapProfileRequestBuilder#HeapProfileRequestBuilder()()` |

| ### Public methods |
|---|---|
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/core/os/HeapProfileRequestBuilder` | `https://developer.android.com/reference/androidx/core/os/HeapProfileRequestBuilder#setBufferSizeKb(kotlin.Int)(int bufferSizeKb)` Set the buffer size in kilobytes for this profiling request. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/core/os/HeapProfileRequestBuilder` | `https://developer.android.com/reference/androidx/core/os/HeapProfileRequestBuilder#setDurationMs(kotlin.Int)(int durationMs)` Set the duration in milliseconds for this profiling request. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/core/os/HeapProfileRequestBuilder` | `https://developer.android.com/reference/androidx/core/os/HeapProfileRequestBuilder#setSamplingIntervalBytes(kotlin.Long)(long samplingIntervalBytes)` Set the sampling interval in bytes for this profiling request. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/core/os/HeapProfileRequestBuilder` | `https://developer.android.com/reference/androidx/core/os/HeapProfileRequestBuilder#setTrackJavaAllocations(kotlin.Boolean)(boolean traceJavaAllocations)` Set whether to track Java allocations rather than native ones. |

### Inherited methods

From [androidx.core.os.ProfilingRequestBuilder](https://developer.android.com/reference/androidx/core/os/ProfilingRequestBuilder) `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/core/os/ProfilingRequest` `https://developer.android.com/reference/androidx/core/os/ProfilingRequestBuilder#build()()`

Build the `https://developer.android.com/reference/androidx/core/os/ProfilingRequest` object which can be used with `https://developer.android.com/reference/androidx/core/os/package-summary#requestProfiling(android.content.Context,androidx.core.os.ProfilingRequest,java.util.concurrent.Executor,java.util.function.Consumer)` to request profiling.
`final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/core/os/HeapProfileRequestBuilder` `https://developer.android.com/reference/androidx/core/os/ProfilingRequestBuilder#setCancellationSignal(android.os.CancellationSignal)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/os/CancellationSignal.html cancellationSignal)`

Set a CancellationSignal to request cancellation of the requested trace.
`final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/core/os/HeapProfileRequestBuilder` `https://developer.android.com/reference/androidx/core/os/ProfilingRequestBuilder#setTag(kotlin.String)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html tag)`

Add data to help identify the output.

## Public constructors

### HeapProfileRequestBuilder

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

```
public HeapProfileRequestBuilder()
```

## Public methods

### setBufferSizeKb

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

```
public final @NonNull HeapProfileRequestBuilder setBufferSizeKb(int bufferSizeKb)
```

Set the buffer size in kilobytes for this profiling request.

### setDurationMs

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

```
public final @NonNull HeapProfileRequestBuilder setDurationMs(int durationMs)
```

Set the duration in milliseconds for this profiling request.

### setSamplingIntervalBytes

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

```
public final @NonNull HeapProfileRequestBuilder setSamplingIntervalBytes(long samplingIntervalBytes)
```

Set the sampling interval in bytes for this profiling request.

### setTrackJavaAllocations

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

```
public final @NonNull HeapProfileRequestBuilder setTrackJavaAllocations(boolean traceJavaAllocations)
```

Set whether to track Java allocations rather than native ones.