File: benchmark.in

package info (click to toggle)
osgcal 0.1.46-2.1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 12,100 kB
  • ctags: 574
  • sloc: sh: 9,204; cpp: 7,028; python: 803; makefile: 192; xml: 159
file content (468 lines) | stat: -rw-r--r-- 9,901 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
#!/bin/bash
#
# Copyright (C) 2006 Mekensleep
#
# Mekensleep
# 24 rue vieille du temple
# 75004 Paris
#       licensing@mekensleep.com
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA.
#
# Authors:
#  Loic Dachary <loic@gnu.org>
#  Cedric Pinson <cpinson@freesheep.org>
#  Jerome Jeannin <griim.work@gmail.com>
#
set -e

export CCACHE_HASHDIR=yes

: ${CVS_USER:=:pserver:anonymous}
: ${CVS_COMPRESS:=-z3}

: ${srcdir:=.}

TMP=$0.$$
PID=$$
DATA_CACHED=/bin/false
declare -i NUMLOOPS=1
declare -i LIMIT_TIME=80000000 # microseconds per outfit
declare -i FOUND_GOOD_ITERATION=0

trap "rm -f $TMP" EXIT INT QUIT TERM

DATA_PATH="${srcdir}/data"

DRY_RUN=0
FILE="benchmark_result.$PID"
XML_FILE="$FILE.xml"

declare -i DICHO=0
declare -i TESTDATE=0
declare -i TESTPERF=0
declare -i TESTLVL=0
declare -i TESTREC=0
declare -i INDEX_DATE=2

declare -a data_date
declare -a date_epoch
declare -a thrs_init
declare -a run_time=(0,0)

declare -i threshold_date=0
declare -i threshold_perf=0
declare -i dicho_level=0
declare -i stop=0

#============================

function usage() {
    echo "  [-h] : print option list"
    echo "  [-t] : don't run test binary"
    echo "  [-v] : enable verbose mode"
    echo "  [-p \"data_path\"] : define data path"
    echo "  [-d \"dates\"] : specify list of date to check (use 'now' for current build)"
    echo "  [-i \"dates\"] : specify interval of date to check (use 'now' for current build"
    echo "  [-l int] : dichotomy depth-limit (use with -i)"
    echo "  [-t \"threshold\"] : threshold for dichotomy stop-condition (use with -i) "
}

#
# CVS related function
#============================

#
# Extract a designated version from the CVS and build the library
# using date stored inside date_epoch; then run the test
#
function getCvsAndTest()
{
  local date
  date=$(date -d "1970-01-01 ${date_epoch[$1]} sec GMT" +%F\ %H:%M)

  
  if cvs ${CVS_COMPRESS} -d${CVS_USER}@cvs.gna.org:/cvs/underware co -D "${date}" -d "osgcal_$1" osgcal && cd "osgcal_$1"
  then 

    autoreconf -i
    ./configure --enable-nprofile
    make -i
    cd ..

    local dir=$(pwd)/"osgcal_$1"
    rm -f osgcal-*.so .libs/osgcal osgcal

    if make CXXFLAGS=-I$dir/include LDFLAGS=$dir/.libs/libosgCal.la osgcal
    then
      RunTest $1
    else
      run_time[$1]="not_build"
    fi
  else
    run_time[$1]="cvs_unvailable"
  fi

  rm -fr osgcal_$1
  rm -f osgcal
}

function BuildCurrentAndTest() 
{
  make clean all
  RunTest $1  # return result_time
  rm -f osgcal
}

#
# Test related function
#============================

#
# Run the benchmark and store in the resTime variable
# the benchmark duration in microseconds 
#
function run() 
{
  if [ $DRY_RUN -eq 1 ]
  then
    run_time[$1]=$LIMIT_TIME
    echo "" > $TMP
  else
    if ! $DATA_CACHED ; 
    then
      if ./osgcal --fixcam --benchmark --numberloops 1 --numberframe 1 ${DATA_PATH}/MC/cal3d.xfg ${DATA_PATH}/MC/outfit??.xfg > $TMP
      then
        DATA_CACHED=/bin/true
      fi
    fi
    
    if ./osgcal --fixcam --benchmark --numberloops $NUMLOOPS ${DATA_PATH}/MC/cal3d.xfg ${DATA_PATH}/MC/outfit??.xfg > $TMP
    then
      run_time[$1]=$(grep ':osgcal:' < $TMP | sed -e 's/\.//g' -e 's/.*:\([0-9][0-9]*\):.*/\1/')
      echo $(grep ':osgcal:' < $TMP)
    else
      run_time[$1]="crash"
    fi
  fi
}

function RunTest() 
{
  echo "Testing :" $(date -d "1970-01-01 ${date_epoch[$1]} sec GMT" +%F\ %H:%M)
  run $1
  if [ $FOUND_GOOD_ITERATION -eq 0 ]
  then
    # testing if previous iteration is realy a good one
    if [ $(echo ${run_time[$1]} | grep -c '^[0-9][0-9]*$') -eq 1 ]
    then      
      FOUND_GOOD_ITERATION=1
      NUMLOOPS=$(awk "END { print int( $LIMIT_TIME / ${run_time[$1]} ) }" < /dev/null) 
      run $1
    fi
  fi
}

#
# Date/Interval related function
#=================================

#
# Set date_epoch according to data_date value
#
function initEpoch() 
{

  INDEX_DATE=${#data_date[*]}

  # if only one date, then we add "now"
  if [ $INDEX_DATE -eq 1 ]
  then
    data_date[1]="now"
    let 'INDEX_DATE = INDEX_DATE + 1'
  fi
 
  # init all epoch
  for d in $(seq 0 $(($INDEX_DATE-1)) )
  do
    date_epoch[$d]=$(date -d ${data_date[$d]} +%s)
  done  
}

#
# add a new date in date_epoch between $1 and $2
#
function findNewDate() 
{  
  DIFF=$(( ${date_epoch[$2]} - ${date_epoch[$1]} ))

  date_epoch[$INDEX_DATE]=$(( ${date_epoch[$1]} + $(( $DIFF / 2 )) ))
  let "INDEX_DATE = INDEX_DATE+1"
}

#
# set up the threshold used in dicho_test
#
function initThreshold() 
{
  NB_THRS=${#thrs_init[*]}
  for i in $(seq 0 $(($NB_THRS-1)) )
  do
    TH_BASE=$( echo ${thrs_init[$i]} | sed 's/^[0-9.]*//' )
    TH_UNIT=$( echo ${thrs_init[$i]} | sed 's/[a-zA-Z%]*$//')

    case $TH_BASE in
      h) # hour
        threshold_date=3600
        ;;
      d) # days
        threshold_date=86400
        ;;
      w) # weeks
        threshold_date=604800
        ;;
      m) # month
        threshold_date=2419200
        ;;
      %) # percent
        threshold_perf=$TH_UNIT
        TESTPERF=1
        ;;
      *) 
        echo "threshold argument invalid"
        return 1;;
    esac
  
    if [ $threshold_date -gt 0 ]
    then
      let 'threshold_date = threshold_date * TH_UNIT'
      TESTDATE=1  
    fi
  done

  TESTREC=$(( $TESTPERF || $TESTDATE ))

  if [ $TESTDATE -eq 0 ]
  then
    echo "you had to set a date threshold with your performance threshold"
    exit 1
  fi

}

#
# set stop if date are to close according to threshold_date
#
function threshold_date() 
{
  if [ $(( ${date_epoch[$2]} - ${date_epoch[$1]} )) -le $threshold_date ] 
  then 
    stop=1
  fi 
}

#
# set stop if perf are to close according to threshold_perf
#
function threshold_perf() 
{ 

  time_to_run=${run_time[$2]}
  reference_time_to_run=${run_time[$1]}

  # if $1 and $2 not numbers or 0, we stop
  if [ $(( $(( $time_to_run )) || $(( $reference_time_to_run )) )) -eq 0 ]
  then
    stop=1
  else
    # if one only is not numbers or 0, we continue !
    if [ $(( $(( $time_to_run )) && $(( $reference_time_to_run )) )) -eq 0 ]
    then
      stop=0
    else
      if [ $(( $reference_time_to_run )) -gt 0 ]
      then 
 
        difference=$(( $time_to_run - $reference_time_to_run))
        percent=$(( $((100 * $difference)) / $reference_time_to_run))

        # if percent is <0, make percent >0
        if [ $percent -lt 0 ]
        then
          percent=$(( -$percent ))
        fi

        # testing percent with threshold_perf
        if [ $percent -le $threshold_perf ]
        then
          stop=1
        fi
      fi
    fi
  fi
}

#
# Test function
#============================

#
# test all date defined in
# data_date
# 
function list_test() 
{
  epochIndex=${#date_epoch[*]}

  for d in $(seq 0 $(($epochIndex-1)) )
  do
    if [ ${data_date[d]} = "now" ]
    then
      BuildCurrentAndTest $d
    else
      getCvsAndTest $d
    fi
  done
}

#
# recursively run the test
# until stop condition is reached
# 
# args : $1 and $2 refers to date_epoch[$n]
#        $3 is the call level
#
function dicho_test() 
{

  # testing stop by perf
  if [ $TESTPERF -eq 1 ]
  then
    threshold_perf $1 $2
  fi

  # testing stop by date
  if [ $TESTDATE -eq 1 ]
  then
    threshold_date $1 $2
  fi

  #testing stop by level
  if [ $TESTLVL -eq 1 ]
  then
    if [ $3 -ge $dicho_level ]
    then
      stop=1
    fi
  fi

  if [ $stop -eq 1 ]
  then
    stop=0
  else
    findNewDate $1 $2 # add a new date at $INDEX_DATE

    getCvsAndTest $(( $INDEX_DATE-1 ))
    dicho_test $1 $(( $INDEX_DATE-1 )) $(( $3+1 ))
    dicho_test $(( $INDEX_DATE-1 )) $2 $(( $3+1 ))
  fi
}

#----------------------------------------------------------

#
# main
#

LAUNCH_TIME=$(date)

while getopts 'hrp:v:d:t:i:l:' o ; do
  case $o in
    h) usage ; exit 0 ;;
    r) # do not run ./osgcal
      DRY_RUN=1
      ;;
    p) # ---
      DATA_PATH=$OPTARG
      ;;
    v) # enable OSG message
      VERBOSE=$OPTARG
	  export OSG_NOTIFY_LEVEL=ALWAYS
      set -x
      ;;
    d) # specify list of dates
      data_date=($OPTARG)
      initEpoch
      ;;
    i) # specify interval
      data_date=($OPTARG)
      DICHO=1
      initEpoch
      if [ $(( ${date_epoch[1]} - ${date_epoch[0]} )) -le 0 ]
      then
        echo "interval is not valid"
        exit 1
      fi
      ;;
    t) # specify threshold
      thrs_init=($OPTARG)
      initThreshold
      ;;
    l) # specify dichotomy level
      dicho_level=$OPTARG
      TESTLVL=1
      TESTREC=1
      ;;
  esac
done

if [ $DICHO -eq 1 ]
then

  if [ $TESTREC -ne 1 ]
  then
    echo "no threshold defined : test aborded"
    exit 1
  fi

  getCvsAndTest 0

  if [ ${data_date[1]} = "now" ]
  then
    BuildCurrentAndTest 1
  else
    getCvsAndTest 1
  fi
  
  dicho_test 0 1 0

else
  list_test
fi

# generating output

echo -e "<?xml-stylesheet type=\"text/xsl\" href=\"bench2html.xsl\"?>\n<benchmark>" > $XML_FILE
echo -e "<title>Osgcal benchmark</title>\n<date>$LAUNCH_TIME</date>" >> $XML_FILE

i=0
while [ "$i" -lt "$INDEX_DATE" ]; do
    echo "<test><date>$(date -d "1970-01-01 ${date_epoch[$i]} sec GMT" +%F\ %H:%M)</date><run_time>${run_time[$i]}</run_time></test>" >> $XML_FILE
    let "i = i + 1"
done

echo "</benchmark>" >> $XML_FILE

xsltproc -o $FILE ${srcdir}/bench2ascii.xsl $XML_FILE