diff options
author | David Peter <mail@david-peter.de> | 2024-06-23 13:29:05 +0200 |
---|---|---|
committer | David Peter <david.peter@bosch.com> | 2024-06-23 13:29:05 +0200 |
commit | 34cd5b9bb51832bdd9a6a9a9900ca65d5336d8a1 (patch) | |
tree | dbebd8d1e0779ad40ac3b2304bbf5a9a0d3f00bb | |
parent | c7be935da3764a4dcd4149e7b06151b9c9711696 (diff) |
Initial work on tracking memory usagetrack-memory-usage
-rw-r--r-- | src/benchmark/benchmark_result.rs | 4 | ||||
-rw-r--r-- | src/benchmark/executor.rs | 4 | ||||
-rw-r--r-- | src/benchmark/timing_result.rs | 3 | ||||
-rw-r--r-- | src/timer/mod.rs | 8 | ||||
-rw-r--r-- | src/timer/unix_timer.rs | 14 |
5 files changed, 29 insertions, 4 deletions
diff --git a/src/benchmark/benchmark_result.rs b/src/benchmark/benchmark_result.rs index b37f725..c03d628 100644 --- a/src/benchmark/benchmark_result.rs +++ b/src/benchmark/benchmark_result.rs @@ -45,6 +45,10 @@ pub struct BenchmarkResult { /// Exit codes of all command invocations pub exit_codes: Vec<Option<i32>>, + /// All max. memory sizes + #[serde(skip_serializing_if = "Option::is_none")] + pub max_rss_byte: Option<Vec<Second>>, + /// Parameter values for this benchmark #[serde(skip_serializing_if = "BTreeMap::is_empty")] pub parameters: BTreeMap<String, String>, diff --git a/src/benchmark/executor.rs b/src/benchmark/executor.rs index d0e748e..a95c687 100644 --- a/src/benchmark/executor.rs +++ b/src/benchmark/executor.rs @@ -99,6 +99,7 @@ impl<'a> Executor for RawExecutor<'a> { time_real: result.time_real, time_user: result.time_user, time_system: result.time_system, + max_rss_byte: Some(result.max_rss_byte), }, result.status, )) @@ -167,6 +168,7 @@ impl<'a> Executor for ShellExecutor<'a> { time_real: result.time_real, time_user: result.time_user, time_system: result.time_system, + max_rss_byte: Some(result.max_rss_byte), }, result.status, )) @@ -226,6 +228,7 @@ impl<'a> Executor for ShellExecutor<'a> { time_real: mean(×_real), time_user: mean(×_user), time_system: mean(×_system), + max_rss_byte: None, }); Ok(()) @@ -279,6 +282,7 @@ impl Executor for MockExecutor { time_real: Self::extract_time(command.get_command_line()), time_user: 0.0, time_system: 0.0, + max_rss_byte: None, }, status, )) diff --git a/src/benchmark/timing_result.rs b/src/benchmark/timing_result.rs index d4b8490..8c55320 100644 --- a/src/benchmark/timing_result.rs +++ b/src/benchmark/timing_result.rs @@ -11,4 +11,7 @@ pub struct TimingResult { /// Time spent in kernel mode pub time_system: Second, + + /// Amount of memory used + pub max_rss_byte: Option<i64>, } diff --git a/src/timer/mod.rs b/src/timer/mod.rs index 2c57c2b..36082a0 100644 --- a/src/timer/mod.rs +++ b/src/timer/mod.rs @@ -32,6 +32,9 @@ struct CPUTimes { /// Total amount of time spent executing in kernel mode pub system_usec: i64, + + /// Total amount of memory used by the process + pub max_rss_byte: i64, } /// 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 max_rss_byte: i64, /// 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, max_rss_byte) = cpu_timer.stop(); Ok(TimerResult { time_real, time_user, time_system, + max_rss_byte, status, }) } diff --git a/src/timer/unix_timer.rs b/src/timer/unix_timer.rs index 1b812b3..6fef456 100644 --- a/src/timer/unix_timer.rs +++ b/src/timer/unix_timer.rs @@ -25,10 +25,10 @@ impl CPUTimer { } } - pub fn stop(&self) -> (Second, Second) { + pub fn stop(&self) -> (Second, Second, i64) { 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.max_rss_byte) } } @@ -45,12 +45,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), + max_rss_byte, } } @@ -70,11 +78,13 @@ fn test_cpu_time_interval() { let t_a = CPUTimes { user_usec: 12345, system_usec: 54321, + max_rss_byte: 0, }; let t_b = CPUTimes { user_usec: 20000, system_usec: 70000, + max_rss_byte: 0, }; let t_zero = cpu_time_interval(&t_a, &t_a); |