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 |
|
---|
30 | NAT_STAT_DEBUG=1
|
---|
31 | NAT_STAT_DEVICE=0
|
---|
32 | NAT_TMP=/tmp
|
---|
33 | NAT_STATS_FMT=wiki
|
---|
34 |
|
---|
35 | NAT_STATS_CONVERTER=$NAT_TMP/converter.awk
|
---|
36 | NAT_STATS_COUNTERS_RAW=${NAT_TMP}/counters.out.raw
|
---|
37 | NAT_STATS_COUNTERS=${NAT_TMP}/counters.out
|
---|
38 | NAT_STATS_REPORT=NAT_STATS_NAME.${NAT_STATS_FMT}
|
---|
39 |
|
---|
40 | NAT_IN_FILE=$1
|
---|
41 |
|
---|
42 | [ x"$TMP" != x ] && NAT_TMP=TMP
|
---|
43 |
|
---|
44 | grep 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
|
---|
48 | cp $NAT_STATS_COUNTERS_RAW $NAT_STATS_COUNTERS
|
---|
49 |
|
---|
50 | cat > $NAT_STATS_CONVERTER <<EOF
|
---|
51 | BEGIN{
|
---|
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 */
|
---|
86 | NF == 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 */
|
---|
96 | NF == 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 | }
|
---|
116 | END{
|
---|
117 | if (FMT == "wiki")
|
---|
118 | print "</table>"
|
---|
119 | }
|
---|
120 | EOF
|
---|
121 | awk -v FMT=$NAT_STATS_FMT -v COUNTERS=profiling -f $NAT_STATS_CONVERTER $NAT_STATS_COUNTERS > $NAT_STATS_REPORT
|
---|
122 | awk -v FMT=$NAT_STATS_FMT -v COUNTERS=counting -f $NAT_STATS_CONVERTER $NAT_STATS_COUNTERS >> $NAT_STATS_REPORT
|
---|
123 |
|
---|