티스토리 뷰

안드로이드의 CPU 사용량과 메모리 사용량을 체크하는 방법입니다.


1. CPU 사용량


$ adb shell top -n 1을 입력하면 CPU 사용량을 출력합니다.


top 에 대한 자세한 설명은 아래 명령을 입력합니다.


$ adb shell top --help


shell 명령을 Android App 에서 수행하려면 다음과 같이 합니다. ( shell 명령 수행시 App 의 권한은 항상 User 이기 때문에 su 권한을 필요로 하는 명령은 수행할 수 없음에 유의하셔야 합니다. )


Runtime runtime = Runtime.getRuntime(); 

Process process; 

String res = "-0-"; 

try { 

String cmd = "top -n 1"; 

process = runtime.exec(cmd); 

InputStream is = process.getInputStream(); 

InputStreamReader isr = new InputStreamReader(is); 

BufferedReader br = new BufferedReader(isr); 

String line ; 

while ((line = br.readLine()) != null) { 

String segs[] = line.trim().split("[ ]+"); 

if (segs[0].equalsIgnoreCase([Your Process ID])) { 

res = segs[1]; 

break; 

}

} catch (Exception e) { 


2. 메모리 사용량


$ adb shell procrank


procrank 명령이 가장 정확한 메모리 사용 정보를 보여준다고 합니다. (by Dianne Hackborn)


특히, 

uss 칼럼은 app 고유의 메모리 사용량을 나타내고,

pss 는 또한 프로세스간에 공유되는 메모리 량을 포함하고 있습니다.


하지만 이 명령은 production device 에는 지원하지 않을수 있습니다. 그때는 다음의 명령을 사용합니다.


$ adb shell dumpsys meminfo

$ adb shell dumpsys meminfo [processname]


위의 명령을 들을 이용하여 CPU 와 Memory 의 사용량을 차트 등으로 한눈에 보여줄 수 있습니다.


참고:

http://groups.google.com/group/android-developers/browse_thread/thread/7ac0db1c3cc989d7/283488c87d76913b?lnk=gst&q=cpu+uasage#283488c87d76913b

http://groups.google.com/group/android-developers/browse_thread/thread/afd865f3eb7494ed/334e64326e98f747?lnk=gst&q=memory+uasage#334e64326e98f747


아래 링크 추가


http://webkebi.zany.kr:9003/board/bView.asp?bCode=91179649&aCode=2511&cBlock=0&cPageNo=1&sType=0&sString=



댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함