plot-timer-events 2.58 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
#!/bin/sh

# find the name of the log file to process, it must not start with a dash.
log_file="v8.log"
for arg in "$@"
do
  if ! expr "X${arg}" : "^X-" > /dev/null; then
    log_file=${arg}
  fi
done

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 20 21
  D8_PATH=$tools_path/..
fi

22 23
d8_exec=$D8_PATH/d8

24
if test ! -x "$d8_exec"; then
25 26 27 28
  D8_PATH=`pwd`/out/native
  d8_exec=$D8_PATH/d8
fi

29
if test ! -x "$d8_exec"; then
30 31 32
  d8_exec=`grep -m 1 -o '".*/d8"' $log_file | sed 's/"//g'`
fi

33
if test ! -x "$d8_exec"; then
34
  echo "d8 shell not found in $D8_PATH"
35
  echo "Please provide path to d8 as env var in D8_PATH"
36 37 38
  exit 1
fi

39 40 41 42 43 44 45 46 47 48 49

contains=0;
for arg in "$@"; do
  `echo "$arg" | grep -q "^--distortion"`
  if test $? -eq 0; then
    contains=1
    break
  fi
done

if test "$contains" -eq 0; then
50 51 52 53
  # Try to find out how much the instrumentation overhead is.
  calibration_log=calibration.log
  calibration_script="for (var i = 0; i < 1000000; i++) print();"

54
  $d8_exec --noopt --prof --logfile $calibration_log \
55
       --log-timer-events -e "$calibration_script" > /dev/null
56 57 58 59 60
  t_1_start=`grep "timer-event-start,\"V8.Execute\"" $calibration_log  \
       | tail -n1 | awk -F, '{print $3}'`
  t_1_end=`grep "timer-event-end,\"V8.Execute\"" $calibration_log  \
       | tail -n1 | awk -F, '{print $3}'`
  n_1=`grep "timer-event\|tick" $calibration_log  | wc -l`
61

62
  $d8_exec --noopt --prof --logfile $calibration_log \
63
       --log-internal-timer-events -e "$calibration_script" > /dev/null
64 65 66 67 68
  t_2_start=`grep "timer-event-start,\"V8.Execute\"" $calibration_log  \
       | tail -n1 | awk -F, '{print $3}'`
  t_2_end=`grep "timer-event-end,\"V8.Execute\"" $calibration_log  \
       | tail -n1 | awk -F, '{print $3}'`
  n_2=`grep "timer-event\|tick" $calibration_log  | wc -l`
69 70 71 72

  rm $calibration_log

  # 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 77
fi

78
cat $log_file |
79 80
    $d8_exec $tools_path/csvparser.js $tools_path/splaytree.js \
    $tools_path/codemap.js $tools_path/profile.js $tools_path/profile_view.js \
81 82 83
    $tools_path/logreader.js $tools_path/arguments.js \
    $tools_path/tickprocessor.js$tools_path/profviz/composer.js \
    $tools_path/profviz/stdio.js \
84 85 86
    -- $@ $options 2>/dev/null > timer-events.plot

success=$?
87
if test $success -ne 0; then
88 89 90 91 92 93
    cat timer-events.plot
else
    cat timer-events.plot | gnuplot > timer-events.png
fi

rm -f timer-events.plot