bootchart instructions and code analysis

Article directory

        • 1 Introduction:
        • The first part: start with the specific use process as follows
        • The second part: let’s talk about how bootchart gets these data information

1 Introduction:

bootchart is an open source software tool for performance analysis of the linux startup process. It automatically collects information such as CPU usage and processes during the system startup process, and displays the analysis results graphically. It can be used as a guide to optimize the system startup process.

Bootchart is an open source software tool for analyzing the linux boot process. There is an integrated bootchart source code in android, the path is system/core/init/bootchart.c

Part 1: Start with the specific usage process as follows RK has been integrated and compiled into the system by default without modification

1. Compile the bootchart in android (not compiled by default)
Execute in the android source code system/core/init/ directory: mm INIT_BOOTCHART=true -B
Or modify the Android.mak file directly

 LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
\t
INIT_BOOTCHART := true

2. Burn the newly compiled android system image to the android device.
Compile and generate a new executable file init, which is located in the root/under the mobile phone file system, and the corresponding flash image is boot.img, so the boot.img containing the new init needs to be reprogrammed

RK does not need to create this file, but it needs to create a data/bootchart/enabled file, see bootchart.cpp for details

3. Create a file/data/bootchart-start on the mobile phone, its content is the sampling time of bootchart
adb shell ‘echo T I M E O U T > / d a t a / b o o t c h a r t ? s t a r t ′ where TIMEOUT > /data/bootchart-start’ where TIMEOUT>/data/bootchart?start′ where TIMEOUT is the expected sampling time in seconds, for example to sample After two minutes, execute:
adb shell ‘echo 120 > /data/bootchart-start’

4. Restart the device, the folder /data/bootchart/ will be automatically created when init is running, and the sampling data will be saved in it. The sampling data consists of 5 files:

-rw-rw-rw-root root 732 1970-01-01 08:00 header
-rw-r--r-- root root 0 1970-01-01 08:00 kernel_pacct
-rwxr-xr-x root root 517150 2014-04-09 12:06 proc_diskstats.log
-rwxr-xr-x root root 2783967 2014-04-09 12:06 proc_ps.log
-rwxr-xr-x root root 152090 2014-04-09 12:06 proc_stat.log

It should be noted that if you no longer use bootchart after running bootchart sampling on the phone, you need to manually delete the file /data/bootchart-start, otherwise bootchart will run every time the phone restarts.

5. File packaging
Execute the command in the /data/bootchart/ directory:

busybox tar -czf bootchart.tgz header proc_stat.log proc_ps.log proc_diskstats.log kernel_pacct

Then copy the generated bootchart.tgz to the computer (ubuntu system) with a USB flash drive.

You can also manually upload these 5 files to the PC through adb pull and package them. Anyway, the final bootchart.tgz is generated

6. Install the bootchart tool on the computer
Use the sudo apt-get install bootchart command to install, if it appears that bootchart cannot normally parse the bootchart.tgz file generated in android.
Need to use the old version of the installation package bootchart_0.9-0ubuntu6_all.deb, you can download it here http://download.csdn.net/detail/sckgenius/7166477.
First sudo apt-get install librsvg2-bin, then sudo dpkg -i bootchart_0.9-0ubuntu6_all.deb.

7. Execute the following command to generate the analysis result chart, and the image file bootchart.png in png format is generated by default:
java -jar /usr/share/bootchart/bootchart.jar /path/to/bootchart.tgz

Upload a bootchart.png picture here:

The second part: let’s talk about how bootchart gets these data information

The analysis is the source code: system\core\init\bootchart.c has only one file

1. Start

Add code through macro definition BOOTCHART in init.c

#if BOOTCHART
static int bootchart_init_action(int nargs, char **args)
{
    bootchart_count = bootchart_init();
    if (bootchart_count < 0) {
        ERROR("bootcharting init failure\\
");
    } else if (bootchart_count > 0) {
        NOTICE("bootcharting started (period=%d ms)\\
", bootchart_count*BOOTCHART_POLLING_MS);
    } else {
        NOTICE("bootcharting ignored\\
");
    }
 
    return 0;
}
#endif

Start by calling bootchart_init()

2. Periodic execution

int main(int argc, char **argv)

{
 
#if BOOTCHART
    queue_builtin_action(bootchart_init_action, "bootchart_init");
#endif
 
    for(;;) {
        int nr, i, timeout = -1;
 
 
#if BOOTCHART
        if (bootchart_count > 0) {
            if (timeout < 0 || timeout > BOOTCHART_POLLING_MS)
                timeout = BOOTCHART_POLLING_MS;
            if (bootchart_step() < 0 || --bootchart_count == 0) {
                bootchart_finish();
                bootchart_count = 0;
            }
        }
#endif
 
        nr = poll(ufds, fd_count, timeout);
        
  }
...
}

Default cycle time: # define BOOTCHART_POLLING_MS 200 /* polling period in ms
*/

3. How to sample data

It is very clear to analyze the source code, that is, through the standard command in linux (similar to executing cat xxx on the shell) and write the result to the corresponding file

 /proc/cmdline
 /proc/version
 /proc/cpuinfo
 Write to file #define LOG_HEADER LOG_ROOT"/header"
 
 /proc/uptime
 /proc/stat
 Write to file #define LOG_STAT LOG_ROOT"/proc_stat.log"
 
 /proc/uptime
 /proc/diskstats
 Write to file #define LOG_DISK LOG_ROOT"/proc_diskstats.log"
 
 /proc/uptime
 /proc/$PID/cmdline
 /proc/$PID/stat
 Write to file #define LOG_PROCS LOG_ROOT"/proc_ps.log"

This file is only opened, nothing is written /* create kernel process accounting file */ #define
LOG_ACCT LOG_ROOT”/kernel_pacct”

File reprint:
bootchart instructions and code analysis

———————
Author: Enlarged EZ
Source: CSDN
Original: https://blog.csdn.net/qq_27061049/article/details/116718728
Copyright statement: This article is the author’s original article, please attach the blog post link for reprinting!
Content analysis By: CSDN, CNBLOG blog post one-click reprint plug-in