Android設(shè)備獲取進(jìn)程線程信息

獲取進(jìn)程線程信息

當(dāng)發(fā)生 ANR 的時候,Android 系統(tǒng)會打印 CPU 相關(guān)的信息到日志中,使用的是ProcessCpuTracker

這樣好像并沒有權(quán)限可以拿到其他應(yīng)用進(jìn)程的 CPU 信息

當(dāng)發(fā)現(xiàn)應(yīng)用的某個進(jìn)程 CPU 使用率比較高的時候,可以通過下面幾個文件檢查該進(jìn)程下各個線程的 CPU 使用率,繼而統(tǒng)計出該進(jìn)程各個線程的時間占比。

Linux環(huán)境下進(jìn)程的CPU占用率

/proc/[pid]/stat // 進(jìn)程 CPU 使用情況

/proc/[pid]/task/[tid]/stat // 進(jìn)程下面各個線程的 CPU 使用情況

/proc/[pid]/sched // 進(jìn)程 CPU 調(diào)度相關(guān)

/proc/loadavg // 系統(tǒng)平均負(fù)載癌刽,uptime 命令對應(yīng)文件

已將這部分邏輯加入網(wǎng)管監(jiān)控中。代碼cn.mwee.android.skynet.appruninfo.util.ProcessCpuTracker

如果需要獲取線程信息打開開關(guān) 會獲取以下信息](http://www.samirchen.com/linux-cpu-performance/)

CPU usage from 180344ms to 243ms ago (2019-02-21 20:54:48.521 to 2019-02-21 20:57:48.622): 0.5% 14771/com.mwee.android.pos.dinner:bizcenter(S): 0.3% user + 0.1% kernel / faults: 1367 minor thread stats: 0.1% 14979/thread_runtime_(R): 0.1% user + 0% kernel / faults: 162 minor 0% 15278/MYD_NetPool_114(S): 0% user + 0% kernel / faults: 193 minor 0% 14902/LogFileThread(S): 0% user + 0% kernel / faults: 296 minor 0% 14781/HeapTaskDaemon(S): 0% user + 0% kernel / faults: 168 minor 0% 14947/MYD_NetPool_114(S): 0% user + 0% kernel / faults: 64 minor 0% 8321/Smack Packet Re(S): 0% user + 0% kernel / faults: 291 minor 0% 14944/MYD_SLooper_114(S): 0% user + 0% kernel / faults: 57 minor 0% 8165/Smack Packet Re(S): 0% user + 0% kernel / faults: 294 minor 0% 14935/MWLog(S): 0% user + 0% kernel / faults: 13 minor 0% 14808/LogFileThread(S): 0% user + 0% kernel / faults: 69 minor 0% 14981/MYD_NetPool_114(S): 0% user + 0% kernel / faults: 13 minor 0% 14983/MYD_NetPool_114(S): 0% user + 0% kernel / faults: 13 minor 0% 15093/MYD_NetPool_114(S): 0% user + 0% kernel / faults: 3 minor 0% 15326/Smack Packet Re(S): 0% user + 0% kernel 0% 24139/Smack Listener (S): 0% user + 0% kernel 0% 24138/Smack Packet Re(S): 0% user + 0% kernel 0% 14771/inner:bizcenter(S): 0% user + 0% kernel / faults: 19 minor 0% 15061/Thread-403(S): 0% user + 0% kernel / faults: 4 minor 0% 14779/FinalizerDaemon(S): 0% user + 0% kernel 0% 14972/Binder_4(S): 0% user + 0% kernel / faults: 8 minor 0% 15009/MYD_SNetPool_11(S): 0% user + 0% kernel 0% 15156/MYD_xmpplink_al(S): 0% user + 0% kernel / faults: 6 minor 0% 14657/Binder_7(S): 0% user + 0% kernel 0% 14987/MYD_NetPool_114(S): 0% user + 0% kernel 0% 14938/WifiManager(S): 0% user + 0% kernel 0% 14789/Binder_2(S): 0% user + 0% kernel / faults: 2 minor 0% 14951/AlpAckLoop(S): 0% user + 0% kernel 0% 19106/Smack Listener (S): 0% user + 0% kernel / faults: 4 minor 0% 19105/Smack Packet Re(S): 0% user + 0% kernel / faults: 1 minor 0% 19104/Smack Packet Wr(S): 0% user + 0% kernel / faults: 6 minor 0% 14778/ReferenceQueueD(S): 0% user + 0% kernel 0% 5790/Binder_6(S): 0% user + 0% kernel 0% 26903/Binder_5(S): 0% user + 0% kernel 0% 14945/ClientHeartBeat(S): 0% user + 0% kernel 0% 14949/ALPServerLoop(S): 0% user + 0% kernel / faults: 4 minor 0% 14783/Binder_1(S): 0% user + 0% kernel 0% 14777/JDWP(S): 0% user + 0% kernel 0% 14960/Binder_3(S): 0% user + 0% kernel 0% 14939/Thread-379(S): 0% user + 0% kernel 0% 14941/Thread-381(S): 0% user + 0% kernel 0% 14940/Thread-380(S): 0% user + 0% kernel 0% 10446/OkHttp Connecti(S): 0% user + 0% kernel 0% 14885/Okio Watchdog(S): 0% user + 0% kernel 0% 14976/thread_runtime_(S): 0% user + 0% kernel 0% 14780/FinalizerWatchd(S): 0% user + 0% kernel 0% 14889/pool-1-thread-1(S): 0% user + 0% kernel 0% 15095/MYD_NetPool_114(S): 0% user + 0% kernel 0% 24137/Smack Packet Wr(S): 0% user + 0% kernel / faults: 1 minor 0% 9534/Smack Listener (S): 0% user + 0% kernel 0% 9511/Smack Packet Re(S): 0% user + 0% kernel 0% 9510/Smack Packet Wr(S): 0% user + 0% kernel / faults: 1 minor 0% 15163/MYD_NetPool_114(S): 0% user + 0% kernel 0% 14776/Signal Catcher(S): 0% user + 0% kernel 0% 15010/MYD_SNetPool_11(S): 0% user + 0% kernel 0% 14989/MYD_SNetPool_11(S): 0% user + 0% kernel 0% 14999/MYD_SNetPool_11(S): 0% user + 0% kernel 0% 14914/BuglyThread-3(S): 0% user + 0% kernel 0% 15094/MYD_NetPool_114(S): 0% user + 0% kernel 0% 14912/BuglyThread-1(S): 0% user + 0% kernel 0% 14818/BuglyThread-1(S): 0% user + 0% kernel 0% 14913/BuglyThread-2(S): 0% user + 0% kernel 0% 15325/Smack Packet Wr(S): 0% user + 0% kernel / faults: 1 minor 0% 15328/Smack Listener (S): 0% user + 0% kernel 0% 14888/OkHttp Connecti(S): 0% user + 0% kernel 0% 14858/MYD_NetPool_114(S): 0% user + 0% kernel 0% 14942/MYD_NetPool_114(S): 0% user + 0% kernel 0% 14859/MYD_NetPool_114(S): 0% user + 0% kernel 0% 14860/MYD_NetPool_114(S): 0% user + 0% kernel 0% 14819/BuglyThread-2(S): 0% user + 0% kernel 0% 14820/BuglyThread-3(S): 0% user + 0% kernel 0% 1495

上面是美易點業(yè)務(wù)中心的線程信息 尝丐。上面可以發(fā)現(xiàn)有幾個重復(fù)的線程显拜,bugly線程都重復(fù)了一次。這是由于不同classloader下 分別init了一次bugly爹袁。Android性能優(yōu)化-線程性能優(yōu)化

線程不是免費的:它們占用內(nèi)存远荠。每個線程最少消耗64k內(nèi)存。如果設(shè)備上安裝了許多應(yīng)用失息,該值就會快速添加譬淳,特別是在調(diào)用棧顯著增長的情況下

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末档址,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子邻梆,更是在濱河造成了極大的恐慌守伸,老刑警劉巖,帶你破解...
    沈念sama閱讀 211,639評論 6 492
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件浦妄,死亡現(xiàn)場離奇詭異尼摹,居然都是意外死亡,警方通過查閱死者的電腦和手機剂娄,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,277評論 3 385
  • 文/潘曉璐 我一進(jìn)店門蠢涝,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人宜咒,你說我怎么就攤上這事惠赫“鸭” “怎么了故黑?”我有些...
    開封第一講書人閱讀 157,221評論 0 348
  • 文/不壞的土叔 我叫張陵,是天一觀的道長庭砍。 經(jīng)常有香客問我场晶,道長,這世上最難降的妖魔是什么怠缸? 我笑而不...
    開封第一講書人閱讀 56,474評論 1 283
  • 正文 為了忘掉前任诗轻,我火速辦了婚禮,結(jié)果婚禮上揭北,老公的妹妹穿的比我還像新娘扳炬。我一直安慰自己,他們只是感情好搔体,可當(dāng)我...
    茶點故事閱讀 65,570評論 6 386
  • 文/花漫 我一把揭開白布恨樟。 她就那樣靜靜地躺著,像睡著了一般疚俱。 火紅的嫁衣襯著肌膚如雪劝术。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 49,816評論 1 290
  • 那天呆奕,我揣著相機與錄音养晋,去河邊找鬼。 笑死梁钾,一個胖子當(dāng)著我的面吹牛绳泉,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播姆泻,決...
    沈念sama閱讀 38,957評論 3 408
  • 文/蒼蘭香墨 我猛地睜開眼圈纺,長吁一口氣:“原來是場噩夢啊……” “哼秦忿!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起蛾娶,我...
    開封第一講書人閱讀 37,718評論 0 266
  • 序言:老撾萬榮一對情侶失蹤灯谣,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后蛔琅,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體胎许,經(jīng)...
    沈念sama閱讀 44,176評論 1 303
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 36,511評論 2 327
  • 正文 我和宋清朗相戀三年罗售,在試婚紗的時候發(fā)現(xiàn)自己被綠了辜窑。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 38,646評論 1 340
  • 序言:一個原本活蹦亂跳的男人離奇死亡寨躁,死狀恐怖穆碎,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情职恳,我是刑警寧澤所禀,帶...
    沈念sama閱讀 34,322評論 4 330
  • 正文 年R本政府宣布,位于F島的核電站放钦,受9級特大地震影響次绘,放射性物質(zhì)發(fā)生泄漏如孝。R本人自食惡果不足惜鳞仙,卻給世界環(huán)境...
    茶點故事閱讀 39,934評論 3 313
  • 文/蒙蒙 一犹撒、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧颓屑,春花似錦斤寂、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,755評論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至丹擎,卻和暖如春尾抑,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背蒂培。 一陣腳步聲響...
    開封第一講書人閱讀 31,987評論 1 266
  • 我被黑心中介騙來泰國打工再愈, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人护戳。 一個月前我還...
    沈念sama閱讀 46,358評論 2 360
  • 正文 我出身青樓翎冲,卻偏偏與公主長得像,于是被迫代替她去往敵國和親媳荒。 傳聞我的和親對象是個殘疾皇子抗悍,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 43,514評論 2 348

推薦閱讀更多精彩內(nèi)容