Hope everyone is well!
I am looking to obtain time spent in each function via xray, but I’ve been unable to figure out how to get llvm-xray account to work with a multithreaded application. Does account require specific flags or considerations to work with multithreaded programs?
I’m aware that, as per an old mailing list email https://groups.google.com/g/llvm-dev/c/Ysval_fSQRU, that llvm-xray has issues with shared libraries: Could this have potential ramifications with e.g. libpthread.so?
Detailed issue report
I’m getting an error as such:
Error processing record: {type: 0; cpu: 9; record-type: enter; function-id: 2; tsc: 8360522561311619; thread-id: 2796286; process-id: 2796286}}
Thread ID: 2796288
(empty stack)
Thread ID: 2796295
(empty stack)
...
Thread ID: 2796293
(empty stack)
I am compiling with -fxray-instrument -fxray-instruction-threshold=1, and running my instrumented binary with XRAY_OPTIONS="patch_premain=true verbosity=2 xray_mode=xray-basic" (I see no errors from the verbose output). My program looks like the following:
void multithread_task(int thread_id)
{
std::this_thread::sleep_for(std::chrono::milliseconds(100));
std::cout << "Thread id: " << thread_id << "\n";
}
int main()
{
std::vector<std::thread> threads;
for (int i = 0; i < NUM_THREADS; i++)
threads.emplace_back(multithread_task, i);
for (std::thread& th : threads)
th.join();
return 0;
Thanks in advance for your time! My last-ditch attempt would be to attempt computing time elapsed from the tsc values in the xray records, although I’ve yet been able to produce accurate numbers: I honestly have no idea how xray is able to calculate time elapsed while simultaneously removing it’s own time-elapsed from the time reported in llvm-xray account ![]()