Module: SchwadPerformanceLogger
- Defined in:
- lib/schwad_performance_logger.rb,
lib/schwad_performance_logger/version.rb
Constant Summary collapse
- VERSION =
"0.5.1"
Class Method Summary collapse
- .all_objects ⇒ Object
- .allocate_count ⇒ Object
- .ips ⇒ Object
- .new(opts = {}) ⇒ Object
- .objects_by_size ⇒ Object
- .profile_memory ⇒ Object
- .time ⇒ Object
Class Method Details
.all_objects ⇒ Object
58 59 60 61 62 63 |
# File 'lib/schwad_performance_logger.rb', line 58 def self.all_objects ObjectSpace.each_object. map(&:class). each_with_object(Hash.new(0)) { |e, h| h[e] += 1 }. sort_by { |k,v| v } end |
.allocate_count ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/schwad_performance_logger.rb', line 42 def self.allocate_count # All objects allocated in block suppress_output do GC.disable before = ObjectSpace.count_objects yield after = ObjectSpace.count_objects after.each { |k,v| after[k] = v - before[k] } after[:T_HASH] -= 1 # probe effect - we created the before hash. after[:FREE] += 1 # same GC.enable @result = after.reject { |k,v| v == 0 } end @result end |
.ips ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/schwad_performance_logger.rb', line 19 def self.ips suppress_output do @result = Benchmark.ips do |x| x.report("PerformanceLogMethod") do yield end end end @result end |
.new(opts = {}) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/schwad_performance_logger.rb', line 11 def self.new(opts={}) if opts.is_a?(Hash) PLogger.new(opts) else puts "I'm sorry, I don't know what you're trying to pass here!\n\n Please refer to the docs or pass an options hash https://github.com/schwad/schwad_performance_logger" end end |
.objects_by_size ⇒ Object
65 66 67 |
# File 'lib/schwad_performance_logger.rb', line 65 def self.objects_by_size ObjectSpace.count_objects_size end |
.profile_memory ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'lib/schwad_performance_logger.rb', line 69 def self.profile_memory suppress_output do @report = MemoryProfiler.report do yield end end @report.pretty_print end |
.time ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/schwad_performance_logger.rb', line 30 def self.time suppress_output do @length_of_time = [] 10.times do start_time = Time.now yield @length_of_time << Time.now - start_time end end puts "Average runtime #{@length_of_time.sum / 10.0} seconds. Max time #{@length_of_time.max}.seconds" end |