Add perf option to art tool
'art --perf' will record user space cycle information
'art --perf-report' will also report the saved data.
When using perf, the temporary data directory is not deleted.
Change-Id: Iadceeb3883f815cac8ed2b8a96b9b8363661d156
diff --git a/tools/art b/tools/art
index 0103071..af96b47 100644
--- a/tools/art
+++ b/tools/art
@@ -53,6 +53,12 @@
elif [ "$1" = "--64" ]; then
DALVIKVM=dalvikvm64
shift
+ elif [ "$1" = "--perf" ]; then
+ PERF="record"
+ shift
+ elif [ "$1" = "--perf-report" ]; then
+ PERF="report"
+ shift
elif expr "$1" : "--" >/dev/null 2>&1; then
echo "unknown option: $1" 1>&2
exit 1
@@ -68,6 +74,11 @@
LIBDIR=$(find_libdir)
LD_LIBRARY_PATH=$ANDROID_ROOT/$LIBDIR
+
+if [ z"$PERF" != z ]; then
+ invoke_with="perf record -o $ANDROID_DATA/perf.data -e cycles:u $invoke_with"
+fi
+
mkdir -p $ANDROID_DATA/dalvik-cache/{arm,arm64,x86,x86_64}
ANDROID_DATA=$ANDROID_DATA \
ANDROID_ROOT=$ANDROID_ROOT \
@@ -75,7 +86,18 @@
$invoke_with $ANDROID_ROOT/bin/$DALVIKVM $lib \
-XXlib:$LIBART \
-Ximage:$ANDROID_ROOT/framework/core.art \
- "$@"
+ -Xcompiler-option --include-debug-symbols \
+ "$@"
+
EXIT_STATUS=$?
-rm -rf $ANDROID_DATA
+
+if [ z"$PERF" != z ]; then
+ if [ z"$PERF" = zreport ]; then
+ perf report -i $ANDROID_DATA/perf.data
+ fi
+ echo "Perf data saved in: $ANDROID_DATA/perf.data"
+else
+ rm -rf $ANDROID_DATA
+fi
+
exit $EXIT_STATUS