aboutsummaryrefslogtreecommitdiff
path: root/init
diff options
context:
space:
mode:
authorQuentin Casasnovas <quentin.casasnovas@mathembedded.com>2012-01-18 02:12:13 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2012-01-18 02:12:13 +0100
commitc158601d50c2fab56ed0043989ba83fa9cd7f96a (patch)
treeba25214c561461587410358da443620bb4a2e437 /init
parentce4f39ac7c6c30e94f7ff392058928bd98347113 (diff)
downloadbusybox-w32-c158601d50c2fab56ed0043989ba83fa9cd7f96a.tar.gz
busybox-w32-c158601d50c2fab56ed0043989ba83fa9cd7f96a.tar.bz2
busybox-w32-c158601d50c2fab56ed0043989ba83fa9cd7f96a.zip
bootchartd: add process accounting feature
function old new delta bootchartd_main 962 1088 +126 finalize 294 357 +63 acct - 33 +33 ------------------------------------------------------------------------------ (add/remove: 2/0 grow/shrink: 2/0 up/down: 222/0) Total: 222 bytes Signed-off-by: Quentin Casasnovas <quentin.casasnovas@mathembedded.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'init')
-rw-r--r--init/bootchartd.c39
1 files changed, 24 insertions, 15 deletions
diff --git a/init/bootchartd.c b/init/bootchartd.c
index cc23e6073..9fd623357 100644
--- a/init/bootchartd.c
+++ b/init/bootchartd.c
@@ -208,14 +208,8 @@ static char *make_tempdir(void)
208 return tempdir; 208 return tempdir;
209} 209}
210 210
211static void do_logging(unsigned sample_period_us) 211static void do_logging(unsigned sample_period_us, int process_accounting)
212{ 212{
213 //# Enable process accounting if configured
214 //if [ "$PROCESS_ACCOUNTING" = "yes" ]; then
215 // [ -e kernel_pacct ] || : > kernel_pacct
216 // accton kernel_pacct
217 //fi
218
219 FILE *proc_stat = xfopen("proc_stat.log", "w"); 213 FILE *proc_stat = xfopen("proc_stat.log", "w");
220 FILE *proc_diskstats = xfopen("proc_diskstats.log", "w"); 214 FILE *proc_diskstats = xfopen("proc_diskstats.log", "w");
221 //FILE *proc_netdev = xfopen("proc_netdev.log", "w"); 215 //FILE *proc_netdev = xfopen("proc_netdev.log", "w");
@@ -223,6 +217,11 @@ static void do_logging(unsigned sample_period_us)
223 int look_for_login_process = (getppid() == 1); 217 int look_for_login_process = (getppid() == 1);
224 unsigned count = 60*1000*1000 / sample_period_us; /* ~1 minute */ 218 unsigned count = 60*1000*1000 / sample_period_us; /* ~1 minute */
225 219
220 if (process_accounting) {
221 close(xopen("kernel_pacct", O_WRONLY | O_CREAT | O_TRUNC));
222 acct("kernel_pacct");
223 }
224
226 while (--count && !bb_got_signal) { 225 while (--count && !bb_got_signal) {
227 char *p; 226 char *p;
228 int len = open_read_close("/proc/uptime", G.jiffy_line, sizeof(G.jiffy_line)-2); 227 int len = open_read_close("/proc/uptime", G.jiffy_line, sizeof(G.jiffy_line)-2);
@@ -253,11 +252,9 @@ static void do_logging(unsigned sample_period_us)
253 wait_more: 252 wait_more:
254 usleep(sample_period_us); 253 usleep(sample_period_us);
255 } 254 }
256
257 // [ -e kernel_pacct ] && accton off
258} 255}
259 256
260static void finalize(char *tempdir, const char *prog) 257static void finalize(char *tempdir, const char *prog, int process_accounting)
261{ 258{
262 //# Stop process accounting if configured 259 //# Stop process accounting if configured
263 //local pacct= 260 //local pacct=
@@ -265,6 +262,9 @@ static void finalize(char *tempdir, const char *prog)
265 262
266 FILE *header_fp = xfopen("header", "w"); 263 FILE *header_fp = xfopen("header", "w");
267 264
265 if (process_accounting)
266 acct(NULL);
267
268 if (prog) 268 if (prog)
269 fprintf(header_fp, "profile.process = %s\n", prog); 269 fprintf(header_fp, "profile.process = %s\n", prog);
270 270
@@ -307,7 +307,7 @@ static void finalize(char *tempdir, const char *prog)
307 fclose(header_fp); 307 fclose(header_fp);
308 308
309 /* Package log files */ 309 /* Package log files */
310 system("tar -zcf /var/log/bootchart.tgz header *.log"); // + $pacct 310 system(xasprintf("tar -zcf /var/log/bootlog.tgz header %s *.log", process_accounting ? "kernel_pacct" : ""));
311 /* Clean up (if we are not in detached tmpfs) */ 311 /* Clean up (if we are not in detached tmpfs) */
312 if (tempdir) { 312 if (tempdir) {
313 unlink("header"); 313 unlink("header");
@@ -315,6 +315,8 @@ static void finalize(char *tempdir, const char *prog)
315 unlink("proc_diskstats.log"); 315 unlink("proc_diskstats.log");
316 //unlink("proc_netdev.log"); 316 //unlink("proc_netdev.log");
317 unlink("proc_ps.log"); 317 unlink("proc_ps.log");
318 if (process_accounting)
319 unlink("kernel_pacct");
318 rmdir(tempdir); 320 rmdir(tempdir);
319 } 321 }
320 322
@@ -338,6 +340,7 @@ int bootchartd_main(int argc UNUSED_PARAM, char **argv)
338 unsigned sample_period_us; 340 unsigned sample_period_us;
339 pid_t parent_pid, logger_pid; 341 pid_t parent_pid, logger_pid;
340 smallint cmd; 342 smallint cmd;
343 int process_accounting;
341 enum { 344 enum {
342 CMD_STOP = 0, 345 CMD_STOP = 0,
343 CMD_START, 346 CMD_START,
@@ -371,6 +374,7 @@ int bootchartd_main(int argc UNUSED_PARAM, char **argv)
371 374
372 /* Read config file: */ 375 /* Read config file: */
373 sample_period_us = 200 * 1000; 376 sample_period_us = 200 * 1000;
377 process_accounting = 0;
374 if (ENABLE_FEATURE_BOOTCHARTD_CONFIG_FILE) { 378 if (ENABLE_FEATURE_BOOTCHARTD_CONFIG_FILE) {
375 char* token[2]; 379 char* token[2];
376 parser_t *parser = config_open2("/etc/bootchartd.conf" + 5, fopen_for_read); 380 parser_t *parser = config_open2("/etc/bootchartd.conf" + 5, fopen_for_read);
@@ -379,11 +383,16 @@ int bootchartd_main(int argc UNUSED_PARAM, char **argv)
379 while (config_read(parser, token, 2, 0, "#=", PARSE_NORMAL & ~PARSE_COLLAPSE)) { 383 while (config_read(parser, token, 2, 0, "#=", PARSE_NORMAL & ~PARSE_COLLAPSE)) {
380 if (strcmp(token[0], "SAMPLE_PERIOD") == 0 && token[1]) 384 if (strcmp(token[0], "SAMPLE_PERIOD") == 0 && token[1])
381 sample_period_us = atof(token[1]) * 1000000; 385 sample_period_us = atof(token[1]) * 1000000;
386 if (strcmp(token[0], "PROCESS_ACCOUNTING") == 0 && token[1]
387 && (strcmp(token[1], "on") == 0 || strcmp(token[1], "yes") == 0)
388 ) {
389 process_accounting = 1;
390 }
382 } 391 }
383 config_close(parser); 392 config_close(parser);
393 if ((int)sample_period_us <= 0)
394 sample_period_us = 1; /* prevent division by 0 */
384 } 395 }
385 if ((int)sample_period_us <= 0)
386 sample_period_us = 1; /* prevent division by 0 */
387 396
388 /* Create logger child: */ 397 /* Create logger child: */
389 logger_pid = fork_or_rexec(argv); 398 logger_pid = fork_or_rexec(argv);
@@ -411,8 +420,8 @@ int bootchartd_main(int argc UNUSED_PARAM, char **argv)
411 putenv((char*)bb_PATH_root_path); 420 putenv((char*)bb_PATH_root_path);
412 421
413 tempdir = make_tempdir(); 422 tempdir = make_tempdir();
414 do_logging(sample_period_us); 423 do_logging(sample_period_us, process_accounting);
415 finalize(tempdir, cmd == CMD_START ? argv[2] : NULL); 424 finalize(tempdir, cmd == CMD_START ? argv[2] : NULL, process_accounting);
416 return EXIT_SUCCESS; 425 return EXIT_SUCCESS;
417 } 426 }
418 427