ddtrace 1.18.0 → 1.23.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (229) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +228 -2
  3. data/LICENSE-3rdparty.csv +1 -1
  4. data/bin/ddprofrb +15 -0
  5. data/bin/ddtracerb +3 -1
  6. data/ext/{ddtrace_profiling_loader/ddtrace_profiling_loader.c → datadog_profiling_loader/datadog_profiling_loader.c} +2 -2
  7. data/ext/{ddtrace_profiling_loader → datadog_profiling_loader}/extconf.rb +3 -3
  8. data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/collectors_cpu_and_wall_time_worker.c +312 -117
  9. data/ext/datadog_profiling_native_extension/collectors_discrete_dynamic_sampler.c +422 -0
  10. data/ext/datadog_profiling_native_extension/collectors_discrete_dynamic_sampler.h +101 -0
  11. data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/collectors_dynamic_sampling_rate.c +22 -14
  12. data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/collectors_dynamic_sampling_rate.h +4 -0
  13. data/ext/datadog_profiling_native_extension/collectors_gc_profiling_helper.c +156 -0
  14. data/ext/datadog_profiling_native_extension/collectors_gc_profiling_helper.h +5 -0
  15. data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/collectors_stack.c +43 -102
  16. data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/collectors_stack.h +10 -3
  17. data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/collectors_thread_context.c +272 -136
  18. data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/collectors_thread_context.h +2 -1
  19. data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/extconf.rb +28 -7
  20. data/ext/datadog_profiling_native_extension/heap_recorder.c +1047 -0
  21. data/ext/datadog_profiling_native_extension/heap_recorder.h +166 -0
  22. data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/helpers.h +6 -0
  23. data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/http_transport.c +15 -19
  24. data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/libdatadog_helpers.c +20 -0
  25. data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/libdatadog_helpers.h +11 -0
  26. data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/native_extension_helpers.rb +50 -4
  27. data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/private_vm_api_access.c +19 -0
  28. data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/private_vm_api_access.h +4 -0
  29. data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/profiling.c +18 -1
  30. data/ext/datadog_profiling_native_extension/ruby_helpers.c +267 -0
  31. data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/ruby_helpers.h +33 -0
  32. data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/stack_recorder.c +476 -58
  33. data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/stack_recorder.h +3 -0
  34. data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/time_helpers.h +2 -0
  35. data/lib/datadog/appsec/contrib/devise/tracking.rb +8 -0
  36. data/lib/datadog/appsec/contrib/rack/request_middleware.rb +45 -14
  37. data/lib/datadog/appsec/event.rb +1 -1
  38. data/lib/datadog/auto_instrument.rb +3 -0
  39. data/lib/datadog/core/configuration/components.rb +7 -6
  40. data/lib/datadog/core/configuration/option.rb +8 -6
  41. data/lib/datadog/core/configuration/settings.rb +259 -60
  42. data/lib/datadog/core/configuration.rb +20 -4
  43. data/lib/datadog/core/diagnostics/environment_logger.rb +4 -3
  44. data/lib/datadog/core/environment/class_count.rb +6 -6
  45. data/lib/datadog/core/environment/git.rb +25 -0
  46. data/lib/datadog/core/environment/identity.rb +18 -48
  47. data/lib/datadog/core/environment/platform.rb +7 -1
  48. data/lib/datadog/core/git/ext.rb +2 -23
  49. data/lib/datadog/core/remote/client/capabilities.rb +1 -1
  50. data/lib/datadog/core/remote/component.rb +25 -12
  51. data/lib/datadog/core/remote/ext.rb +1 -0
  52. data/lib/datadog/core/remote/negotiation.rb +2 -2
  53. data/lib/datadog/core/remote/tie/tracing.rb +39 -0
  54. data/lib/datadog/core/remote/tie.rb +27 -0
  55. data/lib/datadog/core/remote/transport/http/config.rb +1 -1
  56. data/lib/datadog/core/remote/worker.rb +7 -4
  57. data/lib/datadog/core/telemetry/client.rb +18 -10
  58. data/lib/datadog/core/telemetry/emitter.rb +9 -13
  59. data/lib/datadog/core/telemetry/event.rb +247 -56
  60. data/lib/datadog/core/telemetry/ext.rb +4 -0
  61. data/lib/datadog/core/telemetry/heartbeat.rb +1 -3
  62. data/lib/datadog/core/telemetry/http/ext.rb +4 -1
  63. data/lib/datadog/core/telemetry/http/response.rb +4 -0
  64. data/lib/datadog/core/telemetry/http/transport.rb +9 -4
  65. data/lib/datadog/core/telemetry/request.rb +59 -0
  66. data/lib/datadog/core/transport/ext.rb +2 -0
  67. data/lib/datadog/core/utils/url.rb +25 -0
  68. data/lib/datadog/opentelemetry/sdk/propagator.rb +3 -2
  69. data/lib/datadog/opentelemetry.rb +3 -0
  70. data/lib/datadog/profiling/collectors/code_provenance.rb +10 -4
  71. data/lib/datadog/profiling/collectors/cpu_and_wall_time_worker.rb +36 -12
  72. data/lib/datadog/profiling/collectors/info.rb +101 -0
  73. data/lib/datadog/profiling/component.rb +210 -34
  74. data/lib/datadog/profiling/exporter.rb +23 -6
  75. data/lib/datadog/profiling/ext.rb +2 -0
  76. data/lib/datadog/profiling/flush.rb +6 -3
  77. data/lib/datadog/profiling/http_transport.rb +5 -1
  78. data/lib/datadog/profiling/load_native_extension.rb +19 -6
  79. data/lib/datadog/profiling/native_extension.rb +1 -1
  80. data/lib/datadog/profiling/scheduler.rb +4 -6
  81. data/lib/datadog/profiling/stack_recorder.rb +19 -4
  82. data/lib/datadog/profiling/tag_builder.rb +5 -0
  83. data/lib/datadog/profiling/tasks/exec.rb +3 -3
  84. data/lib/datadog/profiling/tasks/help.rb +3 -3
  85. data/lib/datadog/profiling.rb +13 -2
  86. data/lib/datadog/tracing/configuration/ext.rb +0 -1
  87. data/lib/datadog/tracing/configuration/settings.rb +2 -1
  88. data/lib/datadog/tracing/contrib/action_cable/configuration/settings.rb +1 -0
  89. data/lib/datadog/tracing/contrib/action_cable/ext.rb +1 -0
  90. data/lib/datadog/tracing/contrib/action_mailer/configuration/settings.rb +1 -0
  91. data/lib/datadog/tracing/contrib/action_mailer/events/deliver.rb +1 -1
  92. data/lib/datadog/tracing/contrib/action_mailer/ext.rb +1 -0
  93. data/lib/datadog/tracing/contrib/action_pack/configuration/settings.rb +1 -0
  94. data/lib/datadog/tracing/contrib/action_pack/ext.rb +1 -0
  95. data/lib/datadog/tracing/contrib/action_view/configuration/settings.rb +1 -0
  96. data/lib/datadog/tracing/contrib/action_view/ext.rb +1 -0
  97. data/lib/datadog/tracing/contrib/active_job/configuration/settings.rb +1 -0
  98. data/lib/datadog/tracing/contrib/active_job/ext.rb +1 -0
  99. data/lib/datadog/tracing/contrib/active_model_serializers/configuration/settings.rb +1 -0
  100. data/lib/datadog/tracing/contrib/active_model_serializers/ext.rb +1 -0
  101. data/lib/datadog/tracing/contrib/active_record/configuration/resolver.rb +11 -4
  102. data/lib/datadog/tracing/contrib/active_record/configuration/settings.rb +1 -0
  103. data/lib/datadog/tracing/contrib/active_record/ext.rb +1 -0
  104. data/lib/datadog/tracing/contrib/active_support/configuration/settings.rb +1 -0
  105. data/lib/datadog/tracing/contrib/active_support/ext.rb +1 -0
  106. data/lib/datadog/tracing/contrib/analytics.rb +0 -1
  107. data/lib/datadog/tracing/contrib/aws/configuration/settings.rb +1 -0
  108. data/lib/datadog/tracing/contrib/aws/ext.rb +1 -0
  109. data/lib/datadog/tracing/contrib/concurrent_ruby/async_patch.rb +20 -0
  110. data/lib/datadog/tracing/contrib/concurrent_ruby/patcher.rb +11 -1
  111. data/lib/datadog/tracing/contrib/configurable.rb +1 -1
  112. data/lib/datadog/tracing/contrib/dalli/configuration/settings.rb +1 -0
  113. data/lib/datadog/tracing/contrib/dalli/ext.rb +1 -0
  114. data/lib/datadog/tracing/contrib/delayed_job/configuration/settings.rb +1 -0
  115. data/lib/datadog/tracing/contrib/delayed_job/ext.rb +1 -0
  116. data/lib/datadog/tracing/contrib/elasticsearch/configuration/settings.rb +1 -0
  117. data/lib/datadog/tracing/contrib/elasticsearch/ext.rb +1 -0
  118. data/lib/datadog/tracing/contrib/ethon/configuration/settings.rb +1 -0
  119. data/lib/datadog/tracing/contrib/ethon/ext.rb +1 -0
  120. data/lib/datadog/tracing/contrib/excon/configuration/settings.rb +1 -0
  121. data/lib/datadog/tracing/contrib/excon/ext.rb +1 -0
  122. data/lib/datadog/tracing/contrib/extensions.rb +6 -2
  123. data/lib/datadog/tracing/contrib/faraday/configuration/settings.rb +7 -0
  124. data/lib/datadog/tracing/contrib/faraday/ext.rb +1 -0
  125. data/lib/datadog/tracing/contrib/faraday/middleware.rb +1 -1
  126. data/lib/datadog/tracing/contrib/grape/configuration/settings.rb +1 -0
  127. data/lib/datadog/tracing/contrib/grape/ext.rb +1 -0
  128. data/lib/datadog/tracing/contrib/graphql/configuration/settings.rb +1 -0
  129. data/lib/datadog/tracing/contrib/graphql/ext.rb +1 -0
  130. data/lib/datadog/tracing/contrib/grpc/configuration/settings.rb +1 -0
  131. data/lib/datadog/tracing/contrib/grpc/ext.rb +1 -0
  132. data/lib/datadog/tracing/contrib/http/configuration/settings.rb +1 -0
  133. data/lib/datadog/tracing/contrib/http/distributed/fetcher.rb +2 -2
  134. data/lib/datadog/tracing/contrib/http/ext.rb +1 -0
  135. data/lib/datadog/tracing/contrib/httpclient/configuration/settings.rb +1 -0
  136. data/lib/datadog/tracing/contrib/httpclient/ext.rb +1 -0
  137. data/lib/datadog/tracing/contrib/httprb/configuration/settings.rb +1 -0
  138. data/lib/datadog/tracing/contrib/httprb/ext.rb +1 -0
  139. data/lib/datadog/tracing/contrib/kafka/configuration/settings.rb +1 -0
  140. data/lib/datadog/tracing/contrib/kafka/ext.rb +1 -0
  141. data/lib/datadog/tracing/contrib/mongodb/configuration/settings.rb +1 -0
  142. data/lib/datadog/tracing/contrib/mongodb/ext.rb +1 -0
  143. data/lib/datadog/tracing/contrib/mysql2/configuration/settings.rb +5 -0
  144. data/lib/datadog/tracing/contrib/mysql2/ext.rb +1 -0
  145. data/lib/datadog/tracing/contrib/mysql2/instrumentation.rb +2 -1
  146. data/lib/datadog/tracing/contrib/opensearch/configuration/settings.rb +1 -0
  147. data/lib/datadog/tracing/contrib/opensearch/ext.rb +1 -0
  148. data/lib/datadog/tracing/contrib/pg/configuration/settings.rb +1 -0
  149. data/lib/datadog/tracing/contrib/pg/ext.rb +1 -0
  150. data/lib/datadog/tracing/contrib/pg/instrumentation.rb +11 -4
  151. data/lib/datadog/tracing/contrib/presto/configuration/settings.rb +1 -0
  152. data/lib/datadog/tracing/contrib/presto/ext.rb +1 -0
  153. data/lib/datadog/tracing/contrib/qless/configuration/settings.rb +1 -0
  154. data/lib/datadog/tracing/contrib/qless/ext.rb +1 -0
  155. data/lib/datadog/tracing/contrib/que/configuration/settings.rb +1 -0
  156. data/lib/datadog/tracing/contrib/que/ext.rb +1 -0
  157. data/lib/datadog/tracing/contrib/racecar/configuration/settings.rb +1 -0
  158. data/lib/datadog/tracing/contrib/racecar/ext.rb +1 -0
  159. data/lib/datadog/tracing/contrib/rack/configuration/settings.rb +1 -0
  160. data/lib/datadog/tracing/contrib/rack/ext.rb +1 -0
  161. data/lib/datadog/tracing/contrib/rack/middlewares.rb +9 -2
  162. data/lib/datadog/tracing/contrib/rails/auto_instrument_railtie.rb +0 -2
  163. data/lib/datadog/tracing/contrib/rails/configuration/settings.rb +1 -0
  164. data/lib/datadog/tracing/contrib/rails/ext.rb +1 -0
  165. data/lib/datadog/tracing/contrib/rake/configuration/settings.rb +1 -0
  166. data/lib/datadog/tracing/contrib/rake/ext.rb +1 -0
  167. data/lib/datadog/tracing/contrib/redis/configuration/settings.rb +1 -0
  168. data/lib/datadog/tracing/contrib/redis/ext.rb +1 -0
  169. data/lib/datadog/tracing/contrib/redis/instrumentation.rb +2 -2
  170. data/lib/datadog/tracing/contrib/redis/patcher.rb +34 -21
  171. data/lib/datadog/tracing/contrib/resque/configuration/settings.rb +1 -0
  172. data/lib/datadog/tracing/contrib/resque/ext.rb +1 -0
  173. data/lib/datadog/tracing/contrib/rest_client/configuration/settings.rb +1 -0
  174. data/lib/datadog/tracing/contrib/rest_client/ext.rb +1 -0
  175. data/lib/datadog/tracing/contrib/roda/configuration/settings.rb +1 -0
  176. data/lib/datadog/tracing/contrib/roda/ext.rb +1 -0
  177. data/lib/datadog/tracing/contrib/sequel/configuration/settings.rb +1 -0
  178. data/lib/datadog/tracing/contrib/sequel/ext.rb +1 -0
  179. data/lib/datadog/tracing/contrib/shoryuken/configuration/settings.rb +1 -0
  180. data/lib/datadog/tracing/contrib/shoryuken/ext.rb +1 -0
  181. data/lib/datadog/tracing/contrib/sidekiq/configuration/settings.rb +1 -0
  182. data/lib/datadog/tracing/contrib/sidekiq/ext.rb +1 -0
  183. data/lib/datadog/tracing/contrib/sinatra/configuration/settings.rb +1 -0
  184. data/lib/datadog/tracing/contrib/sinatra/ext.rb +1 -0
  185. data/lib/datadog/tracing/contrib/sneakers/configuration/settings.rb +1 -0
  186. data/lib/datadog/tracing/contrib/sneakers/ext.rb +1 -0
  187. data/lib/datadog/tracing/contrib/stripe/configuration/settings.rb +1 -0
  188. data/lib/datadog/tracing/contrib/stripe/ext.rb +1 -0
  189. data/lib/datadog/tracing/contrib/sucker_punch/configuration/settings.rb +1 -0
  190. data/lib/datadog/tracing/contrib/sucker_punch/ext.rb +1 -0
  191. data/lib/datadog/tracing/contrib/trilogy/configuration/settings.rb +58 -0
  192. data/lib/datadog/tracing/contrib/trilogy/ext.rb +27 -0
  193. data/lib/datadog/tracing/contrib/trilogy/instrumentation.rb +94 -0
  194. data/lib/datadog/tracing/contrib/trilogy/integration.rb +43 -0
  195. data/lib/datadog/tracing/contrib/trilogy/patcher.rb +31 -0
  196. data/lib/datadog/tracing/contrib.rb +1 -0
  197. data/lib/datadog/tracing/sampling/matcher.rb +23 -3
  198. data/lib/datadog/tracing/sampling/rule.rb +7 -2
  199. data/lib/datadog/tracing/sampling/rule_sampler.rb +2 -0
  200. data/lib/datadog/tracing/trace_operation.rb +1 -2
  201. data/lib/datadog/tracing/transport/http.rb +1 -0
  202. data/lib/datadog/tracing/transport/trace_formatter.rb +31 -0
  203. data/lib/datadog/tracing.rb +8 -2
  204. data/lib/ddtrace/version.rb +2 -2
  205. metadata +71 -61
  206. data/ext/ddtrace_profiling_native_extension/pid_controller.c +0 -57
  207. data/ext/ddtrace_profiling_native_extension/pid_controller.h +0 -45
  208. data/ext/ddtrace_profiling_native_extension/ruby_helpers.c +0 -110
  209. data/lib/datadog/core/telemetry/collector.rb +0 -240
  210. data/lib/datadog/core/telemetry/v1/app_event.rb +0 -52
  211. data/lib/datadog/core/telemetry/v1/application.rb +0 -92
  212. data/lib/datadog/core/telemetry/v1/configuration.rb +0 -25
  213. data/lib/datadog/core/telemetry/v1/dependency.rb +0 -43
  214. data/lib/datadog/core/telemetry/v1/host.rb +0 -59
  215. data/lib/datadog/core/telemetry/v1/integration.rb +0 -64
  216. data/lib/datadog/core/telemetry/v1/product.rb +0 -36
  217. data/lib/datadog/core/telemetry/v1/telemetry_request.rb +0 -106
  218. data/lib/datadog/core/telemetry/v2/app_client_configuration_change.rb +0 -41
  219. data/lib/datadog/core/telemetry/v2/request.rb +0 -29
  220. data/lib/datadog/profiling/diagnostics/environment_logger.rb +0 -39
  221. /data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/NativeExtensionDesign.md +0 -0
  222. /data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/clock_id.h +0 -0
  223. /data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/clock_id_from_pthread.c +0 -0
  224. /data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/clock_id_noop.c +0 -0
  225. /data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/collectors_idle_sampling_helper.c +0 -0
  226. /data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/collectors_idle_sampling_helper.h +0 -0
  227. /data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/setup_signal_handler.c +0 -0
  228. /data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/setup_signal_handler.h +0 -0
  229. /data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/time_helpers.c +0 -0
@@ -0,0 +1,166 @@
1
+ #pragma once
2
+
3
+ #include <datadog/profiling.h>
4
+ #include <ruby.h>
5
+
6
+ // A heap recorder keeps track of a collection of live heap objects.
7
+ //
8
+ // All allocations observed by this recorder for which a corresponding free was
9
+ // not yet observed are deemed as alive and can be iterated on to produce a
10
+ // live heap profile.
11
+ //
12
+ // NOTE: All public APIs of heap_recorder support receiving a NULL heap_recorder
13
+ // in which case the behaviour will be a noop.
14
+ //
15
+ // WARN: Unless otherwise stated the heap recorder APIs assume calls are done
16
+ // under the GVL.
17
+ typedef struct heap_recorder heap_recorder;
18
+
19
+ // Extra data associated with each live object being tracked.
20
+ typedef struct live_object_data {
21
+ // The weight of this object from a sampling perspective.
22
+ //
23
+ // A notion of weight is preserved for each tracked object to allow for an approximate
24
+ // extrapolation to an unsampled view.
25
+ //
26
+ // Example: If we were sampling every 50 objects, then each sampled object
27
+ // could be seen as being representative of 50 objects.
28
+ unsigned int weight;
29
+
30
+ // Size of this object in memory.
31
+ // NOTE: This only gets updated during heap_recorder_prepare_iteration and only
32
+ // for those objects that meet the minimum iteration age requirements.
33
+ size_t size;
34
+
35
+ // The class of the object that we're tracking.
36
+ // NOTE: This is optional and will be set to NULL if not set.
37
+ char* class;
38
+
39
+ // The GC allocation gen in which we saw this object being allocated.
40
+ //
41
+ // This enables us to calculate the age of this object in terms of GC executions.
42
+ size_t alloc_gen;
43
+
44
+ // The age of this object in terms of GC generations.
45
+ // NOTE: This only gets updated during heap_recorder_prepare_iteration
46
+ size_t gen_age;
47
+
48
+ // Whether this object was previously seen as being frozen. If this is the case,
49
+ // we'll skip any further size updates since frozen objects are supposed to be
50
+ // immutable.
51
+ bool is_frozen;
52
+ } live_object_data;
53
+
54
+ // Data that is made available to iterators of heap recorder data for each live object
55
+ // tracked therein.
56
+ typedef struct {
57
+ ddog_prof_Slice_Location locations;
58
+ live_object_data object_data;
59
+ } heap_recorder_iteration_data;
60
+
61
+ // Initialize a new heap recorder.
62
+ heap_recorder* heap_recorder_new(void);
63
+
64
+ // Free a previously initialized heap recorder.
65
+ void heap_recorder_free(heap_recorder *heap_recorder);
66
+
67
+ // Sets whether this heap recorder should keep track of sizes or not.
68
+ //
69
+ // If set to true, the heap recorder will attempt to determine the approximate sizes of
70
+ // tracked objects and wield them during iteration.
71
+ // If set to false, sizes returned during iteration should not be used/relied on (they
72
+ // may be 0 or the last determined size before disabling the tracking of sizes).
73
+ //
74
+ // NOTE: Default is true, i.e., it will attempt to determine approximate sizes of tracked
75
+ // objects.
76
+ void heap_recorder_set_size_enabled(heap_recorder *heap_recorder, bool size_enabled);
77
+
78
+ // Set sample rate used by this heap recorder.
79
+ //
80
+ // Controls how many recordings will be ignored before committing a heap allocation and
81
+ // the weight of the committed heap allocation.
82
+ //
83
+ // A value of 1 will effectively track all objects that are passed through
84
+ // start/end_heap_allocation_recording pairs. A value of 10 will only track every 10th
85
+ // object passed through such calls and its effective weight for the purposes of heap
86
+ // profiling will be multiplied by 10.
87
+ //
88
+ // NOTE: Default is 1, i.e., track all heap allocation recordings.
89
+ //
90
+ // WARN: Non-positive values will lead to an exception being thrown.
91
+ void heap_recorder_set_sample_rate(heap_recorder *heap_recorder, int sample_rate);
92
+
93
+ // Do any cleanup needed after forking.
94
+ // WARN: Assumes this gets called before profiler is reinitialized on the fork
95
+ void heap_recorder_after_fork(heap_recorder *heap_recorder);
96
+
97
+ // Start a heap allocation recording on the heap recorder for a new object.
98
+ //
99
+ // This heap allocation recording needs to be ended via ::end_heap_allocation_recording
100
+ // before it will become fully committed and able to be iterated on.
101
+ //
102
+ // @param new_obj
103
+ // The newly allocated Ruby object/value.
104
+ // @param weight
105
+ // The sampling weight of this object.
106
+ //
107
+ // WARN: It needs to be paired with a ::end_heap_allocation_recording call.
108
+ void start_heap_allocation_recording(heap_recorder *heap_recorder, VALUE new_obj, unsigned int weight, ddog_CharSlice *alloc_class);
109
+
110
+ // End a previously started heap allocation recording on the heap recorder.
111
+ //
112
+ // It is at this point that an allocated object will become fully tracked and able to be iterated on.
113
+ //
114
+ // @param locations The stacktrace representing the location of the allocation.
115
+ //
116
+ // WARN: It is illegal to call this without previously having called ::start_heap_allocation_recording.
117
+ void end_heap_allocation_recording(heap_recorder *heap_recorder, ddog_prof_Slice_Location locations);
118
+
119
+ // Update the heap recorder to reflect the latest state of the VM and prepare internal structures
120
+ // for efficient iteration.
121
+ //
122
+ // WARN: This must be called strictly before iteration. Failing to do so will result in exceptions.
123
+ void heap_recorder_prepare_iteration(heap_recorder *heap_recorder);
124
+
125
+ // Optimize the heap recorder by cleaning up any data that might have been prepared specifically
126
+ // for the purpose of iterating over the heap recorder data.
127
+ //
128
+ // WARN: This must be called strictly after iteration to ensure proper cleanup and to keep the memory
129
+ // profile of the heap recorder low.
130
+ void heap_recorder_finish_iteration(heap_recorder *heap_recorder);
131
+
132
+ // Iterate over each live object being tracked by the heap recorder.
133
+ //
134
+ // NOTE: Iteration can be called without holding the Ruby Global VM lock.
135
+ // WARN: This must be called strictly after heap_recorder_prepare_iteration and before
136
+ // heap_recorder_finish_iteration.
137
+ //
138
+ // @param for_each_callback
139
+ // A callback function that shall be called for each live object being tracked
140
+ // by the heap recorder. Alongside the iteration_data for each live object,
141
+ // a second argument will be forwarded with the contents of the optional
142
+ // for_each_callback_extra_arg. Iteration will continue until the callback
143
+ // returns false or we run out of objects.
144
+ // @param for_each_callback_extra_arg
145
+ // Optional (NULL if empty) extra data that should be passed to the
146
+ // callback function alongside the data for each live tracked object.
147
+ // @return true if iteration ran, false if something prevented it from running.
148
+ bool heap_recorder_for_each_live_object(
149
+ heap_recorder *heap_recorder,
150
+ bool (*for_each_callback)(heap_recorder_iteration_data data, void* extra_arg),
151
+ void *for_each_callback_extra_arg);
152
+
153
+ // Return a Ruby hash containing a snapshot of this recorder's interesting state at calling time.
154
+ // WARN: This allocates in the Ruby VM and therefore should not be called without the
155
+ // VM lock or during GC.
156
+ VALUE heap_recorder_state_snapshot(heap_recorder *heap_recorder);
157
+
158
+ // v--- TEST-ONLY APIs ---v
159
+
160
+ // Assert internal hashing logic is valid for the provided locations and its
161
+ // corresponding internal representations in heap recorder.
162
+ void heap_recorder_testonly_assert_hash_matches(ddog_prof_Slice_Location locations);
163
+
164
+ // Returns a Ruby string with a representation of internal data helpful to
165
+ // troubleshoot issues such as unexpected test failures.
166
+ VALUE heap_recorder_testonly_debug(heap_recorder *heap_recorder);
@@ -1,5 +1,7 @@
1
1
  #pragma once
2
2
 
3
+ #include <stdint.h>
4
+
3
5
  // Used to mark symbols to be exported to the outside of the extension.
4
6
  // Consider very carefully before tagging a function with this.
5
7
  #define DDTRACE_EXPORT __attribute__ ((visibility ("default")))
@@ -15,3 +17,7 @@
15
17
  // don't like C and I just implemented this as a function.
16
18
  inline static uint64_t uint64_max_of(uint64_t a, uint64_t b) { return a > b ? a : b; }
17
19
  inline static uint64_t uint64_min_of(uint64_t a, uint64_t b) { return a > b ? b : a; }
20
+ inline static long long_max_of(long a, long b) { return a > b ? a : b; }
21
+ inline static long long_min_of(long a, long b) { return a > b ? b : a; }
22
+ inline static double double_max_of(double a, double b) { return a > b ? a : b; }
23
+ inline static double double_min_of(double a, double b) { return a > b ? b : a; }
@@ -30,7 +30,7 @@ inline static ddog_ByteSlice byte_slice_from_ruby_string(VALUE string);
30
30
  static VALUE _native_validate_exporter(VALUE self, VALUE exporter_configuration);
31
31
  static ddog_prof_Exporter_NewResult create_exporter(VALUE exporter_configuration, VALUE tags_as_array);
32
32
  static VALUE handle_exporter_failure(ddog_prof_Exporter_NewResult exporter_result);
33
- static ddog_Endpoint endpoint_from(VALUE exporter_configuration);
33
+ static ddog_prof_Endpoint endpoint_from(VALUE exporter_configuration);
34
34
  static ddog_Vec_Tag convert_tags(VALUE tags_as_array);
35
35
  static void safely_log_failure_to_process_tag(ddog_Vec_Tag tags, VALUE err_details);
36
36
  static VALUE _native_do_export(
@@ -46,17 +46,17 @@ static VALUE _native_do_export(
46
46
  VALUE code_provenance_file_name,
47
47
  VALUE code_provenance_data,
48
48
  VALUE tags_as_array,
49
- VALUE internal_metadata_json
49
+ VALUE internal_metadata_json,
50
+ VALUE info_json
50
51
  );
51
52
  static void *call_exporter_without_gvl(void *call_args);
52
53
  static void interrupt_exporter_call(void *cancel_token);
53
- static VALUE ddtrace_version(void);
54
54
 
55
55
  void http_transport_init(VALUE profiling_module) {
56
56
  VALUE http_transport_class = rb_define_class_under(profiling_module, "HttpTransport", rb_cObject);
57
57
 
58
58
  rb_define_singleton_method(http_transport_class, "_native_validate_exporter", _native_validate_exporter, 1);
59
- rb_define_singleton_method(http_transport_class, "_native_do_export", _native_do_export, 12);
59
+ rb_define_singleton_method(http_transport_class, "_native_do_export", _native_do_export, 13);
60
60
 
61
61
  ok_symbol = ID2SYM(rb_intern_const("ok"));
62
62
  error_symbol = ID2SYM(rb_intern_const("error"));
@@ -94,7 +94,7 @@ static ddog_prof_Exporter_NewResult create_exporter(VALUE exporter_configuration
94
94
 
95
95
  // This needs to be called BEFORE convert_tags since it can raise an exception and thus cause the ddog_Vec_Tag
96
96
  // to be leaked.
97
- ddog_Endpoint endpoint = endpoint_from(exporter_configuration);
97
+ ddog_prof_Endpoint endpoint = endpoint_from(exporter_configuration);
98
98
 
99
99
  ddog_Vec_Tag tags = convert_tags(tags_as_array);
100
100
 
@@ -116,7 +116,7 @@ static VALUE handle_exporter_failure(ddog_prof_Exporter_NewResult exporter_resul
116
116
  rb_ary_new_from_args(2, error_symbol, get_error_details_and_drop(&exporter_result.err));
117
117
  }
118
118
 
119
- static ddog_Endpoint endpoint_from(VALUE exporter_configuration) {
119
+ static ddog_prof_Endpoint endpoint_from(VALUE exporter_configuration) {
120
120
  ENFORCE_TYPE(exporter_configuration, T_ARRAY);
121
121
 
122
122
  ID working_mode = SYM2ID(rb_ary_entry(exporter_configuration, 0)); // SYM2ID verifies its input so we can do this safely
@@ -131,12 +131,12 @@ static ddog_Endpoint endpoint_from(VALUE exporter_configuration) {
131
131
  ENFORCE_TYPE(site, T_STRING);
132
132
  ENFORCE_TYPE(api_key, T_STRING);
133
133
 
134
- return ddog_Endpoint_agentless(char_slice_from_ruby_string(site), char_slice_from_ruby_string(api_key));
134
+ return ddog_prof_Endpoint_agentless(char_slice_from_ruby_string(site), char_slice_from_ruby_string(api_key));
135
135
  } else { // agent_id
136
136
  VALUE base_url = rb_ary_entry(exporter_configuration, 1);
137
137
  ENFORCE_TYPE(base_url, T_STRING);
138
138
 
139
- return ddog_Endpoint_agent(char_slice_from_ruby_string(base_url));
139
+ return ddog_prof_Endpoint_agent(char_slice_from_ruby_string(base_url));
140
140
  }
141
141
  }
142
142
 
@@ -208,6 +208,7 @@ static VALUE perform_export(
208
208
  ddog_prof_Exporter_Slice_File files_to_export_unmodified,
209
209
  ddog_Vec_Tag *additional_tags,
210
210
  ddog_CharSlice internal_metadata,
211
+ ddog_CharSlice info,
211
212
  uint64_t timeout_milliseconds
212
213
  ) {
213
214
  ddog_prof_ProfiledEndpointsStats *endpoints_stats = NULL; // Not in use yet
@@ -220,6 +221,7 @@ static VALUE perform_export(
220
221
  additional_tags,
221
222
  endpoints_stats,
222
223
  &internal_metadata,
224
+ &info,
223
225
  timeout_milliseconds
224
226
  );
225
227
 
@@ -290,7 +292,8 @@ static VALUE _native_do_export(
290
292
  VALUE code_provenance_file_name,
291
293
  VALUE code_provenance_data,
292
294
  VALUE tags_as_array,
293
- VALUE internal_metadata_json
295
+ VALUE internal_metadata_json,
296
+ VALUE info_json
294
297
  ) {
295
298
  ENFORCE_TYPE(upload_timeout_milliseconds, T_FIXNUM);
296
299
  ENFORCE_TYPE(start_timespec_seconds, T_FIXNUM);
@@ -301,6 +304,7 @@ static VALUE _native_do_export(
301
304
  ENFORCE_TYPE(pprof_data, T_STRING);
302
305
  ENFORCE_TYPE(code_provenance_file_name, T_STRING);
303
306
  ENFORCE_TYPE(internal_metadata_json, T_STRING);
307
+ ENFORCE_TYPE(info_json, T_STRING);
304
308
 
305
309
  // Code provenance can be disabled and in that case will be set to nil
306
310
  bool have_code_provenance = !NIL_P(code_provenance_data);
@@ -335,6 +339,7 @@ static VALUE _native_do_export(
335
339
 
336
340
  ddog_Vec_Tag *null_additional_tags = NULL;
337
341
  ddog_CharSlice internal_metadata = char_slice_from_ruby_string(internal_metadata_json);
342
+ ddog_CharSlice info = char_slice_from_ruby_string(info_json);
338
343
 
339
344
  ddog_prof_Exporter_NewResult exporter_result = create_exporter(exporter_configuration, tags_as_array);
340
345
  // Note: Do not add anything that can raise exceptions after this line, as otherwise the exporter memory will leak
@@ -350,6 +355,7 @@ static VALUE _native_do_export(
350
355
  files_to_export_unmodified,
351
356
  null_additional_tags,
352
357
  internal_metadata,
358
+ info,
353
359
  timeout_milliseconds
354
360
  );
355
361
  }
@@ -367,13 +373,3 @@ static void *call_exporter_without_gvl(void *call_args) {
367
373
  static void interrupt_exporter_call(void *cancel_token) {
368
374
  ddog_CancellationToken_cancel((ddog_CancellationToken *) cancel_token);
369
375
  }
370
-
371
- static VALUE ddtrace_version(void) {
372
- VALUE ddtrace_module = rb_const_get(rb_cObject, rb_intern("DDTrace"));
373
- ENFORCE_TYPE(ddtrace_module, T_MODULE);
374
- VALUE version_module = rb_const_get(ddtrace_module, rb_intern("VERSION"));
375
- ENFORCE_TYPE(version_module, T_MODULE);
376
- VALUE version_string = rb_const_get(version_module, rb_intern("STRING"));
377
- ENFORCE_TYPE(version_string, T_STRING);
378
- return version_string;
379
- }
@@ -40,3 +40,23 @@ ddog_CharSlice ruby_value_type_to_char_slice(enum ruby_value_type type) {
40
40
  default: return DDOG_CHARSLICE_C("BUG: Unknown value for ruby_value_type");
41
41
  }
42
42
  }
43
+
44
+ size_t read_ddogerr_string_and_drop(ddog_Error *error, char *string, size_t capacity) {
45
+ if (capacity == 0 || string == NULL) {
46
+ // short-circuit, we can't write anything
47
+ ddog_Error_drop(error);
48
+ return 0;
49
+ }
50
+
51
+ ddog_CharSlice error_msg_slice = ddog_Error_message(error);
52
+ size_t error_msg_size = error_msg_slice.len;
53
+ // Account for extra null char for proper cstring
54
+ if (error_msg_size >= capacity) {
55
+ // Error message too big, lets truncate it to capacity - 1 to allow for extra null at end
56
+ error_msg_size = capacity - 1;
57
+ }
58
+ strncpy(string, error_msg_slice.ptr, error_msg_size);
59
+ string[error_msg_size] = '\0';
60
+ ddog_Error_drop(error);
61
+ return error_msg_size;
62
+ }
@@ -24,8 +24,19 @@ inline static VALUE get_error_details_and_drop(ddog_Error *error) {
24
24
  return result;
25
25
  }
26
26
 
27
+ // Utility function to be able to extract an error cstring from a ddog_Error.
28
+ // Returns the amount of characters written to string (which are necessarily
29
+ // bounded by capacity - 1 since the string will be null-terminated).
30
+ size_t read_ddogerr_string_and_drop(ddog_Error *error, char *string, size_t capacity);
31
+
27
32
  // Used for pretty printing this Ruby enum. Returns "T_UNKNOWN_OR_MISSING_RUBY_VALUE_TYPE_ENTRY" for unknown elements.
28
33
  // In practice, there's a few types that the profiler will probably never encounter, but I've added all entries of
29
34
  // ruby_value_type that Ruby uses so that we can also use this for debugging.
30
35
  const char *ruby_value_type_to_string(enum ruby_value_type type);
31
36
  ddog_CharSlice ruby_value_type_to_char_slice(enum ruby_value_type type);
37
+
38
+ // Returns a dynamically allocated string from the provided char slice.
39
+ // WARN: The returned string must be explicitly freed with ruby_xfree.
40
+ inline static char* string_from_char_slice(ddog_CharSlice slice) {
41
+ return ruby_strndup(slice.ptr, slice.len);
42
+ }
@@ -15,7 +15,7 @@ module Datadog
15
15
  # The MJIT header was introduced on 2.6 and removed on 3.3; for other Rubies we rely on debase-ruby_core_source
16
16
  CAN_USE_MJIT_HEADER = RUBY_VERSION.start_with?('2.6', '2.7', '3.0.', '3.1.', '3.2.')
17
17
 
18
- LIBDATADOG_VERSION = '~> 5.0.0.1.0'
18
+ LIBDATADOG_VERSION = '~> 7.0.0.1.0'
19
19
 
20
20
  def self.fail_install_if_missing_extension?
21
21
  ENV[ENV_FAIL_INSTALL_IF_MISSING_EXTENSION].to_s.strip.downcase == 'true'
@@ -29,7 +29,7 @@ module Datadog
29
29
  # native extension), we need to add a "runpath" -- a list of folders to search for libdatadog.
30
30
  #
31
31
  # This runpath gets hardcoded at native library linking time. You can look at it using the `readelf` tool in
32
- # Linux: e.g. `readelf -d ddtrace_profiling_native_extension.2.7.3_x86_64-linux.so`.
32
+ # Linux: e.g. `readelf -d datadog_profiling_native_extension.2.7.3_x86_64-linux.so`.
33
33
  #
34
34
  # In older versions of ddtrace, we only set as runpath an absolute path to libdatadog.
35
35
  # (This gets set automatically by the call
@@ -67,6 +67,52 @@ module Datadog
67
67
  Pathname.new(libdatadog_lib_folder).relative_path_from(Pathname.new(profiling_native_lib_folder)).to_s
68
68
  end
69
69
 
70
+ # In https://github.com/DataDog/dd-trace-rb/pull/3582 we got a report of a customer for which the native extension
71
+ # only got installed into the extensions folder.
72
+ #
73
+ # But then this fix was not enough to fully get them moving because then they started to see the issue from
74
+ # https://github.com/DataDog/dd-trace-rb/issues/2067 / https://github.com/DataDog/dd-trace-rb/pull/2125 :
75
+ #
76
+ # > Profiling was requested but is not supported, profiling disabled: There was an error loading the profiling
77
+ # > native extension due to 'RuntimeError Failure to load datadog_profiling_native_extension.3.2.2_x86_64-linux
78
+ # > due to libdatadog_profiling.so: cannot open shared object file: No such file or directory
79
+ #
80
+ # The problem is that when loading the native extension from the extensions directory, the relative rpath we add
81
+ # with the #libdatadog_folder_relative_to_native_lib_folder helper above is not correct, we need to add a relative
82
+ # rpath to the extensions directory.
83
+ #
84
+ # So how do we find the full path where the native extension is placed?
85
+ # * From https://github.com/ruby/ruby/blob/83f02d42e0a3c39661dc99c049ab9a70ff227d5b/lib/bundler/runtime.rb#L166
86
+ # `extension_dirs = Dir["#{Gem.dir}/extensions/*/*/*"] + Dir["#{Gem.dir}/bundler/gems/extensions/*/*/*"]`
87
+ # we get that's in one of two fixed subdirectories of `Gem.dir`
88
+ # * From https://github.com/ruby/ruby/blob/83f02d42e0a3c39661dc99c049ab9a70ff227d5b/lib/rubygems/basic_specification.rb#L111-L115
89
+ # we get the structure of the subdirectory (platform/extension_api_version/gem_and_version)
90
+ #
91
+ # Thus, `Gem.dir` of `/var/app/current/vendor/bundle/ruby/3.2.0` becomes (for instance)
92
+ # `/var/app/current/vendor/bundle/ruby/3.2.0/extensions/x86_64-linux/3.2.0/datadog-2.0.0/` or
93
+ # `/var/app/current/vendor/bundle/ruby/3.2.0/bundler/gems/extensions/x86_64-linux/3.2.0/datadog-2.0.0/`
94
+ #
95
+ # We then compute the relative path between these folders and the libdatadog folder, and use that as a relative path.
96
+ def self.libdatadog_folder_relative_to_ruby_extensions_folders(
97
+ gem_dir: Gem.dir,
98
+ libdatadog_pkgconfig_folder: Libdatadog.pkgconfig_folder
99
+ )
100
+ return unless libdatadog_pkgconfig_folder
101
+
102
+ # For the purposes of calculating a folder relative to the other, we don't actually NEED to fill in the
103
+ # platform, extension_api_version and gem version. We're basically just after how many folders it is deep from
104
+ # the Gem.dir.
105
+ expected_ruby_extensions_folders = [
106
+ "#{gem_dir}/extensions/platform/extension_api_version/datadog_version/",
107
+ "#{gem_dir}/bundler/gems/extensions/platform/extension_api_version/datadog_version/",
108
+ ]
109
+ libdatadog_lib_folder = "#{libdatadog_pkgconfig_folder}/../"
110
+
111
+ expected_ruby_extensions_folders.map do |folder|
112
+ Pathname.new(libdatadog_lib_folder).relative_path_from(Pathname.new(folder)).to_s
113
+ end
114
+ end
115
+
70
116
  # Used to check if profiler is supported, including user-visible clear messages explaining why their
71
117
  # system may not be supported.
72
118
  module Supported
@@ -305,8 +351,8 @@ module Datadog
305
351
  no_binaries_for_current_platform = explain_issue(
306
352
  'the `libdatadog` gem installed on your system is missing binaries for your',
307
353
  'platform variant.',
308
- "(Your platform: `#{Gem::Platform.local}`)",
309
- '(Available binaries: ',
354
+ "(Your platform: `#{Libdatadog.current_platform}`)",
355
+ '(Available binaries:',
310
356
  "`#{Libdatadog.available_binaries.join('`, `')}`)",
311
357
  suggested: CONTACT_SUPPORT,
312
358
  )
@@ -471,6 +471,11 @@ int ddtrace_rb_profile_frames(VALUE thread, int start, int limit, VALUE *buff, i
471
471
  // it from https://github.com/ruby/ruby/pull/7116 in a "just in case" kind of mindset.
472
472
  if (cfp == NULL) return 0;
473
473
 
474
+ // As of this writing, we don't support profiling with MN enabled, and this only happens in that mode, but as we
475
+ // probably want to experiment with it in the future, I've decided to import https://github.com/ruby/ruby/pull/9310
476
+ // here.
477
+ if (ec == NULL) return 0;
478
+
474
479
  // Fix: Skip dummy frame that shows up in main thread.
475
480
  //
476
481
  // According to a comment in `backtrace_each` (`vm_backtrace.c`), there's two dummy frames that we should ignore
@@ -871,3 +876,17 @@ static inline int ddtrace_imemo_type(VALUE imemo) {
871
876
  return NULL;
872
877
  }
873
878
  #endif
879
+
880
+ // This is used to workaround a VM bug. See "handle_sampling_signal" in "collectors_cpu_and_wall_time_worker" for details.
881
+ #ifdef NO_POSTPONED_TRIGGER
882
+ void *objspace_ptr_for_gc_finalize_deferred_workaround(void) {
883
+ rb_vm_t *vm =
884
+ #ifndef NO_GET_VM // TODO: Inline GET_VM below once we drop support in dd-trace-rb 2.x for < Ruby 2.5
885
+ GET_VM();
886
+ #else
887
+ thread_struct_from_object(rb_thread_current())->vm;
888
+ #endif
889
+
890
+ return vm->objspace;
891
+ }
892
+ #endif
@@ -55,3 +55,7 @@ void self_test_mn_enabled(void);
55
55
 
56
56
  // Provides more specific information on what kind an imemo is
57
57
  const char *imemo_kind(VALUE imemo);
58
+
59
+ #ifdef NO_POSTPONED_TRIGGER
60
+ void *objspace_ptr_for_gc_finalize_deferred_workaround(void);
61
+ #endif
@@ -1,6 +1,9 @@
1
1
  #include <ruby.h>
2
2
  #include <ruby/thread.h>
3
3
  #include <errno.h>
4
+ #ifdef HAVE_MALLOC_STATS
5
+ #include <malloc.h>
6
+ #endif
4
7
 
5
8
  #include "clock_id.h"
6
9
  #include "helpers.h"
@@ -11,6 +14,7 @@
11
14
 
12
15
  // Each class/module here is implemented in their separate file
13
16
  void collectors_cpu_and_wall_time_worker_init(VALUE profiling_module);
17
+ void collectors_discrete_dynamic_sampler_init(VALUE profiling_module);
14
18
  void collectors_dynamic_sampling_rate_init(VALUE profiling_module);
15
19
  void collectors_idle_sampling_helper_init(VALUE profiling_module);
16
20
  void collectors_stack_init(VALUE profiling_module);
@@ -32,8 +36,9 @@ static void holding_the_gvl_signal_handler(DDTRACE_UNUSED int _signal, DDTRACE_U
32
36
  static VALUE _native_trigger_holding_the_gvl_signal_handler_on(DDTRACE_UNUSED VALUE _self, VALUE background_thread);
33
37
  static VALUE _native_enforce_success(DDTRACE_UNUSED VALUE _self, VALUE syserr_errno, VALUE with_gvl);
34
38
  static void *trigger_enforce_success(void *trigger_args);
39
+ static VALUE _native_malloc_stats(DDTRACE_UNUSED VALUE _self);
35
40
 
36
- void DDTRACE_EXPORT Init_ddtrace_profiling_native_extension(void) {
41
+ void DDTRACE_EXPORT Init_datadog_profiling_native_extension(void) {
37
42
  VALUE datadog_module = rb_define_module("Datadog");
38
43
  VALUE profiling_module = rb_define_module_under(datadog_module, "Profiling");
39
44
  VALUE native_extension_module = rb_define_module_under(profiling_module, "NativeExtension");
@@ -41,7 +46,9 @@ void DDTRACE_EXPORT Init_ddtrace_profiling_native_extension(void) {
41
46
  rb_define_singleton_method(native_extension_module, "native_working?", native_working_p, 0);
42
47
  rb_funcall(native_extension_module, rb_intern("private_class_method"), 1, ID2SYM(rb_intern("native_working?")));
43
48
 
49
+ ruby_helpers_init();
44
50
  collectors_cpu_and_wall_time_worker_init(profiling_module);
51
+ collectors_discrete_dynamic_sampler_init(profiling_module);
45
52
  collectors_dynamic_sampling_rate_init(profiling_module);
46
53
  collectors_idle_sampling_helper_init(profiling_module);
47
54
  collectors_stack_init(profiling_module);
@@ -64,6 +71,7 @@ void DDTRACE_EXPORT Init_ddtrace_profiling_native_extension(void) {
64
71
  rb_define_singleton_method(testing_module, "_native_install_holding_the_gvl_signal_handler", _native_install_holding_the_gvl_signal_handler, 0);
65
72
  rb_define_singleton_method(testing_module, "_native_trigger_holding_the_gvl_signal_handler_on", _native_trigger_holding_the_gvl_signal_handler_on, 1);
66
73
  rb_define_singleton_method(testing_module, "_native_enforce_success", _native_enforce_success, 2);
74
+ rb_define_singleton_method(testing_module, "_native_malloc_stats", _native_malloc_stats, 0);
67
75
  }
68
76
 
69
77
  static VALUE native_working_p(DDTRACE_UNUSED VALUE _self) {
@@ -248,3 +256,12 @@ static void *trigger_enforce_success(void *trigger_args) {
248
256
  ENFORCE_SUCCESS_NO_GVL(syserr_errno);
249
257
  return NULL;
250
258
  }
259
+
260
+ static VALUE _native_malloc_stats(DDTRACE_UNUSED VALUE _self) {
261
+ #ifdef HAVE_MALLOC_STATS
262
+ malloc_stats();
263
+ return Qtrue;
264
+ #else
265
+ return Qfalse;
266
+ #endif
267
+ }