# [GUIDE] DDMS - Dalvik Debug Monitor Server



## ro6666lt (Sep 2, 2011)

This is a tool that, IMO not enough people know about. This guide will help you learn how to use it. Once you read this, you definitely will. word? word.

View attachment 2365


For those who don't know, Android ships with a debugging tool called the Dalvik Debug Monitor Server (DDMS), which provides *screen capture* on the device, port-forwarding services, thread and heap information on the device, *logcat*, process, and radio state information, *incoming call and SMS spoofing*, location data spoofing, and more.

*Running DDMS*

DDMS is integrated into Eclipse and is also shipped in the tools/ directory of the SDK.

From *Eclipse:* Click Window > Open Perspective > Other... > DDMS.
From the *command line:* Type _ddms_ (or _./ddms_ on Mac/Linux) from the tools/ directory.

*Using DDMS*

The following sections describe how to use DDMS and the various tabs and panes that are part of the DDMS GUI. The Eclipse version and the command line version have minor UI differences, but the same functionality. For information on running DDMS, see the previous section in this document, Running DDMS.

*Viewing heap usage for a process*

DDMS allows you to view how much heap memory a process is using. This information is useful in tracking heap usage at a certain point of time during the execution of your application.

*To view heap usage for a process:*

In the Devices tab, select the process that you want to see the heap information for.
Click the Update Heap button to enable heap information for the process.
In the Heap tab, click Cause GC to invoke garbage collection, which enables the collection of heap data. When the operation completes, you will see a group of object types and the memory that has been allocated for each type. You can 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.

*Tracking memory allocation of objects*

DDMS provides a feature to track objects that are being allocated to memory and to see which classes and threads are allocating the objects. This allows you to track, in real time, where objects are being allocated when you perform certain actions in your application. This information is valuable for assessing memory usage that can affect application performance. If you want more granular control over where allocation data is collected, use the startAllocCounting() and stopAllocCounting() methods.

*To track memory allocation of objects:*

In the Devices tab, select the process that you want to enable allocation tracking for.
In the Allocation Tracker tab, click the Start Tracking button to begin allocation tracking. At this point, anything you do in your application will be tracked.
Click Get Allocations to see a list of objects that have been allocated since you clicked on the Start Tracking button. You can click on Get Allocations again to append to the list new objects that 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.

*Working with an emulator or device's file system*

DDMS provides a File Explorer tab that allows you to view, copy, and delete files on the device. This feature is useful in examining files that are created by your application or if you want to transfer files to and from the device.

*To work with an emulator or device's file system:*

In the Devices tab, select the emulator that you want to view the file system for.
To copy a file from the device, locate the file in the File Explorer and click the Pull file button.
To copy a file to the device, click the Push file button on the File Explorer tab.

*Examining thread information*

The Threads tab in DDMS shows you the currently running threads for a selected process.

In the Devices tab, select the process that you want to examine the threads for.
Click the Update Threads button.
In the Threads tab, you can view the thread information for the selected process.

*Starting method profiling:*

Method profiling is a means to track certain metrics about a method, such as number of calls, execution time, and time spent executing the method. If you want more granular control over where profiling data is collected, use the startMethodTracing() and stopMethodTracing() methods. For more information about generating trace logs, see Profiling and Debugging UIs.

*Before you start method profiling in DDMS, be aware of the following restrictions:*

Android 1.5 devices are not supported.
Android 2.1 and earlier devices must have an SD card present and your application must have permission to write to the SD card.
Android 2.2 and later devices do not need an SD card. The trace log files are streamed directly to your development machine.

*To start method profiling:*

On the Devices tab, select the process that you want to enable method profiling for.
Click the Start Method Profiling button.
Interact with your application to start the methods that you want to profile.
Click the Stop Method Profiling button. DDMS stops profiling your application and opens Traceview with the method profiling information that was collected between the time you clicked on Start Method Profiling and Stop Method Profiling.

*Using LogCat*

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. View the Reading and Writing Log Messages. topic for more information on how to log messages to the LogCat.

When you have set up your logging, you can use the LogCat feature of DDMS to filter certain messages with the following buttons:

Verbose
Debug
Info
Warn
Error

You can also setup your own custom filter to specify more details such as filtering messages with the log tags or with the process id that generated the log message. The add filter, edit filter, and delete filter buttons let you manage your custom filters.

*Emulating phone operations and location*

The Emulator control tab lets you simulate a phone's voice and data network status. This is useful when you want to test your application's robustness in differing network environments.

*Changing network state, speed, and latency*

The Telephony Status section of the Emulator controls tab lets you change different aspects of the phone's networks status, speed and latency. The following options are available to you and are effective immediately after you set them:

Voice - unregistered, home, roaming, searching, denied
Data - unregistered, home, roaming, searching, denied
Speed - Full, GSM, HSCSD, GPRS, EDGE, UMTS, HSDPA
Latency - GPRS, EDGE, UMTS

*Spoofing calls or SMS text messages*

The Telephony Actions section of the Emulator controls tab lets you spoof calls and messages. This is useful when you want to to test your application's robustness in responding to incoming calls and messages that are sent to the phone. The following actions are available to you:

Voice - Enter a number in the Incoming number field and click Call to send a simulated call to the emulator or phone. Click the Hang up button to terminate the call.
SMS - Enter a number in the Incoming number field and a message in the Message: field and click the Send button to send the message.
Setting the location of the phone

If your application depends on the location of the phone, you can have DDMS send your device or AVD a mock location. This is useful if you want to test different aspects of your application's location specific features without physically moving. The following geolocation data types are available to you:

Manual - set the location by manually specifying decimal or sexagesimal longitude and latitude values.
GPX - GPS eXchange file
KML - Keyhole Markup Language file

------------------------------------

[via - developer.android.com]


----------



## perfoliate (Jun 10, 2011)

Nice write up

Sent from my ADR6400L using Tapatalk


----------

