Skip to content

Commit

Permalink
panic!
Browse files Browse the repository at this point in the history
  • Loading branch information
realFlowControl committed Dec 14, 2023
1 parent ebbd19d commit 30ff7f3
Showing 1 changed file with 37 additions and 34 deletions.
71 changes: 37 additions & 34 deletions profiling/src/profiling/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,10 @@ impl Profiler {
locals: &RequestLocals,
timestamp: i64,
) -> SampleMessage {
if !locals.profiling_enabled {
panic!("Profiling is disabled and this function should not be called!")
}

// Lay this out in the same order as SampleValues
static SAMPLE_TYPES: &[ValueType; 7] = &[
ValueType::new("sample", "count"),
Expand All @@ -1034,43 +1038,42 @@ impl Profiler {

let mut sample_types = Vec::with_capacity(SAMPLE_TYPES.len());
let mut sample_values = Vec::with_capacity(SAMPLE_TYPES.len());
if locals.profiling_enabled {
// sample, wall-time, cpu-time
let len = 2 + locals.profiling_experimental_cpu_time_enabled as usize;
sample_types.extend_from_slice(&SAMPLE_TYPES[0..len]);
sample_values.extend_from_slice(&values[0..len]);

// alloc-samples, alloc-size
if locals.profiling_allocation_enabled {
sample_types.extend_from_slice(&SAMPLE_TYPES[3..5]);
sample_values.extend_from_slice(&values[3..5]);
}

#[cfg(feature = "timeline")]
if locals.profiling_experimental_timeline_enabled {
sample_types.push(SAMPLE_TYPES[5]);
sample_values.push(values[5]);
}
// sample, wall-time, cpu-time
let len = 2 + locals.profiling_experimental_cpu_time_enabled as usize;
sample_types.extend_from_slice(&SAMPLE_TYPES[0..len]);
sample_values.extend_from_slice(&values[0..len]);

#[cfg(feature = "exception_profiling")]
if locals.profiling_exception_enabled {
sample_types.push(SAMPLE_TYPES[6]);
sample_values.push(values[6]);
}
// alloc-samples, alloc-size
if locals.profiling_allocation_enabled {
sample_types.extend_from_slice(&SAMPLE_TYPES[3..5]);
sample_values.extend_from_slice(&values[3..5]);
}

#[cfg(php_has_fibers)]
if let Some(fiber) = unsafe { ddog_php_prof_get_active_fiber().as_mut() } {
// Safety: the fcc is set by Fiber::__construct as part of zpp,
// which will always set the function_handler on success, and
// there's nothing changing that value in all of fibers
// afterwards, from start to destruction of the fiber itself.
let func = unsafe { &*fiber.fci_cache.function_handler };
if let Some(functionname) = extract_function_name(func) {
labels.push(Label {
key: "fiber",
value: LabelValue::Str(functionname.into()),
});
}
#[cfg(feature = "timeline")]
if locals.profiling_experimental_timeline_enabled {
sample_types.push(SAMPLE_TYPES[5]);
sample_values.push(values[5]);
}

#[cfg(feature = "exception_profiling")]
if locals.profiling_exception_enabled {
sample_types.push(SAMPLE_TYPES[6]);
sample_values.push(values[6]);
}

#[cfg(php_has_fibers)]
if let Some(fiber) = unsafe { ddog_php_prof_get_active_fiber().as_mut() } {
// Safety: the fcc is set by Fiber::__construct as part of zpp,
// which will always set the function_handler on success, and
// there's nothing changing that value in all of fibers
// afterwards, from start to destruction of the fiber itself.
let func = unsafe { &*fiber.fci_cache.function_handler };
if let Some(functionname) = extract_function_name(func) {
labels.push(Label {
key: "fiber",
value: LabelValue::Str(functionname.into()),
});
}
}

Expand Down

0 comments on commit 30ff7f3

Please sign in to comment.