打堆栈
打java堆栈
Exception e = new Exception("xxx");
e.printStackTrace();
或者
android.util.Log.d("xxx", e);
打native堆栈
- 对于c++
mk或者bp文件中引入libutils
#include <utils/CallStack.h>
android::CallStack cs("xxx");
- 对于c
mk或者bp文件中引入libutils,再在项目里再加入一个c++的头文件,比如callstack.h,里面是:
void dumping_callstack(void);
#include <utils/CallStack.h>
extern "C" void dumping_callstack(void);
void dumping_callstack(void) {
android::CallStack cs("xxx");
放开系统日志
一般对某个模块不了解,可以全量开启这块的日志,再结合perfetto/systrace进行分析。
- 一类是protolog
android R才启用
ProtoLog.v(WM_DEBUG_CONFIGURATION, "Starting activity when config "
+ "will change = %b", globalConfigWillChange);
NX563J:/ # wm logging -h
Unknown command
Window manager logging options:
//启动抓取proto logging
start: Start proto logging
//停止抓取proto logging
stop: Stop proto logging
//允许proto logging的输出针对对应group(
enable [group...]: Enable proto logging for given groups
//禁止proto logging的输出针对对应group
disable [group...]: Disable proto logging for given groups
//允许locat的输出针对对应group
enable-text [group...]: Enable logcat logging for given groups
//禁止locat的输出针对对应group
disable-text [group...]: Disable logcat logging for given groups
Not handled, please use `adb shell dumpsys activity service SystemUIService WMShell` if you are looking for ProtoLog in WMShell
enable对应是proto logging这个就是像wms课程时候winscope抓取会把日志写入到data/misc/wmtrace/路径下wm_log.winscope
enable-text对应就是logcat可以直接看到的,这个也就是我们经常用的
- 一类是硬编码的日志开关
public class WindowManagerDebugConfig {
// All output logs in the window manager package use the {@link #TAG_WM} string for tagging
// their log output. This makes it easy to identify the origin of the log message when sifting
// through a large amount of log output from multiple sources. However, it also makes trying
// to figure-out the origin of a log message while debugging the window manager a little
// painful. By setting this constant to true, log messages from the window manager package
// will be tagged with their class names instead fot the generic tag.
static final boolean TAG_WITH_CLASS_NAME = false;
// Default log tag for the window manager package.
static final String TAG_WM = "WindowManager";
static final boolean DEBUG = false;
static final boolean DEBUG_LAYOUT = false;
static final boolean DEBUG_LAYERS = false;
static final boolean DEBUG_INPUT = false;
static final boolean DEBUG_INPUT_METHOD = false;
static final boolean DEBUG_VISIBILITY = false;
static final boolean DEBUG_CONFIGURATION = false;
static final boolean DEBUG_STARTING_WINDOW_VERBOSE = false;
static final boolean DEBUG_WALLPAPER = false;
static final boolean DEBUG_DRAG = true;
static final boolean DEBUG_SCREENSHOT = false;
static final boolean DEBUG_LAYOUT_REPEATS = false;
static final boolean DEBUG_WINDOW_TRACE = false;
static final boolean DEBUG_TASK_MOVEMENT = false;
static final boolean DEBUG_TASK_POSITIONING = false;
static final boolean DEBUG_ROOT_TASK = false;
static final boolean DEBUG_DISPLAY = false;
static final boolean DEBUG_POWER = false;
static final boolean SHOW_VERBOSE_TRANSACTIONS = false;
static final boolean SHOW_LIGHT_TRANSACTIONS = false;
static final boolean SHOW_STACK_CRAWLS = false;
static final boolean DEBUG_WINDOW_CROP = false;
static final boolean DEBUG_UNKNOWN_APP_VISIBILITY = false;
}
private final Predicate<WindowState> mComputeImeTargetPredicate = w -> {
if (DEBUG_INPUT_METHOD && mUpdateImeTarget) Slog.i(TAG_WM, "Checking window @" + w
+ " fl=0x" + Integer.toHexString(w.mAttrs.flags));
return w.canBeImeTarget();
};
看日志
adb logcat只能查看包含main、system 和crash 缓冲区的log。
要查看全部缓冲区日志adb logcat -b all
radio:查看包含无线装置/电话相关消息的缓冲区。
events:查看已经过解译的二进制系统事件缓冲区消息。 EventLog.writeEvent
main:查看主日志缓冲区(默认),不包含系统和崩溃日志消息。Log.d
system:查看系统日志缓冲区(默认)。Slog.d
crash:查看崩溃日志缓冲区(默认)。
all:查看所有缓冲区。
default:包含main、system 和crash 缓冲区
查看kernel日志
常见场景如selinux相关dmesg
AS动态调试
编译userdebug镜像或者尝其他方式使得进程可调试
预期这里会出现system_server等进程。
systrace/perfetto
非常强大的工具,可以用于模块学习或者问题分析。
如何查看trace参考https://blog.csdn.net/learnframework/article/details/135020636
自己添加trace
可以添加的trace包括同步trace(方法、代码块)、异步trace、对于某个值的监听(局限了int和boolean类型,如vsync-sf等),具体加trace方法参考https://blog.csdn.net/learnframework/article/details/133627031
dumpsys及system_server提供的一些adb命令
特定场景的分析工具
window、surfaceFlinger相关问题
winscope参考https://blog.csdn.net/learnframework/article/details/129432374
anr、watchdog、lowmem
这三种场景下会生成/data/anr/traces.txt
dropbox:/data/system/dropbox有一些持久化的系统日志
system_app_anr:系统app无响应
system_app_crash:系统app进程崩溃
system_server_native_crash system进程native出现崩溃
system_server_wtf:system进程发生严重错误
system_server_lowmem:system进程内存不足