TraceProcessor.Session



Handle to query sql data from a PerfettoTrace.

See also
query

Summary

Public functions

Sequence<Row>
query(query: String)

Computes the given query on the currently loaded trace.

Cmn
String

Computes the given metrics, returning the results as JSON text.

Cmn
ByteArray

Computes the given metrics, returning the results as a binary proto.

Cmn
String

Computes the given metrics, returning the result as proto text.

Cmn
ByteArray
rawQuery(query: String)

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

Cmn

Public functions

query

fun query(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 TraceProcessor.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)
}
}

queryMetricsJson

fun queryMetricsJson(metrics: List<String>): String

Computes the given metrics, returning the results as JSON text.

The proto format definition for these metrics can be found here.

See perfetto metric docs for an overview on trace based metrics.

queryMetricsProtoBinary

fun queryMetricsProtoBinary(metrics: List<String>): ByteArray

Computes the given metrics, returning the results as a binary proto.

The proto format definition for decoding this binary format can be found here.

See perfetto metric docs for an overview on trace based metrics.

queryMetricsProtoText

fun queryMetricsProtoText(metrics: List<String>): String

Computes the given metrics, returning the result as proto text.

The proto format definition for these metrics can be found here.

See perfetto metric docs for an overview on trace based metrics.

rawQuery

fun rawQuery(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