home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
tusportal.tus.k12.pa.us
/
tusportal.tus.k12.pa.us.tar
/
tusportal.tus.k12.pa.us
/
Wyse
/
latest-image.raw
/
0.img
/
sbin
/
bootchartd
< prev
next >
Wrap
Text File
|
2010-01-14
|
6KB
|
251 lines
#!/bin/bash
#
# Bootchart logger script
# Ziga Mahkovec <ziga.mahkovec@klika.si>
#
# This script is used for data collection for the bootchart
# boot performance visualization tool (http://www.bootchart.org).
#
# To profile the boot process, bootchartd should be called instead of
# /sbin/init. Modify the kernel command line to include:
# init=/sbin/bootchartd
#
# bootchartd will then start itself in background and exec /sbin/init
# (or an alternative init process if specified using bootchart_init=)
#
# To profile a running system, run:
# $ /sbin/bootchartd start; sleep 30; /sbin/bootchartd stop
#
PATH="/sbin:/bin:/usr/sbin:/usr/bin:$PATH"
# Read configuration.
CONF="/etc/bootchartd.conf"
if [ -f $PWD/bootchartd.conf ]; then
. $PWD/bootchartd.conf
elif [ -f $CONF ]; then
. $CONF
else
echo "$CONF missing"
exit 1
fi
if test -z "`which accton >& /dev/null`"; then
PROCESS_ACCOUNTING="no"
fi
# Start the boot logger.
start()
{
# Mount the temporary file system for log file storage. If possible,
# a temporary directory is created. In most cases though (i.e. during
# boot), a tmpfs is mounted in /mnt. The mount point is immediately
# released using a lazy umount, so the script must never leave that
# directory.
LOG_DIR="$( mktemp -d /tmp/bootchart.XXXXXX 2>/dev/null )"
if [ -z "$LOG_DIR" ]; then
LOG_DIR="/lib/bootchart/mnt"
LAZY_UMOUNT="yes"
mount -n -t tmpfs -o size=$TMPFS_SIZE none "$LOG_DIR" >/dev/null 2>&1
fi
cd "$LOG_DIR"
[ -n "$LAZY_UMOUNT" ] && umount -nfl "$LOG_DIR"
# use dmsg for debugging
mknod kmsg c 1 11
echo "bootchartd started" >> kmsg
# Mount a copy of /proc just for us ...
mkdir proc
mount -n -t proc none proc
# Enable process accounting if configured
if [ "$PROCESS_ACCOUNTING" = "yes" ]; then
> kernel_pacct
accton kernel_pacct
echo "bootchartd pacct started" >> kmsg
fi
#
# Run loggers in background
#
/lib/bootchart/bootchart-collector -p proc $SAMPLE_HZ &
if [ -n "$IN_INIT" ]; then
# If we were called during init, wait for the boot process to end
wait_boot &
elif [ "$#" -gt 0 ]; then
# If a command was passed, run it
# (used for profiling specific applications)
echo "profile.process = $( basename $1 )" >> header
$@
stop
fi
}
# Wait for the boot process to end.
wait_boot()
{
local runlevel=$( sed -n 's/.*:\(.*\):initdefault:.*/\1/gp' /etc/inittab )
# The processes we have to wait for
local exit_proc="kdm_greet xterm konsole stopinitrd metacity mutter compiz"
# Don't exit until *all* the mandatory procs are running. Only used if exit_proc
# is unset.
local mandatory_procs="nautilus mutter"
# early_login in FC4 starts gdm early, so fall back to mingetty
local early_login="no"
grep -q early_login /proc/cmdline && early_login="yes"
if [ "x$runlevel" = "x2" -o "x$runlevel" = "x3" -o "$early_login" = "yes" ]; then
exit_proc="mingetty agetty rungetty getty"
fi
while true; do
if [ -n "$exit_proc" -a -n "$( pidof $exit_proc )" ]; then
# Give the exit process some time to start
stopinitrd=$( pidof stopinitrd )
if [ -n "$stopinitrd" ] ; then
# move initrd logs somewhere safe (?)
pkill -f /lib/bootchart/bootchart-collector
sleep 2 # the even
mv $LOG_DIR/*.log /mnt/dev/shm/
wait
kill $stopinitrd
exit 0
else # give an unambiguous settle afterwards
sleep 20
fi
# Flush the log files
stop
return
else
for proc in $mandatory_procs; do
if ! pidof $proc >/dev/null; then break; fi
sleep 30
stop
return
done
fi
usleep 200000
done;
}
# Stop the boot logger.
# Some final log files are created and then all log files
# from the tmpfs are packaged and stored in $BOOTLOG_DEST.
stop()
{
pkill -f /lib/bootchart/bootchart-collector
sleep 2 # the even
# Stop process accounting if configured
local pacct=
if [ "$PROCESS_ACCOUNTING" = "yes" ]; then
accton
pacct=kernel_pacct
fi
# Write system information
log_header
# Package log files
# FIXME: do we -really- need any of this ?
for i in *.log; do
if test -f /dev/shm/$i; then
cat /dev/shm/$i $i > $i.new && mv $i.new $i
rm /dev/shm/$i
fi
done
dmesg > dmesg
# if it hung - clean it up at least
pkill -9 -f /lib/bootchart/bootchart-collector
# cleanup
rm -f klog
umount proc
rmdir proc
tar -zcf "$BOOTLOG_DEST" header dmesg $pacct *.log
if [ -z "$LAZY_UMOUNT" ]; then
rm "$LOG_DIR"/*
rmdir "$LOG_DIR"
fi
# Render the chart if configured (and the renderer is installed)
if [ "$AUTO_RENDER" = "yes" -a -x /usr/bin/pybootchartgui ]; then
cd $AUTO_RENDER_DIR
/usr/bin/pybootchartgui -o "$AUTO_RENDER_DIR"/bootchart.$AUTO_RENDER_FORMAT -f $AUTO_RENDER_FORMAT "$BOOTLOG_DEST"
fi
}
# Log some basic information about the system.
log_header()
{
if [ -x "/usr/bin/dpkg-query" ]; then
version="$(dpkg-query -f'${Version}' -W bootchart)"
else
version="$(rpm -q bootchart --queryformat '%{VERSION}')"
fi
( echo "version = $version"
echo "title = Boot chart for $(hostname) ($(date))"
echo "system.uname = $(uname -srvm)"
echo "system.release = $(lsb_release -sd)"
echo "system.cpu = $(grep '^model name' /proc/cpuinfo)"\
"($(grep -c '^model name' /proc/cpuinfo))"
echo "system.kernel.options = $(sed q /proc/cmdline)"
) > header
}
if [ $$ -eq 1 ]; then
# Started by the kernel. Start the logger in background and exec
# init(1).
IN_INIT="yes"
echo "Starting bootchart logging"
start &
# Optionally, an alternative init(1) process may be specified using
# the kernel command line (e.g. "bootchart_init=/sbin/initng")
init="/sbin/init"
for i in $@; do
if [ "${i%%=*}" = "bootchart_init" ]; then
init="${i#*=}"
break
fi
if [ "${i%%=*}" = "init" ]; then
_init=${i#*=}
if test "$_init" != "/sbin/bootchartd"; then
init="$_init"
fi
break
fi
done
exec $init $*
fi
case "$1" in
"init")
# Started by the init script
IN_INIT="yes"
echo "Starting bootchart logging"
start &
;;
"start")
# Started by the user
shift
start $@
;;
"stop")
# Signal all background processes to stop logging
killall -USR1 bootchartd
;;
*)
echo $"Usage: $0 {init|start|stop}"
;;
esac