{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

AtraceLogger

public class AtraceLogger


Class contains helper methods to dump atrace info asynchronously while running the test case.

This API is currently in beta.

Summary

Public methods

@NonNull void
atraceStart(
    @NonNull Set<@NonNull String> traceCategoriesSet,
    @NonNull int atraceBufferSize,
    @NonNull int dumpIntervalSecs,
    @NonNull File destDirectory,
    @NonNull String traceFileName
)

Method to start atrace and dump the data at regular interval.

@NonNull void

Method to stop the atrace and write the atrace data cached in byte array list to file.

static @NonNull AtraceLogger
getAtraceLoggerInstance(@NonNull Instrumentation instrumentation)

To make sure only one instance of atrace logger is created.

Public methods

atraceStart

@NonNull
public void atraceStart(
    @NonNull Set<@NonNull String> traceCategoriesSet,
    @NonNull int atraceBufferSize,
    @NonNull int dumpIntervalSecs,
    @NonNull File destDirectory,
    @NonNull String traceFileName
)

Method to start atrace and dump the data at regular interval. Note : Trace info will not be captured during the dumping if there are multiple dumps between the atraceStart and atraceStop

Parameters
@NonNull Set<@NonNull String> traceCategoriesSet

Set of atrace categories (i.e atrace --list_categories)

@NonNull int atraceBufferSize

Size of the circular buffer in kb

@NonNull int dumpIntervalSecs

Periodic interval to dump data from circular buffer

@NonNull File destDirectory

Directory under which atrace logs are stored

@NonNull String traceFileName

is optional parameter.Atrace files are dumped under destDirectory. traceFileName will be indexed based on number of dumps between atraceStart and atraceStop under destDirectory. If traceFileName is null or empty "atrace" name will be used for indexing the files and stored under destDirectory

Throws
java.io.IOException

atraceStop

@NonNull
public void atraceStop()

Method to stop the atrace and write the atrace data cached in byte array list to file.

Throws
java.io.IOException
java.lang.InterruptedException

getAtraceLoggerInstance

@NonNull
public static AtraceLogger getAtraceLoggerInstance(@NonNull Instrumentation instrumentation)

To make sure only one instance of atrace logger is created. Note : Supported only for minsdk version 23 and above because of UiAutomation executeShellCommand limitation.

Parameters
@NonNull Instrumentation instrumentation

Used to execute atrace shell commands

Returns
AtraceLogger

instance of the AtraceLogger