bootchart.c revision e8e581bf256b8c0fbd430935af79fa0e8ee570a1
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright (C) 2009-2013 Intel Coproration
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 <sys/resource.h>
#include <stdio.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <time.h>
#include <getopt.h>
#include <limits.h>
#include <errno.h>
#include <fcntl.h>
#include <stdbool.h>
#include <systemd/sd-journal.h>
#include "util.h"
#include "fileio.h"
#include "macro.h"
#include "conf-parser.h"
#include "strxcpyx.h"
#include "path-util.h"
#include "store.h"
#include "svg.h"
#include "bootchart.h"
double graph_start;
double log_start;
double sampletime[MAXSAMPLES];
int entropy_avail[MAXSAMPLES];
int pscount;
int cpus;
double interval;
int overrun = 0;
static int exiting = 0;
int sysfd=-1;
/* graph defaults */
bool arg_entropy = false;
bool initcall = true;
bool arg_relative = false;
bool arg_filter = true;
bool arg_show_cmdline = false;
bool arg_pss = false;
int samples;
static void signal_handler(int sig) {
if (sig++)
sig--;
exiting = 1;
}
#define BOOTCHART_CONF "/etc/systemd/bootchart.conf"
static void parse_conf(void) {
const ConfigTableItem items[] = {
};
_cleanup_fclose_ FILE *f;
int r;
if (!f)
return;
if (r < 0)
}
};
int c;
int r;
switch (c) {
case 'r':
arg_relative = true;
break;
case 'f':
if (r < 0)
log_warning("failed to parse --freq/-f argument '%s': %s",
break;
case 'F':
arg_filter = false;
break;
case 'C':
arg_show_cmdline = true;
break;
case 'n':
if (r < 0)
log_warning("failed to parse --samples/-n argument '%s': %s",
break;
case 'o':
break;
case 'i':
break;
case 'p':
arg_pss = true;
break;
case 'x':
if (r < 0)
log_warning("failed to parse --scale-x/-x argument '%s': %s",
break;
case 'y':
if (r < 0)
log_warning("failed to parse --scale-y/-y argument '%s': %s",
break;
case 'e':
arg_entropy = true;
break;
case 'h':
exit (EXIT_SUCCESS);
break;
default:
break;
}
}
if (arg_samples_len > MAXSAMPLES) {
return -EINVAL;
}
if (arg_hz <= 0.0) {
return -EINVAL;
}
return 0;
}
static void do_journal_append(char *file)
{
int r, f, j = 0;
ssize_t n;
*p = NULL;
if (bootchart_file)
if (bootchart_message)
if (!p) {
r = log_oom();
return;
}
if (f < 0) {
return;
}
if (n < 0) {
close(f);
return;
}
close(f);
j++;
r = sd_journal_sendv(iovec, j);
if (r < 0)
}
};
char output_file[PATH_MAX];
char datestr[200];
time_t t = 0;
int r;
parse_conf();
if (r < 0)
return EXIT_FAILURE;
/*
* If the kernel executed us through init=/usr/lib/systemd/systemd-bootchart, then
* fork:
* - child logs data
*/
if (getpid() == 1) {
if (fork()) {
/* parent */
}
}
argv[0][0] = '@';
/* start with empty ps LL */
if (!ps_first) {
perror("calloc(ps_struct)");
}
log_uptime();
/* main program loop */
int res;
double sample_stop;
long newint_ns;
double elapsed;
double timeleft;
}
if (sysfd < 0)
if (!build)
"PRETTY_NAME", &build,
NULL);
/* wait for /proc to become available, discarding samples */
if (graph_start <= 0.0)
log_uptime();
else
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 (res) {
/* caught signal, probably HUP! */
break;
}
perror("nanosleep()");
exit (EXIT_FAILURE);
}
} else {
overrun++;
/* calculate how many samples we lost and scrap them */
}
}
/* do some cleanup, close fd's */
}
if (!of) {
}
if (!of) {
exit (EXIT_FAILURE);
}
if (of)
if (sysfd >= 0)
/* nitpic cleanups */
}
/* don't complain when overrun once, happens most commonly on 1st sample */
if (overrun > 1)
return 0;
}