解析 ns2 跟踪文件

发布于 2024-12-18 22:35:58 字数 1436 浏览 5 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南渊 2024-12-25 22:35:58

正如伊恩在对你的问题的评论中所说,这里没有太多可以处理的内容,但是如果我理解你想要正确执行的操作,那么这样的事情应该可以工作:

awk '/^[+r]/{$1~/r/?r[$15]=$2:r[$15]?d[$15]=r[$15]-$2:1} END {for(p in d){sum+=r[p];num++}print sum/num}' trace.file

它会跳过所有不以“+”或“r”开头的行。如果该行以“r”开头,则会向 r 数组添加时间。否则,如果在 r 数组中找到该元素,它会计算延迟并将其添加到 d 数组中。最后,它循环 d 数组中的元素,将总延迟和元素数量相加,并计算平均值。在你的例子中,平均值是 0。

主块末尾的 :1 就在那里,所以我可以使用三元表达式而不是明显更冗长的 if 语句。

编辑:用于处理添加条件的新表达式:

awk '/^[+r]/{$1~/r/?$3>r[$15]?r[$15]=$3:1:!a[$15]||$3<a[$15]?a[$15]=$3:1} END {for(i in r){sum+=r[i]-a[i];num++}print "Average delay", sum/num}'

或作为 awk 文件

/^[+r]/ {
  if ($1 ~ /r/) {
    if ($3 > received[$15])
      received[$15] = $3;
  } else {
    if (!added[$15] || $3 < added[$15])
      added[$15] = $3;
  }
} END {
  for (packet in received) {
    sum += received[packet] - added[packet];
    num++
  }
  print "Average delay", sum/num
}

根据您的算法,似乎 1.745 将是开始时间,而您写的是 2.134。

There's not much to work with here, as Iain said in the comments to your question, but if I understand what you want to do correctly, something like this should work:

awk '/^[+r]/{$1~/r/?r[$15]=$2:r[$15]?d[$15]=r[$15]-$2:1} END {for(p in d){sum+=r[p];num++}print sum/num}' trace.file

It skips all lines not starting with '+' or 'r'. If the line starts with 'r' it adds time to the r array. Otherwise, it calculates the delay and adds it to the d array if the element is found in the r array. Finally it loops over the elements in the d array, adds up the total delay and number of elements and calculates the average from this. In your case the average is 0.

The :1 at the end of the main block is just in there so I can get away with a ternary expression instead of the significantly more verbose if statement.

EDIT: New expression to work with the added conditions:

awk '/^[+r]/{$1~/r/?$3>r[$15]?r[$15]=$3:1:!a[$15]||$3<a[$15]?a[$15]=$3:1} END {for(i in r){sum+=r[i]-a[i];num++}print "Average delay", sum/num}'

or as an awk-file

/^[+r]/ {
  if ($1 ~ /r/) {
    if ($3 > received[$15])
      received[$15] = $3;
  } else {
    if (!added[$15] || $3 < added[$15])
      added[$15] = $3;
  }
} END {
  for (packet in received) {
    sum += received[packet] - added[packet];
    num++
  }
  print "Average delay", sum/num
}

According to your algorithm it seems like 1.745 would be the start time, while you write that 2.134 is.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文