移动测试基础 DDMS 中生成 Trace 的方法原理是什么

思寒_seveniruby · 2014年11月08日 · 最后由 思寒_seveniruby 回复于 2014年11月08日 · 1175 次阅读

http://developer.android.com/tools/debugging/debugging-tracing.html

There are two ways to generate trace logs:

第一种
Include the Debug class in your code and call its methods such as startMethodTracing() and stopMethodTracing(), to start and stop logging of trace information to disk. This option is very precise because you can specify exactly where to start and stop logging trace data in your code.

第二种
Use the method profiling feature of DDMS to generate trace logs. This option is less precise because you do not modify code, but rather specify when to start and stop logging with DDMS. Although you have less control on exactly where logging starts and stops, this option is useful if you don't have access to the application's code, or if you do not need precise log timing.

我好奇的是第二种方法, 他底层的原理是什么, 大家有了解的吗?
是通过往 ADB 或者 JDB 发送什么指令吗?

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
共收到 2 条回复 时间 点赞

看了下代码, 是读取的 ddmlib,jar 来做控制的.
http://www.netmite.com/android/mydroid/2.0/dalvik/docs/debugger.html

adb jdwp 显示所有可供调试的用户进程
使用本地端口号连接到终端的给定进程:
adb forward tcp:xxx jdwp:
直接使用本机绑定的通讯端口,不指定进程
jdb -connect com.sun.jdi.SocketAttach:hostname=localhost,port=xxx

adb jdwp 估计是如下的命令封装
% adb forward tcp:8000 tcp:8000
% adb shell dalvikvm -agentlib:jdwp=transport=dt_socket,address=8000,suspend=y,server=y -cp /data/foo.jar Foo
and then jdb -attach localhost:8000.

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册