diff --git a/benchmarks/benchmarks_helper.rb b/benchmarks/benchmarks_helper.rb new file mode 100644 index 00000000000..5368594c6fb --- /dev/null +++ b/benchmarks/benchmarks_helper.rb @@ -0,0 +1,3 @@ +require 'datadog' +require 'pry' +require_relative 'benchmarks_ips_patch' diff --git a/benchmarks/benchmarks_ips_patch.rb b/benchmarks/benchmarks_ips_patch.rb new file mode 100644 index 00000000000..a7ec63af746 --- /dev/null +++ b/benchmarks/benchmarks_ips_patch.rb @@ -0,0 +1,26 @@ +require 'benchmark/ips' + +module JobReporter + def report(name, *args, **opts, &block) + caller_path = caller_locations.first.path + prefix = File.basename(caller_path).sub(/_.*\z/, '') + name = "#{prefix} - #{name}" + # Older Rubies (e.g. 2.5) do not permit passing *args and &block + # in the same invocation. + if args.any? && block_given? + raise ArgumentError, 'Unsupported usage' + elsif block_given? + if opts.any? + super(name, **opts, &block) + else + super(name, &block) + end + else + super(name, *args, **opts) + end + end +end + +class Benchmark::IPS::Job + prepend JobReporter +end diff --git a/benchmarks/library_gem_loading.rb b/benchmarks/library_gem_loading.rb index 9ec496bd121..d815957f6d8 100644 --- a/benchmarks/library_gem_loading.rb +++ b/benchmarks/library_gem_loading.rb @@ -3,6 +3,7 @@ return unless __FILE__ == $PROGRAM_NAME || VALIDATE_BENCHMARK_MODE +require_relative 'benchmarks_helper' require 'open3' class GemLoadingBenchmark @@ -18,6 +19,7 @@ def benchmark_gem_loading lib = File.expand_path('../lib', '#{__dir__}') $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) + $LOAD_PATH.unshift('#{__dir__}') VALIDATE_BENCHMARK_MODE = #{VALIDATE_BENCHMARK_MODE} require 'benchmark/ips' @@ -27,7 +29,10 @@ def benchmark_gem_loading benchmark_time = VALIDATE_BENCHMARK_MODE ? { time: 0.001, warmup: 0 } : { time: 60, warmup: 5 } x.config(**benchmark_time) - x.report("Gem loading") do + # Because this benchmark is run in a forked process that is passed + # the code via standard input, it cannot figure out the product + # prefix automatically. + x.report("library - Gem loading") do pid = fork { require 'datadog' } _, status = Process.wait2(pid) diff --git a/benchmarks/profiler_allocation.rb b/benchmarks/profiler_allocation.rb index e2cced33c6f..f0803d8f8f2 100644 --- a/benchmarks/profiler_allocation.rb +++ b/benchmarks/profiler_allocation.rb @@ -3,9 +3,7 @@ return unless __FILE__ == $PROGRAM_NAME || VALIDATE_BENCHMARK_MODE -require 'benchmark/ips' -require 'datadog' -require 'pry' +require_relative 'benchmarks_helper' # This benchmark measures the performance of allocation profiling diff --git a/benchmarks/profiler_gc.rb b/benchmarks/profiler_gc.rb index 89a6bfb007b..2bf73432d16 100644 --- a/benchmarks/profiler_gc.rb +++ b/benchmarks/profiler_gc.rb @@ -3,9 +3,7 @@ return unless __FILE__ == $PROGRAM_NAME || VALIDATE_BENCHMARK_MODE -require 'benchmark/ips' -require 'datadog' -require 'pry' +require_relative 'benchmarks_helper' # This benchmark measures the performance of GC profiling diff --git a/benchmarks/profiler_hold_resume_interruptions.rb b/benchmarks/profiler_hold_resume_interruptions.rb index a9257209b8d..42a7f88d3d4 100644 --- a/benchmarks/profiler_hold_resume_interruptions.rb +++ b/benchmarks/profiler_hold_resume_interruptions.rb @@ -3,9 +3,7 @@ return unless __FILE__ == $PROGRAM_NAME || VALIDATE_BENCHMARK_MODE -require 'benchmark/ips' -require 'datadog' -require 'pry' +require_relative 'benchmarks_helper' # This benchmark measures the performance of the hold/resume interruptions used by the DirMonkeyPatches class ProfilerHoldResumeInterruptions diff --git a/benchmarks/profiler_http_transport.rb b/benchmarks/profiler_http_transport.rb index 6388047990f..8044e89463c 100644 --- a/benchmarks/profiler_http_transport.rb +++ b/benchmarks/profiler_http_transport.rb @@ -3,9 +3,7 @@ return unless __FILE__ == $PROGRAM_NAME || VALIDATE_BENCHMARK_MODE -require 'benchmark/ips' -require 'datadog' -require 'pry' +require_relative 'benchmarks_helper' require 'securerandom' require 'socket' diff --git a/benchmarks/profiler_memory_sample_serialize.rb b/benchmarks/profiler_memory_sample_serialize.rb index b378aa719bf..decf40be50f 100644 --- a/benchmarks/profiler_memory_sample_serialize.rb +++ b/benchmarks/profiler_memory_sample_serialize.rb @@ -3,9 +3,7 @@ return unless __FILE__ == $PROGRAM_NAME || VALIDATE_BENCHMARK_MODE -require 'benchmark/ips' -require 'datadog' -require 'pry' +require_relative 'benchmarks_helper' require 'libdatadog' diff --git a/benchmarks/profiler_sample_loop_v2.rb b/benchmarks/profiler_sample_loop_v2.rb index ca72feb440a..bcd3e03304f 100644 --- a/benchmarks/profiler_sample_loop_v2.rb +++ b/benchmarks/profiler_sample_loop_v2.rb @@ -3,9 +3,7 @@ return unless __FILE__ == $PROGRAM_NAME || VALIDATE_BENCHMARK_MODE -require 'benchmark/ips' -require 'datadog' -require 'pry' +require_relative 'benchmarks_helper' # This benchmark measures the performance of the main stack sampling loop of the profiler diff --git a/benchmarks/profiler_sample_serialize.rb b/benchmarks/profiler_sample_serialize.rb index 05b1d3d4adc..7f4886f971d 100644 --- a/benchmarks/profiler_sample_serialize.rb +++ b/benchmarks/profiler_sample_serialize.rb @@ -3,9 +3,7 @@ return unless __FILE__ == $PROGRAM_NAME || VALIDATE_BENCHMARK_MODE -require 'benchmark/ips' -require 'datadog' -require 'pry' +require_relative 'benchmarks_helper' require 'libdatadog' diff --git a/benchmarks/tracing_trace.rb b/benchmarks/tracing_trace.rb index 4d17ed7aa07..6880729bf34 100644 --- a/benchmarks/tracing_trace.rb +++ b/benchmarks/tracing_trace.rb @@ -3,8 +3,7 @@ return unless __FILE__ == $PROGRAM_NAME || VALIDATE_BENCHMARK_MODE -require 'benchmark/ips' -require 'datadog' +require_relative 'benchmarks_helper' class TracingTraceBenchmark module NoopWriter