-
Notifications
You must be signed in to change notification settings - Fork 372
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PROF-9180] Benchmarks for allocation profiling
- Loading branch information
Showing
3 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
# Used to quickly run benchmark under RSpec as part of the usual test suite, to validate it didn't bitrot | ||
VALIDATE_BENCHMARK_MODE = ENV['VALIDATE_BENCHMARK'] == 'true' | ||
|
||
return unless __FILE__ == $PROGRAM_NAME || VALIDATE_BENCHMARK_MODE | ||
|
||
require 'benchmark/ips' | ||
require 'ddtrace' | ||
require 'pry' | ||
require_relative 'dogstatsd_reporter' | ||
|
||
require 'libdatadog' | ||
|
||
puts "Libdatadog from: #{Libdatadog.pkgconfig_folder}" | ||
|
||
# This benchmark measures the performance of sampling + serializing memory profiles. It enables us to evaluate changes to | ||
# the profiler and/or libdatadog that may impact both individual samples, as well as samples over time. | ||
# | ||
METRIC_VALUES = { 'cpu-time' => 0, 'cpu-samples' => 0, 'wall-time' => 0, 'alloc-samples' => 1, 'timeline' => 0 }.freeze | ||
OBJECT_CLASS = 'object'.freeze | ||
|
||
def sample_object(recorder, depth = 0) | ||
if depth <= 0 | ||
Datadog::Profiling::StackRecorder::Testing._native_track_object( | ||
recorder, | ||
Object.new, | ||
1, | ||
OBJECT_CLASS, | ||
) | ||
Datadog::Profiling::Collectors::Stack::Testing._native_sample( | ||
Thread.current, | ||
recorder, | ||
METRIC_VALUES, | ||
[], | ||
[], | ||
400, | ||
false | ||
) | ||
else | ||
sample_object(recorder, depth - 1) | ||
end | ||
end | ||
|
||
class ProfilerMemorySampleSerializeBenchmark | ||
def create_profiler | ||
@heap_samples_enabled = ENV['HEAP_SAMPLES'] == 'true' | ||
@heap_size_enabled = ENV['HEAP_SIZE'] == 'true' | ||
@recorder = Datadog::Profiling::StackRecorder.new( | ||
cpu_time_enabled: false, | ||
alloc_samples_enabled: true, | ||
heap_samples_enabled: @heap_samples_enabled, | ||
heap_size_enabled: @heap_size_enabled, | ||
heap_sample_every: 1, | ||
timeline_enabled: false, | ||
) | ||
end | ||
|
||
def run_benchmark | ||
Benchmark.ips do |x| | ||
benchmark_time = VALIDATE_BENCHMARK_MODE ? { time: 0.01, warmup: 0 } : { time: 10, warmup: 2 } | ||
x.config( | ||
**benchmark_time, | ||
suite: report_to_dogstatsd_if_enabled_via_environment_variable(benchmark_name: 'profiler_memory_sample_serialize') | ||
) | ||
|
||
x.report("sample #{ENV['CONFIG']} heap_samples=#{@heap_samples_enabled} heap_size=#{@heap_size_enabled}") do | ||
samples_per_second = 100 | ||
simulate_seconds = 60 | ||
|
||
(samples_per_second * simulate_seconds).times do |i| | ||
sample_object(@recorder, i % 400) | ||
end | ||
|
||
@recorder.serialize | ||
nil | ||
end | ||
|
||
x.save! 'profiler_memory_sample_serialize-results.json' unless VALIDATE_BENCHMARK_MODE | ||
x.compare! | ||
end | ||
|
||
@recorder.serialize | ||
end | ||
|
||
def run_forever | ||
loop do | ||
1000.times do | ||
Datadog::Profiling::Collectors::ThreadContext::Testing._native_sample(@collector, PROFILER_OVERHEAD_STACK_THREAD) | ||
end | ||
@recorder.serialize | ||
print '.' | ||
end | ||
end | ||
end | ||
|
||
puts "Current pid is #{Process.pid}" | ||
|
||
ProfilerMemorySampleSerializeBenchmark.new.instance_exec do | ||
create_profiler | ||
if ARGV.include?('--forever') | ||
run_forever | ||
else | ||
run_benchmark | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters