/***
This file is part of systemd.
Copyright (C) 2009-2013 Intel Corporation
Authors:
Auke Kok <auke-jan.h.kok@intel.com>
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
/***
Many thanks to those who contributed ideas and code:
- Ziga Mahkovec - Original bootchart author
- Anders Norgaard - PyBootchartgui
- Michael Meeks - bootchart2
- Scott James Remnant - Ubuntu C-based logger
- Arjan van der Ven - for the idea to merge bootgraph.pl functionality
***/
#include <errno.h>
#include <fcntl.h>
#include <getopt.h>
#include <limits.h>
#include <signal.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/resource.h>
#include <time.h>
#include <unistd.h>
#include "sd-journal.h"
#include "alloc-util.h"
#include "bootchart.h"
#include "conf-parser.h"
#include "def.h"
#include "fd-util.h"
#include "fileio.h"
#include "io-util.h"
#include "list.h"
#include "macro.h"
#include "parse-util.h"
#include "path-util.h"
#include "store.h"
#include "string-util.h"
#include "strxcpyx.h"
#include "svg.h"
#include "util.h"
static int exiting = 0;
/* graph defaults */
bool arg_entropy = false;
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;
exiting = 1;
}
static void parse_conf(void) {
};
}
static void help(void) {
printf("Usage: %s [OPTIONS]\n\n"
"Options:\n"
" -r --rel Record time relative to recording\n"
" -f --freq=FREQ Sample frequency [%g]\n"
" -n --samples=N Stop sampling at [%d] samples\n"
" -x --scale-x=N Scale the graph horizontally [%g] \n"
" -y --scale-y=N Scale the graph vertically [%g] \n"
" -p --pss Enable PSS graph (CPU intensive)\n"
" -e --entropy Enable the entropy_avail graph\n"
" -o --output=PATH Path to output files [%s]\n"
" -i --init=PATH Path to init executable [%s]\n"
" -F --no-filter Disable filtering of unimportant or ephemeral processes\n"
" -C --cmdline Display full command lines with arguments\n"
" -c --control-group Display process control group\n"
" --per-cpu Draw each CPU utilization and wait bar also\n"
" -h --help Display this message\n\n"
"See bootchart.conf for more information.\n",
}
enum {
};
{}
};
int c, r;
if (getpid() == 1)
opterr = 0;
switch (c) {
case 'r':
arg_relative = true;
break;
case 'f':
if (r < 0)
log_warning_errno(r, "failed to parse --freq/-f argument '%s': %m",
optarg);
break;
case 'F':
arg_filter = false;
break;
case 'C':
arg_show_cmdline = true;
break;
case 'c':
arg_show_cgroup = true;
break;
case 'n':
if (r < 0)
log_warning_errno(r, "failed to parse --samples/-n argument '%s': %m",
optarg);
break;
case 'o':
break;
case 'i':
break;
case 'p':
arg_pss = true;
break;
case 'x':
if (r < 0)
log_warning_errno(r, "failed to parse --scale-x/-x argument '%s': %m",
optarg);
break;
case 'y':
if (r < 0)
log_warning_errno(r, "failed to parse --scale-y/-y argument '%s': %m",
optarg);
break;
case 'e':
arg_entropy = true;
break;
case ARG_PERCPU:
arg_percpu = true;
break;
case 'h':
help();
return 0;
case '?':
if (getpid() != 1)
return -EINVAL;
else
return 0;
default:
assert_not_reached("Unhandled option code.");
}
if (arg_hz <= 0) {
log_error("Frequency needs to be > 0");
return -EINVAL;
}
return 1;
}
_cleanup_free_ char *p = NULL;
int r, j = 0;
ssize_t n;
if (!bootchart_file)
return log_oom();
if (!bootchart_message)
return log_oom();
if (!p)
return log_oom();
if (fd < 0)
if (n < 0)
return log_error_errno(n, "Failed to read bootchart data: %m");
j++;
r = sd_journal_sendv(iovec, j);
if (r < 0)
log_error_errno(r, "Failed to send bootchart: %m");
return 0;
}
double graph_start;
double log_start;
double interval;
int pscount = 0;
int n_cpus = 0;
int overrun = 0;
time_t t = 0;
int r, samples;
};
parse_conf();
if (r < 0)
return EXIT_FAILURE;
if (r == 0)
return EXIT_SUCCESS;
/*
* If the kernel executed us through init=/usr/lib/systemd/systemd-bootchart, then
* fork:
* - parent execs executable specified via init_path[] (/usr/lib/systemd/systemd by default) as pid=1
* - child logs data
*/
if (getpid() == 1) {
if (fork())
/* parent */
}
argv[0][0] = '@';
/* start with empty ps LL */
if (!ps_first) {
log_oom();
return EXIT_FAILURE;
}
if (arg_relative)
else {
struct timespec n;
double uptime;
log_start = gettime_ns();
}
if (graph_start < 0.0) {
log_error("Failed to setup graph start time.\n\n"
"The system uptime probably includes time that the system was suspended. "
"Use --rel to bypass this issue.");
return EXIT_FAILURE;
}
/* main program loop */
int res;
double sample_stop;
double elapsed;
double timeleft;
if (sampledata == NULL) {
log_oom();
return EXIT_FAILURE;
}
if (sysfd < 0)
if (!build) {
}
if (proc)
else
/* wait for /proc to become available, discarding samples */
if (proc) {
if (r < 0)
return EXIT_FAILURE;
}
sample_stop = gettime_ns();
/*
* check if we have not consumed our entire timeslice. If we
* do, don't sleep and take a new sample right away.
* we'll lose all the missed samples and overrun our total
* time
*/
if (timeleft > 0) {
if (res) {
/* caught signal, probably HUP! */
break;
return EXIT_FAILURE;
}
} else {
overrun++;
/* calculate how many samples we lost and scrap them */
}
}
/* do some cleanup, close fd's */
}
if (!of) {
assert_se(r > 0);
}
if (!of) {
return EXIT_FAILURE;
}
if (r < 0) {
log_error_errno(r, "Error generating svg file: %m");
return EXIT_FAILURE;
}
r = do_journal_append(output_file);
if (r < 0)
return EXIT_FAILURE;
/* nitpic cleanups */
}
}
sampledata = head;
while (sampledata->link_prev) {
}
/* don't complain when overrun once, happens most commonly on 1st sample */
if (overrun > 1)
return 0;
}