[9c22e5]: dae / op_start Maximize Restore History

Download this file

op_start    371 lines (340 with data), 8.7 kB

#!/bin/sh
# $Id: op_start,v 1.16 2000/12/12 02:55:35 moz Exp $
# COPYRIGHT (C) 2000 THE VICTORIA UNIVERSITY OF MANCHESTER and John Levon
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place - Suite 330, Boston, MA 02111-1307, USA.
#

# quick and ugly interface
# op_start --help and op_start --list-events have info

SYSCTL=sysctl

BUF_SIZE=65536
HASH_SIZE=16384
CTR0_EVENT=
CTR1_EVENT=
CTR0_UM=0
CTR1_UM=0
CTR0_COUNT=
CTR1_COUNT=
CTR0_USER=1
CTR0_KERNEL=1
CTR1_USER=1
CTR1_KERNEL=1
USE_PII=0
IGNORE_MYSELF=0
DIR="/var/opd"
MAP_FILE=
VMLINUX=
PID_FILTER=0
PGRP_FILTER=0

help_string='op_start: usage:$
Module options$
  --buffer-size=num            number of samples in kernel buffer$
  --hash-table-size=num        number of entries in kernel hash table$
$
Module per-cpu options. Specify comma-separated values for each CPU$
  --ctr0-event=name            symbolic event name for ctr0$
  --ctr1-event=name            symbolic event name for ctr1$
  --ctr0-count=val             number of events between samples for ctr0$
  --ctr1-count=val             number of events between samples for ctr1$
  --ctr0-unit-mask=val         unit mask for ctr0$
  --ctr1-unit-mask=val         unit mask for ctr1$
  --ctr0-kernel=[0|1]          whether to count kernel events for ctr 0$
  --ctr0-user=[0|1]            whether to count user events for ctr 0$
  --ctr1-kernel=[0|1]          whether to count kernel events for ctr 1$
  --ctr1-user=[0|1]            whether to count user events for ctr1$
  --pid-filter=pid             Only profile process pid (if compiled in)$
  --pgrp-filter=pgrp           Only profile process group pgrp (if compiled in)$
$
Daemon options$
  --use-cpu=[0|1|2]            0 or PPro, 1 for PII, 2 for PIII$
  --ignore-myself=[0|1]        ignore samples for oprofiled$
  --log-file=file              log file$
  --base-dir=dir               base directory of daemon$
  --samples-dir=file           output samples directory$
  --device-file=file           profile device file$
  --map-device-file=file       profile map device file$
  --hash-map-device-file=file  profile hash map device file$
  --map-file=file              System.map for running kernel file$
  --vmlinux=file               vmlinux kernel image$
$
General options$
  --list-events                list event types and unit masks$
  --help                       this message$'

LOG_FILE=
SAMPLES_DIR=
DEVICE_FILE=
MAP_DEVICE_FILE=

# get specified options

while [ "$#" -ne 0 ]
do
	arg=`echo $1 | awk -F= '{print $1}'`
	val=`echo $1 | awk -F= '{print $2}'`
	case "$arg" in
		--use-cpu)
			if [ "$val" != "" ]; then
				USE_PII=$val
			else
				USE_PII=1
			fi
			;;
		--ignore-myself)
			if [ "$val" != "" ]; then
				IGNORE_MYSELF=$val
			else
				IGNORE_MYSELF=1
			fi
			;;
		--buffer-size)
			BUF_SIZE=$val
			;;
		--hash-table-size)
			HASH_SIZE=$val
			;;
		--ctr0-unit-mask)
			CTR0_UM=$val
			;;
		--ctr1-unit-mask)
			CTR1_UM=$val
			;;
		--ctr0-event)
			CTR0_EVENT=$val
			;;
		--ctr1-event)
			CTR1_EVENT=$val
			;;
		--ctr0-count)
			CTR0_COUNT=$val
			;;
		--ctr1-count)
			CTR1_COUNT=$val
			;;
		--ctr0-user)
			CTR0_USER=$val
			;;
		--ctr0-kernel)
			CTR0_KERNEL=$val
			;;
		--ctr0-user)
			CTR0_USER=$val
			;;
		--ctr0-kernel)
			CTR0_KERNEL=$val
			;;
		--base-dir)
			DIR=$val
			;;
		--samples-dir)
			SAMPLES_DIR=$val
			;;
		--device-file)
			DEVICE_FILE=$val
			;;
		--map-device-file)
			MAP_DEVICE_FILE=$val
			;;
		--hash-map-device-file)
			HASH_MAP_DEVICE_FILE=$val
			;;
		--map-file)
			MAP_FILE=$val
			;;
		--vmlinux)
			VMLINUX=$val
			;;
		--pid-filter)
			PID_FILTER=$val
			;;
		--pgrp-filter)
			PGRP_FILTER=$val
			;;
		--help)
			echo $help_string | tr \$ '\n'
			exit 0
			;;
		--list-events)
			exec op_help
			;;
		*)
			echo "Unknown option \"$arg\". See op_start --help"
			exit 1
			;; 
	esac
	shift
done

CTR0_EVENT_VAL=`op_help $CTR0_EVENT`
CTR1_EVENT_VAL=`op_help $CTR1_EVENT`

grep oprof /proc/devices >/dev/null
if [ "$?" -ne 0 ]
then
	modprobe oprofile
	if [ "$?" != "0" ]
	then
		echo "Couldn't load oprofile.o module"
		exit 1
	fi
fi

if [ ! -d "$DIR" ]
then
       mkdir -p "$DIR"
       if [ "$?" != "0" ]
       then
               echo "Couldn't mkdir -p $DIR"
               exit 1
       fi
       chmod 700 "$SAMPLES_DIR"
fi

if [ "$LOG_FILE" = "" ]; then
	LOG_FILE="$DIR/oprofiled.log"
fi
if [ "$SAMPLES_DIR" = "" ]; then
	SAMPLES_DIR="$DIR/samples/"
fi
if [ "$DEVICE_FILE" = "" ]; then
	DEVICE_FILE="$DIR/opdev"
fi
if [ "$MAP_DEVICE_FILE" = "" ]; then
	MAP_DEVICE_FILE="$DIR/opmapdev"
fi
if [ "$HASH_MAP_DEVICE_FILE" = "" ]; then
	HASH_MAP_DEVICE_FILE="$DIR/ophashmapdev"
fi

echo "Parameters used:"
echo "BUF_SIZE $BUF_SIZE"
echo "HASH_SIZE $HASH_SIZE"
echo "CTR0_EVENT $CTR0_EVENT"
echo "CTR1_EVENT $CTR1_EVENT"
echo "CTR0_UM $CTR0_UM"
echo "CTR1_UM $CTR1_UM"
echo "CTR0_COUNT $CTR0_COUNT"
echo "CTR1_COUNT $CTR1_COUNT"
echo "CTR0_OSUSR $CTR0_OSUSR"
echo "CTR1_OSUSR $CTR1_OSUSR"
echo "USE_PII $USE_PII"
echo "IGNORE_MYSELF $IGNORE_MYSELF"
echo "DIR $DIR"
echo "LOG_FILE $LOG_FILE"
echo "SAMPLES_DIR $SAMPLES_DIR"
echo "DEVICE_FILE $DEVICE_FILE"
echo "MAP_DEVICE_FILE $MAP_DEVICE_FILE"
echo "MAP_FILE $MAP_FILE"
echo "VMLINUX $VMLINUX"

>$LOG_FILE

if [ -z "$MAP_FILE" ]
then
	echo "No map file specified."
	echo $help_string | tr \$ '\n'
	exit 1
fi

if [ -z "$VMLINUX" ]
then
	echo "No vmlinux file specified."
	echo $help_string | tr \$ '\n'
	exit 1
fi

if [ -c "$DEVICE_FILE" ]
then
	echo "Removing $DEVICE_FILE"
	rm "$DEVICE_FILE"
fi

if [ -c "$MAP_DEVICE_FILE" ]
then
	echo "Removing $MAP_DEVICE_FILE"
	rm "$MAP_DEVICE_FILE"
fi

if [ -c "$HASH_MAP_DEVICE_FILE" ]
then
	echo "Removing $HASH_MAP_DEVICE_FILE"
	rm "$HASH_MAP_DEVICE_FILE"
fi

if [ ! -d "$SAMPLES_DIR" ]
then
	mkdir -p "$SAMPLES_DIR"
	if [ "$?" != "0" ]
	then
		echo "Couldn't mkdir -p $SAMPLES_DIR"
		exit 1
	fi
	chmod 700 "$SAMPLES_DIR"
else
	cd "$SAMPLES_DIR"
	rm -rf *
fi

MAJOR_NR=`grep oprof /proc/devices | awk '{print $1}'`

echo "Doing mknod $DEVICE_FILE"
mknod "$DEVICE_FILE" c $MAJOR_NR 0
if [ "$?" != "0" ]
then
	echo "Couldn't mknod $DEVICE_FILE"
	exit 1
fi
chmod 700 "$DEVICE_FILE"
 
echo "Doing mknod $HASH_MAP_DEVICE_FILE"
mknod "$HASH_MAP_DEVICE_FILE" c $MAJOR_NR 1
if [ "$?" != "0" ]
then
	echo "Couldn't mknod $HASH_MAP_DEVICE_FILE"
	exit 1
fi
chmod 700 "$HASH_MAP_DEVICE_FILE"

echo "Doing mknod $MAP_DEVICE_FILE"
mknod "$MAP_DEVICE_FILE" c $MAJOR_NR 2
if [ "$?" != "0" ]
then
	echo "Couldn't mknod $MAP_DEVICE_FILE"
	exit 1
fi
chmod 700 "$MAP_DEVICE_FILE"

op_stop

$SYSCTL -w dev.oprofile.hashsize=$HASH_SIZE
$SYSCTL -w dev.oprofile.bufsize=$BUF_SIZE
$SYSCTL -w dev.oprofile.pid_filter=$PID_FILTER 
$SYSCTL -w dev.oprofile.pgrp_filter=$PGRP_FILTER 

# FIXME do something for all CPUs 
if [ "$CTR0_EVENT" != "" ]; then
	$SYSCTL -w dev.oprofile.0.0.enabled=1
	$SYSCTL -w dev.oprofile.0.0.count=$CTR0_COUNT
	$SYSCTL -w dev.oprofile.0.0.kernel=$CTR0_KERNEL
	$SYSCTL -w dev.oprofile.0.0.user=$CTR0_USER
	$SYSCTL -w dev.oprofile.0.0.unit_mask=$CTR0_UM
	$SYSCTL -w dev.oprofile.0.0.event=$CTR0_EVENT_VAL
fi
if [ "$CTR1_EVENT" != "" ]; then
	$SYSCTL -w dev.oprofile.0.1.enabled=1
	$SYSCTL -w dev.oprofile.0.1.count=$CTR1_COUNT
	$SYSCTL -w dev.oprofile.0.1.kernel=$CTR1_KERNEL
	$SYSCTL -w dev.oprofile.0.1.user=$CTR1_USER
	$SYSCTL -w dev.oprofile.0.1.unit_mask=$CTR1_UM
	$SYSCTL -w dev.oprofile.0.1.event=$CTR1_EVENT_VAL
fi
 
OPD_ARGS="--buffer-size=$BUF_SIZE --use-cpu=$USE_PII --ignore-myself=$IGNORE_MYSELF \
	--log-file=$LOG_FILE --base-dir=$DIR --samples-dir=$SAMPLES_DIR \
	--device-file=$DEVICE_FILE --map-device-file=$MAP_DEVICE_FILE \
	--hash-map-device-file=$HASH_MAP_DEVICE_FILE --vmlinux=$VMLINUX"

if [ "$CTR0_EVENT" != "" ]; then
	OPD_ARGS="$OPD_ARGS --ctr0-event=$CTR0_EVENT --ctr0-unit-mask=$CTR0_UM"
fi

if [ "$CTR1_EVENT" != "" ]; then
	OPD_ARGS="$OPD_ARGS --ctr1-event=$CTR0_EVENT --ctr1-unit-mask=$CTR0_UM"
fi
if [ "$MAP_FILE" != "" ]; then
	OPD_ARGS="$OPD_ARGS --map-file=$MAP_FILE"
fi

oprofiled $OPD_ARGS
sleep 2
PID=`ps x | grep oprofiled | grep -v grep | awk '{print $1}'`
if [ "$PID" = "" ]
then
	echo "Couldn't start oprofiled."
	exit 1
fi