Home | History | Annotate | Download | only in tools
      1 #!/bin/sh
      2 
      3 # find the name of the log file to process, it must not start with a dash.
      4 log_file="v8.log"
      5 for arg in "$@"
      6 do
      7   if ! expr "X${arg}" : "^X-" > /dev/null; then
      8     log_file=${arg}
      9   fi
     10 done
     11 
     12 tools_path=`cd $(dirname "$0");pwd`
     13 if test ! "$D8_PATH"; then
     14   d8_public=`which d8`
     15   if test -x "$d8_public"; then D8_PATH=$(dirname "$d8_public"); fi
     16 fi
     17 
     18 if test ! -n "$D8_PATH"; then
     19   D8_PATH=$tools_path/..
     20 fi
     21 
     22 d8_exec=$D8_PATH/d8
     23 
     24 if test ! -x "$d8_exec"; then
     25   D8_PATH=`pwd`/out/native
     26   d8_exec=$D8_PATH/d8
     27 fi
     28 
     29 if test ! -x "$d8_exec"; then
     30   d8_exec=`grep -m 1 -o '".*/d8"' $log_file | sed 's/"//g'`
     31 fi
     32 
     33 if test ! -x "$d8_exec"; then
     34   echo "d8 shell not found in $D8_PATH"
     35   echo "To build, execute 'make native' from the V8 directory"
     36   exit 1
     37 fi
     38 
     39 
     40 contains=0;
     41 for arg in "$@"; do
     42   `echo "$arg" | grep -q "^--distortion"`
     43   if test $? -eq 0; then
     44     contains=1
     45     break
     46   fi
     47 done
     48 
     49 if test "$contains" -eq 0; then
     50   # Try to find out how much the instrumentation overhead is.
     51   calibration_log=calibration.log
     52   calibration_script="for (var i = 0; i < 1000000; i++) print();"
     53 
     54   $d8_exec --nocrankshaft --prof --logfile $calibration_log \
     55        --log-timer-events -e "$calibration_script" > /dev/null
     56   t_1_start=`grep "timer-event-start,\"V8.Execute\"" $calibration_log  \
     57        | tail -n1 | awk -F, '{print $3}'`
     58   t_1_end=`grep "timer-event-end,\"V8.Execute\"" $calibration_log  \
     59        | tail -n1 | awk -F, '{print $3}'`
     60   n_1=`grep "timer-event\|tick" $calibration_log  | wc -l`
     61 
     62   $d8_exec --nocrankshaft --prof --logfile $calibration_log \
     63        --log-internal-timer-events -e "$calibration_script" > /dev/null
     64   t_2_start=`grep "timer-event-start,\"V8.Execute\"" $calibration_log  \
     65        | tail -n1 | awk -F, '{print $3}'`
     66   t_2_end=`grep "timer-event-end,\"V8.Execute\"" $calibration_log  \
     67        | tail -n1 | awk -F, '{print $3}'`
     68   n_2=`grep "timer-event\|tick" $calibration_log  | wc -l`
     69 
     70   rm $calibration_log
     71 
     72   # Overhead in picoseconds.
     73   distortion=`echo "1000*(($t_1_end - $t_1_start) - ($t_2_end - $t_2_start)) \
     74               / ($n_1 - $n_2)" | bc`
     75   options="--distortion=$distortion"
     76 fi
     77 
     78 cat $log_file |
     79     $d8_exec $tools_path/csvparser.js $tools_path/splaytree.js \
     80     $tools_path/codemap.js $tools_path/profile.js $tools_path/profile_view.js \
     81     $tools_path/logreader.js $tools_path/tickprocessor.js \
     82     $tools_path/profviz/composer.js $tools_path/profviz/stdio.js \
     83     -- $@ $options 2>/dev/null > timer-events.plot
     84 
     85 success=$?
     86 if test $success -ne 0; then
     87     cat timer-events.plot
     88 else
     89     cat timer-events.plot | gnuplot > timer-events.png
     90 fi
     91 
     92 rm -f timer-events.plot
     93