StackSamplingRequestBuilder


@RequiresApi(api = 35)
public final class StackSamplingRequestBuilder extends ProfilingRequestBuilder


Request builder to create a request for stack sampling from ProfilingManager.

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,
    StackSamplingRequestBuilder()
        .setBufferSizeKb(1000 /* Requested buffer size in KB */)
        .setDurationMs(10 * 1000 /* Requested profiling duration in millisconds */)
        .setSamplingFrequencyHz(100 /* Requested sampling frequency */)
        .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

Public methods

final @NonNull StackSamplingRequestBuilder
setBufferSizeKb(int bufferSizeKb)

Set the buffer size in kilobytes for this profiling request.

final @NonNull StackSamplingRequestBuilder
setDurationMs(int durationMs)

Set the duration in milliseconds for this profiling request.

final @NonNull StackSamplingRequestBuilder
setSamplingFrequencyHz(int samplingFrequencyHz)

Set the cpu sampling frequency.

Inherited methods

From androidx.core.os.ProfilingRequestBuilder
final @NonNull ProfilingRequest

Build the ProfilingRequest object which can be used with requestProfiling to request profiling.

final @NonNull StackSamplingRequestBuilder

Set a CancellationSignal to request cancellation of the requested trace.

final @NonNull StackSamplingRequestBuilder

Add data to help identify the output.

Public constructors

StackSamplingRequestBuilder

Added in 1.15.0
public StackSamplingRequestBuilder()

Public methods

setBufferSizeKb

Added in 1.15.0
public final @NonNull StackSamplingRequestBuilder setBufferSizeKb(int bufferSizeKb)

Set the buffer size in kilobytes for this profiling request.

setDurationMs

Added in 1.15.0
public final @NonNull StackSamplingRequestBuilder setDurationMs(int durationMs)

Set the duration in milliseconds for this profiling request.

setSamplingFrequencyHz

Added in 1.15.0
public final @NonNull StackSamplingRequestBuilder setSamplingFrequencyHz(int samplingFrequencyHz)

Set the cpu sampling frequency.