-
Notifications
You must be signed in to change notification settings - Fork 0
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 #39 from DataDog/ivoanjo/prof-9926-ruby-test-exten…
…sion-dir-rpath [PROF-9226] Add test for Ruby profiler when extension dir is moved and a relative rpath is needed
- Loading branch information
Showing
5 changed files
with
99 additions
and
1 deletion.
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 |
---|---|---|
@@ -1,6 +1,8 @@ | ||
#==============================================================================# | ||
# Directories to ignore (do not add trailing '/'s, they skip symlinks). | ||
#==============================================================================# | ||
binaries/* | ||
data/* | ||
|
||
.idea | ||
binaries/* | ||
gems.locked |
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,21 @@ | ||
FROM ruby:3.3 | ||
|
||
ENV DD_TRACE_DEBUG true | ||
ENV DD_PROFILING_PPROF_PREFIX="/app/data/profiles_" | ||
ENV EXECUTION_TIME_SEC 5 | ||
|
||
# Copy the Ruby program into the container | ||
COPY ./scenarios/ruby_extension_dir_and_rpath/gems.rb ./scenarios/ruby_basic/main.rb /app/ | ||
RUN chmod 644 /app/* | ||
|
||
# Set the working directory to the location of the program | ||
WORKDIR /app | ||
|
||
RUN bundle config set --local path 'vendor/bundle' | ||
RUN bundle install | ||
RUN rm -f vendor/bundle/ruby/*/gems/*/lib/datadog*so vendor/bundle/ruby/*/bundler/gems/*/lib/datadog*so | ||
RUN bundle config set --local path 'vendor-moved/bundle' | ||
RUN mv vendor vendor-moved | ||
|
||
# Run the program when the container starts | ||
CMD bundle exec ddprofrb exec ruby main.rb |
21 changes: 21 additions & 0 deletions
21
scenarios/ruby_extension_dir_and_rpath/expected_profile.json
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,21 @@ | ||
{ | ||
"test_name":"ruby_basic", | ||
"stacks": [ | ||
{ | ||
"profile-type": "cpu-time", | ||
"stack-content": | ||
[ | ||
{ | ||
"regular_expression": "\u003cmain\u003e;a", | ||
"percent": 33, | ||
"error_margin": 20 | ||
}, | ||
{ | ||
"regular_expression": "\u003cmain\u003e;b", | ||
"percent": 66, | ||
"error_margin": 20 | ||
} | ||
] | ||
} | ||
] | ||
} |
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,3 @@ | ||
source 'https://rubygems.org' | ||
|
||
gem 'datadog' |
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,51 @@ | ||
require 'timeout' | ||
|
||
# The Ruby profiler does not (yet) include a way of exporting a pprof to a file, so we implement it here: | ||
class ExportToFile | ||
PPROF_PREFIX = ENV.fetch('DD_PROFILING_PPROF_PREFIX') | ||
|
||
def export(flush) | ||
File.write("#{PPROF_PREFIX}#{flush.start.strftime('%Y%m%dT%H%M%SZ')}.pprof", flush.pprof_data) | ||
true | ||
end | ||
end | ||
|
||
Datadog.configure do |c| | ||
c.profiling.enabled = true | ||
c.profiling.exporter.transport = ExportToFile.new | ||
end | ||
|
||
Datadog::Profiling.wait_until_running | ||
|
||
def a | ||
x = 0 | ||
i = 0 | ||
while i < 10_000_000 | ||
x += i | ||
i += 1 | ||
end | ||
end | ||
|
||
def b | ||
x = 0 | ||
i = 0 | ||
while i < 20_000_000 | ||
x += i | ||
i += 1 | ||
end | ||
end | ||
|
||
test_duration = 5 | ||
exec_time_env = ENV['EXECUTION_TIME_SEC'] | ||
if exec_time_env | ||
test_duration = exec_time_env.to_i | ||
exit(1) if test_duration == 0 | ||
end | ||
|
||
puts "Executable #{__FILE__} starting for #{test_duration} seconds" | ||
end_time = Time.now + test_duration | ||
while Time.now < end_time | ||
a | ||
b | ||
end | ||
puts "Executable #{__FILE__} finished successfully" |