1#!/bin/sh
2
3#
4# %CopyrightBegin%
5#
6# Copyright Ericsson AB 2007-2019. All Rights Reserved.
7#
8# Licensed under the Apache License, Version 2.0 (the "License");
9# you may not use this file except in compliance with the License.
10# You may obtain a copy of the License at
11#
12#     http://www.apache.org/licenses/LICENSE-2.0
13#
14# Unless required by applicable law or agreed to in writing, software
15# distributed under the License is distributed on an "AS IS" BASIS,
16# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17# See the License for the specific language governing permissions and
18# limitations under the License.
19#
20# %CopyrightEnd%
21
22# Skeleton for a script intended to run the mstone1(N)
23# performance test.
24#
25
26# Get the name of the program
27program=`echo $0 | sed 's#.*/##g'`
28
29usage="\
30Usage: $program [options]
31
32This shell script is used to run the mstone 1 (factor) performance
33test. It is not intended to test the megaco stack but instead to
34give a \"performance value\" of the host on which it is run.
35
36Options:
37 -help                  display this help and exit.
38 -mp <message package>  message package to use for test
39                        default is time_test
40 -h <num>               default process heap size
41 -a <num>               async thread pool size (default is 0)
42 -t <run time>          The runtime of the test
43                        Format: <value>[unit], where unit can be:
44                           s: seconds
45                           m: minutes (default)
46                           h: hours
47                        If no unit is provided, minutes is assumed.
48                        defaults to 10 minutes
49 -f <factor>            normally the test is run with 16 processes
50                        (factor 1), one for each codec config. The test
51                        can however be run with other factors, e.g.
52                        factor 10 means that 10 processes will be started
53                        for each megaco codec config.
54                        The options -s and -f cannot both be present.
55 -s <num sched>         normally the test is run with a fixed factor,
56                        but if this option is given, the number of
57                        schedulers is fixed (to the value set by this option)
58                        and the factor is the variable.
59                        The options -s and -f cannot both be present.
60 -d <drv-mode>          driver mode for the test:
61                        std  - all codec config(s) will be used
62                        flex - only the text codec config(s) utilizing the
63                               flex scanner will be used
64                        nd   - only codec config(s) without drivers will be used
65                        od   - only codec config(s) with drivers will be used
66 -sbt <bind-type>       Set scheduler bind type. See erl man page for more info.
67                        tnnps - Thread no node processor spread (default)
68                        u     - Unbound
69                        ns    - No spread
70                        ts    - Thread spread
71                        ps    - Processor spread
72                        s     - Spread
73                        nnts  - No node thread spread
74                        nnps  - No node processor spread
75 --                     everything after this is just passed on to erl.
76"
77
78ERL_HOME=<path to otp top dir>
79MEGACO_HOME=$ERL_HOME/lib/erlang/lib/megaco-%VSN%
80MEAS_HOME=$MEGACO_HOME/examples/meas
81PATH=$ERL_HOME/bin:$PATH
82
83MODULE=megaco_codec_mstone1
84STARTF="start"
85FACTOR=""
86MSG_PACK=time_test
87SBT="+sbt tnnps"
88RT=10
89
90while test $# != 0; do
91    # echo "DBG: Value = $1"
92    case  $1 in
93        -help)
94            echo "$usage" ;
95            exit 0;;
96
97        -mp)
98            MSG_PACK="$2";
99            shift ; shift ;;
100
101        -h)
102            PHS="+h $2";
103            shift ; shift ;;
104
105        -a)
106            ATP="+A $2";
107            shift ; shift ;;
108
109        -t)
110            RT="$2";
111            shift ; shift ;;
112
113        -d)
114	    case $2 in
115		std)
116		    STARTF="start";
117		    shift ; shift ;;
118		flex)
119		    STARTF="start_flex";
120		    shift ; shift ;;
121		nd)
122		    STARTF="start_no_drv";
123		    shift ; shift ;;
124		od)
125		    STARTF="start_only_drv";
126		    shift ; shift ;;
127		*)
128		    echo "unknown driver mode: $2";
129		    echo "$usage" ;
130		    exit 0
131	    esac;;
132
133        -sbt)
134	    case $2 in
135		tnnps|u|ns|ts|ps|s|nnts|nnps)
136		    SBT="+sbt $2";
137		    shift ; shift ;;
138		*)
139		    echo "unknown scheduler bind type: $2";
140		    echo "$usage" ;
141		    exit 0
142	    esac;;
143
144        -f)
145            if [ "x$SCHED" != "x" ]; then
146                echo "option(s) -s and -f cannot both be given" ;
147                echo "$usage" ;
148                exit 0
149            fi
150            FACTOR="$2";
151            TYPE=factor;
152            shift ; shift ;;
153
154        -s)
155            if [ "x$FACTOR" != "x" ]; then
156                echo "option(s) -f and -s cannot both be given" ;
157                echo "$usage" ;
158                exit 0
159            fi
160            SCHED="$2";
161            TYPE=sched;
162            shift ; shift ;;
163
164        --)
165            shift ;
166            break;;
167
168        *)
169            echo "unknown option: $1";
170            echo "$usage" ;
171            exit 0
172    esac
173done
174
175if [ $TYPE = factor ]; then
176
177    MSTONE="-s $MODULE $STARTF $MSG_PACK $RT $FACTOR"
178
179    # SCHEDS="01 02 04"
180    # SCHEDS="01 02 04 08"
181    # SCHEDS="01 02 04 08 16"
182    # SCHEDS="01 02 04 08 16 32"
183    # SCHEDS="01 02 04 08 16 32 64"
184    SCHEDS="01 02 03 04 05 06 07 08"
185
186    for i in `echo $SCHEDS`; do
187        case $i in
188            01)
189                SMP_INFO="SMP: 1 scheduler"
190                SMP_OPTS="-smp +S $i"
191                LOG="mstone1-f$FACTOR-s$i.log"
192                ;;
193
194            *)
195                SMP_INFO="SMP: $i schedulers"
196                SMP_OPTS="-smp +S $i"
197                LOG="mstone1-f$FACTOR-s$i.log"
198                ;;
199        esac
200
201        echo ""
202        echo "---------------------------------------------"
203        echo "$SMP_INFO"
204        echo ""
205
206        ERL="erl \
207          -noshell \
208          $SBT \
209          $PHS \
210          $ATP \
211          $SMP_OPTS \
212          -pa $MEAS_HOME \
213          $MSTONE \
214          $* \
215          -s init stop"
216
217        echo $ERL
218        $ERL | tee $LOG
219    done
220
221elif [ $TYPE = sched ]; then
222
223    MSTONE="-s $MODULE $STARTF $MSG_PACK $RT"
224
225    # FACTORS="01 02 03 04"
226    # FACTORS="01 02 03 04 05 06 07 08 09 10"
227    FACTORS="01 02 04 08 16 32"
228    # FACTORS="001 010 100"
229
230    case $SCHED in
231        *)
232            SMP_OPTS="-smp +S $SCHED"
233            ;;
234    esac
235
236    for i in `echo $FACTORS`; do
237        LOG="mstone1-s$SCHED-f$i.log"
238
239        echo ""
240        echo "---------------------------------------------"
241        echo "Factor $i"
242        echo ""
243
244        ERL="erl \
245          -noshell \
246          $SBT \
247          $PHS \
248          $ATP \
249          $SMP_OPTS \
250          -pa $MEAS_HOME \
251          $MSTONE $i \
252          $* \
253          -s init stop"
254
255        echo $ERL
256        $ERL | tee $LOG
257    done
258
259
260else
261    echo "Either option -f or -s must be specified"
262    echo "$usage" ;
263    exit 0
264
265fi
266