Android adbプロセス優先度の表示
12880 ワード
概要
システムプロセスにおけるappの優先度を知りたい場合がありますが、何か方法がありますか?答えはあります.adbコマンドによって、システム内のプロセスの優先度を取得することができます.具体的な操作を見てみましょう.
ステップ
ステップ1:プロセスpidの取得
ステップ2:プロセス優先度の表示
frameworks/base/services/java/com/android/server/am/ProcessList.java
上記のファイルでは、
もう1つの方法:dumpsysによる方法
まとめ
上記の2つの方法で、関連プロセスの優先度を取得できます.
システムプロセスにおけるappの優先度を知りたい場合がありますが、何か方法がありますか?答えはあります.adbコマンドによって、システム内のプロセスの優先度を取得することができます.具体的な操作を見てみましょう.
ステップ
ステップ1:プロセスpidの取得
C:\Users\xxx>adb shell ps
USER PID PPID VSIZE RSS WCHAN PC NAME
...
u0_a3 679 109 471124 39808 ffffffff 00000000 S com.android.systemui
u0_a13 846 109 302108 19832 ffffffff 00000000 S com.android.inputmethod.p
inyin
radio 889 109 317536 23220 ffffffff 00000000 S com.android.phone
u0_a9 917 109 487980 85124 ffffffff 00000000 S com.xxx.xxx
...
adb shell ps
により対応するパケットのpidを取得する、例えば、comを取得する.xxx.xxx・このパケットのpidは、917
の値を有する.ステップ2:プロセス優先度の表示
C:\Users\solo>adb shell
shell@imx6:/ $ cat proc/917/oom_adj
0
shell@imx6:/ $
proc
ディレクトリの下に対応するpid
フォルダを見つけて、中のoom_adj
を見てプロセスの優先度を得ることができます.pid
が917のプロセスであり、その値は0
であることがわかります.0
は、プロセスがフロントで実行されていることを示します.これらの値の具体的な定義は、ProcessList.java
というファイルにあります.frameworks/base/services/java/com/android/server/am/ProcessList.java
/**
* Activity manager code dealing with processes.
*/
final class ProcessList {
// OOM adjustments for processes in various states:
// Adjustment used in certain places where we don't know it yet.
// (Generally this is something that is going to be cached, but we
// don't know the exact value in the cached range to assign yet.)
static final int UNKNOWN_ADJ = 16;
// This is a process only hosting activities that are not visible,
// so it can be killed without any disruption.
static final int CACHED_APP_MAX_ADJ = 15;
static final int CACHED_APP_MIN_ADJ = 9;
// The B list of SERVICE_ADJ -- these are the old and decrepit
// services that aren't as shiny and interesting as the ones in the A list.
static final int SERVICE_B_ADJ = 8;
// This is the process of the previous application that the user was in.
// This process is kept above other things, because it is very common to
// switch back to the previous app. This is important both for recent
// task switch (toggling between the two top recent apps) as well as normal
// UI flow such as clicking on a URI in the e-mail app to view in the browser,
// and then pressing back to return to e-mail.
static final int PREVIOUS_APP_ADJ = 7;
// This is a process holding the home application -- we want to try
// avoiding killing it, even if it would normally be in the background,
// because the user interacts with it so much.
static final int HOME_APP_ADJ = 6;
// This is a process holding an application service -- killing it will not
// have much of an impact as far as the user is concerned.
static final int SERVICE_ADJ = 5;
// This is a process with a heavy-weight application. It is in the
// background, but we want to try to avoid killing it. Value set in
// system/rootdir/init.rc on startup.
static final int HEAVY_WEIGHT_APP_ADJ = 4;
// This is a process currently hosting a backup operation. Killing it
// is not entirely fatal but is generally a bad idea.
static final int BACKUP_APP_ADJ = 3;
// This is a process only hosting components that are perceptible to the
// user, and we really want to avoid killing them, but they are not
// immediately visible. An example is background music playback.
static final int PERCEPTIBLE_APP_ADJ = 2;
// This is a process only hosting activities that are visible to the
// user, so we'd prefer they don't disappear.
static final int VISIBLE_APP_ADJ = 1;
// This is the process running the current foreground app. We'd really
// rather not kill it!
static final int FOREGROUND_APP_ADJ = 0;
// This is a system persistent process, such as telephony. Definitely
// don't want to kill it, but doing so is not completely fatal.
static final int PERSISTENT_PROC_ADJ = -12;
// The system process runs at the default adjustment.
static final int SYSTEM_ADJ = -16;
// Special code for native processes that are not being managed by the system (so
// don't have an oom adj assigned by the system).
static final int NATIVE_ADJ = -17;
}
上記のファイルでは、
oom_adj
の値が小さいほど優先度が高いことがわかります.加えて、ps
およびcat
の方式が用いられる.次に、プロセスの優先度を表示する方法を見てみましょう.もう1つの方法:dumpsysによる方法
C:\Users\solo>adb shell dumpsys activity processes
*APP* UID 10009 ProcessRecord{41940070 917:com.xxx.xxx/u0a9}
user #0 uid=10009
dir=/system/app/xxx.apk publicDir=/system/app/xxx.apk data=/data/user/0/com.xxx.xxx
packageList={com.xxx.xxx}
compat={160dpi always-compat}
thread=android.app.ApplicationThreadProxy@4196b5e0
pid=917 starting=false
lastActivityTime=-47m54s745ms lastPssTime=-1m51s601ms nextPssTime=+8s362ms
adjSeq=880 lruSeq=0 lastPss=76916 lastCachedPss=0
keeping=true cached=false empty=false
oom: max=16 curRaw=0 setRaw=0 cur=0 set=0
curSchedGroup=-1 setSchedGroup=-1 systemNoUi=false trimMemoryLevel=0
curProcState=2 repProcState=2 pssProcState=2 setProcState=2 lastStateTime=-58m39s814ms
hasShownUi=true pendingUiClean=true hasAboveClient=false
hasClientActivities=false foregroundActivities=true
lastRequestedGc=-58m39s817ms lastLowMemory=-58m39s817ms reportLowMemory=false
Activities:
- ActivityRecord{4193b008 u0 com.xxx.xxx/.HomeMain t1}
Connected Providers:
- 417e1038/com.android.providers.settings/.SettingsProvider->917:com.spd.home/u0a9 s1/1 u0/0 +58m33s751ms
Receivers:
- ReceiverList{4190ac08 917 com.xxx.xxx/10009/u0 remote:41a8bba8}
- ReceiverList{419c9898 917 com.xxx.xxx/10009/u0 remote:41991410}
- ReceiverList{419e2228 917 com.xxx.xxx/10009/u0 remote:4196dfb8}
- ReceiverList{419e5a70 917 com.xxx.xxx/10009/u0 remote:418b6e20}
- ReceiverList{419ea018 917 com.xxx.xxx/10009/u0 remote:419b8820}
- ReceiverList{41a41510 917 com.xxx.xxx/10009/u0 remote:419970b8}
dumpsys
コマンドにより、対応するパケット名の下のプロセス情報が見つかり、oom: max=16 curRaw=0 setRaw=0 cur=0 set=0
の行が表示されます.cur=0
がプロセスの優先順位です.まとめ
上記の2つの方法で、関連プロセスの優先度を取得できます.