11cb0ef41Sopenharmony_ci#!/bin/bash
21cb0ef41Sopenharmony_ci# Copyright 2012 the V8 project authors. All rights reserved.
31cb0ef41Sopenharmony_ci# Redistribution and use in source and binary forms, with or without
41cb0ef41Sopenharmony_ci# modification, are permitted provided that the following conditions are
51cb0ef41Sopenharmony_ci# met:
61cb0ef41Sopenharmony_ci#
71cb0ef41Sopenharmony_ci#     * Redistributions of source code must retain the above copyright
81cb0ef41Sopenharmony_ci#       notice, this list of conditions and the following disclaimer.
91cb0ef41Sopenharmony_ci#     * Redistributions in binary form must reproduce the above
101cb0ef41Sopenharmony_ci#       copyright notice, this list of conditions and the following
111cb0ef41Sopenharmony_ci#       disclaimer in the documentation and/or other materials provided
121cb0ef41Sopenharmony_ci#       with the distribution.
131cb0ef41Sopenharmony_ci#     * Neither the name of Google Inc. nor the names of its
141cb0ef41Sopenharmony_ci#       contributors may be used to endorse or promote products derived
151cb0ef41Sopenharmony_ci#       from this software without specific prior written permission.
161cb0ef41Sopenharmony_ci#
171cb0ef41Sopenharmony_ci# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
181cb0ef41Sopenharmony_ci# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
191cb0ef41Sopenharmony_ci# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
201cb0ef41Sopenharmony_ci# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
211cb0ef41Sopenharmony_ci# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
221cb0ef41Sopenharmony_ci# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
231cb0ef41Sopenharmony_ci# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
241cb0ef41Sopenharmony_ci# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
251cb0ef41Sopenharmony_ci# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
261cb0ef41Sopenharmony_ci# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
271cb0ef41Sopenharmony_ci# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ci# Runs d8 with the given arguments on the device under 'perf' and
301cb0ef41Sopenharmony_ci# processes the profiler trace and v8 logs using ll_prof.py.
311cb0ef41Sopenharmony_ci# 
321cb0ef41Sopenharmony_ci# Usage:
331cb0ef41Sopenharmony_ci# > ./tools/android-ll-prof.sh (debug|release) "args to d8" "args to ll_prof.py"
341cb0ef41Sopenharmony_ci#
351cb0ef41Sopenharmony_ci# The script creates deploy directory deploy/data/local/tmp/v8, copies there
361cb0ef41Sopenharmony_ci# the d8 binary either from out/android_arm.release or out/android_arm.debug,
371cb0ef41Sopenharmony_ci# and then sync the deploy directory with /data/local/tmp/v8 on the device.
381cb0ef41Sopenharmony_ci# You can put JS files in the deploy directory before running the script.
391cb0ef41Sopenharmony_ci# Note: $ANDROID_NDK_ROOT must be set.
401cb0ef41Sopenharmony_ci
411cb0ef41Sopenharmony_ciMODE=$1
421cb0ef41Sopenharmony_ciRUN_ARGS=$2
431cb0ef41Sopenharmony_ciLL_PROF_ARGS=$3
441cb0ef41Sopenharmony_ci
451cb0ef41Sopenharmony_ciBASE=`cd $(dirname "$0")/..; pwd`
461cb0ef41Sopenharmony_ciDEPLOY="$BASE/deploy"
471cb0ef41Sopenharmony_ci
481cb0ef41Sopenharmony_ciset +e
491cb0ef41Sopenharmony_cimkdir -p "$DEPLOY/data/local/tmp/v8"
501cb0ef41Sopenharmony_ci
511cb0ef41Sopenharmony_cicp "$BASE/out/android_arm.$MODE/d8" "$DEPLOY/data/local/tmp/v8/d8"
521cb0ef41Sopenharmony_ci
531cb0ef41Sopenharmony_ciadb -p "$DEPLOY" sync data
541cb0ef41Sopenharmony_ci
551cb0ef41Sopenharmony_ciadb shell "cd /data/local/tmp/v8;\
561cb0ef41Sopenharmony_ci           perf record -R -e cycles -c 10000 -f -i \
571cb0ef41Sopenharmony_ci           ./d8 --ll_prof --gc-fake-mmap=/data/local/tmp/__v8_gc__ $RUN_ARGS"
581cb0ef41Sopenharmony_ci
591cb0ef41Sopenharmony_ciadb pull /data/local/tmp/v8/v8.log .
601cb0ef41Sopenharmony_ciadb pull /data/local/tmp/v8/v8.log.ll .
611cb0ef41Sopenharmony_ciadb pull /data/perf.data .
621cb0ef41Sopenharmony_ci
631cb0ef41Sopenharmony_ciARCH=arm-linux-androideabi-4.6
641cb0ef41Sopenharmony_ciTOOLCHAIN="${ANDROID_NDK_ROOT}/toolchains/$ARCH/prebuilt/linux-x86/bin"
651cb0ef41Sopenharmony_ci
661cb0ef41Sopenharmony_ci$BASE/tools/ll_prof.py --host-root="$BASE/deploy" \
671cb0ef41Sopenharmony_ci                       --gc-fake-mmap=/data/local/tmp/__v8_gc__ \
681cb0ef41Sopenharmony_ci                       --objdump="$TOOLCHAIN/arm-linux-androideabi-objdump" \
691cb0ef41Sopenharmony_ci                       $LL_PROF_ARGS
70