Skip to content

Commit

Permalink
Preserve ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy committed May 13, 2009
1 parent 4c96397 commit e9c5750
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions tools/profile_requires.rb → tools/profile_requires
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ class << self
self.stats = []

def track_growth(file)
TrackHeapGrowth.stats << [file, TrackHeapGrowth.indent]
TrackHeapGrowth.indent += 1
heap_before, objects_before = GC.allocated_size, ObjectSpace.allocated_objects
result = nil
elapsed = Benchmark.realtime { result = yield }
heap_after, objects_after = GC.allocated_size, ObjectSpace.allocated_objects
TrackHeapGrowth.indent -= 1
TrackHeapGrowth.stats.pop if TrackHeapGrowth.stats.last.first == file
TrackHeapGrowth.stats << [file, TrackHeapGrowth.indent, elapsed, heap_after - heap_before, objects_after - objects_before] if result
result
end
Expand Down Expand Up @@ -69,7 +71,11 @@ def load(file, *args)
end
end

TrackHeapGrowth.stats.reverse_each do |file, indent, sec, bytes, objects|
puts "%10.2f KB %10d obj %8.1f ms %s%s" % [bytes / 1024.0, objects, sec * 1000, ' ' * indent, file]
TrackHeapGrowth.stats.each do |file, indent, sec, bytes, objects|
if sec
puts "%10.2f KB %10d obj %8.1f ms %s%s" % [bytes / 1024.0, objects, sec * 1000, ' ' * indent, file]
else
puts "#{' ' * (42 + indent)}#{file}"
end
end
puts "%10.2f KB %10d obj %8.1f ms %d KB RSS" % [usage, after_live_objects - before_live_objects, elapsed * 1000, after_rss - before_rss]

0 comments on commit e9c5750

Please sign in to comment.