PerfettoSdkHandshake


public final 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(
    @NonNull String targetPackage,
    @NonNull Function1<@NonNull String, @NonNull Map<@NonNull String, @NonNull String>> parseJsonMap,
    @NonNull Function1<@NonNull String, @NonNull String> executeShellCommand
)

Public methods

final @NonNull Response

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

final @NonNull Response
enableTracingColdStart(
    boolean persistent,
    PerfettoSdkHandshake.LibrarySource librarySource
)

Attempts to prepare cold startup tracing in the app.

final @NonNull Response

Attempts to enable tracing in the app.

Public constructors

PerfettoSdkHandshake

Added in 1.0.0
public PerfettoSdkHandshake(
    @NonNull String targetPackage,
    @NonNull Function1<@NonNull String, @NonNull Map<@NonNull String, @NonNull String>> parseJsonMap,
    @NonNull Function1<@NonNull String, @NonNull String> executeShellCommand
)
Parameters
@NonNull String targetPackage

package name of the target app

@NonNull Function1<@NonNull String, @NonNull Map<@NonNull String, @NonNull String>> parseJsonMap

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

@NonNull Function1<@NonNull String, @NonNull String> executeShellCommand

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 methods

disableTracingColdStart

Added in 1.0.0
public final @NonNull Response disableTracingColdStart()

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
public final @NonNull Response enableTracingColdStart(
    boolean persistent,
    PerfettoSdkHandshake.LibrarySource librarySource
)

Attempts to prepare cold startup tracing in the app.

Leaves the app process in a terminated state.

Parameters
boolean persistent

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.

PerfettoSdkHandshake.LibrarySource librarySource

optional AAR or an APK containing libtracing_perfetto.so

enableTracingImmediate

Added in 1.0.0
public final @NonNull Response enableTracingImmediate(
    PerfettoSdkHandshake.LibrarySource librarySource
)

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
PerfettoSdkHandshake.LibrarySource librarySource

optional AAR or an APK containing libtracing_perfetto.so