Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use nimprof?

In one of my Nim projects I'm having performance issues. I'm now trying to use nimprof to see what's going on. I have an import nimprof in my main source file, and I'm compiling with --profiler:on. When I run the program I can see the messages:

writing profile_results.txt...
... done

However, profile_results.txt only contains this:

total executions of each stack trace:
Entry: 1/1 Calls: 2741/2741 = 1.0e+02% [sum: 2741; 2741/2741 = 1.0e+02%]

The run time was about 1 minute -- so I don't think it is just not enough time to sample anything. Is there any way to get something more meaningful out of nimprof?

like image 877
bluenote10 Avatar asked Oct 30 '25 08:10

bluenote10


2 Answers

You need to add the compiler flag --stackTrace:on, or there won't be any function names or line numbers to analyze.

like image 111
ratiotile Avatar answered Oct 31 '25 21:10

ratiotile


1.0e+02% is just a silly way to say 100%. It says it took a lot of stack samples and they were all the same, which is not surprising.

What you need is to actually see the sample. It should appear below the line above. It will show you what the problem is.

Just as an aside, it should show line numbers as well as function names, and it shouldn't just sort the stacks by frequency. The reason is there could easily be a guilty line of code that is on a large fraction of stacks, even though the stacks are otherwise different, so if the stacks are sorted, that line will not be aggregated.

like image 32
Mike Dunlavey Avatar answered Oct 31 '25 20:10

Mike Dunlavey