From 213a9250ce090f75acaac9c87342c325981fc206 Mon Sep 17 00:00:00 2001 From: Gleb Balykov Date: Fri, 15 Sep 2017 22:00:08 +0300 Subject: [PATCH] Add scripts for tracing Tizen .NET applications. --- scripts/heaptrack-pid.sh | 59 +++++++++++++++++++++++++++++++++++ scripts/heaptrack-run.sh | 62 +++++++++++++++++++++++++++++++++++++ scripts/heaptrack.sh | 24 +++++++++++++++ scripts/prepare-device-internal.sh | 32 +++++++++++++++++++ scripts/prepare-device.sh | 23 ++++++++++++++ scripts/which | 63 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 263 insertions(+) create mode 100755 scripts/heaptrack-pid.sh create mode 100755 scripts/heaptrack-run.sh create mode 100755 scripts/heaptrack.sh create mode 100755 scripts/prepare-device-internal.sh create mode 100755 scripts/prepare-device.sh create mode 100755 scripts/which diff --git a/scripts/heaptrack-pid.sh b/scripts/heaptrack-pid.sh new file mode 100755 index 0000000..0fc2716 --- /dev/null +++ b/scripts/heaptrack-pid.sh @@ -0,0 +1,59 @@ +#!/bin/bash -x + +HEAPTRACK_DIR=$1 +RES_FILE=$2 +APP_ID=$3 +APP_PATH=$4 + +CUR_DIR=`pwd` +cd $HEAPTRACK_DIR + +rm -f $RES_FILE +rm -f heaptrack*.gz + +export PATH=${PATH}:${HEAPTRACK_DIR} + +export ELM_ENGINE=wayland_shm +export ECORE_EVAS_ENGINE=wayland_shm +export HOME=/opt/usr/home/owner +export XDG_RUNTIME_DIR=/run/user/5001 +export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/5001/dbus/user_bus_socket +export AUL_APPID=${APP_ID} +export CORECLR_PROFILER={C7BAD323-25F0-4C0B-B354-566390B215CA} +export CORECLR_PROFILER_PATH=${HEAPTRACK_DIR}/libprofiler.so +export CORECLR_ENABLE_PROFILING=1 + + +nohup ./heaptrack /usr/bin/dotnet-launcher --standalone ${APP_PATH} & + +sleep 1 + +PID=$(ps -o pid,cmd ax | grep dotnet-launcher | grep standalone | grep ${APP_PATH} | grep -v -e grep -e heaptrack | awk '{ print $1 }') + +echo "Application PID: $PID. Press 'c' to stop and save results" + +while true +do + read -rsn1 input + if [ "$input" = "c" ]; then + echo "saving result" + break + fi +done + +kill -15 $PID + +for i in `seq 1 1 60`; do + sleep 1; + + kill -0 $PID 2>/dev/null || break + sleep 1 +done + +kill -0 $PID 2>/dev/null && kill -9 $PID 2>/dev/null + +sleep 5 + +mv heaptrack*.gz $RES_FILE + +cd $CUR_DIR diff --git a/scripts/heaptrack-run.sh b/scripts/heaptrack-run.sh new file mode 100755 index 0000000..bcc17f0 --- /dev/null +++ b/scripts/heaptrack-run.sh @@ -0,0 +1,62 @@ +#!/bin/bash -x + +SDB=$1 + +DEVICE_HEAPTRACK_PATH=$2 + +HEAPTRACK_FOR_DEVICE_HOST_PATH=$3 +HEAPTRACK_FOR_HOST_PATH=$4 +SCRIPTS_PATH=$5 +RES_FILE=$6 +APP_ID=$7 +APP_PATH=$8 +LAUNCH_GUI=$9 + +IS_FOUND_APP=$($SDB shell "app_launcher -l | cut -d \"'\" -f 4 | grep -q '^${APP_ID}$'; echo \$?" | tr -d "[:space:]") +if [ "$IS_FOUND_APP" != "0" ]; then + echo "'${APP_ID}' application not found at device" + exit 1 +fi + +IS_FOUND_APP_PATH=$($SDB shell "ls ${APP_PATH} >& /dev/null; echo \$?" | tr -d "[:space:]") +if [ "$IS_FOUND_APP_PATH" != "0" ]; then + echo "'${APP_PATH}' application path not found at device" + exit 1 +fi + +rm -f $RES_FILE + +$SDB shell "mkdir -p $DEVICE_HEAPTRACK_PATH/build/bin; + mkdir -p $DEVICE_HEAPTRACK_PATH/build/lib/heaptrack + mkdir -p $DEVICE_HEAPTRACK_PATH/build/lib/heaptrack/libexec" &>/dev/null +$SDB push $HEAPTRACK_FOR_DEVICE_HOST_PATH/build/bin/* $DEVICE_HEAPTRACK_PATH/build/bin/ &>/dev/null +$SDB push $HEAPTRACK_FOR_DEVICE_HOST_PATH/build/lib/heaptrack/*.so $DEVICE_HEAPTRACK_PATH/build/lib/heaptrack/ &>/dev/null +$SDB push $HEAPTRACK_FOR_DEVICE_HOST_PATH/build/lib/heaptrack/libexec/* $DEVICE_HEAPTRACK_PATH/build/lib/heaptrack/libexec/ &>/dev/null +$SDB push $HEAPTRACK_FOR_DEVICE_HOST_PATH/build/libprofiler.so $DEVICE_HEAPTRACK_PATH/build/bin/ &>/dev/null +$SDB push $SCRIPTS_PATH/* $DEVICE_HEAPTRACK_PATH/build/bin/ &>/dev/null +$SDB shell "cd $DEVICE_HEAPTRACK_PATH/build/bin + ./heaptrack-pid.sh $DEVICE_HEAPTRACK_PATH/build/bin $DEVICE_HEAPTRACK_PATH/build/bin/res.gz ${APP_ID} ${APP_PATH}" + +$SDB pull $DEVICE_HEAPTRACK_PATH/build/bin/res.gz $RES_FILE &>/dev/null + +if [ "$LAUNCH_GUI" == "true" ]; then + echo "Showing malloc consumption" + $HEAPTRACK_FOR_HOST_PATH/build/bin/heaptrack_gui --malloc $RES_FILE 2>gui_malloc.stderr + echo + + echo "Showing managed consumption" + $HEAPTRACK_FOR_HOST_PATH/build/bin/heaptrack_gui --managed --hide-unmanaged-stacks $RES_FILE 2>gui_managed.stderr + echo + + echo "Showing mmap (Private_Dirty part) consumption" + $HEAPTRACK_FOR_HOST_PATH/build/bin/heaptrack_gui --private_dirty $RES_FILE 2>gui_private_dirty.stderr + echo + + echo "Showing mmap (Private_Clean part) consumption" + $HEAPTRACK_FOR_HOST_PATH/build/bin/heaptrack_gui --private_clean $RES_FILE 2>gui_private_clean.stderr + echo + + echo "Showing mmap (Shared_Clean + Shared_Dirty part) consumption" + $HEAPTRACK_FOR_HOST_PATH/build/bin/heaptrack_gui --shared $RES_FILE 2>gui_shared.stderr + echo +fi diff --git a/scripts/heaptrack.sh b/scripts/heaptrack.sh new file mode 100755 index 0000000..94303dd --- /dev/null +++ b/scripts/heaptrack.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +SDB=/home/ubuntu/tizen-studio/tools/sdb +DEVICE_HEAPTRACK_PATH=/opt/heaptrack +HEAPTRACK_FOR_DEVICE_HOST_PATH=/home/ubuntu/heaptrack-arm +HEAPTRACK_FOR_HOST_PATH=/home/ubuntu/heaptrack +SCRIPTS_PATH=/home/ubuntu/heaptrack-scripts +RES_FILE=/home/ubuntu/res.gz +APP_ID=$1 +APP_PATH=$2 + +$SDB root on +LAUNCH_GUI="true" + +$SCRIPTS_PATH/heaptrack-run.sh "$SDB" \ + "$DEVICE_HEAPTRACK_PATH" \ + "$HEAPTRACK_FOR_DEVICE_HOST_PATH" \ + "$HEAPTRACK_FOR_HOST_PATH" \ + "$SCRIPTS_PATH" \ + "$RES_FILE" \ + "$APP_ID" \ + "$APP_PATH" \ + "$LAUNCH_GUI" + diff --git a/scripts/prepare-device-internal.sh b/scripts/prepare-device-internal.sh new file mode 100755 index 0000000..af019e2 --- /dev/null +++ b/scripts/prepare-device-internal.sh @@ -0,0 +1,32 @@ +#!/bin/bash -x + +mount -o remount,rw /; +mv /usr/share/dotnet /opt/usr/dotnet; +mv /usr/share/dotnet.tizen /opt/usr/dotnet.tizen; +chsmack -a _ /opt/usr/dotnet; chsmack -a _ /opt/usr/dotnet.tizen; + +for i in `find /opt/usr/dotnet/`; do chsmack -a _ $i; done; +for i in `find /opt/usr/dotnet.tizen/`; do chsmack -a _ $i; done; + +ln -s /opt/usr/dotnet /usr/share/dotnet; +chsmack -a _ /usr/share/dotnet; +ln -s /opt/usr/dotnet.tizen /usr/share/dotnet.tizen; +chsmack -a _ /usr/share/dotnet.tizen; + +mkdir /opt/usr/lib +mv /usr/lib/debug /opt/usr/lib/debug; +chsmack -a _ /opt/usr/lib/debug; + +for i in `find /opt/usr/lib/debug/`; do chsmack -a _ $i; done; + +ln -s /opt/usr/lib/debug /usr/lib/debug; +chsmack -a _ /usr/lib/debug; + +mkdir /opt/usr/src +mv /usr/src/debug /opt/usr/src/debug; +chsmack -a _ /opt/usr/src/debug; + +for i in `find /opt/usr/src/debug/`; do chsmack -a _ $i; done; + +ln -s /opt/usr/src/debug /usr/src/debug; +chsmack -a _ /usr/src/debug; diff --git a/scripts/prepare-device.sh b/scripts/prepare-device.sh new file mode 100755 index 0000000..757acb1 --- /dev/null +++ b/scripts/prepare-device.sh @@ -0,0 +1,23 @@ +#!/bin/bash -x + +SDB=/home/ubuntu/tizen-studio/tools/sdb +RPMS_DIR=/home/ubuntu/device-rpms +SCRIPTS_PATH=/home/ubuntu/heaptrack-scripts + +$SDB root on + +if [ "$($SDB shell 'ls -d1 /opt/usr/rpms 2> /dev/null')" != "" ]; then + echo "The script already completed for the device. Please, don't use it second time until reset of the device to initial state" + + exit 1 +fi + +$SDB shell "mkdir /opt/usr/rpms" +$SDB push $RPMS_DIR/* /opt/usr/rpms + +$SDB push $SCRIPTS_PATH/prepare-device-internal.sh /opt/usr/rpms +$SDB shell "/opt/usr/rpms/prepare-device-internal.sh" + +$SDB shell "rm /usr/lib/debug/lib/libc-2.24.so.debug" + +$SDB shell "cd /opt/usr/rpms; rpm -i *.rpm;" diff --git a/scripts/which b/scripts/which new file mode 100755 index 0000000..5b2329d --- /dev/null +++ b/scripts/which @@ -0,0 +1,63 @@ +#! /bin/sh +set -ef + +if test -n "$KSH_VERSION"; then + puts() { + print -r -- "$*" + } +else + puts() { + printf '%s\n' "$*" + } +fi + +ALLMATCHES=0 + +while getopts a whichopts +do + case "$whichopts" in + a) ALLMATCHES=1 ;; + ?) puts "Usage: $0 [-a] args"; exit 2 ;; + esac +done +shift $(($OPTIND - 1)) + +if [ "$#" -eq 0 ]; then + ALLRET=1 +else + ALLRET=0 +fi +case $PATH in + (*[!:]:) PATH="$PATH:" ;; +esac +for PROGRAM in "$@"; do + RET=1 + IFS_SAVE="$IFS" + IFS=: + case $PROGRAM in + */*) + if [ -f "$PROGRAM" ] && [ -x "$PROGRAM" ]; then + puts "$PROGRAM" + RET=0 + fi + ;; + *) + for ELEMENT in $PATH; do + if [ -z "$ELEMENT" ]; then + ELEMENT=. + fi + if [ -f "$ELEMENT/$PROGRAM" ] && [ -x "$ELEMENT/$PROGRAM" ]; then + puts "$ELEMENT/$PROGRAM" + RET=0 + [ "$ALLMATCHES" -eq 1 ] || break + fi + done + ;; + esac + IFS="$IFS_SAVE" + if [ "$RET" -ne 0 ]; then + ALLRET=1 + fi +done + +exit "$ALLRET" -- 2.7.4