2 Replies Latest reply: Dec 17, 2009 12:23 PM by 807559 RSS

    Tracing recursive user functions

    807559
      When tracing user functions, how are recursive functions handled. For example, the following code processes the time spent within user dynamic modules. The modules have user created dynamic libraries : MyLib1.so, MyLib2.so, ... I would also like to know if there is someting already in the dtrace toolkit that I can use.
      pid$target:*.so::entry
      {
          self->ts[probemod, probefunc] = timestamp;
      }
      
      pid$target:*.so::return
      /self->ts[probemod, probefunc]/
      {
          @funct_time[probemod, probefunc] = sum(timestamp - self->ts[probemod, probefunc];
          self->ts[probemod, probefunc] = 0;
      As can be seen, if recursive code is used, the self->ts gets reset to timestamp with every entry, and the innermost exit causes a time to be calculated and the ts to be reset. The rest of the returns within the recursion will be ignored because of the conditional.

      I would like to know if someone has already done this before I try to reinvent the wheellor if there is a tool in the dtrace toolkit to do this already.
        • 1. Re: Tracing recursive user functions
          807559
          The well-known method is to use the built-in ustackdepth as a tracker against multiple calls on a function by the same thread.

          The usual issue with profiling recursion, as I understand it, is whether you want the total time a recursion takes, or you want the unit time of each call. In the former case, you might get a kachina-doll effect of longer call times on one function that includes the timing of N subsequent calls to itself. In the latter case, you lose sight of the nesting, which could be a valuable context, given the right case.

          Are you trying to achieve one or both goals?

          Regards,

          Michael
          • 2. Re: Tracing recursive user functions
            807559
            I would want to be able to do both. I suppose that initially, it would be good to see how much recursion is actually taking place and where the main delays are found.