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