blob: 5a1275c8809cc8c3b75b3a6eed768679d5896982 [file] [log] [blame]
Mustafa Ozcelikors33e6aa72017-06-01 11:08:08 +02001#!/bin/bash
2# Copyright (c) 2017 FH Dortmund and others
3# All rights reserved. This program and the accompanying materials
4# are made available under the terms of the Eclipse Public License v1.0
5# which accompanies this distribution, and is available at
6# http://www.eclipse.org/legal/epl-v10.html
7#
8# Description:
9# Linux shell (bash) script that traces linux processes and converts
10# the trace to common tracing format (CTF).
11# perf module should be compiles with libbabeltrace in order to run
12# the tracing utility correctly.
13# Created out directory will contain Processes_List.txt (process IDs
14# are listed), perf.data (trace in perf format), ctf_trace.tar.gz
15# (trace in ctf format)
16# The ctf_format.tar.gz can be extracted in order to visualize the
17# perf streams using Eclipse TraceCompass.
18#
19# Usage:
20# sudo TraceLinuxProcesses.sh <trace_name> <period> <path_to_perf>
21# e.g. sudo TraceLinuxProcesses.sh APP4MC_Trace 15 /home/pi/linux/tools/perf
22# <trace_name>: Trace name for the output
23# <period>: Amount of time in seconds to trace the system
24# <path_to_perf>: Installed perf directory that contains ./perf
25#
26# Authors:
27# M. Ozcelikors <mozcelikors@gmail.com>, FH Dortmund
28#
29
30args=("$@")
31trace_name=${args[0]}
32seconds=${args[1]}
33perf_directory=${args[2]}
34
35if [ "$#" -ne 3 ]; then
36 echo "Entered arguments seem to be incorrect"
37 echo "Right usage: sudo TraceLinuxProcesses.sh <trace_name> <period> <path_to_perf>"
38 echo "e.g. sudo TraceLinuxProcesses.sh APP4MC_Trace 15 /home/pi/linux/tools/perf"
39else
40 echo "### Creating directory.."
41 sudo mkdir out_$trace_name/
42 echo "### Writing out process names.."
43 ps -aux >> out_$trace_name/Processes_List.txt
44 echo "### Tracing with perf for $seconds seconds.."
45 sudo $perf_directory/./perf sched record -o out_$trace_name/perf.data -- sleep $seconds
46 echo "### Converting to data to CTF (Common Tracing Format).."
47 sudo LD_LIBRARY_PATH=/opt/libbabeltrace/lib $perf_directory/./perf data convert -i out_$trace_name/perf.data --to-ctf=./ctf
48 sudo tar -czvf out_$trace_name/trace.tar.gz ctf/
49 sudo rm -rf ctf/
50
51 echo "### Process IDs are written to out_$trace_name/Processes_List.txt"
52 echo "### Trace in Perf format is written to out_$trace_name/perf.data"
53 echo "### Trace in CTF format is written to out_$trace_name/ctf_trace.tar.gz"
54 echo "### Exiting.."
55fi
56
57
58
59
60