Some debugging methods under Android (including kernel debugging methods)

Source: Internet
Author: User

Mainly introduced in addition to the conventional kernel PRINTK and Android Ddms, Logcat outside of a few debugging means.

Including Bugreport, Oprofile, TraceView, Ftrace and so on.

Bugreport

Bugreport is the Android platform's own tool, collects the device end of the detailed situation, you can run directly under the console "Bugreport >/sdcard/bugreport.log" or access to USB Cable and open adb debug to run "adb bugreport > Bugreport.log".
Below is a reference to a crawl of the bugreport.

Related code path
Frameworksasecmdsugreport
Frameworksasecmdsdumpstate
Frameworksasecmdsdumpsys

Oprofile

The principle of

Oprofie is simple: many CPUs provide a so-called performance counter Thing (performance counter),
The general principle is that the program can register to tell the CPU what the event is interested in (such as Cpu_cycle, The CPU undergoes a clock cycle), and after the CPU performs the corresponding operation, it adds 1 to the performance counter, so that the program can be removed.
So, the problem of using Oprofile to locate CPU usage becomes the function in which executable (or so) in the Oprofile collector runs and consumes the most CPU cycles.

In practical applications, oprofile can be used to identify bottlenecks in the system and optimize them.
In the default project in R70, Oprofile is not compiled and needs to be modified externaloprofileopcontrolandroid.mk and EXTERNALOPROFILEDAEMONANDROID.MK
The Local_module_tags attribute in two files is modified from debug to eng or user to compile Oprofile into Android.

In addition, Oprofile needs to open the appropriate compile option in kernel to support kernel corresponding code in the kernel race directory. The corresponding config is as follows:

General Setup [*] Profiling support
config_profiling

General setup <*> OProfile system Profiling
Config_oprofile
Config_ring_buffer
Config_ring_buffer_allow_swap
Config_ring_buffer_benchmark is not set

General Setup Kernel performance Events and Counters
[*] Kernel performance Events and Counters
Config_perf_events
Config_hw_perf_events

Examples:


Finally, install Oprofile on the PC side to parse the results generated by the device side.

If you need to get the final graphical results, you'll also need to install Graphviz.

Once all the preparations are in place, you can start Oprofile to detect the device by running the following command on the device side.

Opcontrol–quick ===> Setup the appropriate environment and parameters

Opcontrol–start ===> Start Oprofile

Opcontrol–status ===> can see the status of Oprofile in the middle

Opcontrol–stop ===> Stop Oprofile

Opcontrol–dump ===> Save the results to the/data/oprofile path

Finally, the Opimport_pull script in the PC-side running Android project can generate the corresponding results callgraph.txt, load.txt, Load2.txt, and Callgraph.png externaloprofile (see below).

Note that you need to set some environment variables and vmlinux files for the device end kernel before running the script.

exportoprofile_events_dir= {Your Android Source dir}/prebuilt/linux-x86_64/oprofile/

Exportoprofile_bin_dir=/{oprofile BIN DIR on Your PC}/

exportout= {Your Android Source dir}/out/target/product/smdkv210

cd {Your Android Source dir}/out/target/product/smdkv210/symbols

ln-s {Your Kernel Source dir}/vmlinux./vmlinux

TraceView

TraceView is an Android-powered tool that is used to analyze the Android side by calling Debug.startmethodtracing (XXXX); The generated file is named Xxxx.trace. This method requires the code of debug.startmethodtracing (XXXX) and debug.stopmethodtracing () to be added to the Android code. By adding these two functions at a reasonable location, the user can visually analyze how long the system is running in this intermediate process, how much time each process began to run, how many times each function ran, and how long each ran.

Ftrace

Ftrace is a tracking tool built into the Linux kernel, starting with 2.6.27 to join the mainstream kernel. The role of Ftrace is to help developers understand the runtime behavior of the Linux kernel for failure debugging or performance analysis.

With Ftrace, you can track kernel function calls, context switches, and see how long interrupts are closed, track latency in the kernel state, and performance issues.

By using Ftrace to trace and debug the kernel, you can find the root of the problem in the kernel, and through ftrace to observe the activities that occur in the kernel, you can understand the kernel's working mechanism.

Ftrace can not respond to the UI of the device, but the console is still active and the kernel is analyzed.

The Ftrace function requires that the corresponding config be opened in the kernel. In addition, opening ftrace will bring additional overhead to the system, so you should turn off Ftrace functionality as much as possible in release releases.

Figure 1.Kernel Hackin

Figure 1. Kernel hacking


Figure 2. Tracers


Figure 3. List of trackers supported by the kernel

In R70 's kernel, Ftrace supported tracer wakeup, Preemptirqsoff, Preemptoff, Irqsoff, function, Sched_switch altogether 6 kinds.

Refer to the connection in reference and the Ftrace.txt under documents race in kernel.

Some of the results obtained are as follows:

Http://www.2cto.com/kf/201501/366871.html

Some debugging methods under Android (including kernel debugging methods)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.