0

I'm trying to profile a C++ shared library on Windows 10, in order to find which lines the program is spending most time on. (The code happens to form part of an R package.)

I've previously used AMD µprof and Very Sleepy. However, I'm now having trouble compiling the code: all these profilers show is which DLL is being used, rather than which function / line.

I suspect that the problem relates to debugging symbol tables being missing. Per Enabling debug symbols in shared library using GCC, I've ensured that a -g flag is applied when compiling each file, and that there is no -s flag at the linker stage. What else do I need to do to allow µprof / Very Sleepy to tell me which lines of the code are proving a bottleneck?

Detailed compilation notes

I'm using RBuildTools MinGW-w64 v3 g++ 8.3.0 to compile the code on 64-bit Windows 10.

Here are some sample compile commands, which are being generated by R, using Makevars / Makeconf templates.

g++  -std=gnu++14 -I"<<include paths>>" -DNDEBUG -g -O2 -Wall  
     -mfpmath=sse -msse2 -mstackrealign
     -c source_file.cpp -o source_file.o

g++ -shared -static-libgcc -g -Og 
    -o PackageName.dll tmp.def source_file.o <<Other files>>
    -L<<Library paths>>

I've also tried replacing -g with -gdwarf-2 -g3, and adding -fno-omit-frame-pointer, per Very Sleepy doesn't see function names when capturing MinGW compiled file.

Running without shared library

ssbssa suggested running against a simple executable.

I tried:

#include <chrono>
#include <thread>
#include <iostream>

long sumto(long n) {
  if(n > 0)   {
    std::this_thread::sleep_for(std::chrono::milliseconds(1));
    return n + sumto(n - 1);
  }
  return 1;
}

int main() {
  std::cout << sumto(1000) << std::endl;
  return 0;
}
>"C:/RBuildTools/4.0/mingw64/bin/"g++ -std=gnu++14 -gdwarf-2 -g3 -Og -c test.cpp

>"C:/RBuildTools/4.0/mingw64/bin/"g++ -std=gnu++14 -gdwarf-2 -g3 -Og -o test test.o

test.exe runs as expected. When I profile test.exe, AMD µprof states "The raw file has no data!", whereas VerySleepy does detect activity in sumto and displays the associated source code.

Martin Smith
  • 3,687
  • 1
  • 24
  • 51

0 Answers0