#! /bin/sh # # This script takes a cpu.dat file and creates a share.dat and an integral.dat # file from it. It takes input of the form , where # filename is the location of the cpu.dat file and window size # is how many CPU quanta to calculate the share over. # Parse the inputs, storing the filename and window size filename="$1" file=${filename##*/} name=${file%%-*} windowSize=$2 # Compute the number of lines in the cpu file wc=`wc -l $filename` totalLines=${wc% *} # Compute the number of processes numberOfProcs=`head -n 1 "../process/${name}.proc"` # Create filenames for the share and integral files newname=${filename%%c*} sharename=${newname}"share.dat" integralname=${newname}"integral.dat" # Clear the share and integral files echo -n "" > $sharename #echo -n "" > $integralname # Traverse each line of the cpu file, calculating each process's share # and integral at every line line=1 while [ $line -le $totalLines ] do process=1 while [ $process -le $numberOfProcs ] do beginCPU=`awk 'NR=='$((line-windowSize))' {print $'$process'}' $filename` endCPU=`awk 'NR=='$line' {print $'$process'}' $filename` windowCPU=$((endCPU-beginCPU)) share=$(echo "scale=6; $windowCPU/$windowSize" | bc) echo -n "$share " >> $sharename process=$((process+1)) done echo "" >> $sharename line=$((line+1)) done