class Memosig::Matcher
Public Class Methods
new(pattern, config)
click to toggle source
# File lib/memosig/matcher.rb, line 6 def initialize(pattern, config) @pattern, @config = prepare_pattern(pattern), config end
Public Instance Methods
match?(process)
click to toggle source
# File lib/memosig/matcher.rb, line 10 def match?(process) @process = process if @process.command =~ @pattern if @process.rss > @config.rss_max take_action else lay_low end true else false end end
Private Instance Methods
lay_low()
click to toggle source
# File lib/memosig/matcher.rb, line 37 def lay_low output "no action on process pid=#{@process.pid} "\ "pattern=#{@pattern.source.inspect} "\ "rss #{@process.rss}<=#{@config.rss_max}" end
prepare_pattern(pattern)
click to toggle source
# File lib/memosig/matcher.rb, line 26 def prepare_pattern(pattern) Regexp.new(pattern.to_s) end
take_action()
click to toggle source
# File lib/memosig/matcher.rb, line 30 def take_action output "sending signal #{@config.signal} to process pid=#{@process.pid} "\ "pattern=#{@pattern.source.inspect} "\ "rss #{@process.rss}>#{@config.rss_max}" Process.kill @config.signal, @process.pid end