From 3751b61cdaaea13f51c6196a24a53139421f56b7 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Mon, 28 Oct 2013 23:59:46 +0100 Subject: tshark-iophs-percent.awk: add script to add percentages Requested by [aspirin] on #wireshark, this script adds a percentage number to the tshark statistics output. Adding a percentage bar can also be done, but is an exercise for later at the moment. --- tshark-iophs-percent.awk | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100755 tshark-iophs-percent.awk (limited to 'tshark-iophs-percent.awk') diff --git a/tshark-iophs-percent.awk b/tshark-iophs-percent.awk new file mode 100755 index 0000000..66dfb6a --- /dev/null +++ b/tshark-iophs-percent.awk @@ -0,0 +1,49 @@ +#!/usr/bin/awk -f +# Appends percentage to output of: +# tshark -z io,phs -w /dev/null -r input.pcapng + +BEGIN { + # Set -v relative=1 to get percentage relative to parent + if (relative) + relative = 1; + else + relative = 0; + + # Set -v by_frames=1 to get percentage based on frames instead of bytes + if (by_frames) + by_frames = 1; + else + by_frames = 0; + + delete lens; + stats = 0; +} + +stats && /bytes:/ { + if (by_frames) + field = NF - 1; + else + field = NF; + + # frames:1 or bytes:1 + split($field, a, ":"); + count = a[2]; + ind = (match($0,/[^ ]/) - 1) / 2; + # Store count in depth. + lens[ind] = count; + + all = lens[0]; + if (ind > 0 && relative) { + all = lens[ind - 1]; + } + + percent = 100 * (count / all); + $0 = $0 "\t" sprintf("%.2f", percent); +} + +# Assume that a line that starts with Filter: marks the start of stats. +/^Filter: / { + stats = 1; +} +# Print all lines +{ print } -- cgit v1.2.1