Is there a way to profile ruby 1.9.2 scripts with memory allocation reports?
Have you tried profiling the GC? Ruby 1.9.2 includes GC::Profiler
.
GC::Profiler.enable
GC.start
puts GC::Profiler.report
You may also want to look at ObjectSpace.count_objects
.
Allocation tracer which works with Ruby 1.9?
It looks like perftools.rb
(https://github.com/tmm1/perftools.rb) can collect information on object allocations, and it works with Ruby 1.9. Unfortunately, it segfaults when I try to use it to trace object allocations!
If the problem is fixed, I will edit this answer.
Is it possible to use ruby-prof to profile memory/allocations in Ruby 2.1.1?
According to a ruby-prof issue we need a patched version of ruby to use the memory profiler.
- https://github.com/ruby-prof/ruby-prof/issues/166
- https://github.com/skaes/rvm-patchsets
What profilers are available for Ruby?
There's a built-in profiler available with "-r profile", which I've used happily.
There's also a gem called ruby-prof.
What are your strategies to keep the memory usage low?
- Choose date structures that are efficient representations, scale well, and do what you need.
- Use algorithms that work using efficient data structures rather than bloated, but easier ones.
- Look else where. Ruby has a C bridge and its much easier to be memory conscious in C than in Ruby.
Can I profile my .zshrc/.zshenv?
Try adding this at the beginning of the file:
# set the trace prompt to include seconds, nanoseconds, script name and line number
# This is GNU date syntax; by default Macs ship with the BSD date program, which isn't compatible
PS4='+$(date "+%s:%N") %N:%i> '
# save file stderr to file descriptor 3 and redirect stderr (including trace
# output) to a file with the script's PID as an extension
exec 3>&2 2>/tmp/startlog.$$
# set options to turn on tracing and expansion of commands contained in the prompt
setopt xtrace prompt_subst
and this at the end:
# turn off tracing
unsetopt xtrace
# restore stderr to the value saved in FD 3
exec 2>&3 3>&-
And you should get a detailed log showing the epoch_second.nanosecond time of the execution of each line. Note that GNU date
(and OS support) is required to have nanosecond output.
Edit:
added comments
Edit 2:
If you have zsh 4.3.12 or later, you should be able to set PS4
like this instead of using the date
command:
zmodload zsh/datetime
setopt promptsubst
PS4='+$EPOCHREALTIME %N:%i> '
which should work on both Linux and OS X to give you nanosecond precision.
Related Topics
How to Recursively Require All Files in a Directory in Ruby
Rails: Why Images Are Not Showing in My Rails Basic App
Using Nokogiri HTML Builder to Create Fragment with Multiple Root Nodes
Sudo Gem Install Pg Won't Work
Learning Ruby: Recommended Blogs to Read
How to Parse Consecutive Tags with Nokogiri
Rails Check_Box_Tag How to Pass Value When Checked Ajaxily
How to Get the Current Route in Rails
How to Run Phantomjs on Heroku
Devise Skip_Confirmation! Fails to Avoid to Send the Confirmation Instructions
Rvm Install: Ruby Installation Error
Trouble Resizing the Default Image with Paperclip
How to Use Ruby Metaprogramming to Add Callbacks to a Rails Model
After Installing Ruby Gems, Running the New Gem Returns "Could Not Find" Errors