[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Perl script



Zutong Sun wrote:
> Hello:
> 	Does anybody have the perl script to extract some results from 
> the trace-all results?
> 	Any help is sure appreciated!
> zutong
> 	[email protected]
> 


The following is an example of a perl script for extracting data
from the trace file. This script however is very specific for one
simulation scenario I used and can not be used generally. Perhaps it
can help you get an idea how you should write a script that suits your
needs.

#!/usr/bin/perl

$name = shift(@ARGV);

open  OUTFILE, ">sent.$name"  or die "Couldn't open sent: $!\n";
open  OUTFILE1, ">dropped.$name"  or die  "Couldn't open dropped: $!\n";
open  OUTFILE2,  ">ack.$name"  or die  "Couldn't open ack: $!\n";

while (<stdin>) {
    # Package sent from node 0 to node 3.
    if(/^\+ ([0-9]+[\.0-9]*) 0 3 tcp [0-9]+ [^ ]+ 2 [0-9]+\.[0-9]+ [0-9]+\.[0-9]+ ([0-9]+) [0-9]+/) 
    {
	$time = $1;
	$packagenr = $2 % 60; 
	print OUTFILE "$time $packagenr\n";
	    
    }
    # Package belonging to flow 2 has been dropped from queue on node 3 on its way to node 4.
    elsif(/^d ([0-9]+[\.0-9]*) 3 4 tcp [0-9]+ [^ ]+ 2 [0-9]+\.[0-9]+ [0-9]+\.[0-9]+ ([0-9]+) [0-9]+/) 
    {
	$time = $1;
	$packagenr = $2 % 60;
	print OUTFILE1 "$time $packagenr\n";  
    }
    # Ack came in for flow 2.
    elsif(/^r ([0-9]+[\.0-9]*) 3 0 ack [0-9]+ [^ ]+ 2 [0-9]+\.[0-9]+ [0-9]+\.[0-9]+ ([0-9]+) [0-9]+/) 
    {
	$time = $1;
	$packagenr = $2 % 60;
	print OUTFILE2 "$time $packagenr\n";
    }    
    else 
    {
	# do nothing
    }
}