[X-ray] How to check successful instrumentation and generate call trace?

Hi all,

I want to test X-ray performance and compare it with other research tools, so I use Clang 7.0.0 to compile and instrument GNU binutils-2.3.1 with the following commands:

cd binutils-2.31/
mkdir build
cd build/
CC=$local/clang CXX=$local/clang++ CFLAGS=-fxray-instrument CXXFLAGS=-fxray-instrument …/configure --prefix=/home/zhangysh1995/local
make

Then I extract instrumentation map with llvm-xray extract addr2line and it returns:

Hi all,

I want to test X-ray performance and compare it with other research tools, so I use Clang 7.0.0 to compile and instrument GNU binutils-2.3.1 with the following commands:

cd binutils-2.31/
mkdir build
cd build/
CC=$local/clang CXX=$local/clang++ CFLAGS=-fxray-instrument CXXFLAGS=-fxray-instrument ../configure --prefix=/home/zhangysh1995/local
make

Then I extract instrumentation map with llvm-xray extract addr2line and it returns:
---
- { id: 1, address: 0x000000000041CD70, function: 0x000000000041CD70, kind: function-enter, always-instrument: false, function-name: '' }
- { id: 1, address: 0x000000000041D026, function: 0x000000000041CD70, kind: function-exit, always-instrument: false, function-name: '' }
- { id: 2, address: 0x000000000041D4F0, function: 0x000000000041D4F0, kind: function-enter, always-instrument: false, function-name: '' }
- { id: 2, address: 0x000000000041DAFA, function: 0x000000000041D4F0, kind: function-exit, always-instrument: false, function-name: '' }
- { id: 3, address: 0x000000000041E570, function: 0x000000000041E570, kind: function-enter, always-in
......
......

Does the map mean that no function is instrumented? Should I change my commands?

This means that the generated binary already has the instrumentation map. It looks like you also already have the function addresses, which if the binary is not stripped of symbols must have the function names. If you add the `-symbolize` flag to the invocation of `llvm-xray extract` then that should get the function names.

BTW, after instrumentation could I run the binary and get trace directly?

You should be able to enable tracing of instrumented binaries using an environment variables.

Here is the link to current documentation: https://llvm.org/docs/XRay.html

In that documentation, it shows the table of options you can set in the XRAY_OPTIONS environment variable:

http://llvm.org/docs/XRay.html#xray-runtime-library

In the example at:

http://llvm.org/docs/XRayExample.html

You can set:

XRAY_OPTIONS="patch_premain=true:xray_mode=xray-basic:verbosity=1”

To get traces.

Cheers

-- Dean

Hi Dean,

Thanks for your last reply.

I compiled “tmux” with CC=clang CXX=clang++ CXXFLAGS=-fxray-instrument CFLAGS=-fxray-instrument, and it succeeded.

I installed the binary with make install to a local folder, and run it with XRAY_OPTIONS=“patch_premain=true:xray_mode=xray-basic:verbosity=1” tmux’.

But after it exited normally, I have no trace generated or any error. And I also used llvm extract -symbolize to make sure the binary is instrumented.

What is the cause for it? Does it depend on functions called during the execution?

What environment variables I should use to guarantee there is always a trace log?

Thank you,
Yushan

Hi Dean,

Thanks for your last reply.

I compiled "tmux" with `CC=clang CXX=clang++ CXXFLAGS=-fxray-instrument CFLAGS=-fxray-instrument`, and it succeeded.

I installed the binary with `make install` to a local folder, and run it with XRAY_OPTIONS="patch_premain=true:xray_mode=xray-basic:verbosity=1" tmux'.

But after it exited normally, I have no trace generated or any error. And I also used `llvm extract -symbolize` to make sure the binary is instrumented.

What is the cause for it? Does it depend on functions called during the execution?

What environment variables I should use to guarantee there is always a trace log?

You already have the right environment variable configured (XRAY_OPTIONS) but I think what’s missing is the runtime library. You should use clang to link as well, adding the ‘-fxray-instrument’ flag to the linker options you pass with clang.

http://llvm.org/docs/XRayExample.html#building-with-xray

"Note that we need to link with Clang as well to get the XRay runtime linked in appropriately.”

Thank you,

No worries, I hope this helps!

Cheers

-- Dean