Initial work on tracking memory usage

This commit is contained in:
David Peter authored and David Peter committed 2024-12-29 12:18:55 +01:00
1 parent f78f482d8f
commit 6556b2bd46
13 files changed
+68 -7

No files matched your search

+4
View File
@@ -42,6 +42,10 @@ pub struct BenchmarkResult {
#[serde(skip_serializing_if = "Option::is_none")]
pub times: Option<Vec<Second>>,
/// Maximum memory usage of the process, in bytes
#[serde(skip_serializing_if = "Option::is_none")]
pub memory_usage_byte: Option<Vec<u64>>,
/// Exit codes of all command invocations
pub exit_codes: Vec<Option<i32>>,
+4
View File
@@ -133,6 +133,7 @@ impl Executor for RawExecutor<'_> {
time_real: result.time_real,
time_user: result.time_user,
time_system: result.time_system,
memory_usage_byte: result.memory_usage_byte,
},
result.status,
))
@@ -204,6 +205,7 @@ impl Executor for ShellExecutor<'_> {
time_real: result.time_real,
time_user: result.time_user,
time_system: result.time_system,
memory_usage_byte: result.memory_usage_byte,
},
result.status,
))
@@ -268,6 +270,7 @@ impl Executor for ShellExecutor<'_> {
time_real: mean(&times_real),
time_user: mean(&times_user),
time_system: mean(&times_system),
memory_usage_byte: 0,
});
Ok(())
@@ -323,6 +326,7 @@ impl Executor for MockExecutor {
time_real: Self::extract_time(command.get_command_line()),
time_user: 0.0,
time_system: 0.0,
memory_usage_byte: 0,
},
status,
))
+4
View File
@@ -151,6 +151,7 @@ impl<'a> Benchmark<'a> {
let mut times_real: Vec<Second> = vec![];
let mut times_user: Vec<Second> = vec![];
let mut times_system: Vec<Second> = vec![];
let mut memory_usage_byte: Vec<u64> = vec![];
let mut exit_codes: Vec<Option<i32>> = vec![];
let mut all_succeeded = true;
@@ -279,6 +280,7 @@ impl<'a> Benchmark<'a> {
times_real.push(res.time_real);
times_user.push(res.time_user);
times_system.push(res.time_system);
memory_usage_byte.push(res.memory_usage_byte);
exit_codes.push(extract_exit_code(status));
all_succeeded = all_succeeded && success;
@@ -315,6 +317,7 @@ impl<'a> Benchmark<'a> {
times_real.push(res.time_real);
times_user.push(res.time_user);
times_system.push(res.time_system);
memory_usage_byte.push(res.memory_usage_byte);
exit_codes.push(extract_exit_code(status));
all_succeeded = all_succeeded && success;
@@ -451,6 +454,7 @@ impl<'a> Benchmark<'a> {
min: t_min,
max: t_max,
times: Some(times_real),
memory_usage_byte: Some(memory_usage_byte),
exit_codes,
parameters: self
.command
+1
View File
@@ -133,6 +133,7 @@ fn create_result(name: &str, mean: Scalar) -> BenchmarkResult {
min: mean,
max: mean,
times: None,
memory_usage_byte: None,
exit_codes: Vec::new(),
parameters: BTreeMap::new(),
}
+3
View File
@@ -11,4 +11,7 @@ pub struct TimingResult {
/// Time spent in kernel mode
pub time_system: Second,
/// Maximum amount of memory used, in bytes
pub memory_usage_byte: u64,
}
+4
View File
@@ -105,6 +105,7 @@ fn test_asciidoc_format_s() {
min: 5.0,
max: 6.0,
times: Some(vec![7.0, 8.0, 9.0]),
memory_usage_byte: None,
exit_codes: vec![Some(0), Some(0), Some(0)],
parameters: {
let mut params = BTreeMap::new();
@@ -124,6 +125,7 @@ fn test_asciidoc_format_s() {
min: 15.0,
max: 16.0,
times: Some(vec![17.0, 18.0, 19.0]),
memory_usage_byte: None,
exit_codes: vec![Some(0), Some(0), Some(0)],
parameters: {
let mut params = BTreeMap::new();
@@ -180,6 +182,7 @@ fn test_asciidoc_format_ms() {
min: 0.015,
max: 0.016,
times: Some(vec![0.017, 0.018, 0.019]),
memory_usage_byte: None,
exit_codes: vec![Some(0), Some(0), Some(0)],
parameters: {
let mut params = BTreeMap::new();
@@ -199,6 +202,7 @@ fn test_asciidoc_format_ms() {
min: 5.0,
max: 6.0,
times: Some(vec![7.0, 8.0, 9.0]),
memory_usage_byte: None,
exit_codes: vec![Some(0), Some(0), Some(0)],
parameters: {
let mut params = BTreeMap::new();
+2
View File
@@ -77,6 +77,7 @@ fn test_csv() {
min: 5.0,
max: 6.0,
times: Some(vec![7.0, 8.0, 9.0]),
memory_usage_byte: None,
exit_codes: vec![Some(0), Some(0), Some(0)],
parameters: {
let mut params = BTreeMap::new();
@@ -96,6 +97,7 @@ fn test_csv() {
min: 15.0,
max: 16.5,
times: Some(vec![17.0, 18.0, 19.0]),
memory_usage_byte: None,
exit_codes: vec![Some(0), Some(0), Some(0)],
parameters: {
let mut params = BTreeMap::new();
+8
View File
@@ -82,6 +82,7 @@ fn test_markdown_format_ms() {
min: 0.1023,
max: 0.1080,
times: Some(vec![0.1, 0.1, 0.1]),
memory_usage_byte: None,
exit_codes: vec![Some(0), Some(0), Some(0)],
parameters: BTreeMap::new(),
},
@@ -96,6 +97,7 @@ fn test_markdown_format_ms() {
min: 2.0020,
max: 2.0080,
times: Some(vec![2.0, 2.0, 2.0]),
memory_usage_byte: None,
exit_codes: vec![Some(0), Some(0), Some(0)],
parameters: BTreeMap::new(),
},
@@ -139,6 +141,7 @@ fn test_markdown_format_s() {
min: 2.0020,
max: 2.0080,
times: Some(vec![2.0, 2.0, 2.0]),
memory_usage_byte: None,
exit_codes: vec![Some(0), Some(0), Some(0)],
parameters: BTreeMap::new(),
},
@@ -153,6 +156,7 @@ fn test_markdown_format_s() {
min: 0.1023,
max: 0.1080,
times: Some(vec![0.1, 0.1, 0.1]),
memory_usage_byte: None,
exit_codes: vec![Some(0), Some(0), Some(0)],
parameters: BTreeMap::new(),
},
@@ -196,6 +200,7 @@ fn test_markdown_format_time_unit_s() {
min: 2.0020,
max: 2.0080,
times: Some(vec![2.0, 2.0, 2.0]),
memory_usage_byte: None,
exit_codes: vec![Some(0), Some(0), Some(0)],
parameters: BTreeMap::new(),
},
@@ -210,6 +215,7 @@ fn test_markdown_format_time_unit_s() {
min: 0.1023,
max: 0.1080,
times: Some(vec![0.1, 0.1, 0.1]),
memory_usage_byte: None,
exit_codes: vec![Some(0), Some(0), Some(0)],
parameters: BTreeMap::new(),
},
@@ -274,6 +280,7 @@ fn test_markdown_format_time_unit_ms() {
min: 2.0020,
max: 2.0080,
times: Some(vec![2.0, 2.0, 2.0]),
memory_usage_byte: None,
exit_codes: vec![Some(0), Some(0), Some(0)],
parameters: BTreeMap::new(),
},
@@ -288,6 +295,7 @@ fn test_markdown_format_time_unit_ms() {
min: 0.1023,
max: 0.1080,
times: Some(vec![0.1, 0.1, 0.1]),
memory_usage_byte: None,
exit_codes: vec![Some(0), Some(0), Some(0)],
parameters: BTreeMap::new(),
},
+8
View File
@@ -136,6 +136,7 @@ fn test_determine_unit_from_results_unit_given_s() {
min: 2.0020,
max: 2.0080,
times: Some(vec![2.0, 2.0, 2.0]),
memory_usage_byte: None,
exit_codes: vec![Some(0), Some(0), Some(0)],
parameters: BTreeMap::new(),
},
@@ -150,6 +151,7 @@ fn test_determine_unit_from_results_unit_given_s() {
min: 0.1023,
max: 0.1080,
times: Some(vec![0.1, 0.1, 0.1]),
memory_usage_byte: None,
exit_codes: vec![Some(0), Some(0), Some(0)],
parameters: BTreeMap::new(),
},
@@ -178,6 +180,7 @@ fn test_determine_unit_from_results_unit_given_ms() {
min: 2.0020,
max: 2.0080,
times: Some(vec![2.0, 2.0, 2.0]),
memory_usage_byte: None,
exit_codes: vec![Some(0), Some(0), Some(0)],
parameters: BTreeMap::new(),
},
@@ -192,6 +195,7 @@ fn test_determine_unit_from_results_unit_given_ms() {
min: 0.1023,
max: 0.1080,
times: Some(vec![0.1, 0.1, 0.1]),
memory_usage_byte: None,
exit_codes: vec![Some(0), Some(0), Some(0)],
parameters: BTreeMap::new(),
},
@@ -220,6 +224,7 @@ fn test_determine_unit_from_results_unit_first_s() {
min: 2.0020,
max: 2.0080,
times: Some(vec![2.0, 2.0, 2.0]),
memory_usage_byte: None,
exit_codes: vec![Some(0), Some(0), Some(0)],
parameters: BTreeMap::new(),
},
@@ -234,6 +239,7 @@ fn test_determine_unit_from_results_unit_first_s() {
min: 0.1023,
max: 0.1080,
times: Some(vec![0.1, 0.1, 0.1]),
memory_usage_byte: None,
exit_codes: vec![Some(0), Some(0), Some(0)],
parameters: BTreeMap::new(),
},
@@ -262,6 +268,7 @@ fn test_determine_unit_from_results_unit_first_ms() {
min: 0.1023,
max: 0.1080,
times: Some(vec![0.1, 0.1, 0.1]),
memory_usage_byte: None,
exit_codes: vec![Some(0), Some(0), Some(0)],
parameters: BTreeMap::new(),
},
@@ -276,6 +283,7 @@ fn test_determine_unit_from_results_unit_first_ms() {
min: 2.0020,
max: 2.0080,
times: Some(vec![2.0, 2.0, 2.0]),
memory_usage_byte: None,
exit_codes: vec![Some(0), Some(0), Some(0)],
parameters: BTreeMap::new(),
},
+4
View File
@@ -88,6 +88,7 @@ fn test_orgmode_format_ms() {
min: 0.1023,
max: 0.1080,
times: Some(vec![0.1, 0.1, 0.1]),
memory_usage_byte: None,
exit_codes: vec![Some(0), Some(0), Some(0)],
parameters: BTreeMap::new(),
},
@@ -102,6 +103,7 @@ fn test_orgmode_format_ms() {
min: 2.0020,
max: 2.0080,
times: Some(vec![2.0, 2.0, 2.0]),
memory_usage_byte: None,
exit_codes: vec![Some(0), Some(0), Some(0)],
parameters: BTreeMap::new(),
},
@@ -147,6 +149,7 @@ fn test_orgmode_format_s() {
min: 2.0020,
max: 2.0080,
times: Some(vec![2.0, 2.0, 2.0]),
memory_usage_byte: None,
exit_codes: vec![Some(0), Some(0), Some(0)],
parameters: BTreeMap::new(),
},
@@ -161,6 +164,7 @@ fn test_orgmode_format_s() {
min: 0.1023,
max: 0.1080,
times: Some(vec![0.1, 0.1, 0.1]),
memory_usage_byte: None,
exit_codes: vec![Some(0), Some(0), Some(0)],
parameters: BTreeMap::new(),
},
+6 -2
View File
@@ -32,6 +32,9 @@ struct CPUTimes {
/// Total amount of time spent executing in kernel mode
pub system_usec: i64,
/// Maximum amount of memory used by the process, in bytes
pub memory_usage_byte: u64,
}
/// Used to indicate the result of running a command
@@ -40,7 +43,7 @@ pub struct TimerResult {
pub time_real: Second,
pub time_user: Second,
pub time_system: Second,
pub memory_usage_byte: u64,
/// The exit status of the process
pub status: ExitStatus,
}
@@ -106,12 +109,13 @@ pub fn execute_and_measure(mut command: Command) -> Result<TimerResult> {
let status = child.wait()?;
let time_real = wallclock_timer.stop();
let (time_user, time_system) = cpu_timer.stop();
let (time_user, time_system, memory_usage_byte) = cpu_timer.stop();
Ok(TimerResult {
time_real,
time_user,
time_system,
memory_usage_byte,
status,
})
}
+17 -2
View File
@@ -1,5 +1,6 @@
#![cfg(not(windows))]
use std::convert::TryFrom;
use std::mem;
use crate::timer::CPUTimes;
@@ -25,10 +26,14 @@ impl CPUTimer {
}
}
pub fn stop(&self) -> (Second, Second) {
pub fn stop(&self) -> (Second, Second, u64) {
let end_cpu = get_cpu_times();
let cpu_interval = cpu_time_interval(&self.start_cpu, &end_cpu);
(cpu_interval.user, cpu_interval.system)
(
cpu_interval.user,
cpu_interval.system,
end_cpu.memory_usage_byte,
)
}
}
@@ -45,12 +50,20 @@ fn get_cpu_times() -> CPUTimes {
const MICROSEC_PER_SEC: i64 = 1000 * 1000;
// Linux and *BSD return the value in KibiBytes, Darwin flavors in bytes
let max_rss_byte = if cfg!(target_os = "macos") || cfg!(target_os = "ios") {
result.ru_maxrss
} else {
result.ru_maxrss * 1024
};
#[allow(clippy::useless_conversion)]
CPUTimes {
user_usec: i64::from(result.ru_utime.tv_sec) * MICROSEC_PER_SEC
+ i64::from(result.ru_utime.tv_usec),
system_usec: i64::from(result.ru_stime.tv_sec) * MICROSEC_PER_SEC
+ i64::from(result.ru_stime.tv_usec),
memory_usage_byte: u64::try_from(max_rss_byte).unwrap_or(0),
}
}
@@ -70,11 +83,13 @@ fn test_cpu_time_interval() {
let t_a = CPUTimes {
user_usec: 12345,
system_usec: 54321,
memory_usage_byte: 0,
};
let t_b = CPUTimes {
user_usec: 20000,
system_usec: 70000,
memory_usage_byte: 0,
};
let t_zero = cpu_time_interval(&t_a, &t_a);
+3 -3
View File
@@ -86,7 +86,7 @@ impl CPUTimer {
Self { job_object }
}
pub fn stop(&self) -> (Second, Second) {
pub fn stop(&self) -> (Second, Second, u64) {
let mut job_object_info =
mem::MaybeUninit::<JOBOBJECT_BASIC_ACCOUNTING_INFORMATION>::uninit();
@@ -114,9 +114,9 @@ impl CPUTimer {
// for all active processes associated with the job, as well as all terminated
// processes no longer associated with the job, in 100-nanosecond ticks."
let kernel: i64 = job_object_info.TotalKernelTime / HUNDRED_NS_PER_MS;
(user as f64 * 1e-6, kernel as f64 * 1e-6)
(user as f64 * 1e-6, kernel as f64 * 1e-6, 0)
} else {
(0.0, 0.0)
(0.0, 0.0, 0)
}
}
}