Skip to content

Commit

Permalink
resource_metering: free leaked thread CPU stats (#15373)
Browse files Browse the repository at this point in the history
close #15304

resource_metering: free leaked thread CPU stats

Signed-off-by: Neil Shen <overvenus@gmail.com>

Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
  • Loading branch information
overvenus and ti-chi-bot[bot] committed Aug 21, 2023
1 parent 2c5e7eb commit e59ad22
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions components/resource_metering/src/recorder/sub_recorder/cpu.rs
Expand Up @@ -49,10 +49,13 @@ impl SubRecorder for CpuRecorder {
fn cleanup(
&mut self,
_records: &mut RawRecords,
_thread_stores: &mut HashMap<Pid, LocalStorage>,
thread_stores: &mut HashMap<Pid, LocalStorage>,
) {
const THREAD_STAT_LEN_THRESHOLD: usize = 500;
// Remove thread stats that are no longer in thread_stores.
self.thread_stats
.retain(|tid, _| thread_stores.contains_key(tid));

const THREAD_STAT_LEN_THRESHOLD: usize = 500;
if self.thread_stats.capacity() > THREAD_STAT_LEN_THRESHOLD
&& self.thread_stats.len() < THREAD_STAT_LEN_THRESHOLD / 2
{
Expand Down

0 comments on commit e59ad22

Please sign in to comment.