-
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 #3797 from DataDog/ivoanjo/prof-10201-coarse-times…
…tamps [PROF-10201] Reduce allocation profiling overhead by using coarse timestamps
- Loading branch information
Showing
8 changed files
with
227 additions
and
58 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,66 @@ | ||
# 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 'datadog' | ||
require 'pry' | ||
require_relative 'dogstatsd_reporter' | ||
|
||
# This benchmark measures the performance of allocation profiling | ||
|
||
class ExportToFile | ||
PPROF_PREFIX = ENV.fetch('DD_PROFILING_PPROF_PREFIX', 'profiler-allocation') | ||
|
||
def export(flush) | ||
File.write("#{PPROF_PREFIX}#{flush.start.strftime('%Y%m%dT%H%M%SZ')}.pprof", flush.pprof_data) | ||
true | ||
end | ||
end | ||
|
||
class ProfilerAllocationBenchmark | ||
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_allocation') | ||
) | ||
|
||
x.report('Allocations (baseline)', 'BasicObject.new') | ||
|
||
x.save! 'profiler-allocation-results.json' unless VALIDATE_BENCHMARK_MODE | ||
x.compare! | ||
end | ||
|
||
Datadog.configure do |c| | ||
c.profiling.enabled = true | ||
c.profiling.allocation_enabled = true | ||
c.profiling.advanced.gc_enabled = false | ||
c.profiling.exporter.transport = ExportToFile.new unless VALIDATE_BENCHMARK_MODE | ||
end | ||
Datadog::Profiling.wait_until_running | ||
|
||
3.times { GC.start } | ||
|
||
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_allocation') | ||
) | ||
|
||
x.report("Allocations (#{ENV['CONFIG']})", 'BasicObject.new') | ||
|
||
x.save! 'profiler-allocation-results.json' unless VALIDATE_BENCHMARK_MODE | ||
x.compare! | ||
end | ||
end | ||
end | ||
|
||
puts "Current pid is #{Process.pid}" | ||
|
||
ProfilerAllocationBenchmark.new.instance_exec do | ||
run_benchmark | ||
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
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
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
Oops, something went wrong.