On Mon, 2 Jul 2001, Robert Feldt wrote:
> Sometimes when profiling I find myself wanting to know how much time is
> spent in GC. I couldn't find a way to do it in pure Ruby so below you'll
> find a patch for adding a GC.time_spent method. It returns the amount of
> user time the process has spent in GC. This script shows the method in
> (artificial) use:



I think this is good. At some point I had added a counter for the number
of currently used cells, total number of cells, total number of objects
ever allocated, ... I think it would be nice to have that available from
Ruby and also your "time spent in gc" and also "number of full gc's done
yet" (don't know how that last one maps to Ruby 1.8 ...)

> 2. set_gc_trace_func
>     Pro: * Faster than above
>          * Can subtract time when profiling
>     Con: * Can't add separate trace funcs for each new event

have a callback GC.finished(start_time,end_time) that you'd just define
like this:

$gc_last_time=0
$gc_total_time=0
$gc_count=0

def GC.finished(start_time,end_time)
	$gc_last_time = end_time - start_time
	$gc_total_time += $gc_last_time
	$gc_count += 1
end



matju