当前位置:网站首页>Anr principle and Practice
Anr principle and Practice
2022-07-07 06:51:00 【Little xian】
Broadcast ANR Design principle
- Only in an orderly broadcast ANR Monitoring of
- AMS Responsible for distributing orderly broadcasts , And set timeout monitoring alarm during distribution , If the broadcast receiver processes the message within the timeout period and AMS If the communication is cancelled, this timeout monitoring will not happen ANR, Otherwise, it will be judged ANR.
- AMS It's used Binder The mechanism and APP Process of communication , When receiving broadcast data , Will encapsulate the data and sendMessage To the main thread message queue , Main thread processing Msg, The final call receiver.onReceive Method .( When there are time-consuming tasks in front of the message queue of the main thread , Or other processes have time-consuming tasks , Affect the scheduling of current events , It's not that the event itself takes too long , Will also trigger ANR)
Service ANR Design principle
Input ANR Design principle
ANR Dump technological process
- Filter out special scenes ( is dump, Shutting down , is crash, Being used by the system kill)
- Find what you need Dump The process of , It mainly includes ANR The parent of the process ,SystemServer process , high CPU Of ( most 5 individual ) process
- send out SIGQUIT Signal the need Dump The process of

- Processes SignalCatcher Thread collects current virtual machine information , Memory information ,class Information ,GC Information , Then suspend all threads , Get the stack information of the thread
- Finally, it's piped to SystemServer, Append write to Trace In file
Application detection ANR
- watchdog
- monitor SIGNALQUIT The signal , Determine your progress ANR When ,Java Get stack information at the end , Or reflection calls inside the virtual machine Dump Stack interface of thread , Get the data and output it to your own directory .
Implementation reference Xcrash:https://github.com/iqiyi/xCrash/blob/master/README.zh-CN.md
obtain ANR Info
- adopt ActivityManagerService.getProcessesInErrorState, Traverse mLruProcesses, And according to the current abnormal state of the process, such as crash perhaps anr type , Return to concrete ProcessErrorStateInfo
ANR The time-consuming situation in the message queue before the occurrence
- At present Trace The business where the stack is located takes a lot of time ;
- At present Trace The business where the stack is located is not time consuming , But historical scheduling has a serious time-consuming ;
- At present Trace The business where the stack is located is not time consuming , But historical scheduling has many messages that take time ;
- At present Trace The business where the stack is located is not time consuming , But there are a large number of repeated messages in historical scheduling ( Business sends messages frequently );
- At present Trace Stack business logic is not time consuming , But other threads have serious resource preemption , Such as IO,Mem,CPU;
- At present Trace Stack business logic is not time consuming , But other processes have serious resource preemption , Such as IO,Mem,CPU;
ANR Log semantic analysis
Load: 2.62 / 2.55 / 2.25
Express :1、5、15 In use and waiting for use within minutes CPU The average number of active processesCPU usage from 0ms to 1987ms later (2020-03-10 08:31:55.169 to 2020-03-10 08:32:17.156)
indicate : Load information is captured in ANR After that 0~1987ms. It also points out that ANR The timing of the :2020-03-10 08:31:55.169
If it is CPU usage xxx awake Said is ANR Previous system load information41% 2080/system_server: 28% user + 12% kernel / faults: 76445 minor 180 major 26% 9378/com.xiaomi.store: 20% user + 6.8% kernel / faults: 68408 minor 68 major
Express : Each process takes up CPU Details of66% TOTAL: 20% user + 15% kernel + 28% iowait + 0.7% irq + 0.7% softirq
Express : All processes occupy CPU Information about
ANR keyword
a. user: User mode ,kernel: Kernel mode
b. faults: Memory page missing ,minor—— Slight ,major—— severe , You need to take data from disk
c. iowait:IO Use ( wait for ) Proportion
d. irq: Hard interrupt ,softirq: Soft interrupt
e. utm: user space time,stm: kernel space time
Reference resources :
- Today's headline ANR Optimization Practice Series - Design principles and influencing factors
- Today's headline ANR Optimization Practice Series - Monitoring tools and analysis ideas
- Today's headline ANR Optimization Practice Series sharing - A collection of case studies
- Android Source code analysis four component series ( 7、 ... and )— Broadcast sending process
- ANR Analyze comprehensively
- How to analyze ANR problem
边栏推荐
- ESXI挂载移动(机械)硬盘详细教程
- Can't you really do it when you are 35 years old?
- Postgresql源码(59)分析事务ID分配、溢出判断方法
- Performance comparison between Ceres solver and g2o
- [noi simulation] regional division (conclusion, structure)
- String (explanation)
- C language interview to write a function to find the first occurrence of substring m in string n.
- SolidWorks的GB库(钢型材库,包括铝型材、铝管等结构)安装及使用教程(生成铝型材为例)
- 一文带你了解静态路由的特点、目的及配置基本功能示例
- 软件测试到了35岁,真的就干不动了吗?
猜你喜欢

Matlab tips (30) nonlinear fitting lsqcurefit

Redis (II) - redis General Command

基于JS的迷宫小游戏

Learning notes | data Xiaobai uses dataease to make a large data screen
![[noi simulation] regional division (conclusion, structure)](/img/7d/4c66cd0a30e52ccd167b6138fcb4df.png)
[noi simulation] regional division (conclusion, structure)

BindingException 异常(报错)处理

Go straight to the 2022ecdc fluorite cloud Developer Conference: work with thousands of industries to accelerate intelligent upgrading

LM small programmable controller software (based on CoDeSys) Note 23: conversion of relative coordinates of servo motor operation (stepping motor) to absolute coordinates

Jetpack Compose 远不止是一个UI框架这么简单~

MATLAB小技巧(29)多项式拟合 plotfit
随机推荐
oracle如何备份索引
基于JS的迷宫小游戏
Maze games based on JS
一条慢SQL拖死整个系统
Can 7-day zero foundation prove HCIA? Huawei certification system learning path sharing
FPGA课程:JESD204B的应用场景(干货分享)
二十岁的我4面拿到字节跳动offer,至今不敢相信
MySQL卸载文档-Windows版
jdbc数据库连接池使用问题
学术报告系列(六) - Autonomous Driving on the journey to full autonomy
from . onnxruntime_ pybind11_ State Import * noqa ddddocr operation error
场馆怎么做体育培训?
肿瘤免疫治疗研究丨ProSci LAG3抗体解决方案
Matlab tips (29) polynomial fitting plotfit
JWT的基础介绍
Redis (II) - redis General Command
根据IP获取地市
String (explanation)
请教一个问题,flink oracle cdc,读取一个没有更新操作的表,隔十几秒就重复读取全量数据
Basic DOS commands