VirtualBox

source: vbox/trunk/src/VBox/Devices/Network/scripts/VBoxConvertNATStats.sh@ 105381

Last change on this file since 105381 was 98103, checked in by vboxsync, 23 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 3.0 KB
Line 
1#!/bin/sh
2## @file
3# ???
4#
5
6#
7# Copyright (C) 2009-2023 Oracle and/or its affiliates.
8#
9# This file is part of VirtualBox base platform packages, as
10# available from https://www.virtualbox.org.
11#
12# This program is free software; you can redistribute it and/or
13# modify it under the terms of the GNU General Public License
14# as published by the Free Software Foundation, in version 3 of the
15# License.
16#
17# This program is distributed in the hope that it will be useful, but
18# WITHOUT ANY WARRANTY; without even the implied warranty of
19# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20# General Public License for more details.
21#
22# You should have received a copy of the GNU General Public License
23# along with this program; if not, see <https://www.gnu.org/licenses>.
24#
25# SPDX-License-Identifier: GPL-3.0-only
26#
27
28#change device to select NAT${NAT_STAT_DEVICE} counters
29
30NAT_STAT_DEBUG=1
31NAT_STAT_DEVICE=0
32NAT_TMP=/tmp
33NAT_STATS_FMT=wiki
34
35NAT_STATS_CONVERTER=$NAT_TMP/converter.awk
36NAT_STATS_COUNTERS_RAW=${NAT_TMP}/counters.out.raw
37NAT_STATS_COUNTERS=${NAT_TMP}/counters.out
38NAT_STATS_REPORT=NAT_STATS_NAME.${NAT_STATS_FMT}
39
40NAT_IN_FILE=$1
41
42[ x"$TMP" != x ] && NAT_TMP=TMP
43
44grep NAT${NAT_STAT_DEVICE} $NAT_IN_FILE > $NAT_STATS_COUNTERS_RAW
45[ $? -ne 0 ] && echo "error happens while grep'ing the NAT's counters" && exit 1
46
47#sed -ne "s/\ */\t/gp" $NAT_STATS_COUNTERS_RAW > $NAT_STATS_COUNTERS
48cp $NAT_STATS_COUNTERS_RAW $NAT_STATS_COUNTERS
49
50cat > $NAT_STATS_CONVERTER <<EOF
51BEGIN{
52 if (FMT == "tsv")
53 OFS="\t";
54 else if (FMT == "wiki")
55 OFS="</td><td>"
56
57 FS=" ";
58 if (FMT == "wiki")
59 print "<table>"
60 if (COUNTERS == "counting")
61 {
62 NF = 2;
63 \$1 = "name"
64 \$2 = "count"
65 if (FMT == "wiki")
66 print "<tr><td>" \$0 "</td></tr>"
67 else
68 print \$0
69 }
70 else if (COUNTERS == "profiling")
71 {
72 NF=6
73 \$1 = "name"
74 \$2 = "ticks_per_count"
75 \$3 = "total_ticks"
76 \$4 = "times"
77 \$5 = "max"
78 \$6 = "min"
79 if (FMT == "wiki")
80 print "<tr><td>" \$0 "</td></tr>"
81 else
82 print \$0
83 }
84}
85/*counting counters */
86NF == 3 && COUNTERS=="counting"{
87 name = \$1
88 count = \$2
89 NF=2
90 if (FMT == "wiki")
91 print "<tr><td>" \$0 "</td></tr>"
92 else
93 print \$0
94}
95/*profiling counters */
96NF == 12 && COUNTERS=="profiling"{
97 name = \$1
98 ticks_per_count = \$2
99 total_ticks = \$5
100 times = \$7
101 max = \$10
102 min = \$12
103 NF=6
104 \$1 = name
105 \$2 = ticks_per_count
106 \$3 = total_ticks
107 \$4 = times
108 \$5 = substr(max,0, index(max, ",") -1)
109 \$6 = substr(min,0, index(min, ")") - 1)
110
111 if (FMT == "wiki")
112 print "<tr><td>" \$0 "</td></tr>"
113 else
114 print \$0
115}
116END{
117 if (FMT == "wiki")
118 print "</table>"
119}
120EOF
121awk -v FMT=$NAT_STATS_FMT -v COUNTERS=profiling -f $NAT_STATS_CONVERTER $NAT_STATS_COUNTERS > $NAT_STATS_REPORT
122awk -v FMT=$NAT_STATS_FMT -v COUNTERS=counting -f $NAT_STATS_CONVERTER $NAT_STATS_COUNTERS >> $NAT_STATS_REPORT
123
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette