static int bootchart_step() { do_log_file(log_stat, "/proc/stat"); do_log_file(log_disks, "/proc/diskstats"); do_log_procs(log_procs); // Stop if /data/bootchart/stop contains 1. std::string stop; if (android::base::ReadFileToString(LOG_STOPFILE, &stop) && stop == "1") { return -1; } return 0; }
/* called each time you want to perform a bootchart sampling op */ int bootchart_step( void ) { do_log_file(log_stat, "/proc/stat"); do_log_file(log_disks, "/proc/diskstats"); do_log_procs(log_procs); /* we stop when /data/bootchart-stop contains 1 */ { char buff[2]; if (proc_read(LOG_STOPFILE,buff,sizeof(buff)) > 0 && buff[0] == '1') { return -1; } } return 0; }
static void do_log_procs(FileBuff log, int old_pid) { DIR* dir; struct dirent* entry; if (!old_pid) { dir = opendir("/proc"); do_log_uptime(log); } else { char tmp[1024]; snprintf(tmp, sizeof(tmp), "/proc/%d/task", old_pid); dir = opendir(tmp); } if (!dir) return; while ((entry = readdir(dir)) != NULL) { /* only match numeric values */ char* end; int pid = strtol( entry->d_name, &end, 10); if (end != NULL && end > entry->d_name && *end == 0) { char filename[32]; char buff[1024]; char cmdline[1024]; int len; int fd; if (pid == old_pid) continue; /* read command line and extract program name */ snprintf(filename,sizeof(filename),"/proc/%d/cmdline",pid); proc_read(filename, cmdline, sizeof(cmdline)); /* read process stat line */ snprintf(filename,sizeof(filename),"/proc/%d/stat",pid); fd = open(filename,O_RDONLY); if (fd >= 0) { len = unix_read(fd, buff, sizeof(buff)-1); close(fd); if (len > 0) { int len2 = strlen(cmdline); if (len2 > 0) { /* we want to substitute the process name with its real name */ const char* p1; const char* p2; buff[len] = 0; p1 = strchr(buff, '('); p2 = strchr(p1, ')'); file_buff_write(log, buff, p1+1-buff); file_buff_write(log, cmdline, strlen(cmdline)); file_buff_write(log, p2, strlen(p2)); } else { /* no substitution */ file_buff_write(log,buff,len); } } } if (old_pid == 0) do_log_procs(log, pid); } } if (!old_pid) do_log_ln(log); closedir(dir); }