4

I'm trying to use gprof in WSL on Windows 10. I hadn't anticipated any difficulty, because it worked fine last time I used it in an Ubuntu virtual box on Windows 7. Following as before the directives from https://www.thegeekstuff.com/2012/08/gprof-tutorial/ I did the following:

g++ -funsigned-char -pg -oayane -std=c++11 *.cc -lgmp
./ayane eqv10.p
gprof ayane gmon.out >report.txt

All of which went apparently without a hitch. The report reads as follows:

Flat profile:

Each sample counts as 0.01 seconds.
 no time accumulated

  %   cumulative   self              self     total           
 time   seconds   seconds    calls  Ts/call  Ts/call  name    
  0.00      0.00     0.00 1376487464     0.00     0.00  typeof(long)
  0.00      0.00     0.00 990300741     0.00     0.00  symp(long)
  0.00      0.00     0.00 889924507     0.00     0.00  std::remove_reference<long&>::type&& std::move<long&>(long&)
  0.00      0.00     0.00 854305643     0.00     0.00  basic(long)
  0.00      0.00     0.00 561627773     0.00     0.00  unify(long, long)
  0.00      0.00     0.00 561627773     0.00     0.00  unify1(long, long)

etc. So it's not like nothing is happening; it's recording lots of function calls, the statistics for which look plausibly correct. The program ran for some tens of seconds, so it's not like it didn't run for long enough. But all the recorded times are zero.

Is there a known problem, or am I doing something wrong?

gprof version:

(base) a@DESKTOP-4B7M920:/mnt/c/ayane$ gprof --version
GNU gprof (GNU Binutils for Ubuntu) 2.30
rwallace
  • 31,405
  • 40
  • 123
  • 242
  • 1
    Just a guess, but... are you using WSL2? WSL1 functions by implementing its own system call translation layer to windows. WSL2 runs as a full-on virtual machine. If you're not using WSL2, then you might try upgrading to see if that fixes it. also, here's another thread on the same problem with other suggestions. https://stackoverflow.com/questions/1030829/gprof-reports-no-time-accumulated – Nicholas Rees Feb 16 '21 at 16:00
  • @NicholasRees `uname -r` says 4.4.0, which a quick Google search says means WSL2. That other post does indeed seem to be the same problem, though the answer seems to be 'yeah gprof is broken on Mac, use Shark instead'; the link to Shark is broken, but I get the impression it is a Mac-specific profiler. – rwallace Feb 16 '21 at 16:07
  • 1
    try wsl -l -v from a command prompt (not from within wsl). My wsl v1 running ubuntu also reports 4.4.0, so I don't think uname will accurately tell you what version of wsl you are running. – Nicholas Rees Feb 16 '21 at 16:17
  • 2
    My WSL1 instances are "4.4.0-19041-Microsoft". WSL2 should be "4.19.104-microsoft-standard". – NotTheDr01ds Feb 16 '21 at 16:20
  • @NicholasRees aha! wsl -l -v says version 1. – rwallace Feb 16 '21 at 16:41
  • 1
    WSL 1 doesn't support `setitimer(ITIMER_PROF, ...)`, so sampling profiling won't work. The `mcount` profiling still works. – Mark Plotnick Feb 16 '21 at 18:07
  • 4
    Dug around a little.. WSL 2 supports profiling on build 19013 or later, or it can be made to support profiling if you build the Linux kernel from source - it just requires a change to a build option. https://github.com/golang/go/issues/22366#issuecomment-535954388 . – Mark Plotnick Feb 16 '21 at 19:21
  • @markplotnick nice! Good research. – Nicholas Rees Feb 16 '21 at 19:59

0 Answers0