Android---adb的常见命令操作

来源:互联网 发布:徐州网络推广学校 编辑:程序博客网 时间:2024/05/22 00:03

Android开发中比较常用的adb命令。


1.adb shell dumpsys meminfo + 包名

查看该包名应用的内存


2.adb shell top -m + 数字

查看应用内存占用率,其中数字为返回的应用数量,从高到低排序


3.adb shell回车

cd /sys/devices/system/cpu/cpu0/cpufreq回车

cat cpuinfo_cur_freq

查看当前CPU的主频(貌似需要一定的访问权限)


4.adb install <apk路径>

安装apk到手机/虚拟机


5.adb logcat

抓取设备的log信息,可以自行添加过滤条件,详细的可以参见这篇文章

http://www.hanshuliang.com/?post=32

这里“引用”一些常见的吧

1. 解析 adb logcat 的帮助信息

在命令行中输入 adb logcat --help 命令, 就可以显示该命令的帮助信息;

[plain] view plaincopy在CODE上查看代码片派生到我的代码片
  1. octopus@octopus:~$ adb logcat --help  
  2. Usage: logcat [options] [filterspecs]  
  3. options include:  
  4.   -s              Set default filter to silent.  
  5.                   Like specifying filterspec '*:s'  
  6.   -f <filename>   Log to file. Default to stdout  
  7.   -r [<kbytes>]   Rotate log every kbytes. (16 if unspecified). Requires -f  
  8.   -n <count>      Sets max number of rotated logs to <count>, default 4  
  9.   -v <format>     Sets the log print format, where <format> is one of:  
  10.   
  11.                   brief process tag thread raw time threadtime long  
  12.   
  13.   -c              clear (flush) the entire log and exit  
  14.   -d              dump the log and then exit (don't block)  
  15.   -t <count>      print only the most recent <count> lines (implies -d)  
  16.   -g              get the size of the log's ring buffer and exit  
  17.   -b <buffer>     Request alternate ring buffer, 'main', 'system', 'radio'  
  18.                   or 'events'. Multiple -b parameters are allowed and the  
  19.                   results are interleaved. The default is -b main -b system.  
  20.   -B              output the log in binary  
  21. filterspecs are a series of   
  22.   <tag>[:priority]  
  23.   
  24. where <tag> is a log component tag (or * for all) and priority is:  
  25.   V    Verbose  
  26.   D    Debug  
  27.   I    Info  
  28.   W    Warn  
  29.   E    Error  
  30.   F    Fatal  
  31.   S    Silent (supress all output)  
  32.   
  33. '*' means '*:d' and <tag> by itself means <tag>:v  
  34.   
  35. If not specified on the commandline, filterspec is set from ANDROID_LOG_TAGS.  
  36. If no filterspec is found, filter defaults to '*:I'  
  37.   
  38. If not specified with -v, format is set from ANDROID_PRINTF_LOG  
  39. or defaults to "brief"  

adb logcat 命令格式 : adb logcat [选项] [过滤项], 其中 选项 和 过滤项 在 中括号 [] 中, 说明这是可选的;


选项解析 : 

-- "-s"选项 : 设置输出日志的标签, 只显示该标签的日志;

--"-f"选项 : 将日志输出到文件, 默认输出到标准输出流中, -f 参数执行不成功;

--"-r"选项 : 按照每千字节输出日志, 需要 -f 参数, 不过这个命令没有执行成功;

--"-n"选项 : 设置日志输出的最大数目, 需要 -r 参数, 这个执行 感觉 跟 adb logcat 效果一样;

--"-v"选项 : 设置日志的输出格式, 注意只能设置一项;

--"-c"选项 : 清空所有的日志缓存信息;

--"-d"选项 : 将缓存的日志输出到屏幕上, 并且不会阻塞;

--"-t"选项 : 输出最近的几行日志, 输出完退出, 不阻塞;

--"-g"选项 : 查看日志缓冲区信息;

--"-b"选项 : 加载一个日志缓冲区, 默认是 main, 下面详解;

--"-B"选项 : 以二进制形式输出日志;

输出指定标签内容 : 

 "-s"选项 : 设置默认的过滤器, 如 我们想要输出 "System.out" 标签的信息, 就可以使用adb logcat -s System.out 命令;

[plain] view plaincopy在CODE上查看代码片派生到我的代码片
  1. octopus@octopus:~$ adb logcat -s System.out  
  2. --------- beginning of /dev/log/system  
  3. --------- beginning of /dev/log/main  
  4. I/System.out(22930): GSM -91  
  5. I/System.out(22930): SignalStrength issssssssss : -91  
  6. I/System.out(22930): GSM -91  
  7. I/System.out(22930): SignalStrength issssssssss : -91  
  8. I/System.out(22930): Supervisor Thread  
  9. I/System.out(22930): Got run mode  

(2) 过滤项解析 


过滤项格式 : <tag>[:priority] , 标签:日志等级, 默认的日志过滤项是 " *:I " ;

-- V : Verbose (明细);

-- D : Debug (调试);

-- I : Info (信息);

-- W : Warn (警告);

-- E : Error (错误);

-- F: Fatal (严重错误);

-- S : Silent(Super all output) (最高的优先级, 可能不会记载东西);

过滤指定等级日志 : 使用 adb logcat 10 *:E 命令, 显示 Error 以上级别的日志;

[plain] view plaincopy在CODE上查看代码片派生到我的代码片
  1. octopus@octopus:~$ adb logcat *:E  
  2.   
  3. Note: log switch off, only log_main and log_events will have logs!  
  4. --------- beginning of /dev/log/main  
  5. E/WifiHW  (  441): wifi_send_command : SCAN_RESULTS ; interface index=0;  
  6. E/WifiHW  (  441): wifi_send_command : AP_SCAN 1 ; interface index=0;  
  7. E/WifiHW  (  441): wifi_send_command : SCAN_RESULTS ; interface index=0;  
  8. E/dalvikvm(  756): GC_CONCURRENT freed 1809K, 27% free 19489K/26695K, paused 16ms+5ms, total 109ms  
  9. E/WifiHW  (  441): wifi_send_command : SCAN ; interface index=0;  
  10. E/WifiHW  (  441): wifi_send_command : AP_SCAN 1 ; interface index=0;  
  11. E/WifiHW  (  441): wifi_send_command : SCAN_RESULTS ; interface index=0;  
  12. E/dalvikvm(  756): GC_CONCURRENT freed 1820K, 27% free 19490K/26695K, paused 16ms+3ms, total 102ms  
  13. E/WifiHW  (  441): wifi_send_command : AP_SCAN 1 ; interface index=0;  
  14. E/WifiHW  (  441): wifi_send_command : SCAN_RESULTS ; interface index=0;  

过滤指定标签等级日志 : 使用 adb logcat WifiHW:D *:S 命令进行过滤;

-- 命令含义 : 输出10条日志, 日志是 标签为 WifiHW, 并且优先级 Debug(调试) 等级以上的级别的日志;

--注意 *:S : 如果没有 *S 就会输出错误;

[plain] view plaincopy在CODE上查看代码片派生到我的代码片
  1. octopus@octopus:~$ adb logcat WifiHW:D *:S  
  2.   
  3. Note: log switch off, only log_main and log_events will have logs!  
  4. --------- beginning of /dev/log/main  
  5. E/WifiHW  (  441): wifi_send_command : SCAN_RESULTS ; interface index=0;  
  6. E/WifiHW  (  441): wifi_send_command : AP_SCAN 1 ; interface index=0;  
  7. E/WifiHW  (  441): wifi_send_command : SCAN_RESULTS ; interface index=0;  
  8. E/WifiHW  (  441): wifi_send_command : AP_SCAN 1 ; interface index=0;  
  9. E/WifiHW  (  441): wifi_send_command : SCAN_RESULTS ; interface index=0;  
  10. E/WifiHW  (  441): wifi_send_command : AP_SCAN 1 ; interface index=0;  
  11. E/WifiHW  (  441): wifi_send_command : SCAN_RESULTS ; interface index=0;  

可以同时设置多个过滤器 : 使用adb logcat WifiHW:D dalvikvm:I *:S 命令, 输出 WifiHW 标签 的 Debug 以上级别 和 dalvikvm 标签的 Info 以上级别的日志;

[plain] view plaincopy在CODE上查看代码片派生到我的代码片
  1. octopus@octopus:~$ adb logcat WifiHW:D dalvikvm:I *:S   
  2.   
  3. Note: log switch off, only log_main and log_events will have logs!  
  4. --------- beginning of /dev/log/main  
  5. E/WifiHW  (  441): wifi_send_command : AP_SCAN 1 ; interface index=0;  
  6. E/WifiHW  (  441): wifi_send_command : SCAN_RESULTS ; interface index=0;  
  7. E/dalvikvm(  756): GC_CONCURRENT freed 1820K, 27% free 19490K/26695K, paused 17ms+2ms, total 110ms  
  8. E/WifiHW  (  441): wifi_send_command : AP_SCAN 1 ; interface index=0;  
  9. E/WifiHW  (  441): wifi_send_command : SCAN_RESULTS ; interface index=0;  
  10. E/WifiHW  (  441): wifi_send_command : AP_SCAN 1 ; interface index=0;  
  11. E/WifiHW  (  441): wifi_send_command : SCAN_RESULTS ; interface index=0;  
  12. E/dalvikvm(  756): GC_CONCURRENT freed 1810K, 27% free 19489K/26695K, paused 17ms+5ms, total 108ms  
  13. E/WifiHW  (  441): wifi_send_command : AP_SCAN 1 ; interface index=0;  
  14. E/WifiHW  (  441): wifi_send_command : SCAN_RESULTS ; interface index=0;  

原创粉丝点击