PerfettoTraceProcessor.Session

class PerfettoTraceProcessor.Session


Handle to query sql data from a PerfettoTrace.

See also
query

Summary

Public functions

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

Computes the given query on the currently loaded trace.

ByteArray
rawQuery(@Language(value = "sql") query: String)

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

Public functions

query

Added in 1.2.0
fun query(@Language(value = "sql") query: String): Sequence<Row>

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
fun rawQuery(@Language(value = "sql") query: String): ByteArray

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