Created
April 10, 2014 13:22
-
-
Save bjjb/10381667 to your computer and use it in GitHub Desktop.
Object profiing, can be enabled/disabled with `kill -27 <pid>` (Ruby 2.1.1 version)
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
| begin | |
| require 'objspace' | |
| trap("PROF") do | |
| if $__PROFILING__ | |
| GC.start | |
| filename = Time.now.strftime("objects-%Y%m%d%H%S.json") | |
| ObjectSpace.dump_all(output: File.open(filename,'w')) | |
| ObjectSpace.trace_object_allocations_stop | |
| $__PROFILING__ = false | |
| puts "STOPPED OBJECT TRACE => #{filename}" | |
| else | |
| ObjectSpace.trace_object_allocations_start | |
| $__PROFILING__ = true | |
| puts "STARTED OBJECT TRACE" | |
| end | |
| end | |
| rescue LoadError | |
| puts "Profiling not started, since we're on #{RUBY_VERSION} (< 2.1)" | |
| end |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's the Ruby 2.0 version