diff options
author | Daniel Mack <daniel@zonque.org> | 2015-04-02 15:15:43 +0200 |
---|---|---|
committer | Daniel Mack <daniel@zonque.org> | 2015-04-03 15:29:18 +0200 |
commit | 1f2ecb0393bf071fcd476300e0b3f94726b01b15 (patch) | |
tree | 8aaee7d724db8cc55139b9779354d3c4458a09f7 /src/bootchart/bootchart.c | |
parent | f91781329c6d8a760e3c1b88b66b0e2137c2e5ab (diff) |
bootchart: kill a bunch of global variables
This code is in a confusingly bad shape. Kill a bunch of global variables
and pass needed variables around in function calls.
Diffstat (limited to 'src/bootchart/bootchart.c')
-rw-r--r-- | src/bootchart/bootchart.c | 55 |
1 files changed, 37 insertions, 18 deletions
diff --git a/src/bootchart/bootchart.c b/src/bootchart/bootchart.c index 8cb1ee6921..95939007b8 100644 --- a/src/bootchart/bootchart.c +++ b/src/bootchart/bootchart.c @@ -58,14 +58,6 @@ #include "bootchart.h" #include "list.h" -double graph_start; -double log_start; -struct ps_struct *ps_first; -int pscount; -int cpus; -double interval; -FILE *of = NULL; -int overrun = 0; static int exiting = 0; #define DEFAULT_SAMPLES_LEN 500 @@ -77,20 +69,17 @@ static int exiting = 0; /* graph defaults */ bool arg_entropy = false; -bool initcall = true; +bool arg_initcall = true; bool arg_relative = false; bool arg_filter = true; bool arg_show_cmdline = false; bool arg_show_cgroup = false; bool arg_pss = false; bool arg_percpu = false; -int samples; int arg_samples_len = DEFAULT_SAMPLES_LEN; /* we record len+1 (1 start sample) */ double arg_hz = DEFAULT_HZ; double arg_scale_x = DEFAULT_SCALE_X; double arg_scale_y = DEFAULT_SCALE_Y; -static struct list_sample_data *sampledata; -struct list_sample_data *head; char arg_init_path[PATH_MAX] = DEFAULT_INIT; char arg_output_path[PATH_MAX] = DEFAULT_OUTPUT; @@ -315,6 +304,11 @@ int main(int argc, char *argv[]) { _cleanup_free_ char *build = NULL; _cleanup_close_ int sysfd = -1; _cleanup_closedir_ DIR *proc = NULL; + _cleanup_fclose_ FILE *of = NULL; + double graph_start; + double log_start; + double interval; + struct ps_struct *ps_first; struct sigaction sig = { .sa_handler = signal_handler, }; @@ -323,7 +317,13 @@ int main(int argc, char *argv[]) { char datestr[200]; time_t t = 0; int r; + int pscount = 0; + int n_cpus = 0; + int overrun = 0; + int samples; struct rlimit rlim; + struct list_sample_data *head; + static struct list_sample_data *sampledata; parse_conf(); @@ -364,7 +364,18 @@ int main(int argc, char *argv[]) { interval = (1.0 / arg_hz) * 1000000000.0; - log_uptime(); + if (arg_relative) + graph_start = log_start = gettime_ns(); + else { + struct timespec n; + double uptime; + + clock_gettime(CLOCK_BOOTTIME, &n); + uptime = (n.tv_sec + (n.tv_nsec / (double) NSEC_PER_SEC)); + + log_start = gettime_ns(); + graph_start = log_start - uptime; + } if (graph_start < 0.0) { log_error("Failed to setup graph start time.\n\n" @@ -409,7 +420,7 @@ int main(int argc, char *argv[]) { /* wait for /proc to become available, discarding samples */ if (proc) { - r = log_sample(proc, samples, &sampledata); + r = log_sample(proc, samples, ps_first, &sampledata, &pscount, &n_cpus); if (r < 0) return EXIT_FAILURE; } @@ -475,7 +486,18 @@ int main(int argc, char *argv[]) { return EXIT_FAILURE; } - r = svg_do(strna(build)); + r = svg_do(of, + strna(build), + head, + ps_first, + samples, + pscount, + n_cpus, + graph_start, + log_start, + interval, + overrun); + if (r < 0) { log_error_errno(r, "Error generating svg file: %m\n"); return EXIT_FAILURE; @@ -485,9 +507,6 @@ int main(int argc, char *argv[]) { do_journal_append(output_file); - if (of) - fclose(of); - /* nitpic cleanups */ ps = ps_first->next_ps; while (ps->next_ps) { |