Re: LuaJIT 2.1 profiler from C/C++

  • From: Mike Pall <mike-1311@xxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Fri, 15 Nov 2013 14:36:42 +0100

rippel tippel wrote:
> However I don't see any information on how much time has been spent
> inside each function; what's the best way to retrieve this from the C
> API? (I guess it could be worked out from the number of samples and
> the sampling interval, but not sure if it's correct/reliable).

The sampling interval is not relevant. Divide the number of
samples at a certain source code location by the total number of
collected samples, multiply by 100 and you get the CPU percentage
for this location.

> Also, in case the depth is > 1, how is it possible to format the
> output in a tree-like fashion, or print levels? It looks like I can
> only append symbols at the end of luaJIT_profile_dumpstack's output
> string.

Well, lines _are_ levels. You can easily post-process the string
into any format if it has a unique separator (e.g. '\n').

But the string must be used as a hash key during sampling to
gather sample counts for the same location. It would be wise to
keep it short. Do any formatting only for the final output after
the run, not during sampling.

--Mike

Other related posts: