A4MCAR - Tracing scripts are added. Improved upon Rover's tracing scripts.
Signed-off-by: Mustafa Ozcelikors <mozcelikors@gmail.com>
diff --git a/a4mcar/high_level_applications/scripts/tracing/ListThreads.sh b/a4mcar/high_level_applications/scripts/tracing/ListThreads.sh
new file mode 100644
index 0000000..436d16f
--- /dev/null
+++ b/a4mcar/high_level_applications/scripts/tracing/ListThreads.sh
@@ -0,0 +1,70 @@
+#!/bin/bash
+# Copyright (c) 2017 FH Dortmund and others
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Description:
+# This script is used for estimating the granularity of a thread by
+# making use of its name and period.
+# Example usage: sudo ./ListThreads.sh -n <process_name>
+#
+# Authors:
+# M. Ozcelikors <mozcelikors@gmail.com>, FH Dortmund
+#
+
+helpwindow ()
+{
+ echo "Arguments for ListThreads.sh are:"
+ echo "#################################################"
+ echo "-h or --help : Show these help instructions"
+ echo "-p or --pid : Progress using Process ID"
+ echo "-n or --name : Progress using Process Name (CMD)"
+ echo "#################################################"
+ echo "Example usage: sudo ./ListThreads.sh -n <process_name> "
+ echo "or sudo ./ListThreads.sh -p <pid>"
+}
+
+if [ "$1" == "" ] || [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
+ helpwindow
+ exit 0
+fi
+
+while [[ $# -gt 1 ]]
+do
+ key="$1"
+ case $key in
+ -p|--pid)
+ pid="$2"
+ shift
+ ;;
+ -n|--name)
+ process_name="$2"
+ shift
+ ;;
+ *)
+ #Unknown
+ helpwindow
+ ;;
+ esac
+ shift
+done
+
+if ! [[ -z ${pid+x} ]]; then
+ ps H -p $pid -o 'pid tid cmd comm'
+elif ! [[ -z ${process_name+x} ]]; then
+ pid=$(pgrep -f $process_name -o)
+ ps H -p $pid -o 'pid tid cmd comm'
+fi
+
+exit $?
+
+
+
+
+
+
+
+
+
diff --git a/a4mcar/high_level_applications/scripts/tracing/MonitorThreads.sh b/a4mcar/high_level_applications/scripts/tracing/MonitorThreads.sh
new file mode 100644
index 0000000..501bc3f
--- /dev/null
+++ b/a4mcar/high_level_applications/scripts/tracing/MonitorThreads.sh
@@ -0,0 +1,66 @@
+#!/bin/bash
+# Copyright (c) 2017 FH Dortmund and others
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Description:
+# This script is used for monitoring core utilization of all threads of
+# a process by the process name.
+# Right usage: ./MonitorThreads.sh -n <process_name>
+# ./MonitorThreads.sh -p <pid>
+# You can access the help instructions by typing ./MonitorThreads.sh --help
+#
+# Authors:
+# M. Ozcelikors <mozcelikors@gmail.com>, FH Dortmund
+#
+
+helpwindow ()
+{
+ echo "Arguments for MonitorThreads.sh are:"
+ echo "#################################################"
+ echo "-h or --help : Show these help instructions"
+ echo "-p or --pid : Progress using Process ID"
+ echo "-n or --name : Progress using Process Name (CMD)"
+ echo "#################################################"
+ echo "Example usage: sudo ./MonitorThreads -n MyApplication"
+ echo " sudo ./MonitorThreads -p 1550"
+}
+
+if [ "$1" == "" ] || [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
+ helpwindow
+ exit 0
+fi
+
+while [[ $# -gt 1 ]]
+do
+ key="$1"
+ case $key in
+ -p|--pid)
+ pid="$2"
+ shift
+ ;;
+ -n|--name)
+ process_name="$2"
+ shift
+ ;;
+ *)
+ #Unknown
+ helpwindow
+ ;;
+ esac
+ shift
+done
+
+
+if ! [[ -z ${pid+x} ]]; then
+ ps H -p $pid -o 'pid tid cmd comm'
+ top H -p $pid
+elif ! [[ -z ${process_name+x} ]]; then
+ pid=$(pgrep -f $process_name -o)
+ ps H -p $pid -o 'pid tid cmd comm'
+ top H -p $pid
+fi
+
+exit $?
diff --git a/a4mcar/high_level_applications/scripts/tracing/ProfileAThread.sh b/a4mcar/high_level_applications/scripts/tracing/ProfileAThread.sh
new file mode 100644
index 0000000..e8c31f6
--- /dev/null
+++ b/a4mcar/high_level_applications/scripts/tracing/ProfileAThread.sh
@@ -0,0 +1,86 @@
+#!/bin/bash
+# Copyright (c) 2017 FH Dortmund and others
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Description:
+# This script is used for estimating the granularity of a thread by
+# making use of its name and period.
+# Example usage: ./ProfileAThread.sh -n <process_name> -t <period> -c <path/to/perf/obj>
+# <period> is in seconds
+#
+# Authors:
+# M. Ozcelikors <mozcelikors@gmail.com>, FH Dortmund
+#
+
+helpwindow ()
+{
+ echo "Arguments for ProfileAThread.sh are:"
+ echo "#################################################"
+ echo "-h or --help : Show these help instructions"
+ echo "-p or --pid : Progress using Process ID"
+ echo "-n or --name : Progress using Process Name (CMD)"
+ echo "-t or --time : Specify period in seconds to analyze"
+ echo "-c or --command : Perf command or path to perf object to run"
+ echo "#################################################"
+ echo "Example usage: sudo ./ProfileAThread.sh -n <process_name> -t <period> -c <path/to/perf/obj>"
+ echo "or sudo ./ProfileAThread.sh -p <pid> -t <period> -c <path/to/perf/obj>"
+}
+
+if [ "$1" == "" ] || [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
+ helpwindow
+ exit 0
+fi
+
+while [[ $# -gt 1 ]]
+do
+ key="$1"
+ case $key in
+ -p|--pid)
+ pid="$2"
+ shift
+ ;;
+ -n|--name)
+ process_name="$2"
+ shift
+ ;;
+ -t|--time)
+ period="$2"
+ shift
+ ;;
+ -c|--command)
+ perf_command="$2"
+ shift
+ ;;
+ *)
+ #Unknown
+ helpwindow
+ ;;
+ esac
+ shift
+done
+
+if ! [[ -z ${perf_command+x} ]]; then
+ if ! [[ -z ${period+x} ]]; then
+ if ! [[ -z ${pid+x} ]]; then
+ $perf_command stat -e instructions:u -p $pid -- sleep $period
+ elif ! [[ -z ${process_name+x} ]]; then
+ pid=$(pgrep -f $process_name -o)
+ $perf_command stat -e instructions:u -p $pid -- sleep $period
+ fi
+ else
+ helpwindow
+ fi
+else
+ helpwindow
+fi
+
+exit $?
+
+
+
+
+
+
diff --git a/a4mcar/high_level_applications/scripts/tracing/ProfileThreadsOfAProcess.sh b/a4mcar/high_level_applications/scripts/tracing/ProfileThreadsOfAProcess.sh
new file mode 100644
index 0000000..f2839b0
--- /dev/null
+++ b/a4mcar/high_level_applications/scripts/tracing/ProfileThreadsOfAProcess.sh
@@ -0,0 +1,82 @@
+#!/bin/bash
+# Copyright (c) 2017 FH Dortmund and others
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Description:
+# This script is used for estimating the granularity of a thread by
+# making use of its name and period.
+# Example usage: ./ProfileThreadsOfAProcess.sh -n <process_name> -t <period> -c <path/to/perf/obj>
+# <period> is in milliseconds
+#
+# Authors:
+# M. Ozcelikors <mozcelikors@gmail.com>, FH Dortmund
+#
+
+helpwindow ()
+{
+ echo "Arguments for ProfileThreadsOfAProcess.sh are:"
+ echo "#################################################"
+ echo "-h or --help : Show these help instructions"
+ echo "-p or --pid : Progress using Process ID"
+ echo "-n or --name : Progress using Process Name (CMD)"
+ echo "-t or --time : Specify period in milliseconds to analyze"
+ echo "-c or --command : Perf command or path to perf object to run"
+ echo "#################################################"
+ echo "Example usage: sudo ./ProfileThreadsOfAProcess.sh -n <process_name> -t <period> -c <path/to/perf/obj>"
+ echo "or sudo ./ProfileThreadsOfAProcess.sh -p <pid> -t <period> -c <path/to/perf/obj>"
+}
+
+if [ "$1" == "" ] || [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
+ helpwindow
+ exit 0
+fi
+
+while [[ $# -gt 1 ]]
+do
+ key="$1"
+ case $key in
+ -p|--pid)
+ pid="$2"
+ shift
+ ;;
+ -n|--name)
+ process_name="$2"
+ shift
+ ;;
+ -t|--time)
+ period="$2"
+ shift
+ ;;
+ -c|--command)
+ perf_command="$2"
+ shift
+ ;;
+ *)
+ #Unknown
+ helpwindow
+ ;;
+ esac
+ shift
+done
+
+if ! [[ -z ${perf_command+x} ]]; then
+ if ! [[ -z ${period+x} ]]; then
+ if ! [[ -z ${pid+x} ]]; then
+ $perf_command stat --per-thread -e instructions:u -p $pid -I $period
+ elif ! [[ -z ${process_name+x} ]]; then
+ pid=$(pgrep -f $process_name -o)
+ $perf_command stat --per-thread -e instructions:u -p $pid -I $period
+ fi
+ else
+ helpwindow
+ fi
+else
+ helpwindow
+fi
+
+exit $?
+
+
diff --git a/a4mcar/high_level_applications/scripts/tracing/TraceLinuxProcesses.sh b/a4mcar/high_level_applications/scripts/tracing/TraceLinuxProcesses.sh
new file mode 100644
index 0000000..765b118
--- /dev/null
+++ b/a4mcar/high_level_applications/scripts/tracing/TraceLinuxProcesses.sh
@@ -0,0 +1,99 @@
+#!/bin/bash
+# Copyright (c) 2017 FH Dortmund and others
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Description:
+# Linux shell (bash) script that traces linux processes and converts
+# the trace to common tracing format (CTF).
+# perf module should be compiles with libbabeltrace in order to run
+# the tracing utility correctly.
+# Created out directory will contain Processes_List.txt (process IDs
+# are listed), perf.data (trace in perf format), ctf_trace.tar.gz
+# (trace in ctf format)
+# The ctf_format.tar.gz can be extracted in order to visualize the
+# perf streams using Eclipse TraceCompass.
+#
+# Usage:
+# sudo ./TraceLinuxProcesses.sh -p <path/to/perf> -n <trace_name> -t <period_to_trace>
+#
+# Authors:
+# M. Ozcelikors <mozcelikors@gmail.com>, FH Dortmund
+#
+
+helpwindow ()
+{
+ echo "Arguments for TraceLinuxProcesses.sh are:"
+ echo "#################################################"
+ echo "-h or --help : Show these help instructions"
+ echo "-p or --path-to-perf : Progress using Process ID"
+ echo "-n or --name : Trace name to be created"
+ echo "-t or --time : Specify period in seconds to trace"
+ echo "#################################################"
+ echo "Example usage: sudo ./TraceLinuxProcesses.sh -p <path/to/perf> -n <trace_name> -t <period_to_trace>"
+}
+
+if [ "$1" == "" ] || [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
+ helpwindow
+ exit 0
+fi
+
+while [[ $# -gt 1 ]]
+do
+ key="$1"
+ case $key in
+ -p|--path-to-perf)
+ perf_directory="$2"
+ shift
+ ;;
+ -n|--name)
+ trace_name="$2"
+ shift
+ ;;
+ -t|--time)
+ seconds="$2"
+ shift
+ ;;
+ *)
+ #Unknown
+ helpwindow
+ ;;
+ esac
+ shift
+done
+
+if ! [[ -z ${perf_directory+x} ]]; then
+ if ! [[ -z ${trace_name+x} ]]; then
+ if ! [[ -z ${seconds+x} ]]; then
+ echo "### Creating directory.."
+ sudo mkdir out_$trace_name/
+ echo "### Writing out process names.."
+ ps -aux >> out_$trace_name/Processes_List.txt
+ echo "### Tracing with perf for $seconds seconds.."
+ sudo $perf_directory/./perf sched record -o out_$trace_name/perf.data -- sleep $seconds
+ echo "### Converting to data to CTF (Common Tracing Format).."
+ sudo LD_LIBRARY_PATH=/opt/libbabeltrace/lib $perf_directory/./perf data convert -i out_$trace_name/perf.data --to-ctf=./ctf
+ sudo tar -czvf out_$trace_name/trace.tar.gz ctf/
+ sudo rm -rf ctf/
+
+ echo "### Process IDs are written to out_$trace_name/Processes_List.txt"
+ echo "### Trace in Perf format is written to out_$trace_name/perf.data"
+ echo "### Trace in CTF format is written to out_$trace_name/ctf_trace.tar.gz"
+ echo "### Exiting.."
+ else
+ helpwindow
+ fi
+ else
+ helpwindow
+ fi
+else
+ helpwindow
+fi
+
+exit $?
+
+
+
+