Last active
September 25, 2015 05:27
-
-
Save tmm1/870398 to your computer and use it in GitHub Desktop.
google-perftools' heap profiler: http://google-perftools.googlecode.com/svn/trunk/doc/heapprofile.html
This file contains 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
module CpuProf | |
require 'ffi' | |
extend FFI::Library | |
ffi_lib FFI::CURRENT_PROCESS | |
begin | |
attach_function :start, :ProfilerStart, [:string], :void | |
attach_function :stop, :ProfilerStop, [], :void | |
rescue FFI::NotFoundError => e | |
STDERR.puts "*** Are you sure you preloaded libprofiler?" | |
STDERR.puts "*** {DYLD_INSERT_LIBRARIES,LD_PRELOAD}=/path/to/lib/libprofiler.so ruby file.rb" | |
STDERR.puts e.inspect | |
exit!(1) | |
end | |
end |
This file contains 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
# Simple memory profiler using google-perftools' tcmalloc. | |
# | |
# Usage: | |
# HeapProf.start("myapp") | |
# 100.times{ "a"*1000 } | |
# HeapProf.dump("checkpoint") | |
# HeapProf.stop | |
# | |
# Reporting: | |
# pprof `which ruby` myapp.0001.heap --gif > myapp.gif | |
# | |
# Advanced (memory growth between two checkpoints): | |
# pprof `which ruby` --base=myapp.0001.heap myapp.0002.heap --gif > myapp.gif | |
# | |
module HeapProf | |
require 'ffi' | |
extend FFI::Library | |
ffi_lib FFI::CURRENT_PROCESS | |
begin | |
attach_function :start, :HeapProfilerStart, [:string], :void | |
attach_function :dump, :HeapProfilerDump, [:string], :void | |
attach_function :stop, :HeapProfilerStop, [], :void | |
rescue FFI::NotFoundError | |
STDERR.puts "*** Are you sure you preloaded libtcmalloc?" | |
STDERR.puts "*** {DYLD_INSERT_LIBRARIES,LD_PRELOAD}=/path/to/lib/libtcmalloc.so ruby file.rb" | |
exit!(1) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment