Boot time/Scripts

From openSUSE

Contents

Various scripts

Scripts to initiate the bootchart process from init level 1

Scripts to help analyzing boot times using bootchart. These scripts enables users to restart the environment by going to init level 1, and then back to init level 5. It will stop bootchart when the gdmgreeter has been loaded.

I will try to provide these as downloadable files, but for now, copy and paste will be needed.

flush-disk.c is written by Robert Love @ Novell and is released under GPLv2.

Installation instructions

Download the files below, then do the following;

Make all files, but flush-disk.c and Makefile, executable (chmod 755 filename)

Place bchart-init and bchart-stop in /etc/init.d

Place bchart.sh in /root/bin

In the directory where flush-disk.c and the Makefile are, run make, then copy flush-disk to /sbin

Usage

Close all open programs

Open a terminal

Become superuser, then run /root/bin/bchart.sh

The environment will be restarted. Wait for the GUI login prompt

Login to the desktop

Open a terminal

Run java -jar /usr/share/java/bootchart.jar /tmp/bootchart.tgz

Review the bootchart.png file with an image viewer of your choice

Files

bchart-init

#! /bin/bash
#
# Author: Magnus Boman <mboman@novell.com>
# Version: 20061017-0.1
#
# /etc/init.d/bchart-init
#
# A script to analyze system startup times with bootchartd
# Certain bits and pieces of "single" has been put in to this script as well
#
### BEGIN INIT INFO
# Provides: bchart-init
# Required-Start: $all
# Required-Stop:
# Default-Start:  1 S
# Default-Stop:
# Description:    Setup the system to analyze startup times with bootchartd
### END INIT INFO

case "$1" in
    start)
	## Make sure we don't run again
	chkconfig bchart-init off

	## Make sure our "stop" script will run
	chkconfig bchart-stop on
	
	## We need to find out about all running processes. We then need to use this information to remove all those processes
	## from the bootchartd results. Otherwise we end up with useless stats
	ps ax -o command=|grep -vix rc|cut -d" " -f 1|tr -d [] >/tmp/running-processes.tmp
	
	## Flush disk buffers
	sync
	sync
	
	for i in `mount | awk '{print $1}' | grep ^"\/dev\/"`; do
		/sbin/flush-disk $i
	done
	
	## Free pagecache, dentries and inodes
	echo 3 > /proc/sys/vm/drop_caches	

	## Start the bootchart deamon
	bootchartd start
	
	## Switch to init level 5
	telinit 5
	
	;;
    stop)
	;;
    *)
	exit 1
	;;
esac


bchart-stop

#! /bin/bash
#
# Author: Magnus Boman <mboman@novell.com>
# Version: 20061017-0.1
#
# /etc/init.d/bchart-stop
#
# A script to analyze system startup times with bootchartd
#
### BEGIN INIT INFO
# Provides: bchart-stop
# Required-Start: xdm
# Required-Stop:
# Default-Start:  5
# Default-Stop:
# Description:    Setup the system to analyze startup times with bootchartd
### END INIT INFO

case "$1" in
    start)
	## Enable "single"
	chkconfig single on
	
	## Make sure we don't run again
	chkconfig bchart-stop off
	
	while [ "`pidof gdmgreeter`" = "" ]; do
		sleep 1
	done

	## Stop the bootchart deamon
	bootchartd stop

	## Wait a couple of seconds to make sure that the bootchart files have been written
	sleep 2

	## Fix up the bootchart process list
	tar xvf /var/log/bootchart.tgz -C /tmp

	## Remove directory path from name in running processes
	for i in `grep ^/ /tmp/running-processes.tmp`; do basename "$i"; done >/tmp/running-processes
	## Get running processes that does not start with a /
	grep -vi ^/ /tmp/running-processes.tmp >>/tmp/running-processes
	echo -n "cat /tmp/proc_ps.log" >/tmp/bootchartd-fixup.sh
	awk '{ printf "|grep -iv \"(" $1 ")\"" }' </tmp/running-processes >>/tmp/bootchartd-fixup.sh
	echo " >/tmp/fixed_proc_ps.log" >>/tmp/bootchartd-fixup.sh
	chmod 755 /tmp/bootchartd-fixup.sh
	/tmp/bootchartd-fixup.sh
	mv /tmp/fixed_proc_ps.log /tmp/proc_ps.log
	tar -zcvf /tmp/bootchart.tgz -C /tmp proc_ps.log proc_diskstats.log proc_stat.log header

	## This doesn't work as bootchart.jar requires an X connection
	## So it needs to be run manually
#	cd /tmp
#	java -jar /usr/share/java/bootchart.jar /tmp/bootchart.tgz

	;;
    stop)
	;;
    *)
	exit 1
	;;
esac


bchart.sh

#!/bin/bash
#
# Author: Magnus Boman <mboman@novell.com>
# Version: 20061010-0.1
#
# /root/bin/bchart.sh
#
# A script to analyze system startup times with bootchartd

# Disable "single" or our script will be terminated once we reached init level 1
chkconfig single off

# Make sure that our script starts when we reach init level 1
chkconfig bchart-init on

# Go to init level 1
telinit 1


Makefile

CFLAGS = -Wall -g
LDFLAGS = -g

prefix = $(HOME)
targets = flush-disk
objs = flush-disk.o

all : $(targets)

flush-disk : $(objs)

clean :
	rm -f $(targets) $(objs)

flush-disk.c

/*

 * flush-disk.c - flush the buffer cache of a given blkdev

 *

 * Robert "Spunky" Love	<rml@novell.com>

 */



#include <stdio.h>

#include <stdlib.h>

#include <fcntl.h>

#include <sys/ioctl.h>

#include <sys/types.h>

#include <sys/stat.h>

#include <linux/fs.h>



int main (int argc, char *argv[])

{

	char *blkdev;

	int fd, ret;



	if (argc < 2) {

		fprintf (stderr, "usage: %s <disk to flush>\n", argv[0]);

		return 1;

	}



	blkdev = argv[1];



	fd = open (blkdev, O_RDONLY);

	if (fd < 0) {

		perror ("open");

		return 1;

	}



	ret = ioctl (fd, BLKFLSBUF);

	if (ret) {

		perror ("ioctl");

		return 1;

	}

		

	return 0;

}