adb shell 명령어

|

시스템 기본정보: 하드웨어, 커널 등
cat /proc/version : 커널 버전
cat /proc/cpuinfo : 프로세서 정보, CPU타입, 모델 제조사 등
cat /porc/meminfo : 메모리 정보, 실제 메모리 및 가상 메모리
cat /proc/devices : 현재 커널에 설정되어 있는 장치 목록
mount : 마운트된 모든 장치 정보
df : 하드디스크 사용량
cat /porc/filesystems : 커널에 설정되어 있는 파일시스템 목록
cat /proc/swaps : 스왑 파티션의 크기와 사용량
cat /proc/interrupts : 장치가 사용중인 인터럽트(IRQ)목록 표시
cat /proc/ioports : 현재 사용중인 input/output 포트
cat /proc/partitions : 파티션 정보
cat /proc/uptime : 시스템이 얼마나 살아있었는지
cat /proc/stat : 시스템 상태에 관한 다양한 정보, CPU 사용 통계, 부팅이후 page fault 발생 횟수 등
cat /proc/zoneinfo : ZONEINFO
dmesg : 시스템 부팅시 나왔던 메시지
ps : 실행중인 프로세스 정보
ps -p - t : 프로세스와 쓰레드 목록
set or printenv : 환경설정값 출력


시스템 리소스 사용 현황
vmstat : 시스템 리소스 상황 모니터, CPU, I/O, Memory 등
cat /proc/diskstats : 디스크 utilization과 throughput. 즉 디스크 I/O현황
top : 시스템 프로세스 상황 모니터링/ 프로세스별 CPU사용량, 메모리와 스왑 사용량 등
procrank : 프로세스별 메모리
dumpsys meminfo [PID] : 해당 프로세스 메모리 상세 정보
cat /proc/[PID]/stat : 해당 프로세스에 대한 정보, 시작시간, 상태, CPU 사용량 등
cat /proc/[PID]/maps : 해당 프로세스의 메모리 맵 정보
cat /proc/vmstat : 버추얼 메모리 통계?
librank : 라이브러리별 메모리 사용량?


네트워크 관련
cat /proc/net/netlink : 네트워크 정보
netcfg : 네트워크 인터페이스와 IP주소 목록
netstat : 네트워크 연결상태 확인
nc : 네트워크용 cat 명령어(netcat)
ifconfig : 네트워크 인터페이스 설정 정보. 장치명을 파라미터로 받음. ip 주소. 서브넷마스크 등
tcpdump : 실시간 패킷 모니터링
iftop : 네트워크를 위한 top
route : 해당 호스트까지 연결하는 중간 경로 정보인 라우팅 테이블 표시
ping : 원격 호스트와의 연결 테스트
cat /proc/net/route : Route


안드로이드 제공
logcat : 로그캣 보기
pm : package manager의 약자. 패키지/permission/instrumentation/feature 목록, 패키지 설치/제거 등
am : activity manager의 약자, 액티비티 시작, Intent 브로드캐스팅, Instrumentation 시작, profiling 시작 / 중지 등
service : 안드로이드 서비스 목록 표시, 서비스에 명령 전달
monkey : 애플리케이션에 랜덤 이벤트 발생시킴. 사용자 이벤트, 시스템 이벤트의 무작위 발행
cat /data/anr/traces.txt : VM TRACES (쓰레드 덤프)
cat /proc/binder/proc/[PID] : 바인더 프로세스 상태
cat /proc/binder/xxx : 바인더 관련 정보(xxx은 transaction, transaction_log, failed_transaction_log, stats 등)
cat /data/system/packages.xml : 설치된 패키지 세팅 정보
setprop : system property 셋팅
getprop : 셋팅된 system property 목록 출력


종합 리포트
dumpsys [service] : app/service 상태정보 덤프, 서비스별로 추가 파라미터 받을 수 있음
dumpstate : device 상태정보 덤프. 상태정보를 추출하는 여러 명령어들의 조합으로 구성
dumpcrash : 애플리케이션이 crach될 때의 상태정보 덤프
bugreport : logcat + dumpsys + dumpstat

그 밖에...
그 밖의 안드로이드 shell 명령어는 /system/bin 및 /system/xbin을 뒤져보면 많이 나온다. 이제 남은 일은 찾아낸 명령어의 사용법, 출력결과를 어떻게 해석할지, 어떤 상황에서 이들을 활용할지 사례조사, 그리고 직접 활용해보는 것이다.

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

ADB (Android Debug Bridge)




ADB의 구성


client : development machine에서 동작. shell에서 client를 invocation해서 command 실행 가능. ADT, DDMS도 client


server : development machine의 background process이며, client와 daemon 사이에서의 communication을 관리


daemon : 각각의 device에서 동작하는 background process


client를 시작하면, ADB server가 실행중인지 확인해서 실행중이지 않으면 server를 시작시킨다. server가 시작되면 TCP의 5037 port로 binding해서 adb client로부터의 command를 받아들이는데, 모든 client는 server와 communication 하기 위해 5037 port를 사용.


실행파일 : ${android_sdk_path}/tools/adb




Command 입력 형식


adb [-d | -e | -s <serialNumber>] <command>


adb devices : adb server와 연결된 device를 보여준다.
형식 : [serialNumber] [state]


serialNumber = type-consolePort (ex : emulator-5554)
state = offline (device가 adb와 아직 연결되지 않았거나 응답이 없는 상태)
            device (adb server와 연결된 상태)


-s option : 여러개의 device가 연결되어 있는 상태에서 특정 device에 command를 입력하고 싶을 때 사용

형식

adb -s <serialNumber> <command>


ex : adb -s emulator-5554 install sample.apk




Port forwarding


device의 port를 forwarding 하고 싶을 때 사용하는 명령

ex : port 6100에서 7100으로 forwarding 하고 싶은 경우
adb forward tcp:6100 tcp:7100




Copying files


pull
device에서 file을 copy해 올 때 사용 (recursively)
adb pull <remote> <local>


push
pull과 반대로 file을 device에 복사해 넣고 싶을 때 사용 (recursively)

adb push <local> <remote>

ex : adb push foo.txt /sdcard/foo.txt) (/sdcard/foo.txt 에서 /sdcard는 device에 존재하는 path




Listing of adb Commands


Options

-d
연결된 USB device에만 direct로 command 전송

USB device가 하나 이상이면 error return

-e
실행중인 device에만 command 전송
하나 이상의 device가 실행중이면 error return


-s <serialNumber>
특정 device에만 command 전송 (serialNumber 형식은 위 내용 참조)



General


devices
연결된 모든 device list 출력


help
제공되는 adb command list 출력


version
adb version 출력



Debug


logcat [<option>] [<filter-specs>]

log data 출력


bugreport

bugreport를 위한 dumpsys(system data dump), dumpstate(state dump), logcat data 출력


jdwp

특정 device의 JDWP process들의 list(pid) 출력



Data

install <path-to-apk>
application 설치


pull <remote> <local>
push <local> <remote>
위 내용 참조



Ports and Networking

forward <local> <remote>
특정 local port를 remote port로 fowarding
Scheme
tcp:<portnum>
local:<UNIX domain socket name>
dev:<character device name>
jdwp:<pid>


ppp <tty> [parm]...
USB로 PPP 실행
<tty> : PPP stream을 위한 tty
[parm] : PPP option



Scripting


get-serialno
adb의 serial number 출력


get-state

adb의 state 출력 (device / offline)


wait-for-device

device가 online일 때 까지 command 실행 정지


ex : adb wait-for-device shell getprop (state가 device가 되면 shell getprop command 실행


Note : 완전히 boot 된 이후에 사용 가능한 install 등의 command를 함께 사용할 경우 wait-for-device는 device state만 확인하므로 fully boot 되지 않았을 경우 error 발생 가능



Server

start-server
adb server가 실행중인지 확인해서 running 상태가 아니면 실행


kill-server
adb server process를 종료



Shell


shell
target device 안에서 remote shell을 시작


shell [<shellCommand>]
target device 안에서 shell command를 실행하고 remote shell을 빠져나간다




Shell Command 실행


ADB는 ash shell을 제공하는데, ash shell의 실행 바이너리는 device 내부의 /system/bin 경로에 존재


adb [-d | -e | -s <serialNumber>] shell로 remote shell을 실행한 후에 shell을 종료하고 싶으면 Ctrl + D or exit 입력



UI/Application Exerciser Monkey


User event의 random stream을 생성해 device에서 실행시키는 tool (stress test 용도)

ex : adb shell monkey -v -p packageName 500 (500가지의 random stream)




Other Shell Commands

device의 /system/bin 경로의 file들을 살펴보거나, adb -help로 확인


dumpsys
system data의 dump를 표시


dumpstate
state의 dump를 file로 저장


logcat [<option>]...[<filter-spec>]

logging을 가능하게 하거나 화면에 표시


dmesg
kernel debugging message를 화면에 출력


start
device를 시작(재시작)


stop
device 종료




Using logcat Commands

adb logcat
단순히 전체 log를 보고싶은 경우 사용 또는 remote shell에서 logcat 실행


Android에서 모든 log message는 tag와 priority를 가지고 있음

tag : system component를 짧은 문자열로 표현 (ex : view system의 경우 "View")
priority (ordered from lowest to highest)
V (Verbose)
D (Debug)
I (Info)
W (Warning)
E (Error)
F (Fatal)
S (Silent)


logcat 실행 후에 나타나는 log message에서 tag와 priority가 첫 column에 priority/tag 형태로 표시

ex : I/ActivityManager( 585) : Starting activity : Intent { action = android.intent.action... }


logcat의 filter는 tag:priority 형태로 표현하는데 tag는 표시하려는 tag의 이름을 입력하면 되고 입력한 priority와 상위 priority의 log들을 표시


ex : adb logcat ActivityManager:I MyApp:D *:S
ActivityManager의 I(Info) level 이상, MyApp의 D(Debug) level 이상의 log들만 표시



default filter expression

환경변수 ANDROID_LOG_TAGS에 default로 사용할 filter expression을 setting 후에 export 해서 사용


ex : export ANDROID_LOG_TAGS="ActivityManager:I MyApp:D *:S"


Note : remote shell을 사용해서 logcat을 실행하고 있을 경우 export 되지 않음 (?)



Controlling Log Output Format


-v option을 사용해서 출력되는 log의 format 변경 가능

output format
brief : priority/tag, PID 표시 (default)
process : PID only
tag : priority/tag only
thread : process:thread, priority/tag only
raw : 다른 metadata field 없이 raw log message 표시
time : date, invocation time, priority/tag, PID
long : 모든 metadata filed와 message 표시


ex : adb logcat -v thread


Viewing Alternative Log Buffers


Android logging system은 log message들을 위해 여러 개의 circular buffer를 가지고 있고 default circular buffer가 모든 log를 보관하지 않기 때문에 다른 circular log buffer의 내용을 보고 싶을 때에는 -b option을 사용해서 circular buffer를 변경해주어야 한다.

Buffers
radio : radio/telephony 관련된 log message를 보관하는 buffer
events : related-events
main : main log buffer (default)


ex : adb logcat -b radio




Viewing stdout and stderr

Android에서는 default로 stdout과 stderr ouput을 /dev/null로 내보내는데, file에 쓰도록 변경 가능하고 이 경우 변경 전에 device를 stop 후 setprop shell command를 실행해서 redirection 설정해야 한다. device start 이후에는 stop 전까지 설정이 유지된다. default로 설정을 유지하고 싶다면, /data/local.prop에 기록

ex :

adb shell stop
adb shell setprop log.redirect-stdio true
adb shell start



Listing of logcat Command Options


-b <buffer>
load log buffer


-c
모든 log를 clear하고 빠져나간다


-d
log를 화면에 dump하고 종료


-f <filename>
log를 <filename>에 기록. default는 stdout


-g
특정 log buffer의 size를 출력하고 종료


-n <count>
rotated log의 최대값을 <count>로 설정. default는 4, -r option이 필요


-r <kbytes>

log file을 <kbytes>씩 rotate. default는 16, -f option 필요

-s
default filter를 silent로 설정


-v <format>
log format을 <format>으로 설정. default는 brief format.



'Android 개발 > 팁 / 활용정보' 카테고리의 다른 글

android emulator 저장소 늘리기  (0) 2011.10.30
Init Logo, Boot Animation 변경  (0) 2011.08.09
adb logcat  (0) 2011.05.31
google map api  (0) 2011.05.18
넥서스원 2.2.1 용 기본 어플 몇개  (1) 2011.04.19
And