Hi All, I've added the usage of BSD process accounting in bootchartd. It gives better grained process timing/knowledge in the final generated graph, especially on slow devices. I don't think there's any overhead in case it is not used.
Please tell me if it needs any modification. Cheers, Quentin
From a04289f5089faf2ee75ed5bde0053e41a3fd94e0 Mon Sep 17 00:00:00 2001 From: Quentin Casasnovas <[email protected]> Date: Wed, 11 Jan 2012 23:44:42 +0000 Subject: [PATCH] [bootchartd] Add process accounting feature Signed-off-by: Quentin Casasnovas <[email protected]> --- init/bootchartd.c | 45 ++++++++++++++++++++++++++++----------------- 1 files changed, 28 insertions(+), 17 deletions(-) diff --git a/init/bootchartd.c b/init/bootchartd.c index 5f6121f..3fcf813 100644 --- a/init/bootchartd.c +++ b/init/bootchartd.c @@ -73,17 +73,17 @@ //# Sampling period (in seconds) //SAMPLE_PERIOD=0.2 // -//not yet supported: -//# tmpfs size -//# (32 MB should suffice for ~20 minutes worth of log data, but YMMV) -//TMPFS_SIZE=32m -// //# Whether to enable and store BSD process accounting information. The //# kernel needs to be configured to enable v3 accounting //# (CONFIG_BSD_PROCESS_ACCT_V3). accton from the GNU accounting utilities //# is also required. //PROCESS_ACCOUNTING="no" // +//not yet supported: +//# tmpfs size +//# (32 MB should suffice for ~20 minutes worth of log data, but YMMV) +//TMPFS_SIZE=32m +// //# Tarball for the various boot log files //BOOTLOG_DEST=/var/log/bootchart.tgz // @@ -208,21 +208,21 @@ static char *make_tempdir(void) return tempdir; } -static void do_logging(unsigned sample_period_us) +static void do_logging(unsigned sample_period_us, smallint process_accounting) { - //# Enable process accounting if configured - //if [ "$PROCESS_ACCOUNTING" = "yes" ]; then - // [ -e kernel_pacct ] || : > kernel_pacct - // accton kernel_pacct - //fi - FILE *proc_stat = xfopen("proc_stat.log", "w"); FILE *proc_diskstats = xfopen("proc_diskstats.log", "w"); //FILE *proc_netdev = xfopen("proc_netdev.log", "w"); FILE *proc_ps = xfopen("proc_ps.log", "w"); + FILE* kernel_pacct = NULL; int look_for_login_process = (getppid() == 1); unsigned count = 60*1000*1000 / sample_period_us; /* ~1 minute */ + if (process_accounting) { + kernel_pacct = xfopen("kernel_pacct", "w"); + acct("kernel_pacct"); + } + while (--count && !bb_got_signal) { char *p; int len = open_read_close("/proc/uptime", G.jiffy_line, sizeof(G.jiffy_line)-2); @@ -254,10 +254,9 @@ static void do_logging(unsigned sample_period_us) usleep(sample_period_us); } - // [ -e kernel_pacct ] && accton off } -static void finalize(char *tempdir, const char *prog) +static void finalize(char *tempdir, const char *prog, smallint process_accounting) { //# Stop process accounting if configured //local pacct= @@ -265,6 +264,9 @@ static void finalize(char *tempdir, const char *prog) FILE *header_fp = xfopen("header", "w"); + if (process_accounting) + acct(NULL); + if (prog) fprintf(header_fp, "profile.process = %s\n", prog); @@ -307,7 +309,10 @@ static void finalize(char *tempdir, const char *prog) fclose(header_fp); /* Package log files */ - system("tar -zcf /var/log/bootchart.tgz header *.log"); // + $pacct + if (process_accounting) + system("tar -zcf /var/log/bootlog.tgz header kernel_pacct *.log"); + else + system("tar -zcf /var/log/bootlog.tgz header *.log"); /* Clean up (if we are not in detached tmpfs) */ if (tempdir) { unlink("header"); @@ -338,6 +343,7 @@ int bootchartd_main(int argc UNUSED_PARAM, char **argv) unsigned sample_period_us; pid_t parent_pid, logger_pid; smallint cmd; + smallint process_accounting = 0; enum { CMD_STOP = 0, CMD_START, @@ -379,6 +385,10 @@ int bootchartd_main(int argc UNUSED_PARAM, char **argv) while (config_read(parser, token, 2, 0, "#=", PARSE_NORMAL & ~PARSE_COLLAPSE)) { if (strcmp(token[0], "SAMPLE_PERIOD") == 0 && token[1]) sample_period_us = atof(token[1]) * 1000000; + if (strcmp(token[0], "PROCESS_ACCOUNTING") == 0 && token[1] && + (strcmp(token[1], "on") == 0 || strcmp(token[1], "yes") == 0)) + process_accounting = 1; + } config_close(parser); } @@ -411,8 +421,9 @@ int bootchartd_main(int argc UNUSED_PARAM, char **argv) putenv((char*)bb_PATH_root_path); tempdir = make_tempdir(); - do_logging(sample_period_us); - finalize(tempdir, cmd == CMD_START ? argv[2] : NULL); + do_logging(sample_period_us, process_accounting); + finalize(tempdir, cmd == CMD_START ? argv[2] : NULL, + process_accounting); return EXIT_SUCCESS; } -- 1.7.8.rc1
signature.asc
Description: OpenPGP digital signature
_______________________________________________ busybox mailing list [email protected] http://lists.busybox.net/mailman/listinfo/busybox
