Created
July 17, 2010 21:54
-
-
Save headius/479875 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# object_walker.rb | |
require 'java' | |
require 'jruby/util' | |
module ObjectWalker | |
import com.sun.jdi.Bootstrap | |
# Generate a histogram of all classes in the system | |
def self.histogram | |
classes = VM.all_classes | |
counts = VM.instance_counts(classes) | |
classes.zip(counts) | |
end | |
# Initialize the singleton VirtualMachine reference | |
def self.init_vm | |
raise "Already initialize" if defined? VM | |
vmm = Bootstrap.virtual_machine_manager | |
sock_conn = vmm.attaching_connectors[0] # not guaranteed to be Socket | |
args = sock_conn.default_arguments | |
args['port'].value = "12345" | |
vm = sock_conn.attach(args) | |
end | |
VM ||= init_vm | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'object_walker' | |
histo = ObjectWalker.histogram | |
histo.sort! {|a,b| b[1] <=> a[1]} | |
histo.each do |cls,num| | |
if num == 0 || cls.name[0..4] != 'ruby.' || cls.name[5..7] == 'jit' | |
next | |
end | |
puts "#{num} instances of #{cls}" | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
~/projects/jruby ➔ jruby object_walker_test.rb | |
11685 instances of class ruby.TZInfo.TimezoneTransitionInfo (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5790)) | |
1040 instances of class ruby.Gem.Version (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5791)) | |
1007 instances of class ruby.Gem.Version (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5792)) | |
984 instances of class ruby.Gem.Requirement (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5793)) | |
951 instances of class ruby.Gem.Requirement (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5794)) | |
592 instances of class ruby.TZInfo.TimezoneOffsetInfo (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5795)) | |
428 instances of class ruby.Gem.Dependency (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5796)) | |
411 instances of class ruby.Gem.Dependency (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5797)) | |
277 instances of class ruby.Gem.Specification (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5798)) | |
269 instances of class ruby.Gem.Specification (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5799)) | |
142 instances of class ruby.ActiveSupport.TimeZone (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5800)) | |
118 instances of class ruby.TZInfo.DataTimezoneInfo (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5801)) | |
118 instances of class ruby.TZInfo.DataTimezone (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5802)) | |
41 instances of class ruby.Gem.Platform (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5803)) | |
41 instances of class ruby.Gem.Platform (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5804)) | |
14 instances of class ruby.Mime.Type (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5805)) | |
12 instances of class ruby.Set (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5806)) | |
8 instances of class ruby.ActionController.MiddlewareStack.Middleware (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5807)) | |
8 instances of class ruby.ActionView.Template (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5808)) | |
7 instances of class ruby.ActionController.Routing.DividerSegment (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5809)) | |
6 instances of class ruby.TZInfo.LinkedTimezone (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5802)) | |
6 instances of class ruby.TZInfo.LinkedTimezoneInfo (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5801)) | |
4 instances of class ruby.ActionController.Routing.DynamicSegment (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5809)) | |
2 instances of class ruby.Gem.SourceIndex (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5810)) | |
2 instances of class ruby.ActiveSupport.Deprecation.DeprecatedConstantProxy (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5811)) | |
2 instances of class ruby.ActiveSupport.Callbacks.Callback (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5812)) | |
2 instances of class ruby.ActionView.Template.EagerPath (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5813)) | |
2 instances of class ruby.ActionController.Routing.Route (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5814)) | |
2 instances of class ruby.ActionController.Routing.ControllerSegment (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5809)) | |
2 instances of class ruby.OptionParser.Switch.NoArgument (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5815)) | |
2 instances of class ruby.OptionParser.Switch.NoArgument (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5816)) | |
1 instances of class ruby.ActionController.Dispatcher (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5817)) | |
1 instances of class ruby.ActionController.Failsafe (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5818)) | |
1 instances of class ruby.ActionController.Filters.BeforeFilter (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5812)) | |
1 instances of class ruby.ActionController.ParamsParser (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5819)) | |
1 instances of class ruby.ActionController.Routing.OptionalFormatSegment (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5809)) | |
1 instances of class ruby.ActionController.Routing.RouteBuilder (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5820)) | |
1 instances of class ruby.ActionController.Routing.RouteSet (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5821)) | |
1 instances of class ruby.ActionController.Routing.RouteSet.NamedRouteCollection (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5822)) | |
1 instances of class ruby.ActionController.Session.CookieStore (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5823)) | |
1 instances of class ruby.ActionController.StringCoercion (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5824)) | |
1 instances of class ruby.ActiveSupport.BufferedLogger (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5825)) | |
1 instances of class ruby.ActiveSupport.Cache.MemoryStore (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5826)) | |
1 instances of class ruby.ActiveSupport.Inflector.Inflections (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5827)) | |
1 instances of class ruby.ActiveSupport.MessageVerifier (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5828)) | |
1 instances of class ruby.ActiveSupport.Multibyte.Codepoint (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5829)) | |
1 instances of class ruby.ActiveSupport.Multibyte.UnicodeDatabase (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5830)) | |
1 instances of class ruby.ERB (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5831)) | |
1 instances of class ruby.Gem.CommandManager (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5832)) | |
1 instances of class ruby.Gem.CommandManager (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5833)) | |
1 instances of class ruby.Gem.ConfigFile (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5834)) | |
1 instances of class ruby.Gem.ConfigFile (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5835)) | |
1 instances of class ruby.Gem.GemPathSearcher (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5836)) | |
1 instances of class ruby.Gem.GemPathSearcher (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5837)) | |
1 instances of class ruby.Gem.SourceIndex (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5838)) | |
1 instances of class ruby.I18n.Backend.Simple (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5839)) | |
1 instances of class ruby.I18n.Config (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5840)) | |
1 instances of class ruby.JRuby.Rack.Booter (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5841)) | |
1 instances of class ruby.JRuby.Rack.Errors (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5842)) | |
1 instances of class ruby.JRuby.Rack.RailsBooter (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5843)) | |
1 instances of class ruby.JRuby.Rack.RailsRequestSetup (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5844)) | |
1 instances of class ruby.JRuby.Rack.RailsWebInfLayout (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5845)) | |
1 instances of class ruby.JRuby.Rack.ServletLog (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5846)) | |
1 instances of class ruby.JRuby.Rack.WebInfLayout (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5847)) | |
1 instances of class ruby.OptionParser.List (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5848)) | |
1 instances of class ruby.OptionParser.List (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5849)) | |
1 instances of class ruby.Rack.Adapter.Rails (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5850)) | |
1 instances of class ruby.Rack.Builder (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5851)) | |
1 instances of class ruby.Rack.File (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5852)) | |
1 instances of class ruby.Rack.File (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5853)) | |
1 instances of class ruby.Rack.Handler.Servlet (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5854)) | |
1 instances of class ruby.Rack.Handler.Servlet (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5855)) | |
1 instances of class ruby.Rack.Head (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5856)) | |
1 instances of class ruby.Rack.MethodOverride (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5857)) | |
1 instances of class ruby.Rack.ShowStatus (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5858)) | |
1 instances of class ruby.Rails.Configuration (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5859)) | |
1 instances of class ruby.Rails.VendorGemSourceIndex (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5860)) | |
1 instances of class ruby.Set (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5861)) | |
1 instances of class ruby.Trinidad.RailsWebApp (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5862)) | |
1 instances of class ruby.Trinidad.Server (loaded by instance of org.jruby.util.ClassCache$OneShotClassLoader(id=5863)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment