1212# This benchmark measures the performance of sampling + serializing memory profiles. It enables us to evaluate changes to
1313# the profiler and/or libdatadog that may impact both individual samples, as well as samples over time.
1414#
15- METRIC_VALUES = { 'cpu-time' => 0 , 'cpu-samples' => 0 , 'wall-time' => 0 , 'alloc-samples' => 1 , 'timeline' => 0 } . freeze
15+ METRIC_VALUES = { 'cpu-time' => 0 , 'cpu-samples' => 0 , 'wall-time' => 0 , 'alloc-samples' => 1 , 'timeline' => 0 , 'heap_sample' => true } . freeze
1616OBJECT_CLASS = 'object' . freeze
1717
1818def sample_object ( recorder , depth = 0 )
@@ -56,6 +56,21 @@ def setup
5656 }
5757 end
5858
59+ def create_objects ( recorder )
60+ samples_per_second = 100
61+ simulate_seconds = 60
62+ retained_objs = [ ]
63+
64+ ( samples_per_second * simulate_seconds ) . times do |i |
65+ obj = sample_object ( recorder , i % 400 )
66+ retained_objs << obj if ( i % @retain_every ) . zero?
67+ end
68+
69+ GC . start unless @skip_end_gc
70+
71+ retained_objs
72+ end
73+
5974 def run_benchmark
6075 Benchmark . ips do |x |
6176 benchmark_time = VALIDATE_BENCHMARK_MODE ? { time : 0.01 , warmup : 0 } : { time : 30 , warmup : 2 }
@@ -65,18 +80,11 @@ def run_benchmark
6580
6681 x . report ( "sample+serialize #{ ENV [ 'CONFIG' ] } retain_every=#{ @retain_every } heap_samples=#{ @heap_samples_enabled } heap_size=#{ @heap_size_enabled } heap_sample_every=#{ @heap_sample_every } skip_end_gc=#{ @skip_end_gc } " ) do
6782 recorder = @recorder_factory . call
68- samples_per_second = 100
69- simulate_seconds = 60
70- retained_objs = [ ]
71-
72- ( samples_per_second * simulate_seconds ) . times do |i |
73- obj = sample_object ( recorder , i % 400 )
74- retained_objs << obj if ( i % @retain_every ) . zero?
75- end
76-
77- GC . start unless @skip_end_gc
83+ retained_objs = create_objects ( recorder )
7884
7985 recorder . serialize
86+
87+ retained_objs . size # Dummy action to make sure this is still alive
8088 end
8189
8290 x . save! "#{ File . basename ( __FILE__ ) } -results.json" unless VALIDATE_BENCHMARK_MODE
0 commit comments