-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2450 from DataDog/ivoanjo/add-sample-loop-benchma…
…rk-new-profiler Add benchmark to test new profiler
- Loading branch information
Showing
2 changed files
with
72 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# typed: ignore | ||
|
||
# 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' | ||
|
||
# This benchmark measures the performance of the main stack sampling loop of the profiler | ||
|
||
class ProfilerSampleLoopBenchmark | ||
def create_profiler | ||
@recorder = Datadog::Profiling::StackRecorder.new | ||
@collector = Datadog::Profiling::Collectors::CpuAndWallTime.new(recorder: @recorder, max_frames: 400, tracer: nil) | ||
end | ||
|
||
def thread_with_very_deep_stack(depth: 500) | ||
deep_stack = proc do |n| | ||
if n > 0 | ||
deep_stack.call(n - 1) | ||
else | ||
sleep | ||
end | ||
end | ||
|
||
Thread.new { deep_stack.call(depth) }.tap { |t| t.name = "Deep stack #{depth}" } | ||
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_sample_loop_v2')) | ||
|
||
x.report("stack collector #{ENV['CONFIG']}") do | ||
Datadog::Profiling::Collectors::CpuAndWallTime::Testing._native_sample(@collector) | ||
end | ||
|
||
x.save! 'profiler-sample-loop-v2-results.json' unless VALIDATE_BENCHMARK_MODE | ||
x.compare! | ||
end | ||
|
||
@recorder.serialize | ||
end | ||
|
||
def run_forever | ||
while true | ||
1000.times { Datadog::Profiling::Collectors::CpuAndWallTime::Testing._native_sample(@collector) } | ||
@recorder.serialize | ||
print '.' | ||
end | ||
end | ||
end | ||
|
||
puts "Current pid is #{Process.pid}" | ||
|
||
ProfilerSampleLoopBenchmark.new.instance_exec do | ||
create_profiler | ||
4.times { thread_with_very_deep_stack } | ||
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