#!/bin/sh -e
### BEGIN INIT INFO
# Provides:          bootchart
# Required-Start:
# Required-Stop:
# Should-Start:      
# Default-Start:     S
# Default-Stop:
# Short-Description: Start bootchart
# Description:       Bootchart is normally started from the initramfs
#                    however this starts it if not
### END INIT INFO

[ -x /lib/bootchart/collector ] || exit 0

# Jail we run from in initramfs
JAIL=/dev/.bootchart

# Where we put the output
LOGS=/var/run/bootchart

test -d $JAIL && exit 0

grep -q "profile" /proc/cmdline && exit 0
grep -q "bootchart=disable" /proc/cmdline && exit 0

if grep -q "bootchart=[0-9]*hz" /proc/cmdline; then
    HZ=$(sed -e 's/.*bootchart=//;s/hz.*//' /proc/cmdline)
else
    HZ=25
fi

# Get lsb functions
. /lib/lsb/init-functions
. /etc/default/rcS

case "$1" in
    start)
	mkdir -p $LOGS
	/lib/bootchart/collector $HZ $LOGS 2>/dev/null &
	;;
    stop|restart|reload|force-reload)
	;;
    *)
	log_success_msg "Usage: /etc/init.d/bootchart {start|stop|restart|reload|force-reload}"
	exit 1
esac

exit 0
