针对logcat中的线程ID,进程ID过滤,好奇的是 线程ID, 并不是Thread类里的ID
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
dumpId("UI Thread: ");
new Thread() {
@Override
public void run() {
dumpId("Child Thread: ");
}
}.start();
}
private void dumpId(String thread) {
Log.i("testMain", thread + "threadid: " + Thread.currentThread().getId());
Log.i("testMain", thread + "process id: " + Process.myUid() + " tid: " + Process.myTid() + " uid:" + Process.myUid());
}
//log
04-04 11:24:39.475 26045 26045 I testMain: UI Thread: threadid: 2
04-04 11:24:39.475 26045 26045 I testMain: UI Thread: process id: 10692 tid: 26045 uid:10692
04-04 11:24:39.476 26045 26107 I testMain: Child Thread: threadid: 503
04-04 11:24:39.476 26045 26107 I testMain: Child Thread: process id: 10692 tid: 26107 uid:10692
结论
- logcat 第3列是PID
- logcat 第4列事TID (Thread id)
- TID 不是
Thread.currentThread().getId()
,而是linux系统调用返回的TIDandroid.os.Process.myTid()