PerfettoSdkHandshake


class PerfettoSdkHandshake


Handshake implementation allowing to enable Perfetto SDK tracing in an app that enables it.

Summary

Nested types

Provides means to sideload Perfetto SDK native binaries

Public constructors

PerfettoSdkHandshake(
    targetPackage: String,
    parseJsonMap: (jsonString: String) -> Map<StringString>,
    executeShellCommand: (command: String) -> String
)

Public functions

Response

Disables cold start tracing in the app if previously enabled by enableTracingColdStart.

Response
enableTracingColdStart(
    persistent: Boolean,
    librarySource: PerfettoSdkHandshake.LibrarySource?
)

Attempts to prepare cold startup tracing in the app.

Response

Attempts to enable tracing in the app.

Public constructors

PerfettoSdkHandshake

Added in 1.0.0
PerfettoSdkHandshake(
    targetPackage: String,
    parseJsonMap: (jsonString: String) -> Map<StringString>,
    executeShellCommand: (command: String) -> String
)
Parameters
targetPackage: String

package name of the target app

parseJsonMap: (jsonString: String) -> Map<StringString>

function parsing a flat map in a JSON format into a Map<String, String> e.g. "{ 'key 1': 'value 1', 'key 2': 'value 2' }" ->mapOf("key 1" to "value 1", "key 2" to "value 2")

executeShellCommand: (command: String) -> String

function allowing to execute adb shell commands on the target device

For error handling, note that parseJsonMap and executeShellCommand will be called on the same thread as enableTracingImmediate and enableTracingColdStart.

Public functions

disableTracingColdStart

Added in 1.0.0
fun disableTracingColdStart(): Response

Disables cold start tracing in the app if previously enabled by enableTracingColdStart.

No-op if cold start tracing was not enabled in the app, or if it was enabled in the non-persistent mode and the app has already been started at least once.

The function initially enables the app process (if not already enabled), but leaves it in a terminated state after executing.

enableTracingColdStart

Added in 1.0.0
fun enableTracingColdStart(
    persistent: Boolean = false,
    librarySource: PerfettoSdkHandshake.LibrarySource? = null
): Response

Attempts to prepare cold startup tracing in the app.

Leaves the app process in a terminated state.

Parameters
persistent: Boolean = false

if set to true, cold start tracing mode is persisted between app runs and must be cleared using disableTracingColdStart. Otherwise, cold start tracing is enabled only for the first app start since enabling. While persistent mode reduces some overhead of setting up tracing, it recommended to use non-persistent mode as it does not pose the risk of leaving cold start tracing persistently enabled in case of a failure to clean-up with disableTracingColdStart.

librarySource: PerfettoSdkHandshake.LibrarySource? = null

optional AAR or an APK containing libtracing_perfetto.so

enableTracingImmediate

Added in 1.0.0
fun enableTracingImmediate(
    librarySource: PerfettoSdkHandshake.LibrarySource? = null
): Response

Attempts to enable tracing in the app. It will wake up (or start) the app process, so it will act as warm/hot tracing. For cold tracing see enableTracingColdStart

Note: if the app process is not running, it will be launched making the method a bad choice for cold tracing (use enableTracingColdStart instead.

Parameters
librarySource: PerfettoSdkHandshake.LibrarySource? = null

optional AAR or an APK containing libtracing_perfetto.so