[5d4628]: dae / op_start  Maximize  Restore  History

Download this file

344 lines (316 with data), 8.4 kB

#!/bin/sh
# $Id: op_start,v 1.15 2000/12/06 20:39:49 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

BUF_SIZE=65536
HASH_SIZE=16384
CTR0_TYPE=
CTR1_TYPE=
CTR0_UM=0
CTR1_UM=0
CTR0_COUNT=
CTR1_COUNT=
CTR0_OSUSR=0
CTR1_OSUSR=0
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-os-usr=val            val==1 for kernel counting, ==2 for userspace only for ctr0$
  --ctr1-os-usr=val            val==1 for kernel counting, ==2 for userspace only 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_TYPE=$val
			;;
		--ctr1-event)
			CTR1_TYPE=$val
			;;
		--ctr0-count)
			CTR0_COUNT=$val
			;;
		--ctr1-count)
			CTR1_COUNT=$val
			;;
		--ctr0-os-usr)
			CTR0_OSUSR=$val
			;;
		--ctr1-os-usr)
			CTR1_OSUSR=$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

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 [ "$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_TYPE $CTR0_TYPE"
echo "CTR1_TYPE $CTR1_TYPE"
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 "$SAMPLES_DIR"
	if [ "$?" != "0" ]
	then
		echo "Couldn't mkdir $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"

oprofctl --device-file="$DEVICE_FILE" --stop >/dev/null 2>&1

oprofctl --device-file="$DEVICE_FILE" --hash-size=$HASH_SIZE --buf-size=$BUF_SIZE
# FIXME: enable SMP setup ...
if [ "$CTR0_TYPE" != "" ]; then
	oprofctl --device-file="$DEVICE_FILE" --cpu=0 --counter=0 --event=$CTR0_TYPE --unit-mask=$CTR0_UM --value=$CTR0_COUNT --os-usr=$CTR0_OSUSR
	if [ "$?" != "0" ]; then echo "oprofctl failed."; exit 1; fi
fi
if [ "$CTR1_TYPE" != "" ]; then
	oprofctl --device-file="$DEVICE_FILE" --cpu=0 --counter=1 --event=$CTR1_TYPE --unit-mask=$CTR1_UM --value=$CTR1_COUNT --os-usr=$CTR1_OSUSR
	if [ "$?" != "0" ]; then echo "oprofctl failed."; exit 1; fi
fi
if [ "$PID_FILTER" != "0" ]; then
	oprofctl --device-file="$DEVICE_FILE" --pid-filter=$PID_FILTER 
	if [ "$?" != "0" ]; then echo "oprofctl failed."; exit 1; fi
fi 
if [ "$PGRP_FILTER" != "0" ]; then
	oprofctl --device-file="$DEVICE_FILE" --pgrp-filter=$PGRP_FILTER 
	if [ "$?" != "0" ]; then echo "oprofctl failed."; exit 1; fi
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_TYPE" != "" ]; then
	OPD_ARGS="$OPD_ARGS --ctr0-event=$CTR0_TYPE --ctr0-unit-mask=$CTR0_UM"
fi

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

oprofctl --device-file="$DEVICE_FILE" --start
if [ "$?" != "0" ]; then echo "oprofctl --start failed."; exit 1; 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

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks