PerfettoTraceProcessor.Session

public final class PerfettoTraceProcessor.Session


Handle to query sql data from a PerfettoTrace.

See also
query

Summary

Public methods

final @NonNull Sequence<@NonNull Row>
query(@Language(value = "sql") @NonNull String query)

Computes the given query on the currently loaded trace.

final @NonNull byte[]
rawQuery(@Language(value = "sql") @NonNull String query)

Computes the given query on the currently loaded trace, returning the resulting protobuf bytes as a ByteArray.

Public methods

query

Added in 1.2.0
public final @NonNull Sequence<@NonNull Rowquery(@Language(value = "sql") @NonNull String query)

Computes the given query on the currently loaded trace.

Each row returned by a query is returned by the Sequence as a Row. To extract data from a Row, query by column name. The following example does this for name, timestamp, and duration of slices:

// Runs the provided callback on each activityStart instance in the trace,
// providing name, start timestamp (in ns) and duration (in ns)
fun PerfettoTraceProcessor.Session.forEachActivityStart(callback: (String, Long, Long) -> Unit) {
query("SELECT name,ts,dur FROM slice WHERE name LIKE \"activityStart\"").forEach {
callback(it.string("name"), it.long("ts"), it.long("dur")
// or, used as a map:
//callback(it["name"] as String, it["ts"] as Long, it["dur"] as Long)
}
}

rawQuery

Added in 1.2.0
public final @NonNull byte[] rawQuery(@Language(value = "sql") @NonNull String query)

Computes the given query on the currently loaded trace, returning the resulting protobuf bytes as a ByteArray.

Use Session.query if you do not wish to parse the Proto result yourself.

The QueryResult protobuf definition can be found in the Perfetto project, which can be used to decode the result returned here with a protobuf parsing library.

Note that this method does not check for errors in the protobuf, that is the caller's responsibility.

See also
query