module MemoryUsageProfiler
Constants
- MEMORY_PROFILE_BANNER
- MEMORY_PROFILE_DURATION
- MEMORY_PROFILE_GC_STAT_HASH
- MEMORY_PROFILE_OUTPUT_PATH
- MEMORY_PROFILE_PROCS
- T_TYPES
- VERSION
Public Class Methods
add(*name, &b)
click to toggle source
# File lib/memory_usage_profiler.rb, line 13 def self.add(*name, &b) MEMORY_PROFILE_BANNER.concat name MEMORY_PROFILE_PROCS << b end
add_proc_meminfo(file, fields)
click to toggle source
# File lib/memory_usage_profiler.rb, line 33 def self.add_proc_meminfo(file, fields) return unless FileTest.exist?(file) regexp = /(#{fields.join("|")}):\s*(\d+) kB/ # check = {}; fields.each{|e| check[e] = true} add(*fields) do |result| text = File.read(file) text.scan(regexp){ # check.delete $1 result << $2 '' } # raise check.inspect unless check.empty? end end
kick(name, &callback)
click to toggle source
# File lib/memory_usage_profiler.rb, line 85 def self.kick(name, &callback) result = [name.to_s] MEMORY_PROFILE_PROCS.each{|pr| pr.call(result) } callback.call(result) end
start_thread(duration=MEMORY_PROFILE_DURATION, file=MEMORY_PROFILE_OUTPUT_PATH)
click to toggle source
# File lib/memory_usage_profiler.rb, line 93 def self.start_thread(duration=MEMORY_PROFILE_DURATION, file=MEMORY_PROFILE_OUTPUT_PATH) require 'time' file = if file == '-' STDOUT else open(file, 'w') end file.sync = true file.puts banner @@thread_running = true Thread.new do Thread.current.abort_on_exception = true while @@thread_running kick(Time.now.iso8601) { |result| file.puts result.join("\t") sleep duration } end end end
stop_thread()
click to toggle source
# File lib/memory_usage_profiler.rb, line 118 def self.stop_thread @@thread_running = false end