@@ -33,9 +33,11 @@ class Monitor
3333 def initialize ( process_id = Process . pid , maximum_size : nil , maximum_size_limit : nil , threshold_size : DEFAULT_THRESHOLD_SIZE , increase_limit : DEFAULT_INCREASE_LIMIT )
3434 @process_id = process_id
3535
36+ @sample_count = 0
3637 @current_size = nil
3738 @maximum_size = maximum_size
3839 @maximum_size_limit = maximum_size_limit
40+ @maximum_observed_size = nil
3941
4042 @threshold_size = threshold_size
4143 @increase_count = 0
@@ -46,6 +48,7 @@ def initialize(process_id = Process.pid, maximum_size: nil, maximum_size_limit:
4648 def as_json ( ...)
4749 {
4850 process_id : @process_id ,
51+ sample_count : @sample_count ,
4952 current_size : @current_size ,
5053 maximum_size : @maximum_size ,
5154 maximum_size_limit : @maximum_size_limit ,
@@ -83,6 +86,9 @@ def memory_usage
8386 System . memory_usage ( @process_id )
8487 end
8588
89+ # @attribute [Integer] The number of samples taken.
90+ attr :sample_count
91+
8692 # @returns [Integer] The last sampled memory usage.
8793 def current_size
8894 @current_size ||= memory_usage
@@ -119,7 +125,9 @@ def leaking?
119125 # Capture a memory usage sample and yield if a memory leak is detected.
120126 #
121127 # @yields {|sample, monitor| ...} If a memory leak is detected.
122- def sample!
128+ def sample! ( memory_usage = self . memory_usage )
129+ @sample_count += 1
130+
123131 self . current_size = memory_usage
124132
125133 if @maximum_observed_size
0 commit comments