#!/bin/bash
#kstrax execution helper script
#COPYRIGHT (C) HITACHI,LTD. 2006
#Created by S.Moriya<s-moriya@sdl.hitachi.co.jp>

function usage() {
    echo "Usage : trace <start/stop> <option(tracing time)>"
}

function start_trace() {
    cd ../kstrax_module/
    ./kernel-rec start
    
    cd ../commands_SMP/
    ./kstrax -b &
}

function stop_trace() {
    local KSTRAX=`ps aux | grep kstrax | grep -v grep | cut -c 5-14`
    local HOSTNAME=`hostname`
    
    kill -INT $KSTRAX
    mv ../commands_SMP/*$HOSTNAME* ../scripts/
    cd ../kstrax_module/
    ./kernel-rec stop
}

if [ $# = "0" ]; then
    usage
elif [ $# = "1" ]; then
    if [ $1 = "start" ]; then
	start_trace
    elif [ $1 = "stop" ]; then
	stop_trace
    else
	usage
    fi
else
    start_trace
    sleep $2
    stop_trace
fi
