Debian Codegraph @

src/plot-netperfmeter-results

raw
1 #!/bin/sh
2 #
3 # Network Performance Meter
4 # Copyright (C) 2009-2024 by Thomas Dreibholz
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #
19 # Contact: [email protected]
20 #
21
22 if [ $# -lt 1 ] ; then
23 echo >&2 "Usage: $0 [Config File] {-ownfile} {-colour|-color|-greyscale|-grayscale|-blackandwhite}"
24 exit 1
25 fi
26
27 # ====== Read configuration from config file ================================
28 CONFIG_FILE="$1"
29 NUM_FLOWS=0
30 VECTOR_ACTIVE_NODE=""
31 VECTOR_PASSIVE_NODE=""
32 if [ ! -e "$CONFIG_FILE" ] ; then
33 echo >&2 "ERROR: Config file $CONFIG_FILE not found!"
34 exit 1
35 fi
36 . $CONFIG_FILE
37 shift
38
39 if [ "$VECTOR_PASSIVE_NODE" = "" -o "$VECTOR_ACTIVE_NODE" = "" -o $NUM_FLOWS -lt 1 ] ; then
40 echo >&2 "ERROR: Bad vector file configuration!"
41 exit 1
42 fi
43 if [ ! -e "$VECTOR_ACTIVE_NODE" ] ; then
44 echo >&2 "ERROR: Vector file $VECTOR_ACTIVE_NODE of active node not found!"
45 exit 1
46 fi
47 if [ ! -e "$VECTOR_PASSIVE_NODE" ] ; then
48 echo >&2 "ERROR: Vector file $VECTOR_ACTIVE_NODE of passive node not found!"
49 exit 1
50 fi
51
52 OUTPUT_PREFIX="`echo "$CONFIG_FILE" | sed -e "s/.config$//g"`"
53
54 echo "Configuration:"
55 echo " - Input of Active Node ($NAME_ACTIVE_NODE) -> $VECTOR_ACTIVE_NODE"
56 echo " - Input of Passive Node ($NAME_PASSIVE_NODE) -> $VECTOR_PASSIVE_NODE"
57 echo " - Output prefix -> $OUTPUT_PREFIX"
58
59
60 # ====== Get options ========================================================
61 PLOT_COLOR_MODE="cmColor"
62 PLOT_OWN_FILE="FALSE"
63 while [ $# -gt 0 ] ; do
64 if [ "$1" = "-ownfile" ] ; then
65 PLOT_OWN_FILE="TRUE"
66 elif [ "$1" = "-colour" -o "$1" = "-color" ] ; then
67 PLOT_COLOR_MODE="cmColor"
68 elif [ "$1" = "-greyscale" -o "$1" = "-grayscale" ] ; then
69 PLOT_COLOR_MODE="cmGrayScale"
70 elif [ "$1" = "-blackandwhite" ] ; then
71 PLOT_COLOR_MODE="cmBlackAndWhite"
72 else
73 echo >&2 "ERROR: Invalid option $1!"
74 exit 1
75 fi
76 shift
77 done
78
79
80 # ====== Create combined data files =========================================
81 SEARCH_PATHS=". /usr/local/bin /usr/bin"
82 COMBINESUMMARIES="combinesummaries"
83 for searchPath in $SEARCH_PATHS ; do
84 if [ -e "$searchPath/$COMBINESUMMARIES" ] ; then
85 COMBINESUMMARIES="$searchPath/combinesummaries"
86 break
87 fi
88 done
89
90 SUMMARY_NAME="$OUTPUT_PREFIX-summary.data.bz2"
91 (
92 echo "--values=\"\"$NAME_ACTIVE_NODE\" 1\""
93 echo "--input=$VECTOR_ACTIVE_NODE"
94 echo "--values=\"\"$NAME_PASSIVE_NODE\" 0\""
95 echo "--input=$VECTOR_PASSIVE_NODE"
96 ) | $COMBINESUMMARIES $SUMMARY_NAME "NodeName IsActive" -quiet
97
98 FLOW_SUMMARY_NAME="$OUTPUT_PREFIX-flows.data.bz2"
99 (
100 i=0
101 while [ $i -lt $NUM_FLOWS ] ; do
102 flowDescriptionVar="\$FLOW$i""_DESCRIPTION"
103 activeVectorVar="\$FLOW$i""_VECTOR_ACTIVE_NODE"
104 passiveVectorVar="\$FLOW$i""_VECTOR_PASSIVE_NODE"
105 eval flowDescription=$flowDescriptionVar
106 eval activeVector=$activeVectorVar
107 eval passiveVector=$passiveVectorVar
108
109 echo "--values=\"\"$flowDescription\" $i \"$NAME_ACTIVE_NODE\" 1\""
110 echo "--input=$activeVector"
111 echo "--values=\"\"$flowDescription\" $i \"$NAME_PASSIVE_NODE\" 0\""
112 echo "--input=$passiveVector"
113 i=$(($i+1))
114 done
115 ) | $COMBINESUMMARIES $FLOW_SUMMARY_NAME "FlowName FlowID NodeName IsActive" -quiet
116
117
118 # ====== Locate plotting scripts ============================================
119 SEARCH_PATHS=". /usr/share/netperfmeter /usr/local/share/netperfmeter"
120 PLOT_PROGRAM_DIR=""
121 PLOT_PROGRAM_SCRIPT="plot-netperfmeter-results.R"
122 for searchPath in $SEARCH_PATHS ; do
123 if [ -e "$searchPath/$PLOT_PROGRAM_SCRIPT" -a -e "$searchPath/plotter.R" ] ; then
124 PLOT_PROGRAM_DIR=$searchPath
125 break
126 fi
127 done
128 if [ "x$PLOT_PROGRAM_DIR" = "x" ] ; then
129 echo >&2 "ERROR: Cannot find $PLOT_PROGRAM_SCRIPT and plotter.R!"
130 exit 1
131 elif [ "$PLOT_PROGRAM_DIR" = "." ] ; then
132 echo " - NOTE: Using $PLOT_PROGRAM_SCRIPT and plotter.R from $searchPath!"
133 fi
134
135
136 # ====== Call the R script for plotting =====================================
137 R CMD BATCH --slave --vanilla \
138 "--args
139 programDirectory=\"$PLOT_PROGRAM_DIR\"
140 configFile=\"$CONFIG_FILE\"
141 summaryFile=\"$SUMMARY_NAME\"
142 flowSummaryFile=\"$FLOW_SUMMARY_NAME\"
143 pdfFilePrefix=\"$OUTPUT_PREFIX\"
144 plotColorMode=$PLOT_COLOR_MODE
145 plotOwnFile=$PLOT_OWN_FILE" \
146 $PLOT_PROGRAM_DIR/$PLOT_PROGRAM_SCRIPT /dev/stdout
147
148
149 # ====== Remove temporary files =============================================
150 echo "Cleaning up"
151 # rm -f $SUMMARY_NAME $FLOW_SUMMARY_NAME