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 [ ! "$D8_PATH" ]; then
     14   d8_public=`which d8`
     15   if [ -x "$d8_public" ]; then D8_PATH=$(dirname "$d8_public"); fi
     16 fi
     17 [ -n "$D8_PATH" ] || D8_PATH=$tools_path/..
     18 d8_exec=$D8_PATH/d8
     19 
     20 if [ ! -x "$d8_exec" ]; then
     21   D8_PATH=`pwd`/out/native
     22   d8_exec=$D8_PATH/d8
     23 fi
     24 
     25 if [ ! -x "$d8_exec" ]; then
     26   d8_exec=`grep -m 1 -o '".*/d8"' $log_file | sed 's/"//g'`
     27 fi
     28 
     29 if [ ! -x "$d8_exec" ]; then
     30   echo "d8 shell not found in $D8_PATH"
     31   echo "To build, execute 'make native' from the V8 directory"
     32   exit 1
     33 fi
     34 
     35 if [[ "$@" != *--distortion* ]]; then
     36   # Try to find out how much the instrumentation overhead is.
     37   calibration_log=calibration.log
     38   calibration_script="for (var i = 0; i < 1000000; i++) print();"
     39 
     40   $d8_exec --nocrankshaft --prof --logfile $calibration_log \
     41        --log-timer-events -e "$calibration_script" > /dev/null
     42   t_1_start=`grep "timer-event-start,\"V8.Execute\"" $calibration_log  \
     43        | tail -n1 | awk -F, '{print $3}'`
     44   t_1_end=`grep "timer-event-end,\"V8.Execute\"" $calibration_log  \
     45        | tail -n1 | awk -F, '{print $3}'`
     46   n_1=`grep "timer-event\|tick" $calibration_log  | wc -l`
     47 
     48   $d8_exec --nocrankshaft --prof --logfile $calibration_log \
     49        --log-internal-timer-events -e "$calibration_script" > /dev/null
     50   t_2_start=`grep "timer-event-start,\"V8.Execute\"" $calibration_log  \
     51        | tail -n1 | awk -F, '{print $3}'`
     52   t_2_end=`grep "timer-event-end,\"V8.Execute\"" $calibration_log  \
     53        | tail -n1 | awk -F, '{print $3}'`
     54   n_2=`grep "timer-event\|tick" $calibration_log  | wc -l`
     55 
     56   rm $calibration_log
     57 
     58   # Overhead in picoseconds.
     59   options=--distortion=
     60   options+=`echo "1000*(($t_1_end - $t_1_start) - ($t_2_end - $t_2_start)) \
     61               / ($n_1 - $n_2)" | bc`
     62   echo $options
     63 fi
     64 
     65 cat $log_file |
     66     $d8_exec $tools_path/csvparser.js $tools_path/splaytree.js \
     67     $tools_path/codemap.js $tools_path/profile.js $tools_path/profile_view.js \
     68     $tools_path/logreader.js $tools_path/tickprocessor.js \
     69     $tools_path/profviz/composer.js $tools_path/profviz/stdio.js \
     70     -- $@ $options 2>/dev/null | gnuplot > timer-events.png
     71