Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 345695 | Differences between
and this patch

Collapse All | Expand All

(-)a/Makefile (-7 / +11 lines)
Lines 8-23 CFLAGS ?= -g -Wall -O0 Link Here
8
BINDIR ?= /usr/bin
8
BINDIR ?= /usr/bin
9
PYTHON ?= python
9
PYTHON ?= python
10
DOCDIR ?= /usr/share/docs/bootchart
10
DOCDIR ?= /usr/share/docs/bootchart
11
LIBDIR ?= /lib
11
ifndef PY_LIBDIR
12
ifndef PY_LIBDIR
12
ifndef NO_PYTHON_COMPILE
13
ifndef NO_PYTHON_COMPILE
13
PY_LIBDIR := $(shell $(PYTHON) -c "from distutils import sysconfig; print(sysconfig.get_config_var('DESTLIB'))")
14
PY_LIBDIR := $(shell $(PYTHON) -c "from distutils import sysconfig; print(sysconfig.get_config_var('DESTLIB'))")
14
else
15
else
15
PY_LIBDIR = /usr/lib/python2.6
16
PY_LIBDIR = /usr${LIBDIR}/python2.6
16
endif
17
endif
17
endif
18
endif
18
PY_SITEDIR ?= $(PY_LIBDIR)/site-packages
19
PY_SITEDIR ?= $(PY_LIBDIR)/site-packages
19
LIBC_A_PATH = /usr/lib
20
LIBC_A_PATH = /usr${LIBDIR}
20
SYSTEMD_UNIT_DIR = /lib/systemd/system
21
SYSTEMD_UNIT_DIR = ${LIBDIR}/systemd/system
21
COLLECTOR = \
22
COLLECTOR = \
22
	collector/collector.o \
23
	collector/collector.o \
23
	collector/output.o \
24
	collector/output.o \
Lines 25-35 COLLECTOR = \ Link Here
25
	collector/tasks-netlink.o \
26
	collector/tasks-netlink.o \
26
	collector/dump.o
27
	collector/dump.o
27
28
28
all: bootchart-collector pybootchartgui/main.py
29
all: bootchart-collector bootchartd pybootchartgui/main.py
29
30
30
%.o:%.c
31
%.o:%.c
31
	$(CC) $(CFLAGS) $(LDFLAGS) -pthread -DVERSION=\"$(VER)\" -c $^ -o $@
32
	$(CC) $(CFLAGS) $(LDFLAGS) -pthread -DVERSION=\"$(VER)\" -c $^ -o $@
32
33
34
bootchartd: bootchartd.in
35
	sed -s "s:@LIBDIR@:${LIBDIR}:g" $^ > $@
36
33
bootchart-collector: $(COLLECTOR)
37
bootchart-collector: $(COLLECTOR)
34
	$(CC) $(CFLAGS) $(LDFLAGS) -pthread -Icollector -o $@ $^
38
	$(CC) $(CFLAGS) $(LDFLAGS) -pthread -Icollector -o $@ $^
35
39
Lines 45-56 py-install-compile: pybootchartgui/main.py Link Here
45
		PYTHONOPTIMIZE=1 $(PYTHON) $(PY_LIBDIR)/py_compile.py *.py ); :
49
		PYTHONOPTIMIZE=1 $(PYTHON) $(PY_LIBDIR)/py_compile.py *.py ); :
46
50
47
install-chroot:
51
install-chroot:
48
	install -d $(DESTDIR)/lib/bootchart/tmpfs
52
	install -d $(DESTDIR)${LIBDIR}/bootchart/tmpfs
49
53
50
install-collector: all install-chroot
54
install-collector: all install-chroot
51
	install -m 755 -D bootchartd $(DESTDIR)/sbin/bootchartd
55
	install -m 755 -D bootchartd $(DESTDIR)/sbin/bootchartd
52
	install -m 644 -D bootchartd.conf $(DESTDIR)/etc/bootchartd.conf
56
	install -m 644 -D bootchartd.conf $(DESTDIR)/etc/bootchartd.conf
53
	install -m 755 -D bootchart-collector $(DESTDIR)/lib/bootchart/bootchart-collector
57
	install -m 755 -D bootchart-collector $(DESTDIR)${LIBDIR}/bootchart/bootchart-collector
54
58
55
install-docs:
59
install-docs:
56
	install -m 644 -D README $(DESTDIR)$(DOCDIR)/README
60
	install -m 644 -D README $(DESTDIR)$(DOCDIR)/README
Lines 67-73 install: all py-install-compile install-collector install-service install-docs Link Here
67
71
68
clean:
72
clean:
69
	-rm -f bootchart-collector bootchart-collector-dynamic \
73
	-rm -f bootchart-collector bootchart-collector-dynamic \
70
	collector/*.o pybootchartgui/main.py
74
	collector/*.o pybootchartgui/main.py bootchartd
71
75
72
dist:
76
dist:
73
	COMMIT_HASH=`git show-ref -s -h | head -n 1` ; \
77
	COMMIT_HASH=`git show-ref -s -h | head -n 1` ; \
(-)a/bootchartd (-200 lines)
Lines 1-200 Link Here
1
#!/bin/bash
2
#
3
# Bootchart logger script
4
# Ziga Mahkovec  <ziga.mahkovec@klika.si>
5
# Michael Meeks  <michael.meeks@novell.com>
6
#
7
# This script is used for data collection for the bootchart2
8
# boot performance visualization tool.
9
#
10
# To profile the boot process, bootchartd should be called instead of
11
# /sbin/init.  Modify the kernel command line to include:
12
#
13
# init=/sbin/bootchartd initcall_debug printk.time=y quiet
14
#
15
# bootchartd will then start itself in background and exec /sbin/init
16
# (or an alternative init process if specified using bootchart_init=)
17
#
18
# To profile a running system, run:
19
# $ /sbin/bootchartd start; sleep 30; /sbin/bootchartd stop
20
#
21
22
# Use a directory we know will be there, such that we can mount
23
# our 'proc' without having to touch a (potentially) read-only
24
# file-system.
25
TMPFS="/lib/bootchart/tmpfs"
26
COLLECTOR_BIN="/lib/bootchart/bootchart-collector"
27
28
# some initrds don't have usleep etc.
29
USLEEP="$COLLECTOR_BIN --usleep"
30
31
# we need to find our tools
32
PATH="/sbin:/bin:/usr/sbin:/usr/bin:$PATH"
33
34
# Defaults, in case we can't find our configuration
35
SAMPLE_HZ=50
36
BUILDLOG_DEST=/var/log/bootchart.tgz
37
AUTO_RENDER="no"
38
AUTO_RENDER_DIR="/var/log"
39
AUTO_RENDER_FORMAT="png"
40
41
# The processes we have to wait for
42
EXIT_PROC="kdm_greet xterm konsole gnome-terminal metacity mutter compiz ldm icewm-session enlightenment"
43
44
# Read configuration.
45
CONF="/etc/bootchartd.conf"
46
if [ -f $PWD/bootchartd.conf ]; then
47
	. $PWD/bootchartd.conf
48
elif [ -f $CONF ]; then
49
	. $CONF
50
else
51
	echo "$CONF missing"
52
fi
53
54
# Start the boot logger.
55
start()
56
{
57
	# If in init start ourselves in our familiar system
58
	if [ -n "$INIT_PROCESS" ]; then
59
#		echo "bootchartd started in init" >> kmsg
60
		$COLLECTOR_BIN $SAMPLE_HZ
61
62
	# Otherwise, manually launched to profile something
63
	else
64
		# bail out, if already running
65
		pidof bootchart-collector && exit 0
66
#		echo "bootchartd started manually" >> kmsg
67
		$COLLECTOR_BIN -r $SAMPLE_HZ &
68
69
		if [ "$#" -gt 0 ]; then
70
			# If a command was passed, run it
71
			# (used for profiling specific applications)
72
			echo "profile.process = $( basename $1 )" >> header
73
			$@
74
			stop
75
		else
76
			echo "no command passed, you need to manually stop the service sometime"
77
		fi
78
	fi
79
}
80
81
# Wait for the boot process to end.
82
wait_boot()
83
{
84
	# Wait for /proc first - without it we have issues
85
	while [ ! -e /proc/cmdline ]; do
86
		$USLEEP 5000
87
	done
88
89
	while true; do
90
		if [ -n "$EXIT_PROC" -a -n "$( pidof $EXIT_PROC )" ]; then
91
			# give an unambiguous settle afterwards - so we get
92
			# more post-login data for slow systems
93
			$USLEEP 20000000
94
95
			# Write / flush the log files
96
			stop
97
			return
98
		fi
99
		$USLEEP 1000000
100
	done;
101
}
102
103
# Extract the log data from the running bootchart collector
104
# process (via ptrace) - fun. Store logs into $BOOTLOG_DEST.
105
stop()
106
{
107
	tmpdir=`mktemp -d /tmp/bootchart.XXXXXXXXXX`
108
	if [ "z$tmpdir" = "z" ]; then
109
		echo "Failed to generate directory for logging"
110
		exit 1
111
	fi
112
113
	if ! $COLLECTOR_BIN --dump $tmpdir; then
114
		echo "Can't extract boot chart from collector"
115
		exit 1
116
	fi
117
118
	cd $tmpdir
119
	if [ ! -e proc_stat.log ]; then
120
		echo "Can't find bootchart output in $tmpdir - aborting"
121
		exit 1
122
	fi
123
124
	# Archive it all up into the bootchart output
125
	tar -zcf "$BOOTLOG_DEST" header dmesg *.log
126
127
	rm -Rf $tmpdir
128
129
	# Render the chart if configured (and the renderer is installed)
130
	if [ "$AUTO_RENDER" = "yes" -a -x /usr/bin/pybootchartgui ]; then
131
		cd $AUTO_RENDER_DIR
132
		/usr/bin/pybootchartgui -o "$AUTO_RENDER_DIR"/bootchart.$AUTO_RENDER_FORMAT -f $AUTO_RENDER_FORMAT "$BOOTLOG_DEST"
133
	fi
134
}
135
136
if [ $$ -eq 1 ]; then
137
	# Either started by the kernel - in which case, we start the
138
	# logger in background and exec init [ re-using this pid (1) ]
139
	# Or - started after the initrd has completed, in which case
140
	# we try to do nothing much.
141
	INIT_PROCESS="yes"
142
	echo "Starting bootchart logging"
143
144
	init="/sbin/init"
145
146
	# Are we running in the initrd ?
147
	if [ -x /init -o -x /linuxrc ]; then
148
		IN_INITRD="yes"
149
		[ -x /linuxrc ] && init="/linuxrc"
150
		[ -x /init ] && init="/init"
151
		start &
152
	else # running inside the main system
153
		echo "bootchart: no initrd used; starting"
154
		start &
155
		wait_boot &
156
		# wait a little, until the collector is going, before allowing
157
		# the rest of the system to charge ahead, so we catch it
158
		$USLEEP 250000
159
		echo "bootchart continuing boot" >> $TMPFS/kmsg
160
	fi
161
162
	# Optionally, an alternative init(1) process may be specified using
163
	# the kernel command line (e.g. "bootchart_init=/sbin/initng")
164
	for i in $@; do
165
		if [ "${i%%=*}" = "bootchart_init" ]; then
166
			init="${i#*=}"
167
			break
168
		fi
169
		if [ "${i%%=*}" = "init" ]; then
170
			_init=${i#*=}
171
			if test "$_init" != "/sbin/bootchartd"; then
172
				init="$_init"
173
				break
174
			fi
175
		fi
176
	done
177
	export PATH=$OLDPATH
178
179
	# switch to - either the initrd's init, or the main system's
180
	exec $init $*
181
fi
182
183
case "$1" in
184
	"start")
185
		# Started by the user
186
		shift
187
		start $@
188
		;;
189
	"wait")
190
		# Wait for boot
191
		wait_boot
192
		;;
193
	"stop")
194
		stop
195
		;;
196
	*)
197
		echo "Usage: $0 {init|start|stop}"
198
		;;
199
esac
200
(-)a/bootchartd.in (-1 / +201 lines)
Line 0 Link Here
0
- 
1
#!/bin/bash
2
#
3
# Bootchart logger script
4
# Ziga Mahkovec  <ziga.mahkovec@klika.si>
5
# Michael Meeks  <michael.meeks@novell.com>
6
#
7
# This script is used for data collection for the bootchart2
8
# boot performance visualization tool.
9
#
10
# To profile the boot process, bootchartd should be called instead of
11
# /sbin/init.  Modify the kernel command line to include:
12
#
13
# init=/sbin/bootchartd initcall_debug printk.time=y quiet
14
#
15
# bootchartd will then start itself in background and exec /sbin/init
16
# (or an alternative init process if specified using bootchart_init=)
17
#
18
# To profile a running system, run:
19
# $ /sbin/bootchartd start; sleep 30; /sbin/bootchartd stop
20
#
21
22
# Use a directory we know will be there, such that we can mount
23
# our 'proc' without having to touch a (potentially) read-only
24
# file-system.
25
LIBDIR="@LIBDIR@"
26
TMPFS="${LIBDIR}/bootchart/tmpfs"
27
COLLECTOR_BIN="${LIBDIR}/bootchart/bootchart-collector"
28
29
# some initrds don't have usleep etc.
30
USLEEP="$COLLECTOR_BIN --usleep"
31
32
# we need to find our tools
33
PATH="/sbin:/bin:/usr/sbin:/usr/bin:$PATH"
34
35
# Defaults, in case we can't find our configuration
36
SAMPLE_HZ=50
37
BUILDLOG_DEST=/var/log/bootchart.tgz
38
AUTO_RENDER="no"
39
AUTO_RENDER_DIR="/var/log"
40
AUTO_RENDER_FORMAT="png"
41
42
# The processes we have to wait for
43
EXIT_PROC="kdm_greet xterm konsole gnome-terminal metacity mutter compiz ldm icewm-session enlightenment"
44
45
# Read configuration.
46
CONF="/etc/bootchartd.conf"
47
if [ -f $PWD/bootchartd.conf ]; then
48
	. $PWD/bootchartd.conf
49
elif [ -f $CONF ]; then
50
	. $CONF
51
else
52
	echo "$CONF missing"
53
fi
54
55
# Start the boot logger.
56
start()
57
{
58
	# If in init start ourselves in our familiar system
59
	if [ -n "$INIT_PROCESS" ]; then
60
#		echo "bootchartd started in init" >> kmsg
61
		$COLLECTOR_BIN $SAMPLE_HZ
62
63
	# Otherwise, manually launched to profile something
64
	else
65
		# bail out, if already running
66
		pidof bootchart-collector && exit 0
67
#		echo "bootchartd started manually" >> kmsg
68
		$COLLECTOR_BIN -r $SAMPLE_HZ &
69
70
		if [ "$#" -gt 0 ]; then
71
			# If a command was passed, run it
72
			# (used for profiling specific applications)
73
			echo "profile.process = $( basename $1 )" >> header
74
			$@
75
			stop
76
		else
77
			echo "no command passed, you need to manually stop the service sometime"
78
		fi
79
	fi
80
}
81
82
# Wait for the boot process to end.
83
wait_boot()
84
{
85
	# Wait for /proc first - without it we have issues
86
	while [ ! -e /proc/cmdline ]; do
87
		$USLEEP 5000
88
	done
89
90
	while true; do
91
		if [ -n "$EXIT_PROC" -a -n "$( pidof $EXIT_PROC )" ]; then
92
			# give an unambiguous settle afterwards - so we get
93
			# more post-login data for slow systems
94
			$USLEEP 20000000
95
96
			# Write / flush the log files
97
			stop
98
			return
99
		fi
100
		$USLEEP 1000000
101
	done;
102
}
103
104
# Extract the log data from the running bootchart collector
105
# process (via ptrace) - fun. Store logs into $BOOTLOG_DEST.
106
stop()
107
{
108
	tmpdir=`mktemp -d /tmp/bootchart.XXXXXXXXXX`
109
	if [ "z$tmpdir" = "z" ]; then
110
		echo "Failed to generate directory for logging"
111
		exit 1
112
	fi
113
114
	if ! $COLLECTOR_BIN --dump $tmpdir; then
115
		echo "Can't extract boot chart from collector"
116
		exit 1
117
	fi
118
119
	cd $tmpdir
120
	if [ ! -e proc_stat.log ]; then
121
		echo "Can't find bootchart output in $tmpdir - aborting"
122
		exit 1
123
	fi
124
125
	# Archive it all up into the bootchart output
126
	tar -zcf "$BOOTLOG_DEST" header dmesg *.log
127
128
	rm -Rf $tmpdir
129
130
	# Render the chart if configured (and the renderer is installed)
131
	if [ "$AUTO_RENDER" = "yes" -a -x /usr/bin/pybootchartgui ]; then
132
		cd $AUTO_RENDER_DIR
133
		/usr/bin/pybootchartgui -o "$AUTO_RENDER_DIR"/bootchart.$AUTO_RENDER_FORMAT -f $AUTO_RENDER_FORMAT "$BOOTLOG_DEST"
134
	fi
135
}
136
137
if [ $$ -eq 1 ]; then
138
	# Either started by the kernel - in which case, we start the
139
	# logger in background and exec init [ re-using this pid (1) ]
140
	# Or - started after the initrd has completed, in which case
141
	# we try to do nothing much.
142
	INIT_PROCESS="yes"
143
	echo "Starting bootchart logging"
144
145
	init="/sbin/init"
146
147
	# Are we running in the initrd ?
148
	if [ -x /init -o -x /linuxrc ]; then
149
		IN_INITRD="yes"
150
		[ -x /linuxrc ] && init="/linuxrc"
151
		[ -x /init ] && init="/init"
152
		start &
153
	else # running inside the main system
154
		echo "bootchart: no initrd used; starting"
155
		start &
156
		wait_boot &
157
		# wait a little, until the collector is going, before allowing
158
		# the rest of the system to charge ahead, so we catch it
159
		$USLEEP 250000
160
		echo "bootchart continuing boot" >> $TMPFS/kmsg
161
	fi
162
163
	# Optionally, an alternative init(1) process may be specified using
164
	# the kernel command line (e.g. "bootchart_init=/sbin/initng")
165
	for i in $@; do
166
		if [ "${i%%=*}" = "bootchart_init" ]; then
167
			init="${i#*=}"
168
			break
169
		fi
170
		if [ "${i%%=*}" = "init" ]; then
171
			_init=${i#*=}
172
			if test "$_init" != "/sbin/bootchartd"; then
173
				init="$_init"
174
				break
175
			fi
176
		fi
177
	done
178
	export PATH=$OLDPATH
179
180
	# switch to - either the initrd's init, or the main system's
181
	exec $init $*
182
fi
183
184
case "$1" in
185
	"start")
186
		# Started by the user
187
		shift
188
		start $@
189
		;;
190
	"wait")
191
		# Wait for boot
192
		wait_boot
193
		;;
194
	"stop")
195
		stop
196
		;;
197
	*)
198
		echo "Usage: $0 {init|start|stop}"
199
		;;
200
esac
201

Return to bug 345695