Android-using DDMS

Source: Internet
Author: User

Original: Http://developer.android.com/tools/debugging/ddms.html#how-ddms-works

Android provides a debug tool called: DDMS, which provides port forwarding services, device screenshots, device thread and heap information, logs, processes, analog phone calls, analog send and receive SMS, analog location data and other functions. This paper is mainly a brief description of the characteristics of DDMS, it is not a comprehensive mining of all the features and functions of DDMS.

Run DDMS

The DDMS is integrated into Eclipse and also has a copy of the SDK's tools directory. The DDMS also supports both simulators and real-world devices. If they are running at the same time, DDMS points to the emulator by default.

· Inside Eclipse: Click- Windows > Open perspective > Other ... > DDMS

· On the command line: Enter the Tools directory, enter: DDMS (Linux/mac platform is./ddms)

How the DDMS and the debugger interact

Inside Android, each application runs in a separate process, each running in its own virtual machine (VM). Every virtual opportunity leaks a unique port number for the debugger to connect to.

When the DDMS is started, it will connect to the ADB. When a device is connected, a virtual machine monitoring service is created between ADB and DDMS, and the monitoring service notifies DDMS when the virtual machine on the device is started or terminated. Once a virtual machine is running, DDMS retrieves the PID of the virtual machine through ADB and then opens a DDMS to the virtual machine debugger through the ADBD background process on the device. DDMS can now use customized wireless protocols and virtual machines for conversations.

DDMS will give each virtual machine on the device a debug port. In general, DDMS will give 8600 to the first debugger, the next is 8601, and so on. When the debugger connects to these ports, all the data on the associated virtual machine is forwarded to the debugger. You can use only one debugger for a port, but DDMS can handle multiple debuggers.

By default, DDMS also listens to another debug port, called the base port (the default port number is 8700). The base port is a port forwarder that can receive data from a virtual machine from any of the debug ports, then goes to port 8700 and then debugs all the virtual machines on the device. The data being forwarded is determined by the process currently selected in the device view of DDMS.

Shows the appearance of Ddms in Eclipse. If you're starting a DDMS from the command line, it looks a little different, but most of the functionality is the same. Note that the highlighted process Com.android.email, which is running inside the emulator, is given a debug port of 8700 and 8606. This indicates that the current DDMS will forward 8606 of the data to 8700.

Figure 1. Screenshot of DDMS

If you are not using Eclipse and ADT, please read configuring your IDE to attach to thedebugging port in order to bind your debugger.

TIP: You can set a lot of DDMS preference through File > Preferences . Preference is saved to $home/.android/ddms.cfg.

Dalvik Debugging problems

Debugging in a Dalvik virtual machine is basically the same as debugging in other virtual machines, but when stepping out of the synchronization block, the current row of the mouse jumps to the last line of the method.

Using DDMS

The following sections describe how to use DDMS, as well as the various pagination and panels on the DDMD interface. The version of Eclipse and the version of the command line are slightly different in the UI, but the functionality is the same. See the section earlier in this article for information on how to run DDMS.

To view heap memory consumed by a process

DDMS allows you to see how much heap memory is being consumed by a process, which is useful for tracking the use of a heap at a point in time application execution.

To view the heap usage of a process:

1. On the Devices page, select the process for which you want to view heap information.

2. Click the Update heap button to allow you to view the heap information for the process.

3. On the heap page, click cause GC to trigger garbage collection, which will heap data information on the phone. When the operation is complete, you will see a lot of data types and the memory they occupy. You can click causegc again to refresh the data.

4. Click on a data type, a histogram appears, showing the number of objects and the memory allocated in byte count.

Memory allocation for tracking objects

DDMS provides an attribute for tracking object memory allocations and can see which classes and threads are allocating objects. This allows you to track in real time which objects are being allocated when your app is doing something. This is useful for evaluating the use of memory that may affect application performance.

Memory allocation for tracking objects:

1. On the Devices page, select the process for which you want to view heap information.

2. On the Allocationtracker page, click the start Tracking button to start tracking. At this point, any action inside the app will be tracked down.

3. Click Get allocations to see the list of objects that have been assigned since you clicked Start Tracking . You can click Get allocations again to append the new object to the assignment.

4. Click the Stop Tracking button button to stop tracking or to clear the data and start over again.

5. Click on a row of data in the list to view more detailed information such as the method and line number of the assigned object's code.

Using the emulator or the file system of the device

DDMS provides a file browser page that allows you to view, copy, and delete files on your device. This feature is useful when checking the files created by your app or when you want to transfer files on your device.

Using the emulator or the file system of the device

1. On the Devices page, select the process for which you want to view heap information.

2. Copy the file from the device, navigate to the file in the file browser , and click the Pull File button.

3. Copy the file to the device and click the pushfile button on the File browser page.

Check thread information

The threads page inside the DDMS shows the currently running thread under a selected process.

1. On the Devices page, select the process for which you want to view heap information.

2. Click the Update Threads button.

3. On the Threads page, you can see the thread information for the selected process.

Start Method Analysis

Method analysis is a way of tracking some information about a method, such as the number of calls, execution time. You can use Startmethodtracing () and stopmethodtracing () if you want to get finer grained control over where to collect the analysis data. For information on how to generate trace logs, refer to: Profiling and Debugging UIs.

Before starting a method analysis in Ddms, be aware of some of the following limitations:

· Android2.1 and earlier versions of the device must have an SD card, and your app must have permission to write the SD card.

· Android2.2 and high-version devices do not require an SD card, and trace logs are sent directly to your development machine.

Start Method Analysis:

1. On the Devices page, select the process for which you want to view heap information.

2. Click the Start methodprofiling button

3. Interact with the app to start the method you want to analyze.

Click the Stop methodprofiling button. DDMS stops analyzing your app, and then opens a TraceView view of the method analysis information that was collected between the Profiling you clicked Start method and the stop methodprofiling .

Using the Network traffic tool

Inside Android 4.0, DDMS contains a detailed network Usage page, which makes it possible for the monitoring application to make a network request. Using this tool, you can monitor when your app is passing data and better optimize the underlying code. You can also apply a "tag" to the network socket before using it to differentiate between different types of traffic,

These tags is shownin a stack area chart in DDMS, as shown in Figure 2:

Figure 2. Network Usage tab.

By Monitoringthe frequency of your data transfers, and the amount of data transferred Duringeach connection, can ident Ify areas of your application that can be Mademore battery-efficient. Generally, you should look for short spikes that can bedelayed, or the should cause a later transfer to be pre-empted.

To betteridentify the cause of transfer spikes, the Trafficstats API allows your to tag the datatransfers occurring within A thread using Setthreadstatstag (), followed by manually tagging (anduntagging) individual sockets using Tagsocket () and UN Tagsocket (). For example:

Trafficstats.setthreadstatstag (0xf00d);
Trafficstats.tagsocket (Outputsocket);
Transfer datausing Socket
Trafficstats.untagsocket (Outputsocket);

alternatively,the apache httpclient and  Urlconnection apis included in the platformautomatically tag sockets internally based on the active tag (as Identifie Dby getthreadstatstag ()). These APIs correctly Tag/untag socketswhen recycled through keep-alive pools. In the following Example, setthreadstatstag ()  sets, the active tag to be 0xf00d. There can only be one active tag perthread. That's the value that would be returned By getthreadstatstag ()  and thus used Byhttpclient to tagsockets. The finally statementinvokes clearthreadstatstag ()  to clear the tag.

Trafficstats.setthreadstatstag (0xf00d);
try {
Make network request using Httpclient.execute ()
} finally{
Trafficstats.clearthreadstatstag ();
}

Socket Taggingis supported in Android 4.0, but real-time stats would only be displayed ondevices running Android 4.0.3 or H Igher.

Using Logcat

Logcat is integrated into the DDMS, and he prints out the messages you use to print messages and other systems using the log class, such as the stack element when an exception occurs. For more information on how to output logs to Logcat, refer to Reading and Writing log Messages.

When you have set up your log, you can use Ddms's Logcat feature to filter specific messages using the following buttons:

· Verbose

· Debug

· Info

· Warn

· Error

You can also set up your own filter custom filter for more details, such as using log tag to filter logs, or to generate a log PID to filter logs. The Add Filter,edit filter, and the Delete filter button allow you to manage these custom filters.

Analog phone operation and location

The Emulator control page allows you to simulate the voice and network status of your phone. It can be very useful when you want to test the robustness of your application in different network environments.

Change the state, speed, and latency of the network

The Telephony status area of the Emulatorcontrols page allows you to change the status, speed, and latency of your mobile network. You can apply the following options, once set, to take effect immediately:

· Voice-unregistered, home, roaming, searching, denied

· Data-unregistered, home, roaming, searching, denied

· Speed-full, GSM, HSCSD, GPRS, EDGE, UMTS, HSDPA

· Latency-gprs, EDGE, UMTS

Analog calls or texting

The telephony actions area of the Emulatorcontrols page simulates calling and texting. It can be very useful when you want to test the robustness of an app when it receives a call or text message. You can do the following actions:

· Voice-Enter a number in the Incoming numbers field, click on the call to the simulator or phone. Click The Hang up button to disconnect.

· sms-Enter a number in the incomingnumber field, enter a text message in the message field, click the Send button, and send a text message.

Set the phone's location information

If your app depends on where your phone is located, you can have DDMS send a fake location to your device or to the simulator. This can be useful when you want to test the location-based features of your application without physically moving the location. The following geographic data types are supported:

· Manual-set the location by manually specifying Decimalor sexagesimal longitude and latitude values.

· Gpx-gps eXchange File

· Kml-keyhole Markup Language File

· Manual-Manually set the latitude and longitude of floating-point numbers

· Gpx-gps Exchange Files

· KML-KML file

For more information on Providingmock location data, see location strategies.

For more information on providing mock position data, refer to: Location strategies.

Attention:

DDMS generated memory dump file cannot be opened directly with the Mat tool, it will prompt the file format is not supported. Required Conversions:

(1) Run CMD,CD to D:\tools\android-sdk\tools directory

(2) Input command Hprof-conv xxxx.hprof yyyy.hprof

Xxxx.hprof is the original file, Yyyy.hprof is the converted file (also generated in the D:\tools\android-sdk\tools directory)

(3) OK,. hprof File Conversion complete

Reference: http://blog.csdn.net/jingwen3699/article/details/7977275

Android-using DDMS

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.