Skip to content

Commit 24b6b3a

Browse files
committed
Merge branch 'master' into delner/20240305_update_2.0
2 parents 4f00746 + e9cb75c commit 24b6b3a

File tree

592 files changed

+1887
-1466
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

592 files changed

+1887
-1466
lines changed

.github/labeler.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ dev/testing:
1414

1515
# Changes to Profiling
1616
profiling:
17-
- any: [ '{lib/datadog/profiling/**,ext/ddtrace_profiling_loader/**,ext/ddtrace_profiling_native_extension/**}' ]
17+
- any: [ '{lib/datadog/profiling/**,ext/datadog_profiling_loader/**,ext/datadog_profiling_native_extension/**}' ]
1818

1919
# Changes to CI-App
2020
ci-app:

.gitlab-ci.yml

+1
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ onboarding_tests:
177177

178178
deploy_to_reliability_env:
179179
stage: deploy
180+
needs: [] # This allows the job to run without prerequisites
180181
rules:
181182
- if: $CI_PIPELINE_SOURCE == "schedule"
182183
when: on_success

.gitlab/benchmarks.yml

+8
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ only-profiling-gc:
8383
DD_PROFILING_NO_SIGNALS_WORKAROUND_ENABLED: "false"
8484
DD_PROFILING_FORCE_ENABLE_GC: "true"
8585

86+
only-profiling-alloc:
87+
extends: .benchmarks
88+
variables:
89+
DD_BENCHMARKS_CONFIGURATION: only-profiling
90+
DD_PROFILING_ENABLED: "true"
91+
DD_PROFILING_NO_SIGNALS_WORKAROUND_ENABLED: "false"
92+
DD_PROFILING_EXPERIMENTAL_ALLOCATION_ENABLED: "true"
93+
8694
profiling-and-tracing:
8795
extends: .benchmarks
8896
variables:

LICENSE-3rdparty.csv

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"Component","Origin","License","Copyright"
22
"debase-ruby_core_source","https://rubygems.org/gems/debase-ruby_core_source","MIT for gem and BSD-2-Clause for Ruby sources","Copyright (c) 2012 Gabriel Horner. Files from Ruby sources are Copyright (C) 1993-2013 Yukihiro Matsumoto. All rights reserved."
3-
"ext/ddtrace_profiling_native_extension/private_vm_api_access","https://github.com/ruby/ruby","BSD-2-Clause","Copyright (C) 1993-2013 Yukihiro Matsumoto. All rights reserved."
3+
"ext/datadog_profiling_native_extension/private_vm_api_access","https://github.com/ruby/ruby","BSD-2-Clause","Copyright (C) 1993-2013 Yukihiro Matsumoto. All rights reserved."
44
"lib/datadog/core/vendor/multipart-post","https://github.com/socketry/multipart-post","MIT","Copyright (c) 2007-2013 Nick Sieger."
55
"lib/datadog/tracing/contrib/active_record/vendor","https://github.com/rails/rails/","MIT","Copyright (c) 2005-2018 David Heinemeier Hansson"
66
"lib/datadog/tracing/contrib/utils/quantization/http.rb","https://github.com/ruby/uri","BSD-2-Clause","Copyright (C) 1993-2013 Yukihiro Matsumoto. All rights reserved."

Rakefile

+4-4
Original file line numberDiff line numberDiff line change
@@ -637,12 +637,12 @@ namespace :changelog do
637637
end
638638

639639
NATIVE_EXTS = [
640-
Rake::ExtensionTask.new("ddtrace_profiling_native_extension.#{RUBY_VERSION}_#{RUBY_PLATFORM}") do |ext|
641-
ext.ext_dir = 'ext/ddtrace_profiling_native_extension'
640+
Rake::ExtensionTask.new("datadog_profiling_native_extension.#{RUBY_VERSION}_#{RUBY_PLATFORM}") do |ext|
641+
ext.ext_dir = 'ext/datadog_profiling_native_extension'
642642
end,
643643

644-
Rake::ExtensionTask.new("ddtrace_profiling_loader.#{RUBY_VERSION}_#{RUBY_PLATFORM}") do |ext|
645-
ext.ext_dir = 'ext/ddtrace_profiling_loader'
644+
Rake::ExtensionTask.new("datadog_profiling_loader.#{RUBY_VERSION}_#{RUBY_PLATFORM}") do |ext|
645+
ext.ext_dir = 'ext/datadog_profiling_loader'
646646
end
647647
].freeze
648648

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# Used to quickly run benchmark under RSpec as part of the usual test suite, to validate it didn't bitrot
2+
VALIDATE_BENCHMARK_MODE = ENV['VALIDATE_BENCHMARK'] == 'true'
3+
4+
return unless __FILE__ == $PROGRAM_NAME || VALIDATE_BENCHMARK_MODE
5+
6+
require 'benchmark/ips'
7+
require 'ddtrace'
8+
require 'pry'
9+
require_relative 'dogstatsd_reporter'
10+
11+
require 'libdatadog'
12+
13+
puts "Libdatadog from: #{Libdatadog.pkgconfig_folder}"
14+
15+
# This benchmark measures the performance of sampling + serializing memory profiles. It enables us to evaluate changes to
16+
# the profiler and/or libdatadog that may impact both individual samples, as well as samples over time.
17+
#
18+
METRIC_VALUES = { 'cpu-time' => 0, 'cpu-samples' => 0, 'wall-time' => 0, 'alloc-samples' => 1, 'timeline' => 0 }.freeze
19+
OBJECT_CLASS = 'object'.freeze
20+
21+
def sample_object(recorder, depth = 0)
22+
if depth <= 0
23+
Datadog::Profiling::StackRecorder::Testing._native_track_object(
24+
recorder,
25+
Object.new,
26+
1,
27+
OBJECT_CLASS,
28+
)
29+
Datadog::Profiling::Collectors::Stack::Testing._native_sample(
30+
Thread.current,
31+
recorder,
32+
METRIC_VALUES,
33+
[],
34+
[],
35+
400,
36+
false
37+
)
38+
else
39+
sample_object(recorder, depth - 1)
40+
end
41+
end
42+
43+
class ProfilerMemorySampleSerializeBenchmark
44+
def create_profiler
45+
@recorder = Datadog::Profiling::StackRecorder.new(
46+
cpu_time_enabled: false,
47+
alloc_samples_enabled: true,
48+
heap_samples_enabled: false,
49+
heap_size_enabled: false,
50+
heap_sample_every: 1,
51+
timeline_enabled: false,
52+
)
53+
end
54+
55+
def run_benchmark
56+
Benchmark.ips do |x|
57+
benchmark_time = VALIDATE_BENCHMARK_MODE ? { time: 0.01, warmup: 0 } : { time: 10, warmup: 2 }
58+
x.config(
59+
**benchmark_time,
60+
suite: report_to_dogstatsd_if_enabled_via_environment_variable(benchmark_name: 'profiler_memory_sample_serialize')
61+
)
62+
63+
x.report("sample+serialize #{ENV['CONFIG']}") do
64+
samples_per_second = 100
65+
simulate_seconds = 60
66+
67+
(samples_per_second * simulate_seconds).times do |i|
68+
sample_object(@recorder, i % 400)
69+
end
70+
71+
@recorder.serialize
72+
nil
73+
end
74+
75+
x.save! 'profiler_memory_sample_serialize-results.json' unless VALIDATE_BENCHMARK_MODE
76+
x.compare!
77+
end
78+
79+
@recorder.serialize
80+
end
81+
82+
def run_forever
83+
loop do
84+
1000.times do |i|
85+
sample_object(@recorder, i % 400)
86+
end
87+
@recorder.serialize
88+
print '.'
89+
end
90+
end
91+
end
92+
93+
puts "Current pid is #{Process.pid}"
94+
95+
ProfilerMemorySampleSerializeBenchmark.new.instance_exec do
96+
create_profiler
97+
if ARGV.include?('--forever')
98+
run_forever
99+
else
100+
run_benchmark
101+
end
102+
end

bin/ddprofrb

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env ruby
2+
require 'datadog/profiling/tasks/exec'
3+
require 'datadog/profiling/tasks/help'
4+
5+
command = ARGV.shift
6+
7+
case command
8+
when 'exec'
9+
Datadog::Profiling::Tasks::Exec.new(ARGV).run
10+
when 'help', '--help'
11+
Datadog::Profiling::Tasks::Help.new.run
12+
else
13+
puts "Command '#{command}' is not valid for ddprofrb."
14+
Datadog::Profiling::Tasks::Help.new.run
15+
end

bin/ddtracerb

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#!/usr/bin/env ruby
2+
Kernel.warn 'WARNING: Use of `ddtracerb` is deprecated, and will be removed in 2.0. Use `ddprofrb` instead.'
3+
24
require 'datadog/profiling/tasks/exec'
35
require 'datadog/profiling/tasks/help'
46

@@ -10,6 +12,6 @@ when 'exec'
1012
when 'help', '--help'
1113
Datadog::Profiling::Tasks::Help.new.run
1214
else
13-
puts "Command '#{command}' is not valid for ddtrace."
15+
puts "Command '#{command}' is not valid for ddtracerb."
1416
Datadog::Profiling::Tasks::Help.new.run
1517
end

ddtrace.gemspec

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Gem::Specification.new do |spec|
4444
.reject { |fn| fn.end_with?('.so', '.bundle') } # Exclude local profiler binary artifacts
4545
.reject { |fn| fn.end_with?('skipped_reason.txt') } # Generated by profiler; should never be distributed
4646

47-
spec.executables = ['ddtracerb']
47+
spec.executables = ['ddtracerb', 'ddprofrb']
4848
spec.require_paths = ['lib']
4949

5050
# Used to serialize traces to send them to the Datadog Agent.
@@ -69,7 +69,7 @@ Gem::Specification.new do |spec|
6969

7070
# Used by profiling (and possibly others in the future)
7171
# When updating the version here, please also update the version in `native_extension_helpers.rb` (and yes we have a test for it)
72-
spec.add_dependency 'libdatadog', '~> 6.0.0.1.0'
72+
spec.add_dependency 'libdatadog', '~> 6.0.0.2.0'
7373

74-
spec.extensions = ['ext/ddtrace_profiling_native_extension/extconf.rb', 'ext/ddtrace_profiling_loader/extconf.rb']
74+
spec.extensions = ['ext/datadog_profiling_native_extension/extconf.rb', 'ext/datadog_profiling_loader/extconf.rb']
7575
end

docs/ProfilingDevelopment.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ with ongoing tracing information, if any. Relies on the `Collectors::Stack` for
3232

3333
## Initialization
3434

35-
When started via `ddtracerb exec` (together with `DD_PROFILING_ENABLED=true`), initialization goes through the following
35+
When started via `ddprofrb exec` (together with `DD_PROFILING_ENABLED=true`), initialization goes through the following
3636
flow:
3737

3838
1. <../lib/datadog/profiling/preload.rb> triggers the creation of the profiler instance by calling the method `Datadog::Profiling.start_if_enabled`

ext/ddtrace_profiling_loader/ddtrace_profiling_loader.c ext/datadog_profiling_loader/datadog_profiling_loader.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// up other's symbols (`RTLD_DEEPBIND`).
1515
//
1616
// But Ruby's extension loading mechanism is not configurable -- there's no way to tell it to use different flags when
17-
// calling `dlopen`. To get around this, this file (ddtrace_profiling_loader.c) introduces another extension
17+
// calling `dlopen`. To get around this, this file (datadog_profiling_loader.c) introduces another extension
1818
// (profiling loader) which has only a single responsibility: mimic Ruby's extension loading mechanism, but when calling
1919
// `dlopen` use a different set of flags.
2020
// This idea was shamelessly stolen from @lloeki's work in https://github.com/rubyjs/mini_racer/pull/179, big thanks!
@@ -48,7 +48,7 @@ static void unload_failed_library(void *handle);
4848

4949
#define DDTRACE_EXPORT __attribute__ ((visibility ("default")))
5050

51-
void DDTRACE_EXPORT Init_ddtrace_profiling_loader(void) {
51+
void DDTRACE_EXPORT Init_datadog_profiling_loader(void) {
5252
VALUE datadog_module = rb_define_module("Datadog");
5353
VALUE profiling_module = rb_define_module_under(datadog_module, "Profiling");
5454
VALUE loader_module = rb_define_module_under(profiling_module, "Loader");

ext/ddtrace_profiling_loader/extconf.rb ext/datadog_profiling_loader/extconf.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
if RUBY_ENGINE != 'ruby' || Gem.win_platform?
55
$stderr.puts(
6-
'WARN: Skipping build of ddtrace profiling loader. See ddtrace profiling native extension note for details.'
6+
'WARN: Skipping build of Datadog profiling loader. See Datadog profiling native extension note for details.'
77
)
88

99
File.write('Makefile', 'all install clean: # dummy makefile that does nothing')
@@ -46,7 +46,7 @@ def add_compiler_flag(flag)
4646
add_compiler_flag '-Wunused-parameter'
4747

4848
# The native extension is not intended to expose any symbols/functions for other native libraries to use;
49-
# the sole exception being `Init_ddtrace_profiling_loader` which needs to be visible for Ruby to call it when
49+
# the sole exception being `Init_datadog_profiling_loader` which needs to be visible for Ruby to call it when
5050
# it `dlopen`s the library.
5151
#
5252
# By setting this compiler flag, we tell it to assume that everything is private unless explicitly stated.
@@ -64,7 +64,7 @@ def add_compiler_flag(flag)
6464
# This makes it easier for development (avoids "oops I forgot to rebuild when I switched my Ruby") and ensures that
6565
# the wrong library is never loaded.
6666
# When requiring, we need to use the exact same string, including the version and the platform.
67-
EXTENSION_NAME = "ddtrace_profiling_loader.#{RUBY_VERSION}_#{RUBY_PLATFORM}".freeze
67+
EXTENSION_NAME = "datadog_profiling_loader.#{RUBY_VERSION}_#{RUBY_PLATFORM}".freeze
6868

6969
create_makefile(EXTENSION_NAME)
7070

0 commit comments

Comments
 (0)