#! /bin/sh # # This script takes input of the form , where filename # is the name of a .proc file containing a list of processes, and memory limit # is an integer listing the amount of memory available. It makes twelve data # files from the .proc file: files listing CPU quanta, shares, and integrals # for the processes over time, for Simple Linear, Start-End, Two Heap, # and In Order scheduling. # It then creates nine plots from the data files. # # File locations: # Process file: ../process/foo.proc # Data files: ../data/foo-SLcpu.dat # ../data/foo-SEcpu.dat # ../data/foo-IOcpu.dat # ../data/foo-THcpu.dat # ../data/foo-SLshare.dat # ../data/foo-SEshare.dat # ../data/foo-IOshare.dat # ../data/foo-THshare.dat # ../data/foo-SLintegral.dat # ../data/foo-SEintegral.dat # ../data/foo-IOintegral.dat # ../data/foo-THshare.dat # Plot files: ../graph/foo-SLcpu.png # ../graph/foo-SEcpu.png # ../graph/foo-IOcpu.png # ../graph/foo-THcpu.png # ../graph/foo-SLshare.png # ../graph/foo-SEshare.png # ../graph/foo-IOshare.png # ../graph/foo-THshare.png # ../graph/foo-SLintegral.png # ../graph/foo-SEintegral.png # ../graph/foo-IOintegral.png # ../graph/foo-THintegral.png # # Make data files from the given process file cd ../java/ java Grapher $1 $2 cd ../scripts/ echo "Creating plot scripts... " # Parse the filename in preparation for creating new filenames filename="$1" file=${filename##*/} name=${file%%.*} # Read the number of processes from the .proc file numberOfProcs=`head -n 1 "$filename"` # Calculate the sum of all shares from the .proc file shareTotal=`awk '{sum += $3} END {print sum}' $filename` # Read and remove the chosen permutations, schedule lengths, total runtimes, # and idle times from the share.dat files SLperm=`head -n 1 "../data/${name}-SLshare.dat"` SEperm=`head -n 1 "../data/${name}-SEshare.dat"` tail -n +2 "../data/${name}-SLshare.dat" > ../data/temp.dat cp ../data/temp.dat ../data/${name}-SLshare.dat tail -n +2 "../data/${name}-SEshare.dat" > ../data/temp.dat cp ../data/temp.dat ../data/${name}-SEshare.dat SLlength=`head -n 1 "../data/${name}-SLshare.dat"` SElength=`head -n 1 "../data/${name}-SEshare.dat"` tail -n +2 "../data/${name}-SLshare.dat" > ../data/temp.dat cp ../data/temp.dat ../data/${name}-SLshare.dat tail -n +2 "../data/${name}-SEshare.dat" > ../data/temp.dat cp ../data/temp.dat ../data/${name}-SEshare.dat SLidle=`tail -n 1 "../data/${name}-SLshare.dat"` SEidle=`tail -n 1 "../data/${name}-SEshare.dat"` IOidle=`tail -n 1 "../data/${name}-IOshare.dat"` THidle=`tail -n 1 "../data/${name}-THshare.dat"` for plotType in SLshare SEshare IOshare THshare do wc=`wc -l "../data/${name}-${plotType}.dat"` lines=${wc% *} head -n $((lines-1)) "../data/${name}-${plotType}.dat" > ../data/temp.dat cp ../data/temp.dat ../data/${name}-${plotType}.dat done SLtime=`tail -n 1 "../data/${name}-SLshare.dat"` SEtime=`tail -n 1 "../data/${name}-SEshare.dat"` IOtime=`tail -n 1 "../data/${name}-IOshare.dat"` THtime=`tail -n 1 "../data/${name}-THshare.dat"` for plotType in SLshare SEshare IOshare THshare do wc=`wc -l "../data/${name}-${plotType}.dat"` lines=${wc% *} head -n $((lines-1)) "../data/${name}-${plotType}.dat" > ../data/temp.dat cp ../data/temp.dat ../data/${name}-${plotType}.dat done # Calculate the share files - no longer used; now we use # exponential averaging, which is much faster #for plotType in SL SE IO TH #do # ./sharemaker "../data/${name}-${plotType}cpu.dat" $SLlength #done # Create twelve gnuscripts and run them using gnuplot for plotType in SLcpu SLshare SLintegral SEcpu SEshare SEintegral IOcpu IOshare IOintegral THcpu THshare THintegral do # Tell gnuplot to create a .png file echo "set term png color" > gnuscript echo "set out '../graph/${name}-${plotType}.png'" >> gnuscript # Add vertical lines to mark each time the schedule completes one run # (only for Simple Linear plots) - no longer used, too clutter-y # if [ $plotType == "SLshare" -o $plotType == "SLcpu" -o $plotType == "SLintegral" ] # then # # time=$SLtime # length=$SLlength # currentTime=$length # while [ $currentTime -le $time ] # do # echo "set arrow from ${currentTime},graph 0 to ${currentTime},graph 1 nohead" >> gnuscript # currentTime=$((currentTime+length)) # done # fi # Add labels listing the total integrals, runtimes, and idle times # of all processes if [[ $plotType == SL* ]] then time=$SLtime idle=$SLidle elif [[ $plotType == SE* ]] then time=$SEtime idle=$SEidle elif [[ $plotType == IO* ]] then time=$IOtime idle=$IOidle elif [[ $plotType == TH* ]] then time=$THtime idle=$THidle fi if [[ $plotType == *integral ]] then totalIntegral=`awk '{for ( i=1 ; i<=NF ; i+=1 ) if ( $i > 0 ) sum = sum + $i ; else sum = sum - $i} END { print sum }' ../data/${name}-${plotType}.dat` echo "set label 'Sum integral of' at graph 0.6,0.25" >> gnuscript echo "set label 'all processes: $totalIntegral' at graph 0.6,0.21" >> gnuscript echo "set label 'Total runtime: $time' at graph 0.6,0.17" >> gnuscript echo "set label 'Total idle time: $idle' at graph 0.6,0.13" >> gnuscript fi if [[ $plotType != *integral ]] then echo "set label 'Total runtime: $time' at graph 0.6,0.75" >> gnuscript echo "set label 'Total idle time: $idle' at graph 0.6,0.71" >> gnuscript fi # Add labels to the axes, a title to the plot, labels listing the # chosen permutation and schedule length, and, for integral plots, a line # at the x axis echo "set xlabel 'Time (in CPU quanta)'" >> gnuscript if [[ $plotType == *cpu ]] then echo "set ylabel 'CPU Quanta Received'" >> gnuscript title="Divison of CPU Quanta among \"$name\" Processes using " elif [[ $plotType == *share ]] then echo "set ylabel 'Share (ratio of CPU quanta received to total CPU quanta given)'" >> gnuscript title="Shares of \"$name\" Processes using " elif [[ $plotType == *integral ]] then echo "set ylabel 'Difference between current share and goal share'" >> gnuscript echo "set xzeroaxis" >> gnuscript title="Integrals of Shares among \"$name\" Processes using " fi if [[ $plotType == SL* ]] then title=${title}"Simple Linear Scheduling" if [[ $plotType != *integral ]] then echo "set label 'Schedule: $SLperm' at graph 0.15,0.75" >> gnuscript echo "set label 'Schedule Length: $SLlength' at graph 0.15,0.71" >> gnuscript fi elif [[ $plotType == SE* ]] then title=${title}"Start-End Scheduling" if [[ $plotType != *integral ]] then echo "set label 'Schedule: $SEperm' at graph 0.15,0.75" >> gnuscript echo "set label 'Schedule Length: $SElength' at graph 0.15,0.71" >> gnuscript fi elif [[ $plotType == IO* ]] then title=${title}"In Order Scheduling" elif [[ $plotType == TH* ]] then title=${title}"Two Heap Scheduling" fi echo "set title '$title'" >> gnuscript # Generate the plotting command echo -n "plot " >> gnuscript loop=1 while [ $loop -le $numberOfProcs ] do procnum=`expr $loop - 1` echo -n "'../data/${name}-${plotType}.dat' u :${loop} t \"Process $procnum\" w lines" >> gnuscript # If making a share plot, add a horizontal line to mark the goal share if [[ $plotType == *share ]] then share=`awk '{if ($1 == '$procnum') print $3}' $filename` shareRatio=$(echo "scale=6; $share/$shareTotal" | bc) echo -n ",f(x)=$shareRatio,f(x) t \"Process ${procnum}'s Goal\" w dots" >> gnuscript fi if [ ! $loop -eq $numberOfProcs ] then echo -n ", " >> gnuscript fi loop=$((loop+1)) done echo "" >> gnuscript echo "set out" >> gnuscript echo "set term x11" >> gnuscript # Run the gnuscript gnuplot gnuscript done # Report that the graphs have been created echo "Graphs and data files created from process file $1."