Sha256: fd1805972841972b0db5914274dc68e836b2b2a6c444920006eb6688eb286a87

Contents?: true

Size: 1.85 KB

Versions: 3

Compression:

Stored size: 1.85 KB

Contents

#pragma once

#include <datadog/profiling.h>
#include "ruby_helpers.h"

inline static ddog_CharSlice char_slice_from_ruby_string(VALUE string) {
  ENFORCE_TYPE(string, T_STRING);
  ddog_CharSlice char_slice = {.ptr = StringValuePtr(string), .len = RSTRING_LEN(string)};
  return char_slice;
}

inline static VALUE ruby_string_from_vec_u8(ddog_Vec_U8 string) {
  return rb_str_new((char *) string.ptr, string.len);
}

inline static VALUE ruby_string_from_error(const ddog_Error *error) {
  ddog_CharSlice char_slice = ddog_Error_message(error);
  return rb_str_new(char_slice.ptr, char_slice.len);
}

inline static VALUE get_error_details_and_drop(ddog_Error *error) {
  VALUE result = ruby_string_from_error(error);
  ddog_Error_drop(error);
  return result;
}

// Utility function to be able to extract an error cstring from a ddog_Error.
// Returns the amount of characters written to string (which are necessarily
// bounded by capacity - 1 since the string will be null-terminated).
size_t read_ddogerr_string_and_drop(ddog_Error *error, char *string, size_t capacity);

// Used for pretty printing this Ruby enum. Returns "T_UNKNOWN_OR_MISSING_RUBY_VALUE_TYPE_ENTRY" for unknown elements.
// In practice, there's a few types that the profiler will probably never encounter, but I've added all entries of
// ruby_value_type that Ruby uses so that we can also use this for debugging.
const char *ruby_value_type_to_string(enum ruby_value_type type);
ddog_CharSlice ruby_value_type_to_char_slice(enum ruby_value_type type);

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

ddog_prof_Endpoint endpoint_from(VALUE exporter_configuration);

ddog_Vec_Tag convert_tags(VALUE tags_as_array);

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
datadog-2.2.0 ext/datadog_profiling_native_extension/libdatadog_helpers.h
datadog-2.1.0 ext/datadog_profiling_native_extension/libdatadog_helpers.h
datadog-2.0.0 ext/datadog_profiling_native_extension/libdatadog_helpers.h