Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions profiling/src/allocation/allocation_ge84.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ unsafe fn alloc_prof_prev_alloc(len: size_t) -> *mut c_void {
let alloc = tls_zend_mm_state_get!(prev_custom_mm_alloc).unwrap();
#[cfg(php_debug)]
{
return alloc(len, ptr::null(), 0, ptr::null(), 0);
alloc(len, ptr::null(), 0, ptr::null(), 0)
}
#[cfg(not(php_debug))]
alloc(len)
Expand Down Expand Up @@ -407,7 +407,7 @@ unsafe fn alloc_prof_prev_free(ptr: *mut c_void) {
let free = tls_zend_mm_state_get!(prev_custom_mm_free).unwrap();
#[cfg(php_debug)]
{
return free(ptr, core::ptr::null(), 0, core::ptr::null(), 0);
free(ptr, core::ptr::null(), 0, core::ptr::null(), 0)
}
#[cfg(not(php_debug))]
free(ptr)
Expand Down Expand Up @@ -530,7 +530,7 @@ unsafe fn alloc_prof_prev_realloc(prev_ptr: *mut c_void, len: size_t) -> *mut c_
let realloc = tls_zend_mm_state_get!(prev_custom_mm_realloc).unwrap();
#[cfg(php_debug)]
{
return realloc(prev_ptr, len, ptr::null(), 0, ptr::null(), 0);
realloc(prev_ptr, len, ptr::null(), 0, ptr::null(), 0)
}
#[cfg(not(php_debug))]
realloc(prev_ptr, len)
Expand Down
33 changes: 19 additions & 14 deletions profiling/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,26 @@ use uuid::Uuid;
/// interior null bytes and must be null terminated.
static PROFILER_NAME: &CStr = c"datadog-profiling";

// SAFETY: PROFILER_NAME is a valid utf8 string.
static PROFILER_NAME_STR: &str = match PROFILER_NAME.to_str() {
Ok(s) => s,
// Panic: we own this string and it should be UTF8 (see PROFILER_NAME above).
Err(_) => panic!(""),
};

/// Version of the profiling module and zend_extension. Must not contain any
/// interior null bytes and must be null terminated.
static PROFILER_VERSION: &[u8] = concat!(env!("PROFILER_VERSION"), "\0").as_bytes();

// SAFETY: PROFILER_VERSION is a byte slice that satisfies the safety requirements.
static PROFILER_VERSION_STR: &str = const {
match unsafe { CStr::from_ptr(PROFILER_VERSION.as_ptr() as *const c_char).to_str() } {
Ok(v) => v,
// Panic: we own this string and it should be UTF8 (see PROFILER_VERSION above).
Err(_) => panic!("PROFILER_VERSION was not a valid utf-8 string"),
}
};

/// Version ID of PHP at run-time, not the version it was built against at
/// compile-time. Its value is overwritten during minit.
static RUNTIME_PHP_VERSION_ID: AtomicU32 = AtomicU32::new(zend::PHP_VERSION_ID);
Expand Down Expand Up @@ -130,18 +146,6 @@ static SAPI: LazyLock<Sapi> = LazyLock::new(|| {
}
});

// SAFETY: PROFILER_NAME is a byte slice that satisfies the safety requirements.
// Panic: we own this string and it should be UTF8 (see PROFILER_NAME above).
static PROFILER_NAME_STR: LazyLock<&'static str> = LazyLock::new(|| PROFILER_NAME.to_str().unwrap());

// SAFETY: PROFILER_VERSION is a byte slice that satisfies the safety requirements.
static PROFILER_VERSION_STR: LazyLock<&'static str> = LazyLock::new(|| {
unsafe { CStr::from_ptr(PROFILER_VERSION.as_ptr() as *const c_char) }
.to_str()
// Panic: we own this string and it should be UTF8 (see PROFILER_VERSION above).
.unwrap()
});

/// The runtime ID, which is basically a universally unique "pid". This makes
/// it almost const, the exception being to re-initialize it from a child fork
/// handler. We don't yet support forking, so we use OnceCell.
Expand Down Expand Up @@ -618,8 +622,9 @@ extern "C" fn rinit(_type: c_int, _module_number: c_int) -> ZendResult {
warn!("{err}");
}
locals.tags = tags;
locals.profiling_experimental_heap_live_enabled =
system_settings.as_ref().profiling_experimental_heap_live_enabled
locals.profiling_experimental_heap_live_enabled = system_settings
.as_ref()
.profiling_experimental_heap_live_enabled
&& config::profiling_experimental_heap_live_enabled_current();
}
locals.system_settings = system_settings;
Expand Down
6 changes: 2 additions & 4 deletions profiling/src/profiling/uploader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,13 @@ impl Uploader {
let index = Arc::unwrap_or_clone(message.index);
let profile = message.profile;

let profiling_library_name: &str = &PROFILER_NAME_STR;
let profiling_library_version: &str = &PROFILER_VERSION_STR;
let agent_endpoint = &self.endpoint;
let endpoint = Endpoint::try_from(agent_endpoint)?;

let tags = Arc::unwrap_or_clone(index.tags);
let mut exporter = libdd_profiling::exporter::ProfileExporter::new(
profiling_library_name,
profiling_library_version,
PROFILER_NAME_STR,
PROFILER_VERSION_STR,
"php",
tags,
endpoint,
Expand Down
Loading