我目前的进展如下,
通过以下方式启用 Bootchart.h
#ifndef BOOTCHART
# define BOOTCHART 1
#endif
之后我编译代码,使 INIT_BOOTCHART=true kernel -j4。所以编译完成后我做了
1. adb root
2. adb shell
3. cd data
4. echo 120 > bootchart-start (cat bootchart-start -> 120)
5. mkdir bootchart
6. reboot bootloader
7. fastboot flash kernel kernel.img
8. reboot
然后我检查 data/bootchart 文件夹内的日志文件。但几分钟后它也是空的。
所以我把一些日志放在 system/core/init/init.c -> bootchart_init_action
static int bootchart_init_action(int nargs, char **args)
{
ERROR("#### JACH #### - BOOTCHART'%d':'%s'\n", 0, "bootchart_init_action -start");
bootchart_count = bootchart_init();
ERROR("#### JACH #### - BOOTCHART'%d':'%s'\n", bootchart_count, "bootchart_init_action -bootchart_count");
if (bootchart_count < 0) {
ERROR("bootcharting init failure\n");
} else if (bootchart_count > 0) {
NOTICE("bootcharting started (period=%d ms)\n", bootchart_count*BOOTCHART_POLLING_MS);
} else {
NOTICE("bootcharting ignored\n");
}
ERROR("#### JACH #### - BOOTCHART'%d':'%s'\n", 0, "bootchart_init_action -end");
return 0;
}
编译上述代码后,我看到 bootchart_init() 函数返回 0 值。下面是日志文件。
<11>[ 2.814551] init: #### JACH #### - BOOTCHART'0':'bootchart_init_action -start'
<11>[ 2.814591] init: #### JACH #### - bootchart_init'0':'start'
<11>[ 2.814704] init: #### JACH #### - BOOTCHART'0':'bootchart_init_action -bootchart_count'
<11>[ 2.814721] init: #### JACH #### - BOOTCHART'0':'bootchart_init_action -end'
所以 bootchart_init() 如下:
#define LOG_STARTFILE "/data/bootchart-start"
int bootchart_init( void )
{
ERROR("#### JACH #### - bootchart_init'%d':'%s'\n", 0, "start");
int ret;
char buff[4];
int timeout = 0, count = 0;
buff[0] = 0;
proc_read( LOG_STARTFILE, buff, sizeof(buff) );
if (buff[0] != 0) {
timeout = atoi(buff);;
ERROR("#### JACH #### - bootchart_init'%d':'%s'\n", timeout, "timeout");
}
else {
/* when running with emulator, androidboot.bootchart=<timeout>
* might be passed by as kernel parameters to specify the bootchart
* timeout. this is useful when using -wipe-data since the /data
* partition is fresh
*/
char cmdline[1024];
char* s;
#define KERNEL_OPTION "androidboot.bootchart="
proc_read( "/proc/cmdline", cmdline, sizeof(cmdline) );
s = strstr(cmdline, KERNEL_OPTION);
if (s) {
s += sizeof(KERNEL_OPTION)-1;
timeout = atoi(s);
}
}
if (timeout == 0)
return 0;
if (timeout > BOOTCHART_MAX_TIME_SEC)
timeout = BOOTCHART_MAX_TIME_SEC;
count = (timeout*1000 + BOOTCHART_POLLING_MS-1)/BOOTCHART_POLLING_MS;
do {ret=mkdir(LOG_ROOT,0755);}while (ret < 0 && errno == EINTR);
file_buff_open(log_stat, LOG_STAT);
file_buff_open(log_procs, LOG_PROCS);
file_buff_open(log_disks, LOG_DISK);
/* create kernel process accounting file */
{
int fd = open( LOG_ACCT, O_WRONLY|O_CREAT|O_TRUNC,0644);
if (fd >= 0) {
close(fd);
acct( LOG_ACCT );
}
}
log_header();
ERROR("#### JACH #### - bootchart_init'%d':'%s'\n", 0, "end");
return count;
}
我猜在启动时上面的代码(proc_read( LOG_STARTFILE, buff, sizeof(buff) );
)没有读取或写入数据的权限,或者没有创建文件分区。而且我对超时进行了硬编码,但bootchart_step()
功能仍然有效,但是日志文件没有写入 data/bootchart 文件夹。
但我不知道如何启用这个问题。感谢您参加我的提问。