# AtraceLogger

Summary:[Methods](https://developer.android.com/reference/android/support/test/rule/logging/AtraceLogger#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/support/test/rule/logging/AtraceLogger#inhmethods)\|[\[Expand All\]](https://developer.android.com/reference/android/support/test/rule/logging/AtraceLogger#)  

# AtraceLogger

| This package is part of the Android[support library](https://developer.android.com/topic/libraries/support-library)which is no longer maintained. The support library has been superseded by[AndroidX](https://developer.android.com/jetpack/androidx)which is part of[Jetpack](https://developer.android.com/jetpack). We recommend using the AndroidX libraries in all new projects. You should also consider[migrating](https://developer.android.com/jetpack/androidx/migrate)existing projects to AndroidX. To find the AndroidX class that maps to this deprecated class, see the AndroidX support library[class mappings](https://developer.android.com/jetpack/androidx/migrate/class-mappings).

`
public


class
AtraceLogger
`  
`

extends `[Object](https://developer.android.com/reference/java/lang/Object.html)`


``


`

|---|------------------------------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) ||
| ↳ | android.support.test.rule.logging.AtraceLogger |

<br />

*** ** * ** ***

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

**This API is currently in beta.**

## Summary

|                                                                                                                                                                                                                                                                                                                                                                              ### Public methods                                                                                                                                                                                                                                                                                                                                                                               ||
|------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` void`                                                                                                          | ` `[atraceStart](https://developer.android.com/reference/android/support/test/rule/logging/AtraceLogger#atraceStart(java.util.Set<java.lang.String>, int, int, java.io.File, java.lang.String))`(`[Set](https://developer.android.com/reference/java/util/Set.html)`<`[String](https://developer.android.com/reference/java/lang/String.html)`> traceCategoriesSet, int atraceBufferSize, int dumpIntervalSecs, `[File](https://developer.android.com/reference/java/io/File.html)` destDirectory, `[String](https://developer.android.com/reference/java/lang/String.html)` traceFileName) ` Method to start atrace and dump the data at regular interval. |
| ` void`                                                                                                          | ` `[atraceStop](https://developer.android.com/reference/android/support/test/rule/logging/AtraceLogger#atraceStop())`() ` Method to stop the atrace and write the atrace data cached in byte array list to file.                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| ` static `[AtraceLogger](https://developer.android.com/reference/android/support/test/rule/logging/AtraceLogger) | ` `[getAtraceLoggerInstance](https://developer.android.com/reference/android/support/test/rule/logging/AtraceLogger#getAtraceLoggerInstance(android.app.Instrumentation))`(`[Instrumentation](https://developer.android.com/reference/android/app/Instrumentation.html)` instrumentation) ` To make sure only one instance of atrace logger is created.                                                                                                                                                                                                                                                                                                     |

| ### Inherited methods |
|-----------------------|---|
| [![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/android/support/test/rule/logging/AtraceLogger#)From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object.html)` ` |-------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object.html)          | ` clone() `                                                                                | | ` boolean`                                                                          | ` equals(`[Object](https://developer.android.com/reference/java/lang/Object.html)` arg0) ` | | ` void`                                                                             | ` finalize() `                                                                             | | ` final `[Class](https://developer.android.com/reference/java/lang/Class.html)`<?>` | ` getClass() `                                                                             | | ` int`                                                                              | ` hashCode() `                                                                             | | ` final void`                                                                       | ` notify() `                                                                               | | ` final void`                                                                       | ` notifyAll() `                                                                            | | ` `[String](https://developer.android.com/reference/java/lang/String.html)          | ` toString() `                                                                             | | ` final void`                                                                       | ` wait(long arg0, int arg1) `                                                              | | ` final void`                                                                       | ` wait(long arg0) `                                                                        | | ` final void`                                                                       | ` wait() `                                                                                 | ||

## Public methods

### atraceStart

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

<br />

|                                                                                                                                                                 Parameters                                                                                                                                                                  ||
|----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `traceCategoriesSet` | `Set`: Set of atrace categories (i.e atrace --list_categories) <br />                                                                                                                                                                                                                                                 |
| `atraceBufferSize`   | `int`: Size of the circular buffer in kb <br />                                                                                                                                                                                                                                                                       |
| `dumpIntervalSecs`   | `int`: Periodic interval to dump data from circular buffer <br />                                                                                                                                                                                                                                                     |
| `destDirectory`      | `File`: Directory under which atrace logs are stored <br />                                                                                                                                                                                                                                                           |
| `traceFileName`      | `String`: 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 <br /> |

|                                       Throws                                       ||
|---------------------------------------------------------------------------------|---|
| [IOException](https://developer.android.com/reference/java/io/IOException.html) |   |

### atraceStop

```
void atraceStop ()
```

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

<br />

|                                                      Throws                                                      ||
|-----------------------------------------------------------------------------------------------------|-------------|
|                                                                                                     | IOException |
| [InterruptedException](https://developer.android.com/reference/java/lang/InterruptedException.html) |             |
| [IOException](https://developer.android.com/reference/java/io/IOException.html)                     |             |

### getAtraceLoggerInstance

```
AtraceLogger getAtraceLoggerInstance (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.

<br />

|                                     Parameters                                     ||
|-------------------|-----------------------------------------------------------------|
| `instrumentation` | `Instrumentation`: Used to execute atrace shell commands <br /> |

|                                                                   Returns                                                                   ||
|--------------------------------------------------------------------------------------------------------|-------------------------------------|
| [AtraceLogger](https://developer.android.com/reference/android/support/test/rule/logging/AtraceLogger) | instance of the AtraceLogger <br /> |

-

  ## Classes

  - [AtraceLogger](https://developer.android.com/reference/android/support/test/rule/logging/AtraceLogger)