AtraceLogger


@RequiresApi(value = 21)
public class AtraceLogger


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

Supported only for minsdk version 21 and above because of UiAutomation#executeShellCommand availability.

Summary

Public methods

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

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

void

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

static AtraceLogger

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

Public methods

atraceStart

public void atraceStart(
    Set<String> traceCategoriesSet,
    int atraceBufferSize,
    int dumpIntervalSecs,
    File destDirectory,
    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
Set<String> traceCategoriesSet

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

int atraceBufferSize

Size of the circular buffer in kb

int dumpIntervalSecs

Periodic interval to dump data from circular buffer

File destDirectory

Directory under which atrace logs are stored

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

atraceStop

public void atraceStop()

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

getAtraceLoggerInstance

public static AtraceLogger getAtraceLoggerInstance(Instrumentation instrumentation)

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

Parameters
Instrumentation instrumentation

Used to execute atrace shell commands

Returns
AtraceLogger

instance of the AtraceLogger