diff options
author | Peter Wu <lekensteyn@gmail.com> | 2013-10-28 23:59:46 +0100 |
---|---|---|
committer | Peter Wu <lekensteyn@gmail.com> | 2013-10-28 23:59:46 +0100 |
commit | 3751b61cdaaea13f51c6196a24a53139421f56b7 (patch) | |
tree | 8f2a056045af83bf082e9f5685a35924b5c4d63c | |
parent | b597cfb5143b1b13ed8f5a64f142476a6f7eea9a (diff) | |
download | wireshark-notes-3751b61cdaaea13f51c6196a24a53139421f56b7.tar.gz |
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.
-rwxr-xr-x | tshark-iophs-percent.awk | 49 |
1 files changed, 49 insertions, 0 deletions
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 } |