Skip to content

Instantly share code, notes, and snippets.

@cohalz
Last active August 29, 2015 14:11
Show Gist options
  • Save cohalz/b7b732dc7ba3fe72f16d to your computer and use it in GitHub Desktop.
Save cohalz/b7b732dc7ba3fe72f16d to your computer and use it in GitHub Desktop.
import scala.io.Source
val seqr = """.*:(.*\..*)\sIP.*seq\s[0-9]+?:(.+?),""".r
val ackr = """.*:(.*\..*)\sIP.*?Flags\s\[\.\],\sack\s(.+?),\swin.*""".r
if(args.length > 0) {
val lines = Source.fromFile(args(0)).getLines().toList
val seqs = for {
line <- lines
seq <- seqr.findFirstMatchIn(line)
} yield List(seq.group(1),seq.group(2))
val tmps = for {
line <- lines
ack <- ackr.findFirstMatchIn(line)
} yield List(ack.group(1),ack.group(2))
val acks = for {
i <- 0 until tmps.length -1
if tmps(i)(1) != tmps(i+1)(1)
} yield List(tmps(i)(0),tmps(i)(1))
val time = for {
seq <- seqs
ack <- acks
if seq(1) == ack(1)
} yield ack(0).toDouble - seq(0).toDouble
println("average = " + time.sum/time.length)
}
else Console.err.println("Please enter inputfile")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment