summaryrefslogtreecommitdiff
path: root/src/bootchart/bootchart.c
diff options
context:
space:
mode:
authorHarald Hoyer <harald@redhat.com>2013-02-12 15:36:29 -0800
committerAuke Kok <auke-jan.h.kok@intel.com>2013-02-12 16:06:06 -0800
commitf2f85884caac671da84256acb44148df9a4dca70 (patch)
tree51daf3484ea3940508d6be3bb38db9b71b4a16cf /src/bootchart/bootchart.c
parent759c945a43577d56e85a927f15e7d9aaa94a4e4a (diff)
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
Diffstat (limited to 'src/bootchart/bootchart.c')
-rw-r--r--src/bootchart/bootchart.c23
1 files changed, 17 insertions, 6 deletions
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);