2017-11-03 21 views
0

그래서 최근에는 ns2 추적 파일을 구문 분석하고 처리량을 계산하는 python 스크립트를 작성했습니다. 나 또한 같은 일을하지만 조금 다르게 인터넷에서 다운로드 한 펄 스크립트를 가지고있다. 나는 granularity (perl 스크립트에서 사용 된)가 의미하는 것을 이해하는 데 어려움을 겪고있다. 누군가 나를 도울 수 있습니까? 감사. 코드는 아래에 제공됩니다.처리량을 계산하기 위해 파이썬 스크립트와 perl 스크립트의 차이점과 세분성의 의미는 무엇입니까?

trace = open('window_size_23.tr' , 'r') 
s = 0 
prev = 0.0 
start = 0.0 
end = 0.0 
for line in trace: 
    words = line.split(' ') 
    if line.startswith('r') and 'tcp' in line and words[3] == '1' and 
words[8] == '0.0' and words[9] == '1.0': 

     s = s + int(words[5]) 
     if prev == 0.0: 
      start = float(words[1]) 
     prev = float(words[1]) 
end = prev 
throughput = (s*8.0)/((end - start)*1000000) 
print throughput, start, end 

여기에 단위 https://www.google.com/webhp?hl=all&gws_rd=ssl#hl=en&q=ns2+what+is+granularity

무엇인지 펄 스크립트

$infile=$ARGV[0]; 
    $destnode=$ARGV[1]; 
    $fromport=$ARGV[2]; 
    $toport=$ARGV[3]; 
    $granularity=$ARGV[4]; 

    $sum=0; 
    $grantsum=0; 
    $clock=0; 

    open (DATA,"<$infile") || die "Can't open $infile $!"; 
    while (<DATA>) 
    { 
     @x = split(' '); 
     if ($x[1]-$clock <= $granularity) 
     { 
      if ($x[0] eq 'r') 
      { 
       if ($x[3] eq $destnode && $x[8] eq $fromport && $x[9] 
       eq $toport) 
       { 
        if ($x[4] eq 'tcp') 
        { 
         $sum=$sum+$x[5]; 
         $grantsum=$grantsum+$x[5]; 
        } 
       } 
      } 
     } 
     else 
     { 
      $throughput=0.000008*$sum/$granularity; 
      print STDOUT "$clock $throughput\n"; 

      $clock=$clock+$granularity; 

      if ($x[0] eq 'r' && $x[3] eq $destnode && $x[8] eq 
      $fromport && $x[9] eq $toport && $x[4] eq 'tcp') 
      { 
       $sum=$x[5]; 
       $grantsum=$grantsum+$x[5]; 
      } 
      else 
      { 
       $sum=0; 
      } 

      while ($x[1]-$clock > $granularity) 
      { 
       print STDOUT "$clock 0.0\n"; 
       $clock=$clock+$granularity; 
      } 
     } 
} 

$throughput=0.000008*$sum/$granularity; 
print STDOUT "$clock $throughput\n"; 
$clock=$clock+$granularity; 

print STDERR "Avg throughput $fromport - $toport = ", 
     0.000008*$grantsum/$clock,"MBytes/sec \n"; 

close DATA; 

exit(0); 
+0

'$ 세분성'스위치를 사용하여 스크립트를 실행할 때 cmdline에서 입력하는 변수 이름이 될 것이고 그러면 $ ARGV [4];에서 올 것입니다 여기서 세분성은 초 단위라고합니다. –

답변