From: SASADA Koichi Date: 2012-11-27T17:23:10+09:00 Subject: [ruby-core:50208] Re: [ruby-trunk - Feature #7434] Allow caller_locations and backtrace_locations to receive negative params (2012/11/27 15:52), sam.saffron (Sam Saffron) wrote: > Issue #7434 has been updated by sam.saffron (Sam Saffron). > > >> My question is: use-case of negative number for performance. Your answer only shows "backtrace is big". > > Apologies, well for MiniProfiler ( https://github.com/SamSaffron/MiniProfiler/tree/master/Ruby ) we gather stack traces quite aggressively, every time a query is execute a backtrace is materialized. > > A classic place of where I would like to cut down on backtrace overhead is the sampling profiler see: https://github.com/SamSaffron/MiniProfiler/blob/master/Ruby/lib/mini_profiler/profiler.rb#L289 I think you need to grab all of stack each time. I'm not sure the negative number is good for this reason. > Another use case would be a user option for :application_trace_only, that would figure out how many frames to skip in the first SQL interception and store that on the Thread so following calls to grab stack traces only include the "application" section and the framework stuff is not gathered. You need to grab all of stack trace to check which is skipped frame or not. Please correct my if my understanding is wrong. I also am not sure why negative number is needed for this purpose. ---- Ah, I understand your purpose. I can't understand how to use negative number. But I understand now. [top of stack frame] caller foo4 foo3 foo2 foo1 f/w3 # f/w = framework f/w2 f/w1 main [bottom of stack frame] In this case, framework consumes 3 frames and you only want to know stack frame only "all of frame size - framework frame size (=3)". I missed the point that framework knows how many frames consumed (in this case: 3). 2nd argument is "how many frames from top". So your suggestion. (2nd argument) `n' means: if n > 0 how many frames from top of frame elsif n <= 0 how many frames should *eliminate* from bottom of frame end I feel it makes sense. The last point is API design. "negative number" to this purpose is feasible? Any other example for other methods? -- // SASADA Koichi at atdot dot net