MEASUREMENT_TIME: set the time in seconds where bootchartd runs BOOTLOG_TEMP_DIR: path where temporary files will be created BOOTLOG_DEST: output directory for the bootchartd tarball
Signed-off-by: Felipe Ortiz <[email protected]> --- The objective of this patch is to add some options to make bootchartd useful on systems where directories are restricted and the boot times are longer than usual. init/bootchartd.c | 64 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 50 insertions(+), 14 deletions(-) diff --git a/init/bootchartd.c b/init/bootchartd.c index 0929890a3..f1bb31eb2 100644 --- a/init/bootchartd.c +++ b/init/bootchartd.c @@ -79,6 +79,15 @@ //# Sampling period (in seconds) //SAMPLE_PERIOD=0.2 // +//# Time to measure (approximate, in seconds) +//MEASUREMENT_TIME=60 +// +//# Temporal directory +//BOOTLOG_TEMP_DIR=/tmp +// +//# Tarball for the various boot log files +//BOOTLOG_DEST=/var/log/bootchart.tgz +// //not yet supported: //# tmpfs size //# (32 MB should suffice for ~20 minutes worth of log data, but YMMV) @@ -90,9 +99,6 @@ //# is also required. //PROCESS_ACCOUNTING="no" // -//# Tarball for the various boot log files -//BOOTLOG_DEST=/var/log/bootchart.tgz -// //# Whether to automatically stop logging as the boot process completes. //# The logger will look for known processes that indicate bootup completion //# at a specific runlevel (e.g. gdm-binary, mingetty, etc.). @@ -184,10 +190,12 @@ static int dump_procs(FILE *fp, int look_for_login_process) return found_login_process; } -static char *make_tempdir(void) +static char *make_tempdir(const char *bootlog_temp_dir) { - char template[] = "/tmp/bootchart.XXXXXX"; - char *tempdir = xstrdup(mkdtemp(template)); + const char *directory = "bootchart.XXXXXX"; + char *tempdir = xasprintf("%s/%s", bootlog_temp_dir, directory); + tempdir = mkdtemp(tempdir); + if (!tempdir) { #ifdef __linux__ /* /tmp is not writable (happens when we are used as init). @@ -216,14 +224,14 @@ static char *make_tempdir(void) return tempdir; } -static void do_logging(unsigned sample_period_us, int process_accounting) +static void do_logging(unsigned sample_period_us, int process_accounting, int measurement_time) { FILE *proc_stat = xfopen_for_write("proc_stat.log"); FILE *proc_diskstats = xfopen_for_write("proc_diskstats.log"); //FILE *proc_netdev = xfopen_for_write("proc_netdev.log"); FILE *proc_ps = xfopen_for_write("proc_ps.log"); int look_for_login_process = (getppid() == 1); - unsigned count = 60*1000*1000 / sample_period_us; /* ~1 minute */ + unsigned count = measurement_time*1000*1000 / sample_period_us; if (process_accounting) { close(xopen("kernel_pacct", O_WRONLY | O_CREAT | O_TRUNC)); @@ -262,7 +270,7 @@ static void do_logging(unsigned sample_period_us, int process_accounting) } } -static void finalize(char *tempdir, const char *prog, int process_accounting) +static void finalize(char *tempdir, const char *prog, int process_accounting, const char *bootlog_dest) { //# Stop process accounting if configured //local pacct= @@ -315,7 +323,7 @@ static void finalize(char *tempdir, const char *prog, int process_accounting) fclose(header_fp); /* Package log files */ - system(xasprintf("tar -zcf /var/log/bootlog.tgz header %s *.log", process_accounting ? "kernel_pacct" : "")); + system(xasprintf("tar -zcf %s header %s *.log", bootlog_dest, process_accounting ? "kernel_pacct" : "")); /* Clean up (if we are not in detached tmpfs) */ if (tempdir) { unlink("header"); @@ -345,10 +353,20 @@ static void finalize(char *tempdir, const char *prog, int process_accounting) int bootchartd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int bootchartd_main(int argc UNUSED_PARAM, char **argv) { - unsigned sample_period_us; pid_t parent_pid, logger_pid; smallint cmd; int process_accounting; + + /* config file options */ + unsigned sample_period_us; + int measurement_time; + char bootlog_tempdir[PATH_MAX] = { 0 }; + char bootlog_dest[PATH_MAX] = { 0 }; + + /* Default directories */ + const char *default_bootlog_tempdir = "/tmp"; + const char *default_bootlog_dest = "/var/log/bootchart.tgz"; + enum { CMD_STOP = 0, CMD_START, @@ -383,6 +401,10 @@ int bootchartd_main(int argc UNUSED_PARAM, char **argv) /* Read config file: */ sample_period_us = 200 * 1000; process_accounting = 0; + measurement_time = 60; + memcpy(bootlog_tempdir, default_bootlog_tempdir, strlen(default_bootlog_tempdir)); + memcpy(bootlog_dest, default_bootlog_dest, strlen(default_bootlog_dest)); + if (ENABLE_FEATURE_BOOTCHARTD_CONFIG_FILE) { char* token[2]; parser_t *parser = config_open2("/etc/bootchartd.conf" + 5, fopen_for_read); @@ -396,6 +418,16 @@ int bootchartd_main(int argc UNUSED_PARAM, char **argv) ) { process_accounting = 1; } + if (strcmp(token[0], "MEASUREMENT_TIME") == 0 && token[1]) + measurement_time = atoi(token[1]); + if (strcmp(token[0], "BOOTLOG_TEMP_DIR") == 0 && token[1]) { + memset(bootlog_tempdir, 0, PATH_MAX); + memcpy(bootlog_tempdir, token[1], strnlen(token[1], PATH_MAX)); + } + if (strcmp(token[0], "BOOTLOG_DEST") == 0 && token[1]) { + memset(bootlog_dest, 0, PATH_MAX); + memcpy(bootlog_dest, token[1], strnlen(token[1], PATH_MAX)); + } } config_close(parser); if ((int)sample_period_us <= 0) @@ -427,9 +459,13 @@ int bootchartd_main(int argc UNUSED_PARAM, char **argv) if (cmd == CMD_PID1 && !getenv("PATH")) putenv((char*)bb_PATH_root_path); - tempdir = make_tempdir(); - do_logging(sample_period_us, process_accounting); - finalize(tempdir, cmd == CMD_START ? argv[2] : NULL, process_accounting); + tempdir = make_tempdir(bootlog_tempdir); + do_logging(sample_period_us, process_accounting, measurement_time); + finalize(tempdir, cmd == CMD_START ? argv[2] : NULL, process_accounting, bootlog_dest); + + if (tempdir) + free(tempdir); + return EXIT_SUCCESS; } -- 2.45.2 _______________________________________________ busybox mailing list [email protected] https://lists.busybox.net/mailman/listinfo/busybox
