Android DDMS如何使用

article/2025/10/13 22:55:56
               

Android DDMS如何使用?

By: 海市蜃楼 | In: Android开发

112009

DDMS 的全称是Dalvik Debug Monitor Service,它为我们提供例如:为测试设备截屏,针对特定的进程查看正在运行的线程以及堆信息、Logcat、广播状态信息、模拟电话呼叫、接收SMS、虚拟地理坐标等等。

如何启动 DDMS

DDMS 工具存放在SDK – tools/路径下,启动DDMS方法如下:

  1. 直接双击ddms.bat运行;
  2. 在Eclipes调试程序的过程中启动DDMS,在Eclipes中的界面如下:
    Eclipes-DDMS
    选择“Other”,界面如下:
    Open-Perspective
    双击DDMS就可以启动了。

DDMS对Emulator和外接测试机有同等效用。如果系统检测到它们(VM)同时运行,那么DDMS将会默认指向 Emulator。以上2种启动后的操作有些不一样,建议分别尝试下。

DDMS 的工作原理

DDMS将搭建起IDE与测试终端(Emulator 或者connected device)的链接,它们应用各自独立的端口监听调试器的信息,DDMS可以实时监测到测试终端的连接情况。当有新的测试终端连接后,DDMS将捕捉到终端的ID,并通过adb建立调试器,从而实现发送指令到测试终端的目的。
DDMS-Device
DDMS监听第一个终端App进程的端口为8600,APP进程将分配8601,如果有更多终端或者更多APP进程将按照这个顺序依次类推。DDMS通过8700端口(”base port”)接收所有终端的指令。

下边通过GUI详细了解DDMS的一些功能

Devices

在GUI的左上角可以看到标签为”Devices”的面板,这里可以查看到所有与DDMS连 接的终端的详细信息,以及每个终端正在运行的APP进程,每个进程最右边相对应的是与调试器链接的端口。因为Android是基于Linux内核开发的操 作平台,同时也保留了Linux中特有的进程ID,它介于进程名和端口号之间。
DDMS-Device
在面板的右上角有一排很重要的按键他们分别是Debug the selected process、Update Threads、Update Heap、Stop Process和ScreenShot。

Emulator Control

通过这个面板的一些功能可以非常容易的使测试终端模拟真实手机所具备的一些交互功能,比如:接听电话,根据选项模拟各种不同网络情况,模拟接受SMS消息和发送虚拟地址坐标用于测试GPS功能等。
DDMS-Control
Telephony Status: 通过选项模拟语音质量以及信号连接模式。
Telephony Actions: 模拟电话接听和发送SMS到测试终端。
Location Control: 模拟地理坐标或者模拟动态的路线坐标变化并显示预设的地理标识,可以通过以下3种方式:

  • Manual: 手动为终端发送二维经纬坐标。
  • GPX: 通过GPX文件导入序列动态变化地理坐标,从而模拟行进中GPS变化的数值。
  • KML: 通过KML文件导入独特的地理标识,并以动态形式根据变化的地理坐标显示在测试终端。

Threads、Heap、File Exporler

DDMS-THF
这几项,我们在其他开发工具中也经常使用,就在不此详细说明了。通过File Exporler可以查看Android模拟器中的文件,可以很方便的导入/出文件。

Locate、Console

DDMS-LC
Locate:显示输出的调试信息,详见Android下如何调试程序?;
Console:是Android模拟器输出的信息,加载程序等信息;

使用DDMS模拟发送短信,操作过程如下:

在Emulator Control\Telephony Actions 中输入以下内容
DDMS-SMS
单击发送后,在Android模拟器中打开Messaging,看到下面的短信:
DDMS-Message
单击新短信,详细查看短信内容:
AVD-Message
中文显示为乱码,在未来的开发中,我们必须要注意中文字符的问题。

总结说明

DDMS是我们开发人员最好的调试工具,它将是每个从事Android开发的人员都不可缺少的。


Using DDMS

IN THIS DOCUMENT

  1. Running DDMS
  2. How DDMS Interacts with a Debugger
  3. Using DDMS
    1. Viewing heap usage for a process
    2. Tracking memory allocation of objects
    3. Working with an emulator or device's file system
    4. Examining thread information
    5. Starting method profiling
    6. Using the Network Traffic tool
    7. Using LogCat
    8. Emulating phone operations and location

Android ships with a debugging tool called the Dalvik Debug Monitor Server (DDMS), which provides port-forwarding services, screen capture on the device, thread and heap information on the device, logcat, process, and radio state information, incoming call and SMS spoofing, location data spoofing, and more. This page provides a modest discussion of DDMS features; it is not an exhaustive exploration of all the features and capabilities.

Running DDMS


DDMS is integrated into Eclipse and is also shipped in the tools/ directory of the SDK. DDMS works with both the emulator and a connected device. If both are connected and running simultaneously, DDMS defaults to the emulator.

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

How DDMS Interacts with a Debugger


On Android, every application runs in its own process, each of which runs in its own virtual machine (VM). Each VM exposes a unique port that a debugger can attach to.

When DDMS starts, it connects to adb. When a device is connected, a VM monitoring service is created between adb and DDMS, which notifies DDMS when a VM on the device is started or terminated. Once a VM is running, DDMS retrieves the VM's process ID (pid), via adb, and opens a connection to the VM's debugger, through the adb daemon (adbd) on the device. DDMS can now talk to the VM using a custom wire protocol.

DDMS assigns a debugging port to each VM on the device. Typically, DDMS assigns port 8600 for the first debuggable VM, the next on 8601, and so on. When a debugger connects to one of these ports, all traffic is forwarded to the debugger from the associated VM. You can only attach a single debugger to a single port, but DDMS can handle multiple, attached debuggers.

By default, DDMS also listens on another debugging port, the DDMS "base port" (8700, by default). The base port is a port forwarder, which can accept VM traffic from any debugging port and forward it to the debugger on port 8700. This allows you to attach one debugger to port 8700, and debug all the VMs on a device. The traffic that is forwarded is determined by the currently selected process in the DDMS Devices view.

The following screenshot shows a typical DDMS screen in Eclipse. If you are starting DDMS from the command line, the screen is slightly different, but much of the functionality is identical. Notice that the highlighted process,com.android.email, that is running in the emulator has the debugging port 8700 assigned to it as well as 8606. This signifies that DDMS is currently forwarding port 8606 to the static debugging port of 8700.

Figure 1. Screenshot of DDMS

If you are not using Eclipse and ADT, read Configuring your IDE to attach to the debugging port, for more information on attaching your debugger.

Tip: You can set a number of DDMS preferences in File > Preferences. Preferences are saved to$HOME/.android/ddms.cfg.

Known debugging issues with Dalvik
Debugging an application in the Dalvik VM should work the same as it does in other VMs. However, when single-stepping out of synchronized code, the "current line" cursor may jump to the last line in the method for one step.

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:

  1. In the Devices tab, select the process that you want to see the heap information for.
  2. Click the Update Heap button to enable heap information for the process.
  3. 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.
  4. 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.

To track memory allocation of objects:

  1. In the Devices tab, select the process that you want to enable allocation tracking for.
  2. In the Allocation Tracker tab, click the Start Tracking button to begin allocation tracking. At th

http://chatgpt.dhexx.cn/article/qIG25apT.shtml

相关文章

Android studio如何使用DDMS

Android studio如何使用DDMS 一、启动AS 1.首先查看AS 的SDK路径。 二、启动DDMS 1.进入到D:\software\SDK目录下的tools文件夹中,找到monitor.bat批量处理文件。 2.鼠标左键双击monitor.bat批量处理文件,会出现类似cmd的输入面板,然后会迅速自动关闭。再等几秒钟会出…

搭建ddms环境

搭建ddms环境 参考地址:https://blog.csdn.net/songyi160/article/details/53107245 直接打开sdk目录中 F:\Android\sdk\tools\monitor.bat 打开模拟器,启动一个app,打开monitor.bat

ddms权限解决

本期给大家带来的是解决DDMS无法查看/data目录问题。1.为什么我们要进入ddms,这里我知道的现在--files explorer,这个菜单下,是属于模拟机的根目录一类的。就是存下东西。2.但是有些模拟器会出现文件无法查看,导入,导出&#xff0…

Android Studio DDMS

DDMS(Dalvik Debug Monitor Service) 是 Android 开发环境中的Dalvik虚拟机调试监控服务。 AS 3.3 工具箱里面 DDMS,实际上3.X以后这个工具已被替代了,有Layout Inspector布局的调试,Android Profiler 测量应用性能 如…

ddms java 截图,DDMS 那些事

谈到安卓应用优化,不得不提一个工具——DDMS,DDMS的主要作用就是检测一段时间内cpu的占用率,精确到各个方法的占用时间,通过DDMS发现主线程被过分阻塞的方法,找到这些容易阻塞主线程的方法,可以通过合理的子…

DDMS工具使用

往期推荐 快速定位关键代码 Smali文件详解 Java层逆向分析-Dalvik字节码 修改资源去广告 1.DDMS工具的介绍 DDMS的全称是Dalvik Debug Monitor Service,是Android开发环境中的Dalvik虚拟机调试监控服务。 DDMS的作用是提供截屏,查看线程和堆的信息&#xff0c…

DDMS打开路径

路径:已下载到本地的Sdk目录中,sdk\sdk-tools-windows-3859397\tools\lib\monitor-x86_64/monitor.exe 打开monitor.exe,即打开ddms,连接手机设备,打开应用,即可看到对应的日志

DDMS使用

安装 Android studio 自带 设置debug 链接:https://pan.baidu.com/s/1wQbeG8K4bevOMpd6lhaw9A 提取码:x9fr 用magisk刷入 开启debug 不然不显示进程 设置 ro.debuggable1 设置 ro.secure0 https://blog.csdn.net/jinmie0193/article/details/1113558…

ddms工具使用以及案例

ddms工具使用以及案例 ddms的主要用途,就是查看app的各种输出,尤其是日志的输出和方法剖析 工具准备 环境配置连接:https://blog.csdn.net/tianyi19/article/details/115335951 用到的apk 链接:https://pan.baidu.com/s/1rAONbtafSYos-IKHddQw2w 提取码&#x…

DDMS工具的使用

1、DDMS工作原理 DDMS是IDE与测试终端的桥梁,它实时监测到测试终端的连接情况,当有新的测试终端连接后,DDMS将捕捉到终端的ID,并通过adb建立调试器,从而实现发送指令到测试终端的目的。 2、DDMS主要作用 1&#xff0…

DDMS全解

DDMS 的全称是 Dalvik Debug Monitor Service, 它为我们提供例如:为测试设备截屏、针对特定的进程查看正在运行的线程以及堆信息、Logcat、 广播状态信息、模拟电话呼叫、接收SMS、虚拟地理坐标等等。 一、如何启动 DDMS DDMS 工具存放在 SDK 的 tools 路…

Android开发调试必备 - DDMS

一、真机调试的两个必备条件 (1)手机打开开发者模式并且运行USB调试 (2)PC上装好手机对应的驱动(现在的安卓手机连接电脑一般都需要安装驱动,让电脑能够驱动安卓手机) 二、DDMS(DalvikDebugMonitorServer)四个主要窗口 Devices&#xff1a…

旧版Xcode8.3.3.xip解压时提示『归档不是来自Apple』填坑

百度结果 几乎全是: 1.保证存储空间 20G 2.去除解压验证 xattr -d com.apple.quarantine Xcode_8_beta.xip 3.双击解压 然而试了并不行,因为验证早已经关了。 最后解决是: 证书过期,把系统日期改为前几年解决问题。

apple Xcode xip安装

1.保证存储空间 20G 2.去除解压验证 xattr -d com.apple.quarantine Xcode_8_beta.xip 3.双击解压 压缩后,打本地目录,双击。开始安装。

Mac实用小技巧之解压(.xip)文件

Mac下解压(.xip)文件 在安装Xcode的时候,我从官网下载了一个Xcode的安装文件,但是这个文件是(.xip)压缩文件,我使用了很多解压软件,都没有解压成功,最后上网查看,大家推荐了一种方法 “通用”里有时没有“任…

安装Xcode的xip安装包的一些注意事项

需求场景 需要同时安装多个 Xcode 时需要安装较老版本 Xcode 时 下载地址 https://developer.apple.com/download/more/ 注意事项 1. 安全性 打来安全和隐私中的任何来源 高版本系统没有显示的情况下,可以终端输入:sudo spctl --master-disable 2. 去除解压验证…

ARM Linux 的XIP还是挺好用的

MergeFile下载(微软SkyDrive):http://cid-a0a942ebd8c6c3b5.office.live.com/self.aspx/.Documents/MergeFiles.rar 一般来说,现在的ARM Linux嵌入式系统都是将Image拷贝到SDRAM中进行运行的标准方式,尤其是像S3C6410和…

macOS Mojave 解压xip失败的问题

写这个博客主要是记录最近更新 macOS 10.14 和升级了Xcode10后要重新下载一个旧版的Xcode所踩的坑。 1、首先要打开通用的任何来源这个选项: 发现提示“xxxxxx 已损坏,打不开。” (很多破解版的软件安装不成功就是这个问题) 是因为macOS Sier…

ESP32系列--存储器类型和XIP特性

一、目的 当我们通过ESP-IDF开发ESP32时,可能会遇到类似这样的场景需要对某个函数的执行速度进行优化例如中断执行函数需要快入快出,那么应该怎么做呢,ESP-IDF里面有没有提供这样的方法或者机制呢? 按照常识我们总认为内部SRAM的读…

Raspberry Pi Pico SDK开发-Flash-XIP

Flash-XIP RP2040 由 Raspberry Pi 设计,具有双核 Arm Cortex-M0+ 处理器和 264KB 内部 RAM,并支持高达 16MB 的片外闪存。 广泛的灵活 I/O 选项包括 I2C、SPI 和独特的可编程 I/O (PIO)。 本实例将演示如何使用Flash。 1、Flash-XIP介绍 RP2040使用就地执行 (execute-in-…