[英]Difference between my python script and the perl script to calculate throughput and what does granularity mean?
因此,我最近编写了一个python脚本,用于解析ns2跟踪文件并计算吞吐量。 我还有一个从Internet下载的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
这是Perl脚本
$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);
Google,什么是粒度https://www.google.com/webhp?hl=all&gws_rd=ssl#hl=zh-CN&q=ns2+what+is+granularity
。 例如 →“ ..粒度(即不同的抽象水平 )..”
。 https://www.researchgate.net/post/Bandwidth_Estimation_in_ns212→ “ ..具有精细的粒度时间戳(如果不是微秒,则为毫秒)。”
所有ns2 awk,perl脚本https://drive.google.com/file/d/0B7S255p3kFXNdkdRalVpWk56MmM/view?usp=sharing
分析工具(awk,python):APP-工具https://github.com/WiNG-NITK/APP-Tool
示例,APP-Tool→吞吐量→图像
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.