Skip to content

Commit 7b22f21

Browse files
authored
Merge pull request #3856 from DataDog/ivoanjo/fix-use-of-inline
[NO-TICKET] Fix profiler `inline` helpers not working when optimization disabled
2 parents 84e92fa + 0ca54ec commit 7b22f21

9 files changed

+26
-26
lines changed

ext/datadog_profiling_native_extension/collectors_discrete_dynamic_sampler.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#define EMA_SMOOTHING_FACTOR 0.6
2222

2323
static void maybe_readjust(discrete_dynamic_sampler *sampler, long now_ns);
24-
inline bool should_readjust(discrete_dynamic_sampler *sampler, coarse_instant now);
24+
static inline bool should_readjust(discrete_dynamic_sampler *sampler, coarse_instant now);
2525

2626
void discrete_dynamic_sampler_init(discrete_dynamic_sampler *sampler, const char *debug_name, long now_ns) {
2727
sampler->debug_name = debug_name;
@@ -119,7 +119,7 @@ static void maybe_readjust(discrete_dynamic_sampler *sampler, long now_ns) {
119119
if (should_readjust(sampler, to_coarse_instant(now_ns))) discrete_dynamic_sampler_readjust(sampler, now_ns);
120120
}
121121

122-
inline bool should_readjust(discrete_dynamic_sampler *sampler, coarse_instant now) {
122+
static inline bool should_readjust(discrete_dynamic_sampler *sampler, coarse_instant now) {
123123
long this_window_time_ns =
124124
sampler->last_readjust_time_ns == 0 ? ADJUSTMENT_WINDOW_NS : now.timestamp_ns - sampler->last_readjust_time_ns;
125125

ext/datadog_profiling_native_extension/datadog_ruby_common.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ NORETURN(void raise_unexpected_type(VALUE value, const char *value_name, const c
3333
// Helper to retrieve Datadog::VERSION::STRING
3434
VALUE datadog_gem_version(void);
3535

36-
inline static ddog_CharSlice char_slice_from_ruby_string(VALUE string) {
36+
static inline ddog_CharSlice char_slice_from_ruby_string(VALUE string) {
3737
ENFORCE_TYPE(string, T_STRING);
3838
ddog_CharSlice char_slice = {.ptr = RSTRING_PTR(string), .len = RSTRING_LEN(string)};
3939
return char_slice;
@@ -45,12 +45,12 @@ ddog_prof_Endpoint endpoint_from(VALUE exporter_configuration);
4545
__attribute__((warn_unused_result))
4646
ddog_Vec_Tag convert_tags(VALUE tags_as_array);
4747

48-
inline static VALUE ruby_string_from_error(const ddog_Error *error) {
48+
static inline VALUE ruby_string_from_error(const ddog_Error *error) {
4949
ddog_CharSlice char_slice = ddog_Error_message(error);
5050
return rb_str_new(char_slice.ptr, char_slice.len);
5151
}
5252

53-
inline static VALUE get_error_details_and_drop(ddog_Error *error) {
53+
static inline VALUE get_error_details_and_drop(ddog_Error *error) {
5454
VALUE result = ruby_string_from_error(error);
5555
ddog_Error_drop(error);
5656
return result;

ext/datadog_profiling_native_extension/helpers.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
// @ivoanjo: After trying to read through https://stackoverflow.com/questions/3437404/min-and-max-in-c I decided I
66
// don't like C and I just implemented this as a function.
7-
inline static uint64_t uint64_max_of(uint64_t a, uint64_t b) { return a > b ? a : b; }
8-
inline static uint64_t uint64_min_of(uint64_t a, uint64_t b) { return a > b ? b : a; }
9-
inline static long long_max_of(long a, long b) { return a > b ? a : b; }
10-
inline static long long_min_of(long a, long b) { return a > b ? b : a; }
11-
inline static double double_max_of(double a, double b) { return a > b ? a : b; }
12-
inline static double double_min_of(double a, double b) { return a > b ? b : a; }
7+
static inline uint64_t uint64_max_of(uint64_t a, uint64_t b) { return a > b ? a : b; }
8+
static inline uint64_t uint64_min_of(uint64_t a, uint64_t b) { return a > b ? b : a; }
9+
static inline long long_max_of(long a, long b) { return a > b ? a : b; }
10+
static inline long long_min_of(long a, long b) { return a > b ? b : a; }
11+
static inline double double_max_of(double a, double b) { return a > b ? a : b; }
12+
static inline double double_min_of(double a, double b) { return a > b ? b : a; }

ext/datadog_profiling_native_extension/http_transport.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ struct call_exporter_without_gvl_arguments {
2121
bool send_ran;
2222
};
2323

24-
inline static ddog_ByteSlice byte_slice_from_ruby_string(VALUE string);
24+
static inline ddog_ByteSlice byte_slice_from_ruby_string(VALUE string);
2525
static VALUE _native_validate_exporter(VALUE self, VALUE exporter_configuration);
2626
static ddog_prof_Exporter_NewResult create_exporter(VALUE exporter_configuration, VALUE tags_as_array);
2727
static VALUE handle_exporter_failure(ddog_prof_Exporter_NewResult exporter_result);
@@ -57,7 +57,7 @@ void http_transport_init(VALUE profiling_module) {
5757
rb_global_variable(&library_version_string);
5858
}
5959

60-
inline static ddog_ByteSlice byte_slice_from_ruby_string(VALUE string) {
60+
static inline ddog_ByteSlice byte_slice_from_ruby_string(VALUE string) {
6161
ENFORCE_TYPE(string, T_STRING);
6262
ddog_ByteSlice byte_slice = {.ptr = (uint8_t *) StringValuePtr(string), .len = RSTRING_LEN(string)};
6363
return byte_slice;

ext/datadog_profiling_native_extension/libdatadog_helpers.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <datadog/profiling.h>
44
#include "ruby_helpers.h"
55

6-
inline static VALUE ruby_string_from_vec_u8(ddog_Vec_U8 string) {
6+
static inline VALUE ruby_string_from_vec_u8(ddog_Vec_U8 string) {
77
return rb_str_new((char *) string.ptr, string.len);
88
}
99

@@ -20,6 +20,6 @@ ddog_CharSlice ruby_value_type_to_char_slice(enum ruby_value_type type);
2020

2121
// Returns a dynamically allocated string from the provided char slice.
2222
// WARN: The returned string must be explicitly freed with ruby_xfree.
23-
inline static char* string_from_char_slice(ddog_CharSlice slice) {
23+
static inline char* string_from_char_slice(ddog_CharSlice slice) {
2424
return ruby_strndup(slice.ptr, slice.len);
2525
}

ext/datadog_profiling_native_extension/private_vm_api_access.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ VALUE thread_name_for(VALUE thread) {
311311
// with diagnostic stuff. See https://nelkinda.com/blog/suppress-warnings-in-gcc-and-clang/#d11e364 for details.
312312
#pragma GCC diagnostic push
313313
#pragma GCC diagnostic ignored "-Wunused-parameter"
314-
inline static int
314+
static inline int
315315
calc_pos(const rb_iseq_t *iseq, const VALUE *pc, int *lineno, int *node_id)
316316
{
317317
VM_ASSERT(iseq);
@@ -364,7 +364,7 @@ calc_pos(const rb_iseq_t *iseq, const VALUE *pc, int *lineno, int *node_id)
364364
// Copyright (C) 1993-2012 Yukihiro Matsumoto
365365
// to support our custom rb_profile_frames (see below)
366366
// Modifications: None
367-
inline static int
367+
static inline int
368368
calc_lineno(const rb_iseq_t *iseq, const VALUE *pc)
369369
{
370370
int lineno;

ext/datadog_profiling_native_extension/time_helpers.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ typedef struct {
2121

2222
#define MONOTONIC_TO_SYSTEM_EPOCH_INITIALIZER {.system_epoch_ns_reference = INVALID_TIME, .delta_to_epoch_ns = INVALID_TIME}
2323

24-
inline long retrieve_clock_as_ns(clockid_t clock_id, raise_on_failure_setting raise_on_failure) {
24+
static inline long retrieve_clock_as_ns(clockid_t clock_id, raise_on_failure_setting raise_on_failure) {
2525
struct timespec clock_value;
2626

2727
if (clock_gettime(clock_id, &clock_value) != 0) {
@@ -32,8 +32,8 @@ inline long retrieve_clock_as_ns(clockid_t clock_id, raise_on_failure_setting ra
3232
return clock_value.tv_nsec + SECONDS_AS_NS(clock_value.tv_sec);
3333
}
3434

35-
inline long monotonic_wall_time_now_ns(raise_on_failure_setting raise_on_failure) { return retrieve_clock_as_ns(CLOCK_MONOTONIC, raise_on_failure); }
36-
inline long system_epoch_time_now_ns(raise_on_failure_setting raise_on_failure) { return retrieve_clock_as_ns(CLOCK_REALTIME, raise_on_failure); }
35+
static inline long monotonic_wall_time_now_ns(raise_on_failure_setting raise_on_failure) { return retrieve_clock_as_ns(CLOCK_MONOTONIC, raise_on_failure); }
36+
static inline long system_epoch_time_now_ns(raise_on_failure_setting raise_on_failure) { return retrieve_clock_as_ns(CLOCK_REALTIME, raise_on_failure); }
3737

3838
// Coarse instants use CLOCK_MONOTONIC_COARSE on Linux which is expected to provide resolution in the millisecond range:
3939
// https://docs.redhat.com/en/documentation/red_hat_enterprise_linux_for_real_time/7/html/reference_guide/sect-posix_clocks#Using_clock_getres_to_compare_clock_resolution
@@ -43,9 +43,9 @@ typedef struct coarse_instant {
4343
long timestamp_ns;
4444
} coarse_instant;
4545

46-
inline coarse_instant to_coarse_instant(long timestamp_ns) { return (coarse_instant) {.timestamp_ns = timestamp_ns}; }
46+
static inline coarse_instant to_coarse_instant(long timestamp_ns) { return (coarse_instant) {.timestamp_ns = timestamp_ns}; }
4747

48-
inline coarse_instant monotonic_coarse_wall_time_now_ns(void) {
48+
static inline coarse_instant monotonic_coarse_wall_time_now_ns(void) {
4949
#ifdef HAVE_CLOCK_MONOTONIC_COARSE // Linux
5050
return to_coarse_instant(retrieve_clock_as_ns(CLOCK_MONOTONIC_COARSE, DO_NOT_RAISE_ON_FAILURE));
5151
#else // macOS

ext/libdatadog_api/datadog_ruby_common.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ NORETURN(void raise_unexpected_type(VALUE value, const char *value_name, const c
3333
// Helper to retrieve Datadog::VERSION::STRING
3434
VALUE datadog_gem_version(void);
3535

36-
inline static ddog_CharSlice char_slice_from_ruby_string(VALUE string) {
36+
static inline ddog_CharSlice char_slice_from_ruby_string(VALUE string) {
3737
ENFORCE_TYPE(string, T_STRING);
3838
ddog_CharSlice char_slice = {.ptr = RSTRING_PTR(string), .len = RSTRING_LEN(string)};
3939
return char_slice;
@@ -45,12 +45,12 @@ ddog_prof_Endpoint endpoint_from(VALUE exporter_configuration);
4545
__attribute__((warn_unused_result))
4646
ddog_Vec_Tag convert_tags(VALUE tags_as_array);
4747

48-
inline static VALUE ruby_string_from_error(const ddog_Error *error) {
48+
static inline VALUE ruby_string_from_error(const ddog_Error *error) {
4949
ddog_CharSlice char_slice = ddog_Error_message(error);
5050
return rb_str_new(char_slice.ptr, char_slice.len);
5151
}
5252

53-
inline static VALUE get_error_details_and_drop(ddog_Error *error) {
53+
static inline VALUE get_error_details_and_drop(ddog_Error *error) {
5454
VALUE result = ruby_string_from_error(error);
5555
ddog_Error_drop(error);
5656
return result;

ext/libdatadog_api/extconf.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def skip_building_extension!(reason)
6767

6868
if ENV['DDTRACE_DEBUG'] == 'true'
6969
$defs << '-DDD_DEBUG'
70-
CONFIG['optflags'] = '-O1'
70+
CONFIG['optflags'] = '-O0'
7171
CONFIG['debugflags'] = '-ggdb3'
7272
end
7373

0 commit comments

Comments
 (0)