This week was quite hectic for me with course assignments and their merciless deadlines. One such assignment in Advanced Computer Architecture was simulation of various benchmarks in alpha architecture in simplescalar, a well-known computer architecture simulator. I was supposed to run a total of 4 benchmarks with different configurations of cache memory, instruction issue widths, commit widths, in-order execution modes, etc and I had to plot the required performance parameters for every benchmark. A conservative estimate would be around 40 plots!
Since the simulation platform was Linux, I could breathe a sigh of relief since most things can be automated using a powerful tool called shell. Scripting made my life easier here since I can automate a bunch of simulations without having to keep an eye on each and every simulation which would take anywhere from 20 minutes to 20 hours.
The problem arose when it came to plotting the performance results. Because, each simulation had its own output file which has its performance parameters. While most of my colleagues resorted to manually taking down values from the simulation file and plotting them using Microsoft excel, I thought why not this can be automated. ;)
But plotting a graph in terminal will not be as simple as plotting it in Excel, but if I manage to pull it off, that will be something I can be a little proud of. Besides that, I show (off to :p) my friends, how awesome piece of a tool shell is.
APPROACH:
A simple performance comparison plot would be a bar chart. The wget tool's download progress indicator in a Linux command line is somewhat similar to
============================================>| 89%
This is a minimalistic indicator and does the job well. So, I thought of comparing the parameters using a horizontal bar graph which will be simple and visually appealing too. So my rough idea was to implement something like
param1: |||||||||||||||||||||||||||||||||||||||||||||||||||| 67%
param2: ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| 75%
param3: |||||||||||||||||||||||||||||| 39%
Pretty huh ? :) This can be displayed in terminal interface and looks little geeky too. I started off writing a script which
- Takes the simulation file name as command-line argument
- Uses grep & awk to grab the performance parameters from the file
- Find the maximum and taking it as a reference (100%)
- Scaling others and plot in command-line as vertical bar graph
This worked well, and did the job ! But I found that something was missing. Colors!! Displaying the output in colors and weird way in Turbo C (graphics.h) was my something I loved in school. A little googling of about colored text outputs in terminal led me to an impressive tool called tput. It does basic coloring of texts, few formatting options like bold, underline, etc.
So I modified my code and added this feature. What a beauty!! The output had a colorful geeky touch which was quite impressive.
Sample Script:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#The MIT License (MIT) | |
# | |
#Copyright (c) <2014> <Amutha Bharathi> | |
# | |
#Permission is hereby granted, free of charge, to any person obtaining a copy | |
#of this software and associated documentation files (the "Software"), to deal | |
#in the Software without restriction, including without limitation the rights | |
#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
#copies of the Software, and to permit persons to whom the Software is | |
#furnished to do so, subject to the following conditions: | |
# | |
#The above copyright notice and this permission notice shall be included in | |
#all copies or substantial portions of the Software. | |
# | |
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
#THE SOFTWARE. | |
#Author: Amutha Bharathi, Masters EE, University of Minnesota- Twin- cities | |
#This file takes a simulator output file as command-line arg , extracts and compares various benchmark parameters | |
#!/bin/bash | |
if [ ! -e $1 ]; then # If file doesn't exist | |
echo "$(tput bold)$(tput setaf 1)File: $1 not found !$(tput sgr0)" | |
echo " " | |
exit | |
fi | |
if [ ! $1 ];then # If the file-name argument is not passed | |
echo "$(tput bold)$(tput setaf 4)This script requires a simulation-file name as argument.!$(tput sgr0)" | |
echo " " | |
exit | |
fi | |
echo " " | |
echo "$(tput bold) Simulation File:$(tput setaf 2)$(tput setab 0) $1 $(tput sgr 0)" | |
echo "" | |
sim_time=`grep "sim_elapse*" $1 | awk '{print $2}'` | |
echo "" | |
#Function | |
disp_bar(){ # Two arguments: 1) percentage to display 2) color of the bar | |
max=`expr $1 / 2` | |
for (( i = 0 ; i <= $max ; i++ )) | |
do | |
echo -n "$(tput dim)$(tput bold)$(tput setab $2) " | |
done | |
} | |
# Instructions Comparison | |
#-------------------------------------------------------------- | |
commit_ins=`grep "_insn" $1|awk 'NR==1{print $2}'` | |
exec_ins=`grep "_insn" $1|awk 'NR==2{print $2}'` | |
#print the Executed instruction(100%) scale first | |
echo -n "$(tput bold)Executed Insn $exec_ins | " | |
disp_bar 100 3 | |
echo "$(tput sgr 0) 100%" | |
#print the committed instruction % | |
comm_per=`echo "scale=2; $commit_ins*100/$exec_ins"| bc` | |
comm_bar=`bc <<< $comm_per/1` # convert to integer | |
echo -n "$(tput bold)Committed Insn $commit_ins | " | |
disp_bar $comm_bar 7 | |
echo "$(tput sgr 0) $comm_per%" | |
echo " " |
hahahaha :) .. put our Robiot here too . Good Blog
ReplyDelete