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 String

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

final @NonNull byte[]

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

final @NonNull String

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

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

queryMetricsJson

Added in 1.3.0
public final @NonNull String queryMetricsJson(@NonNull List<@NonNull String> metrics)

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
public final @NonNull byte[] queryMetricsProtoBinary(@NonNull List<@NonNull String> metrics)

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
public final @NonNull String queryMetricsProtoText(@NonNull List<@NonNull String> metrics)

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