This commit is contained in:
David Peter 2024-07-04 15:44:35 +02:00 committed by GitHub
commit 171356267d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 29 additions and 4 deletions

View File

@ -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>,

View File

@ -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(&times_real),
time_user: mean(&times_user),
time_system: mean(&times_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,
))

View File

@ -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>,
}

View File

@ -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,
})
}

View File

@ -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);