打堆棧
打java堆棧
Exception e = new Exception("xxx");
e.printStackTrace();
或者
android.util.Log.d("xxx", e);
打native堆棧
- 對(duì)于c++
mk或者bp文件中引入libutils
#include <utils/CallStack.h>
android::CallStack cs("xxx");
- 對(duì)于c
mk或者bp文件中引入libutils敬鬓,再在項(xiàng)目里再加入一個(gè)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");
放開系統(tǒng)日志
一般對(duì)某個(gè)模塊不了解,可以全量開啟這塊的日志印蓖,再結(jié)合perfetto/systrace進(jìn)行分析辽慕。
- 一類是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:
//啟動(dòng)抓取proto logging
start: Start proto logging
//停止抓取proto logging
stop: Stop proto logging
//允許proto logging的輸出針對(duì)對(duì)應(yīng)group(
enable [group...]: Enable proto logging for given groups
//禁止proto logging的輸出針對(duì)對(duì)應(yīng)group
disable [group...]: Disable proto logging for given groups
//允許locat的輸出針對(duì)對(duì)應(yīng)group
enable-text [group...]: Enable logcat logging for given groups
//禁止locat的輸出針對(duì)對(duì)應(yīng)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對(duì)應(yīng)是proto logging這個(gè)就是像wms課程時(shí)候winscope抓取會(huì)把日志寫入到data/misc/wmtrace/路徑下wm_log.winscope
enable-text對(duì)應(yīng)就是logcat可以直接看到的,這個(gè)也就是我們經(jīng)常用的
- 一類是硬編碼的日志開關(guān)
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 緩沖區(qū)的log溅蛉。
要查看全部緩沖區(qū)日志adb logcat -b all
radio:查看包含無(wú)線裝置/電話相關(guān)消息的緩沖區(qū)。
events:查看已經(jīng)過(guò)解譯的二進(jìn)制系統(tǒng)事件緩沖區(qū)消息摆尝。 EventLog.writeEvent
main:查看主日志緩沖區(qū)(默認(rèn))温艇,不包含系統(tǒng)和崩潰日志消息。Log.d
system:查看系統(tǒng)日志緩沖區(qū)(默認(rèn))堕汞。Slog.d
crash:查看崩潰日志緩沖區(qū)(默認(rèn))勺爱。
all:查看所有緩沖區(qū)。
default:包含main讯检、system 和crash 緩沖區(qū)
查看kernel日志
常見場(chǎng)景如selinux相關(guān)dmesg
AS動(dòng)態(tài)調(diào)試
編譯userdebug鏡像或者嘗其他方式使得進(jìn)程可調(diào)試
預(yù)期這里會(huì)出現(xiàn)system_server等進(jìn)程琐鲁。
systrace/perfetto
非常強(qiáng)大的工具,可以用于模塊學(xué)習(xí)或者問(wèn)題分析人灼。
如何查看trace參考https://blog.csdn.net/learnframework/article/details/135020636
自己添加trace
可以添加的trace包括同步trace(方法围段、代碼塊)、異步trace投放、對(duì)于某個(gè)值的監(jiān)聽(局限了int和boolean類型奈泪,如vsync-sf等),具體加trace方法參考https://blog.csdn.net/learnframework/article/details/133627031
dumpsys及system_server提供的一些adb命令
特定場(chǎng)景的分析工具
window、surfaceFlinger相關(guān)問(wèn)題
winscope參考https://blog.csdn.net/learnframework/article/details/129432374
anr灸芳、watchdog涝桅、lowmem
這三種場(chǎng)景下會(huì)生成/data/anr/traces.txt
dropbox:/data/system/dropbox有一些持久化的系統(tǒng)日志
system_app_anr:系統(tǒng)app無(wú)響應(yīng)
system_app_crash:系統(tǒng)app進(jìn)程崩潰
system_server_native_crash system進(jìn)程native出現(xiàn)崩潰
system_server_wtf:system進(jìn)程發(fā)生嚴(yán)重錯(cuò)誤
system_server_lowmem:system進(jìn)程內(nèi)存不足