Method: RubyProf::Profile#merge!
- Defined in:
- lib/ruby-prof/profile.rb
#merge! ⇒ Object
call-seq: merge! -> self
Merges RubyProf threads whose root call_trees reference the same target method. This is useful when profiling code that uses a main thread/fiber to distribute work to multiple workers. If there are tens or hundreds of workers, viewing results per worker thread/fiber can be overwhelming. Using merge!
will combine the worker times together into one result.
Note the reported time will be much greater than the actual wall time. For example, if there are 10 workers that each run for 5 seconds, merged results will show one thread that ran for 50 seconds.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/ruby-prof/profile.rb', line 48 def merge! # First group threads by their root call tree target (method). If the methods are # different than there is nothing to merge grouped = threads.group_by do |thread| thread.call_tree.target end # For each target, get the first thread. Then loop over the remaining threads, # and merge them into the first one and ten delete them. So we will be left with # one thread per target. grouped.each do |target, threads| thread = threads.shift threads.each do |other_thread| thread.merge!(other_thread) remove_thread(other_thread) end thread end self end |