Class: MemoryWatch

Inherits:
Object
  • Object
show all
Defined in:
lib/memory_watch.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ MemoryWatch

Returns a new instance of MemoryWatch.



5
6
7
8
9
10
11
12
13
14
# File 'lib/memory_watch.rb', line 5

def initialize(options)
  self.callback         = options[:callback]             || lambda {|pid| p pid}
  self.callback_message = (options[:callback_message]    || "Callback Triggered").strip
  self.watch_string     = Regexp.escape((options[:watch] || "this poem is a pomme").strip)
  self.delay            = options[:delay]                || 60
  self.num_cycles       = options[:num_cycles]           || 3
  self.num_over_marks   = options[:num_over_marks]       || 2
  self.high_water_mb    = options[:high_water_mb]        || 700
  self.high_water_pids  = {}
end

Instance Attribute Details

#callbackObject

Returns the value of attribute callback.



2
3
4
# File 'lib/memory_watch.rb', line 2

def callback
  @callback
end

#callback_messageObject

Returns the value of attribute callback_message.



2
3
4
# File 'lib/memory_watch.rb', line 2

def callback_message
  @callback_message
end

#delayObject

Returns the value of attribute delay.



2
3
4
# File 'lib/memory_watch.rb', line 2

def delay
  @delay
end

#high_water_mbObject

Returns the value of attribute high_water_mb.



2
3
4
# File 'lib/memory_watch.rb', line 2

def high_water_mb
  @high_water_mb
end

#high_water_pidsObject

Returns the value of attribute high_water_pids.



2
3
4
# File 'lib/memory_watch.rb', line 2

def high_water_pids
  @high_water_pids
end

#num_cyclesObject

Returns the value of attribute num_cycles.



2
3
4
# File 'lib/memory_watch.rb', line 2

def num_cycles
  @num_cycles
end

#num_over_marksObject

Returns the value of attribute num_over_marks.



2
3
4
# File 'lib/memory_watch.rb', line 2

def num_over_marks
  @num_over_marks
end

#pidsObject

Returns the value of attribute pids.



2
3
4
# File 'lib/memory_watch.rb', line 2

def pids
  @pids
end

#watch_stringObject

Returns the value of attribute watch_string.



2
3
4
# File 'lib/memory_watch.rb', line 2

def watch_string
  @watch_string
end

Instance Method Details

#cycleObject



16
17
18
19
20
21
22
# File 'lib/memory_watch.rb', line 16

def cycle
  self.num_cycles.times do 
    _check_pids
    sleep self.delay
  end
  _trigger_callback
end