The Network Profiler displays realtime network activity on a timeline, showing data sent and received, as well as the current number of connections. This lets you examine how and when your app transfers data, and optimize the underlying code appropriately.
To open the Network Profiler, follow these steps:
- Click View > Tool Windows > Android Profiler (you can also click Android Profiler in the toolbar).
- Select the device and app process you want to profile from the Android Profiler toolbar. If you've connected a device over USB but don't see it listed, ensure that you have enabled USB debugging.
- Click anywhere in the NETWORK timeline to open the Network Profiler.
To select a portion of the timeline, inspect a list of network requests sent and responses received, or view detailed information about a selected file, you must enable advanced profiling.
Why you should profile your app's network activity
When your app makes a request to the network, the device must use the power-hungry mobile or WiFi radios to send and receive packets. The radios not only use power to transfer data, but also use extra power to turn on and to stay awake.
Using the Network Profiler, you can look for frequent, short spikes of network activity, which mean that your app requires the radios to turn on frequently, or to stay awake for long periods to handle many short requests close together. This pattern indicates that you may be able to optimize your app for improved battery performance by batching network requests, thereby reducing the number of times the radios must turn on to send or receive data. This also allows the radios to switch into low-power mode to save battery in the longer gaps between batched requests.
For more information about techniques to optimize your app's network activity, read Reducing Network Battery Drain.
Network Profiler overview
At the top of the window, you can see the event timeline and 1 radio power state (high/low) vs Wi-Fi. On the timeline, you can 2 click and drag to select a portion of the timeline to inspect the traffic.
In the 3 pane below the timeline, select one of the following tabs for more detail about the network activity during the selected portion of the timeline:
- Connection View: Lists files that were sent or received during the selected portion of the timeline across all of your app's CPU threads. For each request, you can inspect the size, type, status, and transmission duration. You can sort this list by clicking any of the column headers. You also see a detailed breakdown of the selected portion of the timeline, showing when each file was sent or received.
- Thread View: Displays network activity of each of your app's CPU threads. As shown in the figure 2, this view allows you to inspect which of your app's threads are responsible for each network request.
From either the Connection View or Thread View, click a request name to inspect 4 detailed information about the data sent or received. Click the tabs to view the response header and body, request header and body, or call stack.
URL url = new URL(MY_URL_EN); HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); ... // Sets acceptable encodings in the request header. urlConnection.setRequestProperty("Accept-Encoding", "identity");
Network connection troubleshooting
If the Network Profiler detects traffic values, but cannot identify any supported network requests, you will receive the following error message:
"Network Profiling Data Unavailable: There is no information for the network traffic you've selected."
Currently, the Network Profiler supports only the
OkHttp libraries for network
connections. If your app uses another network connection library, you may not be
able to view your network activity in the Network Profiler. If you have received
this error message, but your app does use
report a bug, or
search the issue tracker
to include your feedback in an existing report that's related to your issue. You
can also use these resources to request support for additional libraries.