Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document Android system tracing #34

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions howto/android/system-tracing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
This guide describes how to enable system tracing in Android using Anbox Cloud.

## Enable Android System Tracing

1. To enable Android system tracing, add the `android.enable_tracing` flag into the feature file. In the Android container, run:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the Android container

I changed the "development container" to "Android container". Is it correct? Or should this be "In the Anbox instance"?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Android runs in a container nested in an instance (container or VM), so that seems accurate to me.


```bash
echo "android.enable_tracing" >> /var/lib/anbox/features
```
2. Specify the category you want to trace in the Android system using the `debug.atrace.tags.enableflags` system property. The supported categories are defined in [trace.h](https://cs.android.com/android/platform/superproject/main/+/main:system/core/libcutils/include/cutils/trace.h;l=50?q=ATRACE_TAG_INPUT).

For instance, to enable the graphics category, add the following to the `/var/lib/anbox/android.json` file:

```json
{
"hardware": "ranchu",
"api_level": 31,
"properties": [ "debug.atrace.tags.enableflags=2" ]
}
```
Comment on lines +12 to +20
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to reboot the instance after changing the android.json file, but we need to double-check this with @morphis or @adglkh.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not strictly necessary to define the property here. This is only needed if you want to trace system services. However if that is the intention you need to put it here.

3. Launch an Anbox session and initiate tracing via the HTTP endpoint. This will not only trace the Anbox session but also capture events aggregated under the category specified in the above system property.:

```bash
curl --unix-socket /run/user/1000/anbox/sockets/api.unix --request POST --data '{"enable":true}' s/1.0/tracing
```
After your desired tracing time, stop the tracing:
```bash
curl --unix-socket /run/user/1000/anbox/sockets/api.unix --request POST --data '{"enable":false}' s/1.0/tracing
```
The resulting trace file is available in the response once tracing is disabled. The trace file should look similar to:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So... The file is not available then, the _path_to the file is available in the response.


```json
{
"metadata": {
"path": "/var/lib/anbox/traces/anbox_884277.0"
},
"status": "Success",
"status_code": 200,
"type": "sync"
}
```


4. Pull the trace file from the Android container:
```bash
lxc file pull <container>/var/lib/anbox/traces/anbox_884277.0 ./
```
Load the trace file into the [Perfetto UI](https://ui.perfetto.dev/) for visualisation.