Skip to content

Commit

Permalink
Improve behaviour when all shards are used
Browse files Browse the repository at this point in the history
We weren't detecting when all the shards were full correctly, use the
right variable for the limit.

Additionally, do a partial reset of the state when all shards are in
use. This needs two improvements, mainly resetting the BPF maps with a
rate-limit in place.
  • Loading branch information
javierhonduco committed Apr 3, 2024
1 parent 0edcae4 commit 0b854c0
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/profiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ impl Collector {
}

// Static config
const MAX_UNWIND_INFO_SHARDS: u64 = 50;
const MAX_SHARDS: u64 = MAX_UNWIND_INFO_SHARDS as u64;
const SHARD_CAPACITY: usize = MAX_UNWIND_TABLE_SIZE as usize;
// Make each perf buffer 512 KB
// TODO: should make this configurable via a command line argument in future
Expand Down Expand Up @@ -835,7 +835,7 @@ impl Profiler<'_> {
.mappings
.iter()
{
if self.native_unwind_state.shard_index > MAX_UNWIND_INFO_SHARDS {
if self.native_unwind_state.shard_index > MAX_SHARDS {
error!("No more unwind info shards available");
break;
}
Expand Down Expand Up @@ -1001,9 +1001,17 @@ impl Profiler<'_> {
"live shard exceeds the maximum capacity"
);

if self.native_unwind_state.shard_index >= MAX_UNWIND_INFO_SHARDS {
error!("used all the shards, samples might be lost");
break;
if self.native_unwind_state.shard_index >= MAX_SHARDS {
warn!("used all the shards, wiping state");

self.native_unwind_state.live_shard.truncate(0);
self.native_unwind_state.shard_index = 0;

// TODO: clear BPF maps but ensure this doesn't happen too often.
self.native_unwind_state.build_id_to_executable_id = HashMap::new();

// The next call to this method will continue populating the needed data.
return;
}

let free_space: usize = SHARD_CAPACITY - self.native_unwind_state.live_shard.len();
Expand Down

0 comments on commit 0b854c0

Please sign in to comment.