2026-10-05 14:15:34 +02:00
|
|
|
use serde::Serialize;
|
2026-10-05 09:47:09 +02:00
|
|
|
|
2026-10-05 14:15:34 +02:00
|
|
|
use statistical::{mean, median, standard_deviation};
|
2022-02-20 13:44:34 +01:00
|
|
|
|
2026-10-05 14:15:34 +02:00
|
|
|
use crate::util::units::Second;
|
|
|
|
|
use crate::{
|
|
|
|
|
outlier_detection::modified_zscores,
|
|
|
|
|
util::min_max::{max, min},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/// Performance metric measurements and exit code for a single run
|
|
|
|
|
#[derive(Debug, Default, Clone, Serialize, PartialEq)]
|
2026-10-05 09:47:09 +02:00
|
|
|
pub struct Measurement {
|
2026-10-05 14:15:34 +02:00
|
|
|
/// Elapsed wall clock time (real time)
|
|
|
|
|
pub wall_clock_time: Second,
|
2022-02-20 13:44:34 +01:00
|
|
|
|
|
|
|
|
/// Time spent in user mode
|
2026-10-05 14:15:34 +02:00
|
|
|
pub user_time: Second,
|
2022-02-20 13:44:34 +01:00
|
|
|
|
|
|
|
|
/// Time spent in kernel mode
|
2026-10-05 14:15:34 +02:00
|
|
|
pub system_time: Second,
|
2024-06-23 13:29:05 +02:00
|
|
|
|
2026-10-05 14:15:34 +02:00
|
|
|
/// Maximum memory usage of the process, in bytes
|
|
|
|
|
pub memory_usage_byte: u64,
|
2026-10-05 09:47:09 +02:00
|
|
|
|
2026-10-05 14:15:34 +02:00
|
|
|
/// Exit codes of the process
|
|
|
|
|
pub exit_code: Option<i32>,
|
2022-02-20 13:44:34 +01:00
|
|
|
}
|
2026-10-05 10:10:09 +02:00
|
|
|
|
2026-10-05 14:15:34 +02:00
|
|
|
#[derive(Debug, Default, Clone, Serialize, PartialEq)]
|
2026-10-05 10:10:09 +02:00
|
|
|
pub struct Measurements {
|
|
|
|
|
pub measurements: Vec<Measurement>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Measurements {
|
2026-10-05 12:46:10 +02:00
|
|
|
pub fn new(measurements: Vec<Measurement>) -> Self {
|
|
|
|
|
Self { measurements }
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-05 10:10:09 +02:00
|
|
|
pub fn len(&self) -> usize {
|
|
|
|
|
self.measurements.len()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn is_empty(&self) -> bool {
|
|
|
|
|
self.measurements.is_empty()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn push(&mut self, measurement: Measurement) {
|
|
|
|
|
self.measurements.push(measurement);
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-05 14:15:34 +02:00
|
|
|
pub fn wall_clock_times(&self) -> Vec<Second> {
|
|
|
|
|
self.measurements
|
|
|
|
|
.iter()
|
|
|
|
|
.map(|m| m.wall_clock_time)
|
|
|
|
|
.collect()
|
2026-10-05 10:10:09 +02:00
|
|
|
}
|
|
|
|
|
|
2026-10-05 14:15:34 +02:00
|
|
|
/// The average wall clock time
|
|
|
|
|
pub fn mean(&self) -> Second {
|
|
|
|
|
mean(&self.wall_clock_times())
|
2026-10-05 10:10:09 +02:00
|
|
|
}
|
|
|
|
|
|
2026-10-05 13:57:31 +02:00
|
|
|
/// The standard deviation of all wall clock times. Not available if only one run has been performed
|
2026-10-05 14:15:34 +02:00
|
|
|
pub fn stddev(&self) -> Option<Second> {
|
|
|
|
|
let times = self.wall_clock_times();
|
2026-10-05 13:57:31 +02:00
|
|
|
|
2026-10-05 14:15:34 +02:00
|
|
|
let t_mean = mean(×);
|
|
|
|
|
if times.len() > 1 {
|
|
|
|
|
Some(standard_deviation(×, Some(t_mean)))
|
2026-10-05 10:10:09 +02:00
|
|
|
} else {
|
2026-10-05 14:15:34 +02:00
|
|
|
None
|
2026-10-05 10:10:09 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-05 14:15:34 +02:00
|
|
|
/// The median wall clock time
|
|
|
|
|
pub fn median(&self) -> Second {
|
|
|
|
|
median(&self.wall_clock_times())
|
2026-10-05 10:10:09 +02:00
|
|
|
}
|
|
|
|
|
|
2026-10-05 14:15:34 +02:00
|
|
|
/// The minimum wall clock time
|
|
|
|
|
pub fn min(&self) -> Second {
|
|
|
|
|
min(&self.wall_clock_times())
|
2026-10-05 10:10:09 +02:00
|
|
|
}
|
|
|
|
|
|
2026-10-05 14:15:34 +02:00
|
|
|
/// The maximum wall clock time
|
|
|
|
|
pub fn max(&self) -> Second {
|
|
|
|
|
max(&self.wall_clock_times())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// The average user time
|
|
|
|
|
pub fn user_mean(&self) -> Second {
|
|
|
|
|
mean(
|
|
|
|
|
&self
|
|
|
|
|
.measurements
|
|
|
|
|
.iter()
|
|
|
|
|
.map(|m| m.user_time)
|
|
|
|
|
.collect::<Vec<_>>(),
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// The average system time
|
|
|
|
|
pub fn system_mean(&self) -> Second {
|
|
|
|
|
mean(
|
|
|
|
|
&self
|
|
|
|
|
.measurements
|
|
|
|
|
.iter()
|
|
|
|
|
.map(|m| m.system_time)
|
|
|
|
|
.collect::<Vec<_>>(),
|
|
|
|
|
)
|
2026-10-05 10:10:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn modified_zscores(&self) -> Vec<f64> {
|
2026-10-05 14:15:34 +02:00
|
|
|
modified_zscores(&self.wall_clock_times())
|
2026-10-05 10:10:09 +02:00
|
|
|
}
|
2026-10-05 11:14:09 +02:00
|
|
|
|
|
|
|
|
pub fn peak_memory_usage_mean(&self) -> Information {
|
|
|
|
|
mean(self.measurements.iter().map(|m| m.peak_memory_usage))
|
|
|
|
|
}
|
2026-10-05 10:10:09 +02:00
|
|
|
}
|