0

I'm trying to profile a group of mutually recursive functions. Preferably I'd like to see for each function how much time it takes relative to the other functions. However due to these functions being mutually recursive, regular profiling shows all functions taking up 100% time.

What I'd like my profiling to do is show the inclusive time of each function, without including the time it spends on the recursive calls. So for example A calls both B and C; B calls A again; and C doesn't call anything. For A I'd like to see the % of times when either A is on top of the call stack, or A;C (with C being the top), but not A;B. I guess the profiling should never look beyond any of the mutually recursive functions when looking at the call stack, so call stack XAZ (bottom to top) becomes AZ and XAZB becomes just B.

I guess one solution would be to write each function into a tail recursive form, then put everything except the tail-call into a separate non-recursive function. However this would be a big rewrite and would also effect the performance characteristics of the program, so it's far from ideal.

Ideally there would be a profiler with configuration options to help me out. I'm working in C#. Is there one? Otherwise do you think it might be possible to hack the profile session files to get what I want?

Thanks in advance!

KeyboardDrummer
  • 577
  • 5
  • 21

1 Answers1

0

You want to know the fraction of time that A appears only once on the call stack? Get some call stack samples and select out just those. This is a little unusual. Mostly people want to know what fraction of time A is responsible for (and lines of code within A). i.e. how much time would be saved if A were free? The answer is, it's just the fraction of samples containing A, whether at one level or more than one.

I get stack samples manually because I'm looking for speedups, and precision of timing is not so important. Maybe the profiler will give you access to the raw samples, if you ask nicely.

Community
  • 1
  • 1
Mike Dunlavey
  • 40,059
  • 14
  • 91
  • 135