From: Robert Klemme Date: 2012-07-03T16:02:00+09:00 Subject: Re: Using binding + set trace func to capture execution state On Tue, Jul 3, 2012 at 8:05 AM, Reginald Tan wrote: > > > > > To achieve your goal you'd need to copy the state of variables at each > > tracefunc invocation. Even worse, as the objects themselves may change, > > you will need to do a deep copy each time (otherwise you'll pluck into > > exactly the same problem with object instance variables). I would > > suggest > > marshalling the objects and writing them to something like tmpfs, then > > using a special tool to navigate the captured information. > > > > This is going to consume a lot of memory. I repeat: a lot. Like tens > > of gigabytes for a complex thing like... Sinatra. And probably > > terabytes > > for Rails. > > Hmm, you're right, it would not be efficient at all to store all those > variables especially in a large program. Especially since you would have to store the complete graph of objects reachable from every scope because the change might be in an object referenced through some intermediate objects. > I guess another possible approach is to rerun the program every time i > want to inspect a variable. Since I know which file and line the > variable is, I can use that as a condition on set_trace_func handler on > when to output that variable. What about debug output? You can make that pretty efficient: if ENV["DEBUG"] def debug; $stderr.puts(yield) end else def debug; end end debug { sleep 1; "Complex operation" } Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/