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.

String

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

ByteArray

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

String

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

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)
}
}

queryMetricsJson

Added in 1.3.0
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

Added in 1.3.0
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

Added in 1.3.0
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

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