Tuesday, November 2, 2010

PERL me once, shame on you. PERL me twice, shame on me. PERL me thrice.....now that's nice!

English is certainly not the most spoken language in the world, being heavily overshadowed by Mandarin Chinese. But, it comes in at fair 2nd, spanning almost 400 million people across the globe. PERL on the other hand, probably comes in at a rigorously debated last place, or pretty darn close to it. One thing we can all agree on though is that a programming language whose intention was to create a seamless, convenient programming environment, still requires plenty of translation from one programmer to the next. In other words, the majority of my work the past 2 weeks centered around adapting old scripts in PERL to our newly created scripts via Stephanie's scripts and documenting accordingly.....that, and spending endless hours conjuring the perfect Halloween costume, which inevitably ended in me showcasing my inner nerd.


As the 2nd commandment of Stephanie's Undergraduate Research states, thou shalt have nothing to show for it more often than not. Fortunately, for my piece in the project, coding and documentation updates would be the upside to this, being immediately (for the most part) available and indicative of progress. But, we don't clock in/out while we're coding (We pretty much remain clocked in), so the time spent analyzing and coding certainly isn't accurately reflected enough in a small script that taunted you for hours on end. This was expected going in, for we are not naive knaves. On a positive note, however, the past 2 weeks were much more productive than the first week of learning PERL, given that I had something to build off of. The end reward of it all was a final tri-fecta of scripts that can read an input file of data taken from our 2 host computers, discard the trans fats, and give us what we want, the way we want it. Watch out Burger King!


Moving beyond our current work, with this being the mid-point in the semester, it seems fitting to take a look at how far we have progressed in the past 2 months. In reviewing Ben's (Last year's SSU CREU recipient) information from last year, being able to continue from where he left off seemed like quite the daunting task. Vaguely recalling him coming into our class to speak with Dr. Rivoire about scripts that had been running for 4 days straight did not perpetuate feelings of confidence, to say the least. To put it in perspective though, reading the articles about CPU/GPU analysis for our first week of CREU work didn't necessarily accomplish that either. And, to think that we are now doing exactly what I was not sure how we would even begin to tackle in the first place is evidence enough of progress. It has been quite the experience proving to myself that I could take on tasks that were totally benign to my previous Linux experience, as well as learn a completely new language without it being an available course here in the CS department - Quite the leap from sitting in the lab letting Lady Gaga pwn our computers. I've taken the logical approaches and confidence gained from the past 2 months and have applied them to my other classes/daily life. Heck, just by the nature of me being on campus more to work on CREU has subsequently ushered me into spending more time on other school work as well. And with that, I must bid you all adieu, but not without leaving the throngs of onlookers a taste of our PERL magnificence. Au revoir!



Our CPU (1 of 3 items we are currently analyzing) parsing script and output:

#!/usr/bin/perl

package test;

#Opens cpu data profile, spits out an error if it does not open.
open(FILE, "
#Reads in each line of the file one at a time.
foreach $line ()
{
#Splits the line into variables that we can use or trash.
($time, $ampm, $cputype, $c, $d, $e, $f, $g, $usage) = split(' ',$line);
($hr, $min, $sec) = split (":", $time);

#Checks to see if it is 12 in the morning, subtracts 12 if so (To reflect 24 hr time stamp)
if ($ampm eq "AM" && $hr eq "12")
{
$hr = $hr - 12;
}

#Checks to see if it is after 12PM, adds 12 if so (To reflect 24 hr time stamp)
if ($ampm eq "PM" && $hr ne "12")
{
$hr = $hr + 12;
}

#Checks to see if it is the first CPU being read, in order to print out 1 time stamp, rather than multiple of the same time stamp.
if ($cputype eq "0")
{
print $hr;
print ":";
print $min;
print ":";
print $sec;
print ",";
#Usage is the 100% minus the idle.
printf "%.2f", (100 - $usage);
}

elsif ($cputype eq "1")
{
print ",";
printf "%.2f", (100 - $usage);
}

elsif ($cputype eq "2")
{
print ",";
printf "%.2f", (100 - $usage);
}
elsif ($cputype eq "3")
{
print ",";
printf "%.2f", (100 - $usage);
print "\n";
}
else
{
}
}
}

Original File:
06:47:02 PM CPU %user %nice %system %iowait %steal %idle
06:47:03 PM all 0.50 0.00 1.01 0.00 0.00 98.49
06:47:03 PM 0 0.00 0.00 1.98 0.00 0.00 98.02
06:47:03 PM 1 0.00 0.00 1.00 0.00 0.00 99.00
06:47:03 PM 2 0.99 0.00 0.99 0.00 0.00 98.02
06:47:03 PM 3 1.04 0.00 0.00 0.00 0.00 98.96

06:47:03 PM CPU %user %nice %system %iowait %steal %idle
06:47:04 PM all 0.00 0.00 0.56 0.00 0.00 99.44
06:47:04 PM 0 0.00 0.00 1.00 0.00 0.00 99.00
06:47:04 PM 1 0.00 0.00 0.98 0.00 0.00 99.02
06:47:04 PM 2 0.00 0.00 0.00 0.00 0.00 100.00
06:47:04 PM 3 0.00 0.00 0.00 0.00 0.00 100.00


New Output File (5 out of 1000's of lines)

18:47:03,1.98,1.00,1.98,1.04
18:47:04,1.00,0.98,0.00,0.00
18:47:05,1.00,1.00,0.00,0.00
18:47:06,1.00,0.99,0.00,0.00
18:47:07,1.00,1.00,0.00,0.00

** This will be saved as a .csv file which can be read into Microsoft Excel and made very aesthetically pleasing!




No comments:

Post a Comment