Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Mar 20th, 2008 | Syntax: Ruby | Size: 1.29 KB | Hits: 214 | Expires: Never
Copy text to clipboard
  1. #!/usr/bin/env ruby
  2. # Script for checking whether pages are made dirty after a garbage collection.
  3.  
  4. def load_rails
  5.         require 'rubygems'
  6.         gem 'rails'
  7.         require 'initializer'
  8.         require 'active_support'
  9.         require 'action_controller'
  10.         require 'action_view'
  11.         require 'active_record'
  12.         puts "Loaded Ruby on Rails version #{Rails::VERSION::STRING}"
  13. end
  14.  
  15. def print_statistics
  16.         if ObjectSpace.respond_to?(:statistics)
  17.                 puts "========================================================="
  18.                 puts "--------------- Before garbage collection ---------------"
  19.                 puts ObjectSpace.statistics
  20.         end
  21.         ObjectSpace.garbage_collect
  22.         if ObjectSpace.respond_to?(:statistics)
  23.                 puts "--------------- After garbage collection ----------------"
  24.                 puts ObjectSpace.statistics
  25.                 puts "========================================================="
  26.         end
  27. end
  28.  
  29. def start
  30.         if GC.respond_to?(:copy_on_write_friendly=)
  31.                 GC.copy_on_write_friendly = true
  32.         end
  33.         load_rails
  34.         ObjectSpace.garbage_collect
  35.        
  36.         pid = fork do
  37.                 pid = fork do
  38.                         puts "Child process #{$$} created. Press Enter to start garbage collection."
  39.                         STDIN.readline
  40.                        
  41.                         print_statistics
  42.                         puts "Garbage collection finished. Press Enter to exit."
  43.                         STDIN.readline
  44.                         exit!
  45.                 end
  46.                 Process.waitpid(pid)
  47.                 exit!
  48.         end
  49.         Process.waitpid(pid)
  50. end
  51.  
  52. start