I am trying to set up LLVM Xray with my codebase. My goal is to instrument just a few functions, to be minimally intrusive. But I am failing to even get the basic example to work.
For this question I wrote a small test
// test.cpp
[[gnu::noinline]] int doit() {
return 0;
}
int main() {
for ( int j=0; j<100000000; ++j ) {
doit();
}
}
Then I compile and run the above example using clang 14.0.6
$ clang++ -O3 test.cpp -fxray-instrument -fxray-instruction-threshold=1 -o test
$ ls -1
attr.txt
test.cpp
test
According to the documentation, I have to run with environment variables set up
$ XRAY_OPTIONS="patch_premain=true xray_mode=xray-basic verbosity=3" ./test
==219673==XRay: Log file in 'xray-log.test.ym8oWP'
==219673==Skipping buffer for TID: 219673; Offset = 0
==219673==Cleaned up log for TID: 219673
The trace file seems generated ok
$ ls -1
attr.txt
test
test.cpp
xray-log.test.ym8oWP
But when I try to look into the trace file, I get the following error
$ llvm-xray account --instr_map=./test xray-log.test.ym8oWP
llvm-xray: Failed loading input file 'xray-log.test.ym8oWP'
Unsupported version for Basic/Naive Mode logging: 768
I tried changing several parameters but nothing works.
When I look into the binary, everything seems ok
$ llvm-xray extract ./test
---
- { id: 1, address: 0x420ED0, function: 0x420ED0, kind: function-enter, always-instrument: false, function-name: '', version: 2 }
- { id: 1, address: 0x420EFC, function: 0x420ED0, kind: function-exit, always-instrument: false, function-name: '', version: 2 }
- { id: 1, address: 0x420F6E, function: 0x420ED0, kind: function-exit, always-instrument: false, function-name: '', version: 2 }
- { id: 2, address: 0x420F80, function: 0x420F80, kind: function-enter, always-instrument: false, function-name: '', version: 2 }
- { id: 2, address: 0x420FB4, function: 0x420F80, kind: function-exit, always-instrument: false, function-name: '', version: 2 }
...
The trace file has 0x0300 as the version number while the source code states that the enumeration is either 0x01 (basic) or 0x02 (fdr).
$ hexdump -C ./xray-log.test.d0IxRD
00000000 03 00 00 00 ff 00 00 00 68 4e 9d 1e 01 00 00 00 |........hN......|
00000010 90 38 c3 37 fe 7f 00 00 00 20 00 00 00 00 00 00 |.8.7..... ......|
00000020
The sources for that compiler version show that the headers should look like one of the following
// 0x01 0x00 0x00 0x00 - version 1, "naive" format
// 0x01 0x00 0x01 0x00 - version 1, "flight data recorder" format
// 0x02 0x00 0x01 0x00 - version 2, "flight data recorder" format
Any ideas?
UPDATE: Filed issue on LLVM Project https://github.com/llvm/llvm-project/issues/57657