Many of us are familiar with Android devices, but very few of us actually know about the Android Device Monitor. In short, an Android Device Monitor is a tool that helps to manage Android devices, develop Android applications and more. It is a standalone tool that provides a graphical user interface for debugging and analysing several android applications. The tool includes the following:
- - DDMS
- - Systrace
- - Traceview
- - Tracer for OpenGL ES
- - Hierarchy Viewer
a) Heap information -
- - Dalvik Debug Monitor Server (DDMS), an Android Studio debugging tool, provides port-forwarding services, screen capture, thread and heap information, logcat, process, and radio state information, incoming call and SMS spoofing, location data spoofing, and more on the device.
- - DDMS works with both the emulator and a connected device. If both are connected and running simultaneously, DDMS defaults to the emulator.
DDMS allows you to view the heap memory being used by a process. This information is useful in tracking heap usage at a certain point of time during execution of the application.
Follow the steps to view heap usage for a process:
- - In the Devices tab, select the process for which heap information is needed.
- - Click the update heap button to enable heap information for the process
- - In the Heap tab, click Cause GC to invoke garbage collection, to enable heap data collection. Once the operation gets completed, memory allotted for the group of object types will be visible. Click Cause GC again to refresh the data.
- - Click on an object type in the list to see a bar graph that shows the number of objects allocated for a particular memory size in bytes.
b) Tracking memory allocations
DDMS provides a feature to track objects for which memory is being allocated and to see which classes and threads are allocating the objects. This helps to track, where objects are being allocated, in real time. This information is valuable for assessing memory usage that can impact application performance.
Follow the steps to track memory allocation of objects:
- - In the Devices tab, select the process to enable allocation tracking
- - In the Allocation Tracker tab, click the Start Tracking button to begin allocation tracking. At this point, everything in the application will be tracked
- - Click Get Allocations to view a list of objects that have been allocated since Start Tracking button was clicked. Click on Get Allocations again to append to the list new objects that have been allocated.
- - To stop tracking or to clear the data and start over, click the Stop Tracking button.
- - Click on a specific row in the list to see more detailed information such as the method and line number of the code that allocated the object.
c) Threads information
The Threads tab in DDMS shows currently running threads for a selected process.
- - In the Devices tab, select the process to examine the threads
- - Click the Update Threads button
- - In the Threads tab, view thread information for the selected process
d) Network statistics –
DDMS includes a Detailed Network Usage tab that makes it possible to track when application is making network requests. This tool helps to monitor how and when the app transfers the data and optimizes the underlying code.
e) Logcat for collecting logs –
LogCat is integrated into DDMS, and outputs the messages, that you print out using the Log class along with other system messages such as stack traces, when exceptions are thrown.
Reading Logs –
Every Android log message has a tag and a priority associated with it.The tag of a log message is a short string indicating the system component from which the message originates (for example, "View" for the view system).
The priority can be one of the following character values, ordered from lowest to highest priority:
- - V — Verbose (lowest priority)
- - D — Debug
- - I — Info
- - W — Warning
- - E — Error
- - F — Fatal
- - S — Silent (highest priority, on which nothing is ever printed)
Obtain a list of tags used in the system, along with priorities, by running LogCat and observe the first two columns of each message, given as
Custom filter can be added to specify more details such as filtering messages with the log tags or with the process id that generated the log message. Custom filters can be managed through add filter, edit filter, and delete filter buttons.
Saving Log files –
- - After completing the steps that must be logged, select the desired area by means of the mouse with SHIFT key, or select all pressing combination of keys CTRL + A
- - In LogCat there is also functionality of creating filters in order to log only certain processes or messages with specific tags. To create a filter, it is necessary to click on the plus symbol "+" in Saved Filters section, and then specify the name of the filter and at least one parameter for filtering
The Systrace tool helps to analyse the performance of the application. It captures and displays the number of times the applications and other Android system processes have been executed. The tool combines data from the Android kernel such as - the CPU scheduler, disk activity, and application threads, to generate an HTML report. It shows an overall picture of the processes of an Android device, for a given period of time.
The Systrace tool is particularly useful in diagnosing display problems where an application is slow to draw or stutters while displaying motion or animation.
Follow the steps to run the Systrace capture user interface:
- - Navigate through SDK tools/ directory
- - Run the monitor program
- - In the Devices tab, select the device on which to run a trace. If no devices are listed, make sure the device is connected via USB cable and debugging is enabled on the device
- - Click the Systrace icon at the top of the Devices panel to configure tracing
- - Set the tracing options and click OK to start the trace Sample Systrace HTML report
Traceview is a graphical viewer for execution logs saved by the application. Traceview helps to debug the application and profile its performance.
Follow the steps to start the Traceview tool:
- - Start the Android Device Monitor
- - In the Android Device Monitor tool bar, click DDMS and select a process
- - Click the Start Method Profiling icon to start method profiling
- - After the profiling is complete, click the Stop Method Profiling icon to display the Traceview
Traceview, displays the log data in two panels:
- - timeline panel -- describes when each thread and method started and stopped
- - profile panel -- provides a summary of what happened inside a method.
ZenQ has a team of skilled professionals, having the expertise in carrying out all sort of debugging and analysis using Android Device Monitor. Our clients have experienced enhancement in Android apps performance.