Skip to content

Commit

Permalink
Add warning for negative IO delta values (kaspanet#277)
Browse files Browse the repository at this point in the history
Added a warning message in case the new IO read or write bytes values are less than the previous values. This was done using the unwrap_or_else() function to prevent the program from potentially crashing when the subtraction operation results in a negative value.
  • Loading branch information
biryukovmaxim authored Oct 2, 2023
1 parent 9f23f97 commit 918644c
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions metrics/perf_monitor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use kaspa_core::{
service::{AsyncService, AsyncServiceFuture},
tick::{TickReason, TickService},
},
trace,
trace, warn,
};
use workflow_perf_monitor::{
cpu::{processor_numbers, ProcessStat},
Expand Down Expand Up @@ -48,8 +48,15 @@ impl<TS: AsRef<TickService>> Monitor<TS> {
let IOStats { read_bytes: disk_io_read_bytes, write_bytes: disk_io_write_bytes, .. } = get_process_io_stats()?;

let time_delta = last_log_time.elapsed();
let read_delta = disk_io_read_bytes - last_read;
let write_delta = disk_io_write_bytes - last_written;

let read_delta = disk_io_read_bytes.checked_sub(last_read).unwrap_or_else(|| {
warn!("new io read bytes value is less than previous, new: {disk_io_read_bytes}, previous: {last_read}");
0
});
let write_delta = disk_io_write_bytes.checked_sub(last_written).unwrap_or_else(|| {
warn!("new io write bytes value is less than previous, new: {disk_io_write_bytes}, previous: {last_written}");
0
});

let now = Instant::now();
last_log_time = now;
Expand Down

0 comments on commit 918644c

Please sign in to comment.