VBoxConvertNATStats.sh revision c7814cf6e1240a519cbec0441e033d0e2470ed00
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync#!/bin/sh
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync#
c7814cf6e1240a519cbec0441e033d0e2470ed00vboxsync# Copyright (C) 2009-2010 Oracle Corporation
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync#
82bcaaf8077ba892f39afb721dca149353c63d2cvboxsync# This file is part of VirtualBox Open Source Edition (OSE), as
82bcaaf8077ba892f39afb721dca149353c63d2cvboxsync# available from http://www.virtualbox.org. This file is free software;
82bcaaf8077ba892f39afb721dca149353c63d2cvboxsync# you can redistribute it and/or modify it under the terms of the GNU
82bcaaf8077ba892f39afb721dca149353c63d2cvboxsync# General Public License (GPL) as published by the Free Software
82bcaaf8077ba892f39afb721dca149353c63d2cvboxsync# Foundation, in version 2 as it comes in the "COPYING" file of the
82bcaaf8077ba892f39afb721dca149353c63d2cvboxsync# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
82bcaaf8077ba892f39afb721dca149353c63d2cvboxsync# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
82bcaaf8077ba892f39afb721dca149353c63d2cvboxsync#
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync#change device to select NAT${NAT_STAT_DEVICE} counters
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsyncNAT_STAT_DEBUG=1
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsyncNAT_STAT_DEVICE=0
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsyncNAT_TMP=/tmp
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsyncNAT_STATS_FMT=wiki
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsyncNAT_STATS_CONVERTER=$NAT_TMP/converter.awk
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsyncNAT_STATS_COUNTERS_RAW=${NAT_TMP}/counters.out.raw
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsyncNAT_STATS_COUNTERS=${NAT_TMP}/counters.out
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsyncNAT_STATS_REPORT=NAT_STATS_NAME.${NAT_STATS_FMT}
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsyncNAT_IN_FILE=$1
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync[ x"$TMP" != x ] && NAT_TMP=TMP
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsyncgrep NAT${NAT_STAT_DEVICE} $NAT_IN_FILE > $NAT_STATS_COUNTERS_RAW
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync[ $? -ne 0 ] && echo "error happens while grep'ing the NAT's counters" && exit 1
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync#sed -ne "s/\ */\t/gp" $NAT_STATS_COUNTERS_RAW > $NAT_STATS_COUNTERS
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsynccp $NAT_STATS_COUNTERS_RAW $NAT_STATS_COUNTERS
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsynccat > $NAT_STATS_CONVERTER <<EOF
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsyncBEGIN{
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync if (FMT == "tsv")
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync OFS="\t";
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync else if (FMT == "wiki")
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync OFS="</td><td>"
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync FS=" ";
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync if (FMT == "wiki")
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync print "<table>"
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync if (COUNTERS == "counting")
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync {
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync NF = 2;
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync \$1 = "name"
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync \$2 = "count"
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync if (FMT == "wiki")
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync print "<tr><td>" \$0 "</td></tr>"
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync else
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync print \$0
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync }
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync else if (COUNTERS == "profiling")
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync {
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync NF=6
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync \$1 = "name"
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync \$2 = "ticks_per_count"
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync \$3 = "total_ticks"
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync \$4 = "times"
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync \$5 = "max"
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync \$6 = "min"
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync if (FMT == "wiki")
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync print "<tr><td>" \$0 "</td></tr>"
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync else
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync print \$0
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync }
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync}
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync/*counting counters */
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsyncNF == 3 && COUNTERS=="counting"{
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync name = \$1
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync count = \$2
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync NF=2
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync if (FMT == "wiki")
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync print "<tr><td>" \$0 "</td></tr>"
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync else
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync print \$0
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync}
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync/*profiling counters */
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsyncNF == 12 && COUNTERS=="profiling"{
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync name = \$1
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync ticks_per_count = \$2
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync total_ticks = \$5
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync times = \$7
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync max = \$10
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync min = \$12
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync NF=6
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync \$1 = name
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync \$2 = ticks_per_count
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync \$3 = total_ticks
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync \$4 = times
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync \$5 = substr(max,0, index(max, ",") -1)
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync \$6 = substr(min,0, index(min, ")") - 1)
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync if (FMT == "wiki")
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync print "<tr><td>" \$0 "</td></tr>"
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync else
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync print \$0
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync}
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsyncEND{
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync if (FMT == "wiki")
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync print "</table>"
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync}
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsyncEOF
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsyncawk -v FMT=$NAT_STATS_FMT -v COUNTERS=profiling -f $NAT_STATS_CONVERTER $NAT_STATS_COUNTERS > $NAT_STATS_REPORT
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsyncawk -v FMT=$NAT_STATS_FMT -v COUNTERS=counting -f $NAT_STATS_CONVERTER $NAT_STATS_COUNTERS >> $NAT_STATS_REPORT
d9a56535f83f926b52a6c3bc55da1cb37bf23b96vboxsync