Skip to content

Instantly share code, notes, and snippets.

@RamKromberg
Created September 8, 2016 16:30
Show Gist options
  • Save RamKromberg/21f64797e972564139c8ac84c364b943 to your computer and use it in GitHub Desktop.
Save RamKromberg/21f64797e972564139c8ac84c364b943 to your computer and use it in GitHub Desktop.
systemd-bootchart.nix WIP
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.systemd-bootchart;
systemd-bootchart = with pkgs; stdenv.mkDerivation rec {
version = "230";
name = "systemd-bootchart-v${version}";
src = fetchFromGitHub {
owner = "systemd";
repo = "systemd-bootchart";
rev = "v${version}";
sha256 = "1dbscx7hsvn6a5rbjfmpskwnp0n2hpwdb8n85gssnlmxas7cw72f";
};
postPatch = ''
substituteInPlace man/custom-man.xsl --replace \
http://docbook.sourceforge.net/release/xsl/current/manpages \
${docbook_xsl}/xml/xsl/docbook/manpages
substituteInPlace man/standard-options.xml --replace \
http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd \
${docbook_xml_dtd_45}/xml/dtd/docbook/docbookx.dtd
substituteInPlace man/standard-conf.xml --replace \
http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd \
${docbook_xml_dtd_45}/xml/dtd/docbook/docbookx.dtd
substituteInPlace man/systemd-bootchart.xml --replace \
http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd \
${docbook_xml_dtd_42}/xml/dtd/docbook/docbookx.dtd
substituteInPlace man/bootchart.conf.xml --replace \
http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd \
${docbook_xml_dtd_42}/xml/dtd/docbook/docbookx.dtd
'';
preConfigure = "./autogen.sh";
configureFlags = [ "--with-rootprefix=$(out)" ];
buildInputs = [
autoconf automake pkgconfig libtool intltool systemd libxslt.bin
docbook_xsl docbook_xml_dtd_45 docbook_xml_dtd_42
];
postInstall = ''
rm -f $out/etc/systemd/bootchart.conf
ln -s /etc/systemd/bootchart.conf $out/etc/systemd/bootchart.conf
'';
meta = with stdenv.lib; {
homepage = https://github.com/systemd/systemd-bootchart;
description = "Boot performance graphing tool";
license = with licenses; [ gpl2Plus lgpl21Plus ];
platforms = platforms.linux;
};
};
in
{
options = {
services.systemd-bootchart = {
enable = mkOption {
default = false;
description = ''
Enable the boot performance graphing tool.
'';
};
daemon = mkOption {
default = true;
description = ''
Enable the boot performance graphing tool daemon.
Disables the default kernel command line <literal>init=</literal> option.
Note: Kernel <literal>init=</literal> is currently unimplemented.
'';
};
samples = mkOption {
default = "500";
description = ''
Configure the amount of samples to record in total before bootchart exits.
Each sample will record at intervals defined by <literal>frequency=</literal>.
'';
};
frequency = mkOption {
default = "25";
description = ''
Configure the sample log frequency.
This can be a fractional number, but must be larger than <literal>0.0</literal>.
Most systems can cope with values under <literal>25–50</literal> without impacting boot time severely.
'';
};
relative = mkOption {
default = "no";
description = ''
Configures whether the left axis of the output graph equals <literal>time=0.0</literal> (<literal>CLOCK_MONOTONIC</literal> start).
This is useful for using bootchart at post-boot time to profile an already booted system, otherwise the graph would become extremely large.
If set to yes, the horizontal axis starts at the first recorded sample instead of <literal>time=0.0</literal>.
'';
};
filter = mkOption {
default = "yes";
description = ''
Configures whether the resulting graph should omit tasks that did not contribute significantly to the boot.
Processes that are too short-lived (only seen in one sample) or that do not consume any significant CPU time (less than <literal>0.001sec</literal>) will not be displayed in the output graph.
'';
};
output = mkOption {
default = "/run/log";
description = ''
Configures the output directory for writing the graphs.
By default, bootchart writes the graphs to <literal>/run/log</literal>.
'';
};
init = mkOption {
default = "${systemd}/lib/systemd/systemd";
description = ''
Configures bootchart to run a non-standard binary instead of <literal>/usr/lib/systemd/systemd</literal>.
This option is only relevant if bootchart was invoked from the kernel command line with <literal>init=/usr/lib/systemd/systemd-bootchart</literal>.
Note: Kernel <literal>init=</literal> is currently unimplemented.
'';
};
plotMemoryUsage = mkOption {
default = "no";
description = ''
If set to yes, enables logging and graphing of processes' PSS memory consumption.
'';
};
plotEntropyGraph = mkOption {
default = "no";
description = ''
If set to yes, enables logging and graphing of the kernel random entropy pool size.
'';
};
scaleX = mkOption {
default = "100";
description = ''
Horizontal scaling factor for all variable graph components.
'';
};
scaleY = mkOption {
default = "20";
description = ''
Vertical scaling factor for all variable graph components.
'';
};
controlGroup = mkOption {
default = "no";
description = ''
Display process control group.
'';
};
perCPU = mkOption {
default = "no";
description = ''
Display per CPU.
'';
};
};
};
config = mkIf cfg.enable {
environment.etc."systemd/bootchart.conf".text = ''
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# 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.
#
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See bootchart.conf(5) for details.
[Bootchart]
Samples=${cfg.samples}
Frequency=${cfg.frequency}
Relative=${cfg.relative}
Filter=${cfg.filter}
Output=${cfg.output}
Init=${cfg.init}
PlotMemoryUsage=${cfg.plotMemoryUsage}
PlotEntropyGraph=${cfg.plotEntropyGraph}
ScaleX=${cfg.scaleX}
ScaleY=${cfg.scaleY}
ControlGroup=${cfg.controlGroup}
PerCPU=${cfg.perCPU}
'';
#TODO: Implement real init=${systemd-bootchart}/lib/systemd/systemd-bootchart instead of a daemon.
#journalctl -b -F BOOTCHART --full
systemd.services = mkIf cfg.daemon {
systemd-bootchart = {
description = "Boot Process Profiler";
documentation = "man:systemd-bootchart.service(1) man:bootchart.conf(5)";
defaultDependencies = "no";
wantedBy = [ "sysinit.target" ];
serviceConfig.ExecStart = "${systemd-bootchart}/lib/systemd/systemd-bootchart -r";
};
};
environment.systemPackages = [ systemd-bootchart ];
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment