title: Building Perf with Babeltrace (for Perf to CTF Conversion)
body: <p>I am trying to use TraceCompass in order to further investigate my system trace. For that purpose, you need CTF format and there are two possible ways to obtain it in Linux, afaik:</p>
  
  <ol>
  <li>Using LTTng for tracing and using CTF format from that</li>
  <li>Using 'perf data convert' in order to create CTF data from perf.data</li>
  </ol>
  
  <p>I have been trying to use the second option as the first one requires installation of tracepoints and what I got from perf is simply enough for me.
  So assuming I have my perf.data available,
  Applying</p>
  
  <pre><code>perf data convert --to-ctf=./ctf 
  </code></pre>
  
  <p>resulted in:  <strong>No version support compiled in.</strong>
  Digging into the online resources from lwn, I have found out that this conversion is not available without babeltrace. In order to install babeltrace I have tried following methods:</p>
  
  <p><strong>1st one:</strong></p>
  
  <pre><code>sudo apt-get install libbabeltrace-ctf-dev libbabeltrace-ctf1 libbabeltrace1 libbabeltrace-dev python3-babeltrace
  </code></pre>
  
  <p>which did not quite solve the problem of: <strong>No version support compiled in.</strong></p>
  
  <p><strong>2nd one</strong></p>
  
  <p>I have tried building babeltrace from source. I dug and found all its dependencies beforehand:</p>
  
  <pre><code>sudo apt-get install dh-autoreconf bison libdw-dev libelf-dev flex uuid-dev libpopt-dev
  git clone git://git.efficios.com/babeltrace.git
  cd babeltrace
  ./bootstrap
  sudo ./configure --prefix=/opt/libbabeltrace LDFLAGS=-L/usr/local/lib
  sudo make -j4 prefix=/opt/libbabeltrace
  sudo make install prefix=/opt/libbabeltrace
  </code></pre>
  
  <p>Then tried,</p>
  
  <pre><code>LD_LIBRARY_PATH=/opt/libbabeltrace/lib perf data convert --to-ctf=./ctf
  </code></pre>
  
  <p>Which also resulted in the error: <strong>No version support compiled in.</strong></p>
  
  <p>So, all in all, right now I think that the problem is linking babeltrace with perf. Though I do not know yet how to compile perf with babeltrace support. Should I build everything from kernel modules (given below) or is there a workaround to re-compile or adapt my current perf with babeltrace support?</p>
  
  <p>Please note that perf/core_ctf_convert is implemented in this kernel module: <code>git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git</code></p>
  
  <p>Also note that I am using Raspbian Jessie on a Raspberry Pi 3.</p>
  
  <p>Guidance is appreciated in advance.</p>
  
  <p>Cheers,</p>
  
  <p><strong>References:</strong></p>
  
  <p><a href="https://lwn.net/Articles/634333/" rel="nofollow noreferrer">https://lwn.net/Articles/634333/</a></p>
  
  <p><a href="http://tracingsummit.org/w/images/9/98/TracingSummit2014-Perf-CTF.pdf" rel="nofollow noreferrer">http://tracingsummit.org/w/images/9/98/TracingSummit2014-Perf-CTF.pdf</a></p>
  
  <p><a href="https://patchwork.kernel.org/patch/5883821/" rel="nofollow noreferrer">https://patchwork.kernel.org/patch/5883821/</a></p>
  
  <p><a href="https://patchwork.kernel.org/patch/5858601/" rel="nofollow noreferrer">https://patchwork.kernel.org/patch/5858601/</a></p>
  
  <hr>
  
  <p><strong>EDIT : RESOLVED</strong>
  Okay, this was tricky. First off, all credits go to jolsa from kernel.org who with his suggestions made me figure this out.</p>
  
  <p>After the libbabeltrace is built from source, the following is done:</p>
  
  <p>Some dependencies installed (some might not be needed, these are what I've installed to fulfil most of the tracing features available for Raspbian. Unfortunately bfd is not available, afaik)</p>
  
  <pre><code>sudo apt-get install libnewt-dev binutils-arm-none-eabi libcrypto++-dev libunwind-dev systemtap-sdt-dev libssl-dev libperl-dev libiberty-dev
  </code></pre>
  
  <p>Then,</p>
  
  <pre><code>sudo git clone git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git
  cd linux/tools/perf
  sudo git checkout perf/core
  sudo LIBBABELTRACE=1 LIBBABELTRACE_DIR=/opt/libbabeltrace/ make
  sudo LIBBABELTRACE=1 LIBBABELTRACE_DIR=/opt/libbabeltrace/ make install
  </code></pre>
  
  <p>After the installation is complete, the perf is executed with the LD_LIBRARY_PATH env. i.e.</p>
  
  <p>From the directory where perf.data is located, call the following assuming the newly built perf is located at /home/user/linux/tools/perf:</p>
  
  <pre><code>sudo LD_LIBRARY_PATH=/opt/libbabeltrace/lib ./home/user/linux/tools/perf/perf data convert --to-ctf=./ctf
  </code></pre>
  
  <p>And then, the CTF could be imported to TraceCompass :)</p>
  
  <p><a href="https://i.stack.imgur.com/QjR4b.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QjR4b.png" alt="TraceCompass"></a></p>