Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PROF-4780] Add libddprof dependency to power the new Ruby profiler #2028

Merged
merged 19 commits into from
May 19, 2022
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 1 addition & 16 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,11 @@
/tmp/
/log/
TODO
ext/**/skipped_reason.txt

# Used by dotenv library to load environment variables.
# .env

## Specific to RubyMotion:
.dat*
.repl_history
build/
*.bridgesupport
build-iPhoneOS/
build-iPhoneSimulator/

## Specific to RubyMotion (use of CocoaPods):
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#
# vendor/Pods/

## Documentation cache and generated files:
/.yardoc/
/_yardoc/
Expand Down
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ if RUBY_PLATFORM != 'java'
gem 'google-protobuf', ['~> 3.0', '!= 3.7.0', '!= 3.7.1', '< 3.19.2']
end
end
gem 'libddprof', '~> 0.3.0.1.0'

# For type checking
# Sorbet releases almost daily, with new checks introduced that can make a
Expand Down
3 changes: 3 additions & 0 deletions ddtrace.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,8 @@ Gem::Specification.new do |spec|
# Used by appsec
spec.add_dependency 'libddwaf', '~> 1.3.0.1.0'

# Used by profiling
spec.add_dependency 'libddprof', '~> 0.6.0.1.0'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's real now!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LET'S GO!!!


spec.extensions = ['ext/ddtrace_profiling_native_extension/extconf.rb', 'ext/ddtrace_profiling_loader/extconf.rb']
end
61 changes: 26 additions & 35 deletions ext/ddtrace_profiling_native_extension/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,26 @@

require_relative 'native_extension_helpers'

def skip_building_extension!
SKIPPED_REASON_FILE = "#{__dir__}/skipped_reason.txt".freeze
begin
File.delete(SKIPPED_REASON_FILE)
rescue StandardError => _e
# Not a problem if the file doesn't exist or we can't delete it
end
ivoanjo marked this conversation as resolved.
Show resolved Hide resolved

def skip_building_extension!(reason)
$stderr.puts(Datadog::Profiling::NativeExtensionHelpers::Supported.failure_banner_for(**reason))
File.write(
SKIPPED_REASON_FILE,
Datadog::Profiling::NativeExtensionHelpers::Supported.render_skipped_reason_file(**reason),
)

File.write('Makefile', 'all install clean: # dummy makefile that does nothing')
exit
end

unless Datadog::Profiling::NativeExtensionHelpers::Supported.supported?
$stderr.puts(Datadog::Profiling::NativeExtensionHelpers::Supported.unsupported_reason)
skip_building_extension!
skip_building_extension!(Datadog::Profiling::NativeExtensionHelpers::Supported.unsupported_reason)
end

$stderr.puts(%(
Expand Down Expand Up @@ -48,6 +60,12 @@ def add_compiler_flag(flag)
end
end

# Older gcc releases may not default to C99 and we need to ask for this. This is also used:
# * by upstream Ruby -- search for gnu99 in the codebase
# * by msgpack, another ddtrace dependency
# (https://github.com/msgpack/msgpack-ruby/blob/18ce08f6d612fe973843c366ac9a0b74c4e50599/ext/msgpack/extconf.rb#L8)
add_compiler_flag '-std=gnu99'

# Gets really noisy when we include the MJIT header, let's omit it
add_compiler_flag '-Wno-unused-function'

Expand Down Expand Up @@ -78,24 +96,10 @@ def add_compiler_flag(flag)
end

# If we got here, libddprof is available and loaded

# TODO: Temporarily disabled for PR https://github.com/DataDog/dd-trace-rb/pull/1885; will be re-enabled in a follow-up PR
# ENV['PKG_CONFIG_PATH'] = "#{ENV['PKG_CONFIG_PATH']}:#{Libddprof.pkgconfig_folder}"
# unless pkg_config('ddprof_ffi')
# $stderr.puts(%(
# +------------------------------------------------------------------------------+
# | Skipping build of profiling native extension: |
# | failed to configure `libddprof` for compilation. |
# | |
# | The Datadog Continuous Profiler will not be available, |
# | but all other ddtrace features will work fine! |
# | |
# | For help solving this issue, please contact Datadog support at |
# | <https://docs.datadoghq.com/help/>. |
# +------------------------------------------------------------------------------+
# ))
# skip_building_extension!
# end
ENV['PKG_CONFIG_PATH'] = "#{ENV['PKG_CONFIG_PATH']}:#{Libddprof.pkgconfig_folder}"
unless pkg_config('ddprof_ffi_with_rpath')
skip_building_extension!(Datadog::Profiling::NativeExtensionHelpers::Supported::FAILED_TO_CONFIGURE_LIBDDPROF)
end

# Tag the native extension library with the Ruby version and Ruby platform.
# This makes it easier for development (avoids "oops I forgot to rebuild when I switched my Ruby") and ensures that
Expand All @@ -115,20 +119,7 @@ def add_compiler_flag(flag)
original_common_headers = MakeMakefile::COMMON_HEADERS
MakeMakefile::COMMON_HEADERS = ''.freeze
unless have_macro('RUBY_MJIT_H', mjit_header_file_name)
$stderr.puts(%(
+------------------------------------------------------------------------------+
| WARNING: Unable to compile a needed component for ddtrace native extension. |
| Your C compiler or Ruby VM just-in-time compiler seems to be broken. |
| |
| The Datadog Continuous Profiler will not be available, |
| but all other ddtrace features will work fine! |
| |
| For help solving this issue, please contact Datadog support at |
| <https://docs.datadoghq.com/help/>. |
+------------------------------------------------------------------------------+

))
skip_building_extension!
skip_building_extension!(Datadog::Profiling::NativeExtensionHelpers::Supported::COMPILATION_BROKEN)
end
MakeMakefile::COMMON_HEADERS = original_common_headers

Expand Down
Loading