Permalink
Browse files

Preserve ordering

  • Loading branch information...
1 parent 4c96397 commit e9c5750bd1bb15b2d551ee014f06bd5019f2357d @jeremy jeremy committed May 13, 2009
Showing with 8 additions and 2 deletions.
  1. +8 −2 tools/{profile_requires.rb → profile_requires}
View
@@ -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
@@ -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.