谁不是一边燃一边丧,一边拼命一边又不想活了。
前言
最近这阵子又回来爱奇艺实习了,实习的任务是分析爱奇艺的APM平台上的卡顿栈的问题。爱奇艺的APM平台上的卡顿栈都是系统栈,很少有比较明显的栈。因此,只能从源码开始逐层分析。通过分析源码的逐层调用,来判断是否是因为主线程(UI线程)持有子线程的锁导致卡顿,亦或者是由于频繁的进行IPC导致,或者是因为读写竞争导致的问题……
对于源码的分析有利于快速的定位到问题所在,当然,可以借此机会,深入了解Android底层原理和实现。工作本身就是枯燥无味的,但是能够将枯燥无味的生活变为提升自己的方式,有何不可呢?
下载源码
看源码还是看这个好:BeesAndroid——This project aims to help more wireless development engineers understand and master the Android system by providing a series of tools and methods.
这里的教程也是基于这个项目而写的,欢迎关注这个项目。
repo
在线撸源码的网站:http://androidxref.com/
repo是拉取谷歌官方源码的工具,必须要用到它。
下载
下载repo,默认是官方源:
mkdir ~/bin
PATH=~/bin:$PATH
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
如果你没有翻墙,可以使用清华大学的repo镜像:https://mirrors.tuna.tsinghua.edu.cn/help/git-repo/
下载完成后将bin/repo打开,将里面的REPO_URL改成清华大学的镜像:
https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/'
配置git
git config --global user.text "Your Name"
git config --global user.email "you@example.com"
如果是没在翻墙的环境中,就需要配置下git的代理:
git config --global http.proxy 'socks5://127.0.0.1:1080'
git config --global https.proxy 'socks5://127.0.0.1:1080'
初始化仓库
repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest
如果需要某个特定的Android版本,可以在后面指定版本号。
Android系统各版本号:https://source.android.com/source/build-numbers.html#source-code-tags-and-builds
repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-7.1.1_r28
注:更多源码版本可以参见https://source.android.com/source/build-numbers
下载源码
注意:源码编译之后大概有140G的大小,请确保有充足的空间来下载源码并编译。如果是希望导入到IDEA中,需要对源码进行编译,我编译Android 7.1.1大概花了两个小时多。
同步源码树,开始下载源码,如果后续下载中断,也可以重复执行这个命令。
# 单线程
repo sync
# 指定并发数
repo sync -j4
源码的下载会经常中断,我们可以写一个脚本自动repo sync,保存成repo.sh
,放到WORKING_DIRECTORY目录下
#!/bin/bash
#FileName jkYishon.sh
PATH=~/bin:$PATH
repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-7.1.1_r28
repo sync
while [ $? = 1 ]; do
echo "====