From f2f85884caac671da84256acb44148df9a4dca70 Mon Sep 17 00:00:00 2001 From: Harald Hoyer Date: Tue, 12 Feb 2013 15:36:29 -0800 Subject: bootchart: make bootchart work from within the initrd With this patch, bootchart can be started from within the initramfs via the kernel command line "rdinit=/usr/lib/systemd/systemd-bootchart" see: http://harald.fedorapeople.org/downloads/bootchart-20130207-1652.svg --- src/bootchart/bootchart.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'src/bootchart/bootchart.c') diff --git a/src/bootchart/bootchart.c b/src/bootchart/bootchart.c index 6b9252dbb9..fb95c6b807 100644 --- a/src/bootchart/bootchart.c +++ b/src/bootchart/bootchart.c @@ -47,7 +47,7 @@ struct cpu_stat_struct cpustat[MAXCPUS]; int pscount; int cpus; double interval; -FILE *of; +FILE *of = NULL; int overrun = 0; static int exiting = 0; @@ -64,7 +64,7 @@ double scale_x = 100.0; /* 100px = 1sec */ double scale_y = 20.0; /* 16px = 1 process bar */ char init_path[PATH_MAX] = "/sbin/init"; -char output_path[PATH_MAX] = "/var/log"; +char output_path[PATH_MAX] = "/run/log"; static struct rlimit rlim; @@ -235,6 +235,7 @@ int main(int argc, char *argv[]) execl(init_path, init_path, NULL); } } + argv[0][0] = '@'; /* start with empty ps LL */ ps_first = calloc(1, sizeof(struct ps_struct)); @@ -264,6 +265,14 @@ int main(int argc, char *argv[]) sampletime[samples] = gettime_ns(); + if (!of && (access(output_path, R_OK|W_OK|X_OK) == 0)) { + t = time(NULL); + strftime(datestr, sizeof(datestr), "%Y%m%d-%H%M", localtime(&t)); + snprintf(output_file, PATH_MAX, "%s/bootchart-%s.svg", output_path, datestr); + of = fopen(output_file, "w"); + } + + /* wait for /proc to become available, discarding samples */ if (!(graph_start > 0.0)) log_uptime(); @@ -323,11 +332,13 @@ int main(int argc, char *argv[]) } closedir(proc); - t = time(NULL); - strftime(datestr, sizeof(datestr), "%Y%m%d-%H%M", localtime(&t)); - snprintf(output_file, PATH_MAX, "%s/bootchart-%s.svg", output_path, datestr); + if (!of) { + t = time(NULL); + strftime(datestr, sizeof(datestr), "%Y%m%d-%H%M", localtime(&t)); + snprintf(output_file, PATH_MAX, "%s/bootchart-%s.svg", output_path, datestr); + of = fopen(output_file, "w"); + } - of = fopen(output_file, "w"); if (!of) { perror("open output_file"); exit (EXIT_FAILURE); -- cgit v1.2.3-54-g00ecf