java cef 崩溃,xCrash异常补抓分析-Java奔溃

news/2024/10/17 22:17:26/

近来看了一些异常补抓相关资料,正好补一下相应的操作,发现爱奇艺的一个Xcrash的异常补抓框架

文章分为三部分,分别是Java奔溃,卡顿补抓,以及Native崩溃。

可以看一下基本架构的全貌

c99b18c8c91a5236758e088d85dc035f.png

这一节是Java崩溃的说明

基本初始化是在自定义的Application的attachBaseContext来进行,在这里设置主线程异常崩溃补抓的UncaughtExceptionHandler

void initialize(int pid, String processName, String appId, String appVersion, String logDir, boolean rethrow,

int logcatSystemLines, int logcatEventsLines, int logcatMainLines,

boolean dumpFds, boolean dumpNetworkInfo, boolean dumpAllThreads, int dumpAllThreadsCountMax, String[] dumpAllThreadsWhiteList,

ICrashCallback callback) {

this.pid = pid;

this.processName = (TextUtils.isEmpty(processName) ? "unknown" : processName);

this.appId = appId;

this.appVersion = appVersion;

this.rethrow = rethrow;

this.logDir = logDir;

this.logcatSystemLines = logcatSystemLines;

this.logcatEventsLines = logcatEventsLines;

this.logcatMainLines = logcatMainLines;

this.dumpFds = dumpFds;

this.dumpNetworkInfo = dumpNetworkInfo;

this.dumpAllThreads = dumpAllThreads;

this.dumpAllThreadsCountMax = dumpAllThreadsCountMax;

this.dumpAllThreadsWhiteList = dumpAllThreadsWhiteList;

this.callback = callback;

//保存默认的异常补抓

this.defaultHandler = Thread.getDefaultUncaughtExceptionHandler();

try {

//设置新的异常补抓

Thread.setDefaultUncaughtExceptionHandler(this);

} catch (Exception e) {

XCrash.getLogger().e(Util.TAG, "JavaCrashHandler setDefaultUncaughtExceptionHandler failed", e);

}

}

继承接口uncaughtException

@Override

public void uncaughtException(Thread thread, Throwable throwable) {

if (defaultHandler != null) {

Thread.setDefaultUncaughtExceptionHandler(defaultHandler);

}

try {

//回调自己的逻辑

handleException(thread, throwable);

} catch (Exception e) {

XCrash.getLogger().e(Util.TAG, "JavaCrashHandler handleException failed", e);

}

if (this.rethrow) {

if (defaultHandler != null) {

defaultHandler.uncaughtException(thread, throwable);

}

} else {

//栈记录清空

ActivityMonitor.getInstance().finishAllActivities();

//强杀进程

Process.killProcess(this.pid);

System.exit(10);

}

}

处理补抓到的java异常

```

private void handleException(Thread thread, Throwable throwable) {

Date crashTime = new Date();

//notify the java crash 通知native和anr监听为处理为java崩溃

NativeHandler.getInstance().notifyJavaCrashed();

AnrHandler.getInstance().notifyJavaCrashed();

//create log file 日志地址

File logFile = null;

try {

String logPath = String.format(Locale.US, "%s/%s_%020d_%s__%s%s", logDir, Util.logPrefix, startTime.getTime() * 1000, appVersion, processName, Util.javaLogSuffix);

logFile = FileManager.getInstance().createLogFile(logPath);

} catch (Exception e) {

XCrash.getLogger().e(Util.TAG, "JavaCrashHandler createLogFile failed", e);

}

//get emergency 日志头信息

String emergency = null;

try {

emergency = getEmergency(crashTime, thread, throwable);

} catch (Exception e) {

XCrash.getLogger().e(Util.TAG, "JavaCrashHandler getEmergency failed", e);

}

//write info to log file 编写日志文件

if (logFile != null) {

//使用文本处理

RandomAccessFile raf = null;


http://www.ppmy.cn/news/248345.html

相关文章

没有容器Java怎么不停止_java – Maven Cargo不会停止容器

我有一个maven项目,我想使用Cargo-Maven-Plugin(1.1.1)启动和停止tomcat服务器来运行集成测试. org.codehaus.cargo cargo-maven2-plugin 1.1.1 start-container pre-integration-test start stop-container post-integration-test stop installed tomcat6x http://archive.apa…

java script 调用c_java script中的四种函数调用

撰写此文源于最近在看Douglas Crockford的’JavaScript:The Good Parts’中文译本《Javascript语言精粹》时,发现一些自己不知道或者没有一下子理解的东西,拿出来细细研究并记录一下。 函数被作为很重要的一部分在书中做了详细的介绍和举例。感觉函数的四…

java日期类型_Java 基础【12】 日期类型

java api中日期类型的继承关系 java.lang.Object --java.util.Date --java.sql.Date --java.sql.Time --java.sql.Timestamp 1. java.util.Date表示特定的瞬间,精确到了毫秒 两个构造函数(别的过期了的我就不说了) Date() Date(long date) 主要方法》》 boolean a…

未来计算机一种新兴的计算机类型,酷毙了!10款神奇的未来计算机

原标题:酷毙了!10款神奇的未来计算机 未来计算机的发展趋势怎样?你有想过未来的计算机会有什么新功能?下面奇艺网带来10款神奇的未来计算机,每一款都酷毙了,只想说来十台试试! 1)投影触摸笔记本…

Java即时编译器原理解析及实践

跟其他常见的编程语言不同,Java将编译过程分成了两个部分,这就对性能带来了一定的影响。而即时(Just In Time, JIT)编译器能够提高Java程序的运行速度。 本文会先解析一下即时编译器的原理,然后再分享一些在美团实践的…

计算机视觉(十六):目标检测概述

1 什么是目标检测 目标检测(Object Detection)的任务是找出图像中所有感兴趣的目标(物体),确定它们的类别和位置。 例子:确定某张给定图像中是否存在给定类别(比如人、车、自行车、狗和猫&…

Java已死?重庆java培训学校

一、什么情况下会发生栈内存溢出? 1、栈是线程私有的,栈的生命周期和线程一样,每个方法在执行的时候就会创建一个栈帧,它包含局部变量表、操作数栈、动态链接、方法出口等信息,局部变量表又包括基本数据类型和对象的引…

java api model_Java编译器API简介

今天给大家分享的是Java编译器API简介,文章部分内容摘自【优锐课】学习笔记。 Java编译器API Java编译器API是Java模块(称为java.compiler)的一部分。该模块包括语言模型和注释处理,以及编译器API。它定义了Java编程语言和编译器工具的类型和模型声明&am…