Skip to content

Commit

Permalink
fix(profiler) prevent emitting empty profiles (#2397)
Browse files Browse the repository at this point in the history
* panic!

* do not send empty samples to the other thread

* ignore empty samples in sampling thread

* Update profiling/src/profiling/mod.rs

Co-authored-by: Levi Morrison <[email protected]>

* if profiling is disabled, we do not need any other checks

---------

Co-authored-by: Levi Morrison <[email protected]>
  • Loading branch information
realFlowControl and morrisonlevi authored Jan 16, 2024
1 parent 32251e3 commit 5334fb5
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions profiling/src/profiling/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,12 @@ impl TimeCollector {
profiles: &mut HashMap<ProfileIndex, InternalProfile>,
started_at: &WallTime,
) {
if message.key.sample_types.len() == 0 {
// profiling disabled, this should not happen!
warn!("A sample with no sample types was recorded in the profiler. Please report this to Datadog.");
return;
}

let profile: &mut InternalProfile = if let Some(value) = profiles.get_mut(&message.key) {
value
} else {
Expand Down Expand Up @@ -1034,6 +1040,7 @@ 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;
Expand Down

0 comments on commit 5334fb5

Please sign in to comment.