|
1 | 1 | # frozen_string_literal: true
|
2 | 2 |
|
3 |
| -# This file is used to load the profiling native extension. It works in two steps: |
4 |
| -# |
5 |
| -# 1. Load the datadog_profiling_loader extension. This extension will be used to load the actual extension, but in |
6 |
| -# a special way that avoids exposing native-level code symbols. See `datadog_profiling_loader.c` for more details. |
7 |
| -# |
8 |
| -# 2. Use the Datadog::Profiling::Loader exposed by the datadog_profiling_loader extension to load the actual |
9 |
| -# profiling native extension. |
10 |
| -# |
11 |
| -# All code on this file is on-purpose at the top-level; this makes it so this file is executed only once, |
12 |
| -# the first time it gets required, to avoid any issues with the native extension being initialized more than once. |
13 |
| - |
14 | 3 | begin
|
15 |
| - require "datadog_profiling_loader.#{RUBY_VERSION}_#{RUBY_PLATFORM}" |
| 4 | + require "datadog_profiling_native_extension.#{RUBY_VERSION}_#{RUBY_PLATFORM}" |
16 | 5 | rescue LoadError => e
|
17 | 6 | raise LoadError,
|
18 | 7 | "Failed to load the profiling loader extension. To fix this, please remove and then reinstall datadog " \
|
19 | 8 | "(Details: #{e.message})"
|
20 | 9 | end
|
21 |
| - |
22 |
| -extension_name = "datadog_profiling_native_extension.#{RUBY_VERSION}_#{RUBY_PLATFORM}" |
23 |
| -file_name = "#{extension_name}.#{RbConfig::CONFIG["DLEXT"]}" |
24 |
| -full_file_path = "#{__dir__}/../../#{file_name}" |
25 |
| - |
26 |
| -unless File.exist?(full_file_path) |
27 |
| - extension_dir = Gem.loaded_specs["datadog"].extension_dir |
28 |
| - candidate_path = "#{extension_dir}/#{file_name}" |
29 |
| - if File.exist?(candidate_path) |
30 |
| - full_file_path = candidate_path |
31 |
| - else |
32 |
| - # We found none of the files. This is unexpected. Let's go ahead anyway, the error is going to be reported further |
33 |
| - # down anyway. |
34 |
| - end |
35 |
| -end |
36 |
| - |
37 |
| -init_function_name = "Init_#{extension_name.split(".").first}" |
38 |
| - |
39 |
| -status, result = Datadog::Profiling::Loader._native_load(full_file_path, init_function_name) |
40 |
| - |
41 |
| -raise "Failure to load #{extension_name} due to #{result}" if status == :error |
0 commit comments