SystemTraceRequestBuilder


@RequiresApi(api = 35)
class SystemTraceRequestBuilder : ProfilingRequestBuilder


Request builder to create a request for a system trace 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,
    SystemTraceRequestBuilder()
        .setBufferSizeKb(1000 /* Requested buffer size in KB */)
        .setDurationMs(60 * 1000 /* Requested profiling duration in millisconds */)
        .setBufferFillPolicy(BufferFillPolicy.RING_BUFFER /* Buffer fill policy */)
        .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 functions

SystemTraceRequestBuilder

Set the buffer fill policy.

SystemTraceRequestBuilder
setBufferSizeKb(bufferSizeKb: Int)

Set the buffer size in kilobytes for this profiling request.

SystemTraceRequestBuilder
setDurationMs(durationMs: Int)

Set the duration in milliseconds for this profiling request.

Inherited functions

From androidx.core.os.ProfilingRequestBuilder
ProfilingRequest

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

SystemTraceRequestBuilder

Set a CancellationSignal to request cancellation of the requested trace.

SystemTraceRequestBuilder
setTag(tag: String)

Add data to help identify the output.

Public constructors

SystemTraceRequestBuilder

Added in 1.15.0
SystemTraceRequestBuilder()

Public functions

setBufferFillPolicy

Added in 1.15.0
fun setBufferFillPolicy(bufferFillPolicy: BufferFillPolicy): SystemTraceRequestBuilder

Set the buffer fill policy.

setBufferSizeKb

Added in 1.15.0
fun setBufferSizeKb(bufferSizeKb: Int): SystemTraceRequestBuilder

Set the buffer size in kilobytes for this profiling request.

setDurationMs

Added in 1.15.0
fun setDurationMs(durationMs: Int): SystemTraceRequestBuilder

Set the duration in milliseconds for this profiling request.