Module: BleakHouse::Analyzer
- Defined in:
- lib/bleak_house/analyzer.rb
Class Method Summary collapse
- .diff(outputs) ⇒ Object
-
.run(*args) ⇒ Object
Analyze a compatible
bleak.dump
.
Class Method Details
.diff(outputs) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/bleak_house/analyzer.rb', line 35 def self.diff(outputs) # Calculate the diff diff = Hash.new(0) # Iterate each item outputs.each_with_index do |output, index| output[3..-1].each do |line| c, key = line.split(" ", 2) index.zero? ? diff[key] -= c.to_i : diff[key] += c.to_i end end # Format the lines in descending order diff.sort_by do |key, value| -value end.map do |key, value| "#{value.to_s.rjust(6)} #{key}" end end |
.run(*args) ⇒ Object
Analyze a compatible bleak.dump
. Accepts one or more filename and the number of lines to display.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/bleak_house/analyzer.rb', line 6 def self.run(*args) lines = args.last[/^\d+$/] ? args.pop.to_i : 20 raise "Can't diff more than 2 files" if args.size > 2 outputs = args.map do |file| filled, free = `tail -n 2 #{file}`.split("\n") unless filled =~ /filled/ and free =~ /free/ raise "#{file} is incomplete or corrupted" end length = `wc #{file}`.to_i - 2 cmd = ENV['NO_TRACE'] ? "awk -F: '{print $3}' " + file : "cat #{file}" cmd += " | sort | uniq -c | sort -nr | head -#{lines}" ["#{length} total objects", "#{filled} heap slots", "#{free} heap slots"] + `#{cmd}`.split("\n") end if outputs.size == 1 # Just output the data puts "Displaying top #{lines} most common line/class pairs" puts outputs.first else puts "Displaying change in top #{lines} most common line/class pairs" puts diff(outputs) end end |