Skip to content

Commit 95ab4b6

Browse files
Revert "[SVLS-8002] fix: collect CPU metric offsets on PlatformStart (#930)" (#938)
**Please include Jira ticket in title.** ## Overview ## Testing
1 parent 9f655d6 commit 95ab4b6

File tree

2 files changed

+9
-30
lines changed

2 files changed

+9
-30
lines changed

bottlecap/src/lifecycle/invocation/processor.rs

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,15 @@ impl Processor {
141141
// Resume tmp, fd, and threads enhanced metrics monitoring
142142
self.enhanced_metrics.resume_usage_metrics_monitoring();
143143

144+
// Collect offsets for network and cpu metrics
144145
let network_offset: Option<NetworkData> = proc::get_network_data().ok();
146+
let cpu_offset: Option<CPUData> = proc::get_cpu_data().ok();
147+
let uptime_offset: Option<f64> = proc::get_uptime().ok();
148+
145149
let enhanced_metric_offsets = Some(EnhancedMetricData {
146150
network_offset,
147-
cpu_offset: None,
148-
uptime_offset: None,
151+
cpu_offset,
152+
uptime_offset,
149153
});
150154
self.context_buffer
151155
.add_enhanced_metric_data(&request_id, enhanced_metric_offsets);
@@ -315,23 +319,6 @@ impl Processor {
315319
.try_into()
316320
.unwrap_or_default();
317321
self.context_buffer.add_start_time(&request_id, start_time);
318-
319-
if self.config.lambda_proc_enhanced_metrics {
320-
let cpu_offset: Option<CPUData> = proc::get_cpu_data().ok();
321-
let uptime_offset: Option<f64> = proc::get_uptime().ok();
322-
if let Some(context) = self.context_buffer.get_mut(&request_id) {
323-
if let Some(ref mut enhanced_data) = context.enhanced_metric_data {
324-
enhanced_data.cpu_offset = cpu_offset;
325-
enhanced_data.uptime_offset = uptime_offset;
326-
} else {
327-
context.enhanced_metric_data = Some(EnhancedMetricData {
328-
network_offset: None,
329-
cpu_offset,
330-
uptime_offset,
331-
});
332-
}
333-
}
334-
}
335322
}
336323

337324
#[allow(clippy::too_many_arguments)]

bottlecap/src/metrics/enhanced/lambda.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -370,12 +370,6 @@ impl Lambda {
370370
let uptime = uptime_data_end - uptime_data_offset;
371371
let total_idle_time = cpu_data_end.total_idle_time_ms - cpu_data_offset.total_idle_time_ms;
372372

373-
// Change in uptime should be positive and greater than total idle time across all cores
374-
if uptime <= 0.0 || (uptime * num_cores) < total_idle_time {
375-
debug!("Invalid uptime, skipping CPU utilization metrics");
376-
return;
377-
}
378-
379373
let mut max_idle_time = 0.0;
380374
let mut min_idle_time = f64::MAX;
381375
let now = std::time::UNIX_EPOCH
@@ -389,8 +383,6 @@ impl Lambda {
389383
cpu_data_offset.individual_cpu_idle_times.get(cpu_name)
390384
{
391385
let idle_time = cpu_idle_time - cpu_idle_time_offset;
392-
let idle_time = idle_time.max(0.0); // Ensure idle time is non-negative
393-
394386
if idle_time < min_idle_time {
395387
min_idle_time = idle_time;
396388
}
@@ -402,15 +394,15 @@ impl Lambda {
402394

403395
// Maximally utilized CPU is the one with the least time spent in the idle process
404396
// Multiply by 100 to report as percentage
405-
let cpu_max_utilization = ((uptime - min_idle_time).max(0.0) / uptime) * 100.0;
397+
let cpu_max_utilization = ((uptime - min_idle_time) / uptime) * 100.0;
406398

407399
// Minimally utilized CPU is the one with the most time spent in the idle process
408400
// Multiply by 100 to report as percentage
409-
let cpu_min_utilization = ((uptime - max_idle_time).max(0.0) / uptime) * 100.0;
401+
let cpu_min_utilization = ((uptime - max_idle_time) / uptime) * 100.0;
410402

411403
// CPU total utilization is the proportion of total non-idle time to the total uptime across all cores
412404
let cpu_total_utilization_decimal =
413-
((uptime * num_cores) - total_idle_time).max(0.0) / (uptime * num_cores);
405+
((uptime * num_cores) - total_idle_time) / (uptime * num_cores);
414406
// Multiply by 100 to report as percentage
415407
let cpu_total_utilization_pct = cpu_total_utilization_decimal * 100.0;
416408
// Multiply by num_cores to report in terms of cores

0 commit comments

Comments
 (0)