1#!/bin/sh
2
3# find the name of the log file to process, it must not start with a dash.
4log_file="v8.log"
5for arg in "$@"
6do
7  if ! expr "X${arg}" : "^X-" > /dev/null; then
8    log_file=${arg}
9  fi
10done
11
12tools_path=`cd $(dirname "$0");pwd`
13if test ! "$D8_PATH"; then
14  d8_public=`which d8`
15  if test -x "$d8_public"; then D8_PATH=$(dirname "$d8_public"); fi
16fi
17
18if test ! -n "$D8_PATH"; then
19  D8_PATH=$tools_path/..
20fi
21
22d8_exec=$D8_PATH/d8
23
24if test ! -x "$d8_exec"; then
25  D8_PATH=`pwd`/out/native
26  d8_exec=$D8_PATH/d8
27fi
28
29if test ! -x "$d8_exec"; then
30  d8_exec=`grep -m 1 -o '".*/d8"' $log_file | sed 's/"//g'`
31fi
32
33if 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
37fi
38
39
40contains=0;
41for arg in "$@"; do
42  `echo "$arg" | grep -q "^--distortion"`
43  if test $? -eq 0; then
44    contains=1
45    break
46  fi
47done
48
49if 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"
76fi
77
78cat $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
85success=$?
86if test $success -ne 0; then
87    cat timer-events.plot
88else
89    cat timer-events.plot | gnuplot > timer-events.png
90fi
91
92rm -f timer-events.plot
93