AndroidSystemDebug官方指导
Google是AOSP项目的主导者,关于Android开发有两大官网,在“资料收集”篇有提到就是Android Open Source Project与Android Developers官网。在这两大网站上有关于aosp项目和app开发的一切官方资料。Google公司的工作是值得认可的,所以我们的任务第一步要整理学习前人的工作,避免重复造轮子。
本篇将过滤AOSP与developer官网提到的开发调试工具及方法。本文只给出地址及简介。
AOSP、Developer两大官网内容详实,建议Android系统开发者和app开发者通读,对了解Adroid OS全貌有帮助。
AuthBlog:秋城https://www.cnblogs.com/houser0323
Contents
1. AOSP
本章列出的内容主要关注Android系统/平台。
Git
Android选择使用Git来做工程代码版本控制
Repo
简单来说,repo用来管理繁多的Git仓库。
In most situations, you can use Git instead of Repo, or mix Repo and Git commands to form complex commands.
However, using Repo for basic across-network operations makes your work much simpler. For more details on Repo, see
the Repo Command Reference, Repo README, and thePreupload Hooks(tests) that can be enabled in Repo.
Other-tools
codereview。
Gerrit is a web-based code review system for projects that use Git. Gerrit encourages a more centralized use of Git by
allowing all authorized users to submit changes, which are automatically merged if they pass code review. In addition,
Gerrit makes reviewing easy, displaying changes side by side in the browser and enabling inline comments.
提示:关于在线阅读代码强烈推荐两个网站:https://cs.android.com/ 与 https://android.googlesource.com/
Android Code Search allows you to search through AOSP without downloading anything. You can use Code Search to
view the AOSP source code, switch between open source branches, and navigate cross-references. For more
information, see the Google Developers site for the Code Search documentation.
时代变了,Android应用开发建议使用AS这个IDE。
Android Studio is the official integrated development environment (IDE) for Android app development.
What is Soong?
Android系统源码如此庞大,是如何组织编译的呢?Android7.0之前只用GNU Make。7.0开始引入了Soong编译系统。
The Soong build system was introduced in Android 7.0 (Nougat) to replace Make. It leverages the Kati GNU Make
clone tool and Ninja build system component to speed up builds of Android.
See the Android Make Build System description in the Android Open Source Project (AOSP) for general instructions
and Build System Changes for Android.mk Writers to learn about modifications needed to adapt from Make to Soong.
See the build-related entries in the glossary for definitions of key terms and the Soong reference files for complete details.
Set up environment
提示:这个脚本有大用,特别是查找源码文件
$ source build/envsetup.sh
Flashing Devices
编译好的img如何刷到设备?答:用fastboot与adb。一般用SDK工具包里的,自己用源码编译也可Building fastboot and adb
Android Flash Tool
这个只支持Google的手机平台,例如Pixel,感兴趣可以看看。
Using Reference Boards
Google推荐的开发板,可作了解。
Generic System Images
这个就是在GMS认证中常提到的GSI,翻译为“通用系统镜像”,是纯Android实现硬件无关。
GSIs are used for running VTS and CTS-on-GSI tests. The system image of an Android device is replaced with a GSI then
tested with the Vendor Test Suite (VTS) and the Compatibility Test Suite (CTS) to ensure that the device implements
vendor interfaces correctly with the latest version of Android.
https://source.android.google.cn/setup/create/cuttlefish#cuttlefish_and_android_emulator
关于虚拟设备,可作了解。
Compiling with Jack for Android 6.08.1
Jack 工具链已被弃用。Jack 是 Android 6.0-8.1 的默认 Android 编译工具链。有关以上版本的Android编译调试可参考。
Android Continuous Integration
AOSP项目的ci,持续集成。我们目前没有投入参与到AOSP的开发工作,感兴趣可关注。
AOSP Java Code Style for Contributors
Google官方的AOSP代码规范/建议。核心思想是保持上下文风格的一致性。
Android Community and Contacts
关于AOSP项目的社区、论坛、博客等等地址汇总。我们部门目前没有投入参与到AOSP的开发工作,感兴趣可关注。
Android Live-Lock Daemon
Android10上更新的守护进程,旨在捕获和减少内核死锁问题。
Android 10 includes the Android Live-Lock Daemon (llkd), which is designed to catch and mitigate kernel deadlocks. For details on using llkd, refer to the README.md.
Interface Hashing
HIDL相关,cts-on-gsi遇到过因修改.hal文件但未添加其哈希值到current.txt导致的失败项。涉及到这个工具Hashing with hidl-gen
Using c2hal
c2hal用于HAL层开发的工具。
VNDK ABI checker
vnedor NDK开发相关,这是芯片厂商的工作内容,可作了解。
VNDK Definition Tool
vnedor NDK开发相关,这是芯片厂商的工作内容,可作了解。
Additional Resources
关于Vendor Interface Object开发,这是芯片厂商的工作内容,可作了解。
assemble_vintf;GTest
tinyxml2 (external/tinyxml2) for serializing/deserializing the object to/from XML. BSD-like license.
libselinux (external/selinux/libselinux) for getting policydb version. Public domain license.
libz (external/zlib) for decompressing /proc/config.gz. BSD-like license.
libvintf project uses Apache 2.0 license (with appropriate MODULE_LICENSE_APACHE2 and NOTICE files).
Fastboot in User Space
fastboot是一个刷写分区镜像img的工具。
Android 10 adds support for resizable partitions by relocating the fastboot implementation from bootloader to user
space. This relocation enables moving the flashing code into a maintainable and testable common location with only the
vendor-specific parts of fastboot implemented by a Hardware Abstraction Layer (HAL).
Android Compatibility Definition Document
传说中的CDD。只有完全通过GMS认证测试的设备才可称之为真正的Android兼容设备。没过的可以理解为衍mo生gai设备。
Color Management
显示相关
Android Platform Testing
测试是软件工程的重要部分,关于Android平台系统的测试有如下阐述。
instrumentation tests
native tests using the gtest framework.
Android Compatibility Test Suite
Vendor Test Suite
Trade Federation
提示:最后这个页面是一个cmd-debug工具的总结 Debugging
Reading Bug Reports:如何阅读bugreport
Diagnosing Native Crashes:如何分析Native层(c/c++)的Crash
以下是性能相关的工具和论述。
Use Simpleperf to evaluate the performance of a device. Simpleperf is a native profiling tool for both applications and
native processes on Android. Use CPU Profiler to inspect app CPU usage and thread activity in real time.
Understanding Systrace
systrace 是分析 Android 设备性能的主要工具.
systrace is the primary tool for analyzing Android device performance. However, it's really a wrapper around other tools. It's the host-side wrapper around atrace, the device-side executable that controls userspace tracing and sets up ftrace, and the primary tracing mechanism in the Linux kernel. systrace uses atrace to enable tracing, then reads the ftrace buffer and wraps it all in a self-contained HTML viewer. (While newer kernels have support for Linux Enhanced Berkeley Packet Filter (eBPF), the following documentation pertains to the 3.18 kernel (no eFPF) as that's what was used on the Pixel/Pixel XL.)
systrace is owned by the Google Android and Google Chrome teams and is open source as part of the Catapult project. In addition to systrace, Catapult includes other useful utilities. For example, ftrace has more features than can be directly enabled by systrace or atrace and contains some advanced functionality that is critical to debugging performance problems. (These features require root access and often a new kernel.)
Using ftrace
ftrace 是一种调试工具,用于了解 Linux 内核中的情况。
ftrace is a debugging tool for understanding what is going on inside the Linux kernel. The following sections detail basic ftrace functionality, ftrace usage with atrace (which captures kernel events), and dynamic ftrace.
Identifying Capacity-Related Jank
关于设备负载能力的卡顿。
Capacity is the total amount of some resource (CPU, GPU, etc.) a device possesses over some amount of time. This page describes how to identify and address capacity-related jank issues.
Identifying Jitter-Related Jank
关于抖动的卡顿。
Jitter is the random system behavior that prevents perceptible work from running. This page describes how to identify and address jitter-related jank issues.
Implementing Test Harness Mode
Android 10中添加的一项功能,适用于希望使一个设备或一组设备自动化的第三方应用程序开发人员。该功能提供了一种擦除 Android设备上所有用户数据,保留ADB密钥以及跳过所有首次设置屏幕的方法。这使用户可以在启动后立即运行UI测试,而无需任何手动交互。
这个测试框架有点意思,可以进一步研究下。
Test Harness Mode is a feature added in Android 10 for third-party app developers that wish to automate a device or a fleet of devices. The feature provides a method to wipe all user data on an Android device, retain ADB keys, and skip all first-time setup screens. This enables the user to run a UI test immediately after startup without any manual interaction.
Using GDB
用GDB调试Android。
The GNU Project debugger (GDB) is a commonly used UNIX debugger. This page details using gdb to debug Android apps and processes for platform developers. For third-party app development, see Debug your app.
Dumping User and Kernel Stacks on Kernel Events
关于内核调试的论述,发生内核事件时转储用户和内核堆栈。Installing adeb
For more information on trace, see the BCC trace tool documentation. For more information about running BCC on Android devices, see the adeb project's BCC howto.
用于内存调试的7个工具。
Address Sanitizer
Heapprofd
Malloc debug
libmemunreachable
Malloc hooks
Malloc statistics
Dalvik Debug Monitor Server
Network Connectivity Tests
一个网络连接自测的工具,蓝牙WiFi移动网络。
Android Connectivity Testing Suite (ACTS) tests fill the testing gap between Android’s framework APIs and chipset certifications. These tests validate the functionality of various aspects of the Bluetooth, Wi-Fi, and cellular radios as used by the Android framework.
Rescue Party
一种设备的保护模式,崩溃的信息会存放到/data/system/uiderrors.txt
永久性的 PackageManager 日志中。
storaged
Android O 添加的storaged守护进程,在Android上收集和发布存储指标。
Android O adds support for storaged, an Android native daemon that collects and publishes storage metrics on Android devices.
Diskstat (including stalled diskstats) and eMMC information is logged to the Android event log, where a platform checkin service collects the logs.
storaged operations occur automatically and are handled entirely by the Android framework, so you don't need to do any implementation work. This page describes the design of storaged (including new interfaces) and how to use it to get I/O status from the kernel.
Using Strace
查看linux系统调用(system call)的工具。
Strace enables you to see the system calls a process makes and what those system calls return.
Security Enhancements
关于安全在每个版本都有许多增强安全的工具,此处不一一列举。
Application Signing
安全相关,应用签名的论述。
Validating SELinux
关于SELinux的开发验证有以下俩工具,结合dmsg和logcat日志进行分析。
sepolicy-analyze
Using audit2allow
verifiedboot
关于verifiedboot的功能,实现和验证。
Generating the hash tree
Security Testing
关于安全性的测试工具和论述。此处只列举名称:AddressSanitizer, HWAddressSanitizer,LLVM Sanitizers,BoundsSanitizer,Scudo,Tagged Pointers,Building a Pixel kernel with KASAN+KCOV,Fuzzing with libFuzzer,Control Flow Integrity,Kernel Control Flow Integrity,Integer Overflow Sanitization,Execute-only Memory (XOM) for AArch64 Binaries,ShadowCallStack。
Measuring Audio Latency
音频延迟的测试工具及论述。
The Dr. Rick O'Rang loopback app is an Android app for audio feedback testing. You can download the app from Google Play or get the source code from GitHub.
Dr. Rick O'Rang audio loopback dongleThe Dr. Rick O'Rang audio loopback dongle is handy for measuring round-trip latency over the headset connector.
Audio Debugging
Bluetooth Verifying and Debugging
关于蓝牙调试的论述。
WLAN
Testing, Debugging, and Tuning Wi-Fi
关于WiFi调试的论述。
Running ACTS Telephony Tests
上面提到过的连接性测试ACTS。
The Android Comms Test Suite (ACTS) performs automated testing of connectivity stacks, such as Wi-Fi, Bluetooth, and cellular services. The testing tool requires adb. and Python, and it can be found in tools/test/connectivity/acts.
This page describes how to run the basic telephony tests available in Android Open Source Project (AOSP) for a user with two phones.
Tracking BufferQueue with Systrace
用Systrace调试BufferQueue
To understand how graphics buffers move around, use Systrace, a tool that records device activity over a short period of time. The system-level graphics code is well instrumented, as is much of the relevant app framework code.
Tracing Window Transitions
WinScope是一种记录分析WindowManager和SurfaceFlinger状态的工具。
WinScope provides the infrastructure and tools to record and analyze WindowManager and SurfaceFlinger states during and after window transitions. WinScope records all pertinent system service states to a trace file, which you can use to replay and step through the transitions.
Getevent
提示:inuput流程调试中非常重要的工具,用于动态显示内核输入事件。
The getevent tool runs on the device and provides information about input devices and a live dump of kernel input events.
This tool is useful for ensuring device drivers are reporting the expected set of capabilities for each input device and are generating the desired stream of input events.
Validate Keymaps Tool
按键映射开发工作的验证工具。
The Android framework has a small tool called
validatekeymaps
to validate the syntax of input device configuration files, key layout files, key character maps files and virtual key definition files.
Data Saver mode
流量监控程序。
APK Caching
A/B分区方案相关。
Optimizing Boot Times
提示:优化系统启动时间的相关论述,很有价值.从内核到BootLoader到init.rc到开机动画等等。
This document provides partner guidance for improving boot times for specific Android devices. Boot time is an important component of system performance as users must wait for boot to complete before they can use the device. For devices such as cars where cold boot-up happens more frequently, having a quick boot time is critical (no one likes waiting for dozens of seconds just to input a navigation destination).
Android 8.0 allows for reduced boot times by supporting several improvements across a range of components. The following table summarizes these performance improvements (as measured on a Google Pixel and Pixel XL devices).
Bootchart provides CPU and I/O load breakdown of all processes for the whole system. It doesn't require rebuilding system image and can be used as a quick sanity check before diving into systrace.
Systrace allows collecting both kernel and Android traces during boot up. Visualization of systrace can help in analyzing specific problem during the boot-up. (However, to check the average number or accumulated number during the entire boot, it is easier to look into kernel trace directly).
Generating whitelists
特权白名单检查生成工具。
Controlling system suspend
关于电能消耗调试。
Android Runtime (ART) and Dalvik
关于AndroidRuntime思想架构以及开发调试的内容。
OTA Package Tools
build/make/tools/releasetools
这个工程路径下有许多脚本工具,OTA编译相关。
2. Developer
本章列出的内容主要关注Android 应用(App)。
Generic System Image
通用系统镜像。
Dynamic System Update (DSU)
动态系统更新,Android 10上的实验功能。
Android App Bundle
国际市场需要关注这个,新的apk机制,关于Google Play Store中安装的第三方应用。
Command line tools only
Android Studio中的基础工具命令行版本,都在这个套件里。
If you do not need Android Studio, you can download the basic Android command line tools below. You can use the included sdkmanager to download other SDK packages.
These tools are included in Android Studio.
Measure app performance with Android Profiler
Android Studio 3.0 及更高版本中的 Android Profiler 取代 Android Monitor 工具,提供实时数据,用于获取 CPU、内存、网络和电池资源使用情况。
Android5.0及以上的系统才能用。
The Android Profiler in Android Studio 3.0 and higher replaces the Android Monitor tools. The Android Profiler tools provide real-time data to help you to understand how your app uses CPU, memory, network, and battery resources.
For details about each of the profilers, see the following:
The Android Profiler is compatible with Android 5.0 (API level 21) and higher.
Command line tools
提示:列举Android SDK中重要的命令行工具。
此处先罗列一下:aapt2,adb,apkanalyzer,apksinger,bmgr,bundletool,d8,dmtracedump,dumpsys,ect1tool,jobb,jetifier-standalone,logcat,mksdcard,sdkmanager,systrace,perfetto,zipalign,Environment variables。
Android SDK Tools
- apkanalyzer
Provides insight into the composition of your APK after the build process completes.- avdmanager
Allows you to create and manage Android Virtual Devices (AVDs) from the command line.- jobb
Allows you to build encrypted and unencrypted APK expansion files in Opaque Binary Blob (OBB) format.- lint
A code scanning tool that can help you to identify and correct problems with the structural quality of your code.- monkeyrunner
Provides the command line interface for running program that can install an Android app or test package, run it, send keystrokes to it, takes screenshots, and more.- sdkmanager
Allows you to view, install, update, and uninstall packages for the Android SDK.
This package includes other tools that you don't need to invoke from the command line (such as ProGuard for code shrinking and obfuscation).
- aapt2
Parses, indexes, and compiles Android resources into a binary format that is optimized for the Android platform, and packages the compiled resources into a single output.- apksigner
Signs APKs and checks whether APK signatures will be verified successfully on all platform versions that a given APK supports.- zipalign
Optimizes APK files by ensuring that all uncompressed data starts with a particular alignment relative to the start of the file.
In addition to downloading from the SDK Manager, you can download the SDK Platform Tools here.
- adb
Android Debug Bridge (adb) is a versatile tool that lets you manage the state of an emulator instance or Android-powered device. You can also use it to install an APK on a device.- etc1tool
A command line utility that lets you encode PNG images to the ETC1 compression standard and decode ETC1 compressed images back to PNG.- fastboot
Flashes a device with platform and other system images. For flashing instructions, see Factory Images for Nexus and Pixel Devices.- logcat
This is a tool invoked via adb to view app and system logs.
Android Vitals
这个是Google的一项应用性能优化工具,Google Play相关。可作了解。
Diagnose and fix bad behaviors
Core vitals:
ANR rates
Crash rates
Excessive wakeups
Stuck partial wake locks
All other vitals:
Excessive background Wi-Fi scans
Excessive background network usage
App startup time
Slow rendering
Frozen frames
Permission denials
System tracing guides
提示:第三次提到system trace系统跟踪,其在Android性能调试中的重要性不言而喻。我们通过system trace工具产生的report来分析应用的性能。
To learn more about system tracing tools, see the following guides:
- Inspect CPU activity with CPU Profiler
Shows how to profile your app’s CPU usage and thread activity in Android Studio.- System Tracing system app
Explains how to capture a system trace directly on any device running Android 9 (API level 28) or higher.- Systrace command-line reference
Defines the different options and flags that you can pass into the command-line interface for Systrace.- Running Perfetto using ADB
Describes how to run the perfetto command-line tool to capture traces.- Running Perfetto
External documentation that describes how to build and run the perfetto command-line tool to capture traces.- Perfetto UI
The Perfetto Web-based trace viewer opens Perfetto traces and displays a complete report. You can also open Systrace traces in this viewer using the legacy UI option.- Navigate a Systrace report
Lists the elements of a typical report, presents keyboard shortcuts for navigating through the report, and describes how to identify types of performance problems.- Define custom events
Describes how you can apply custom labels to specific sections of your code, allowing for easier root-cause analysis in Systrace or Perfetto.
Inspect GPU rendering speed and overdraw
利用Setting--->>Developer options(开发者选项)中的功能检查GPU渲染和绘制。
Android includes some on-device developer options that help you visualize where your app might be running into issues rendering its UI, such as performing more rendering work than necessary, or executing long thread and GPU operations. This page describes how to debug GPU overdraw and profile GPU rendering.
来源:https://www.cnblogs.com/houser0323/p/12404188.html