Skip to content

Commit

Permalink
Use wait4 instead of getrusage
Browse files Browse the repository at this point in the history
  • Loading branch information
sharkdp committed Dec 29, 2024
1 parent f88851c commit ab811dd
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 149 deletions.
13 changes: 6 additions & 7 deletions src/benchmark/benchmark_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ pub struct BenchmarkRun {

/// Time spent in kernel mode
pub system_time: Second,

/// Maximum memory usage of the process, in bytes
pub memory_usage_byte: u64,

/// Exit codes of the process
pub exit_code: Option<i32>,
}

/// Set of values that will be exported.
Expand All @@ -36,13 +42,6 @@ pub struct BenchmarkResult {
/// All run time measurements
pub runs: Vec<BenchmarkRun>,

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

/// Parameter values for this benchmark
#[serde(skip_serializing_if = "BTreeMap::is_empty")]
pub parameters: BTreeMap<String, String>,
Expand Down
26 changes: 18 additions & 8 deletions src/benchmark/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,15 +448,25 @@ impl<'a> Benchmark<'a> {
command_with_unused_parameters: self.command.get_name_with_unused_parameters(),
runs: times_real
.iter()
.zip(times_user.iter().zip(times_system.iter()))
.map(|(wall_clock_time, (user_time, system_time))| BenchmarkRun {
wall_clock_time: *wall_clock_time,
user_time: *user_time,
system_time: *system_time,
})
.zip(times_user.iter())
.zip(times_system.iter())
.zip(memory_usage_byte.iter())
.zip(exit_codes.iter())
.map(
|(
(((wall_clock_time, user_time), system_time), memory_usage_byte),
exit_code,
)| {
BenchmarkRun {
wall_clock_time: *wall_clock_time,
user_time: *user_time,
system_time: *system_time,
memory_usage_byte: *memory_usage_byte,
exit_code: *exit_code,
}
},
)
.collect(),
memory_usage_byte: Some(memory_usage_byte),
exit_codes,
parameters: self
.command
.get_parameters()
Expand Down
4 changes: 2 additions & 2 deletions src/benchmark/relative_speed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ fn create_result(name: &str, mean: Scalar) -> BenchmarkResult {
wall_clock_time: mean,
user_time: mean,
system_time: 0.,
memory_usage_byte: 1024,
exit_code: Some(0),
}],
memory_usage_byte: None,
exit_codes: Vec::new(),
parameters: BTreeMap::new(),
}
}
Expand Down
20 changes: 8 additions & 12 deletions src/benchmark/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,29 +193,25 @@ fn scheduler_basic() -> Result<()> {
- wall_clock_time: 0.123
user_time: 0
system_time: 0
memory_usage_byte: 0
exit_code: 0
- wall_clock_time: 0.123
user_time: 0
system_time: 0
memory_usage_byte:
- 0
- 0
exit_codes:
- 0
- 0
memory_usage_byte: 0
exit_code: 0
- command: sleep 0.456
runs:
- wall_clock_time: 0.456
user_time: 0
system_time: 0
memory_usage_byte: 0
exit_code: 0
- wall_clock_time: 0.456
user_time: 0
system_time: 0
memory_usage_byte:
- 0
- 0
exit_codes:
- 0
- 0
memory_usage_byte: 0
exit_code: 0
"#);

Ok(())
Expand Down
16 changes: 12 additions & 4 deletions src/export/csv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,24 @@ fn test_csv() {
wall_clock_time: 7.0,
user_time: 7.0,
system_time: 0.0,
memory_usage_byte: 1024,
exit_code: Some(0),
},
BenchmarkRun {
wall_clock_time: 8.0,
user_time: 8.0,
system_time: 0.0,
memory_usage_byte: 1024,
exit_code: Some(0),
},
BenchmarkRun {
wall_clock_time: 12.0,
user_time: 12.0,
system_time: 0.0,
memory_usage_byte: 1024,
exit_code: Some(0),
},
],
memory_usage_byte: None,
exit_codes: vec![Some(0), Some(0), Some(0)],
parameters: {
let mut params = BTreeMap::new();
params.insert("foo".into(), "one".into());
Expand All @@ -106,20 +110,24 @@ fn test_csv() {
wall_clock_time: 17.0,
user_time: 17.0,
system_time: 0.0,
memory_usage_byte: 1024,
exit_code: Some(0),
},
BenchmarkRun {
wall_clock_time: 18.0,
user_time: 18.0,
system_time: 0.0,
memory_usage_byte: 1024,
exit_code: Some(0),
},
BenchmarkRun {
wall_clock_time: 19.0,
user_time: 19.0,
system_time: 0.0,
memory_usage_byte: 1024,
exit_code: Some(0),
},
],
memory_usage_byte: None,
exit_codes: vec![Some(0), Some(0), Some(0)],
parameters: {
let mut params = BTreeMap::new();
params.insert("foo".into(), "one".into());
Expand Down
64 changes: 48 additions & 16 deletions src/export/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,24 @@ fn test_markup_export_auto_ms() {
wall_clock_time: 0.09,
user_time: 0.09,
system_time: 0.,
memory_usage_byte: 1024,
exit_code: Some(0),
},
BenchmarkRun {
wall_clock_time: 0.10,
user_time: 0.10,
system_time: 0.,
memory_usage_byte: 1024,
exit_code: Some(0),
},
BenchmarkRun {
wall_clock_time: 0.14,
user_time: 0.14,
system_time: 0.,
memory_usage_byte: 1024,
exit_code: Some(0),
},
],
memory_usage_byte: None,
exit_codes: vec![Some(0), Some(0), Some(0)],
parameters: BTreeMap::new(),
},
BenchmarkResult {
Expand All @@ -56,20 +60,24 @@ fn test_markup_export_auto_ms() {
wall_clock_time: 2.0,
user_time: 2.0,
system_time: 0.,
memory_usage_byte: 1024,
exit_code: Some(0),
},
BenchmarkRun {
wall_clock_time: 3.0,
user_time: 3.0,
system_time: 0.,
memory_usage_byte: 1024,
exit_code: Some(0),
},
BenchmarkRun {
wall_clock_time: 4.0,
user_time: 4.0,
system_time: 0.,
memory_usage_byte: 1024,
exit_code: Some(0),
},
],
memory_usage_byte: None,
exit_codes: vec![Some(0), Some(0), Some(0)],
parameters: BTreeMap::new(),
},
];
Expand Down Expand Up @@ -125,20 +133,24 @@ fn test_markup_export_auto_s() {
wall_clock_time: 2.1,
user_time: 2.1,
system_time: 0.,
memory_usage_byte: 1024,
exit_code: Some(0),
},
BenchmarkRun {
wall_clock_time: 2.2,
user_time: 2.2,
system_time: 0.,
memory_usage_byte: 1024,
exit_code: Some(0),
},
BenchmarkRun {
wall_clock_time: 2.3,
user_time: 2.3,
system_time: 0.,
memory_usage_byte: 1024,
exit_code: Some(0),
},
],
memory_usage_byte: None,
exit_codes: vec![Some(0), Some(0), Some(0)],
parameters: BTreeMap::new(),
},
BenchmarkResult {
Expand All @@ -149,20 +161,24 @@ fn test_markup_export_auto_s() {
wall_clock_time: 0.1,
user_time: 0.1,
system_time: 0.,
memory_usage_byte: 1024,
exit_code: Some(0),
},
BenchmarkRun {
wall_clock_time: 0.2,
user_time: 0.2,
system_time: 0.,
memory_usage_byte: 1024,
exit_code: Some(0),
},
BenchmarkRun {
wall_clock_time: 0.3,
user_time: 0.3,
system_time: 0.,
memory_usage_byte: 1024,
exit_code: Some(0),
},
],
memory_usage_byte: None,
exit_codes: vec![Some(0), Some(0), Some(0)],
parameters: BTreeMap::new(),
},
];
Expand Down Expand Up @@ -218,20 +234,24 @@ fn test_markup_export_manual_ms() {
wall_clock_time: 2.1,
user_time: 2.1,
system_time: 0.,
memory_usage_byte: 1024,
exit_code: Some(0),
},
BenchmarkRun {
wall_clock_time: 2.2,
user_time: 2.2,
system_time: 0.,
memory_usage_byte: 1024,
exit_code: Some(0),
},
BenchmarkRun {
wall_clock_time: 2.3,
user_time: 2.3,
system_time: 0.,
memory_usage_byte: 1024,
exit_code: Some(0),
},
],
memory_usage_byte: None,
exit_codes: vec![Some(0), Some(0), Some(0)],
parameters: BTreeMap::new(),
},
BenchmarkResult {
Expand All @@ -242,20 +262,24 @@ fn test_markup_export_manual_ms() {
wall_clock_time: 0.1,
user_time: 0.1,
system_time: 0.,
memory_usage_byte: 1024,
exit_code: Some(0),
},
BenchmarkRun {
wall_clock_time: 0.2,
user_time: 0.2,
system_time: 0.,
memory_usage_byte: 1024,
exit_code: Some(0),
},
BenchmarkRun {
wall_clock_time: 0.3,
user_time: 0.3,
system_time: 0.,
memory_usage_byte: 1024,
exit_code: Some(0),
},
],
memory_usage_byte: None,
exit_codes: vec![Some(0), Some(0), Some(0)],
parameters: BTreeMap::new(),
},
];
Expand Down Expand Up @@ -310,20 +334,24 @@ fn test_markup_export_manual_s() {
wall_clock_time: 2.01,
user_time: 2.01,
system_time: 0.,
memory_usage_byte: 1024,
exit_code: Some(0),
},
BenchmarkRun {
wall_clock_time: 2.02,
user_time: 2.02,
system_time: 0.,
memory_usage_byte: 1024,
exit_code: Some(0),
},
BenchmarkRun {
wall_clock_time: 2.03,
user_time: 2.03,
system_time: 0.,
memory_usage_byte: 1024,
exit_code: Some(0),
},
],
memory_usage_byte: None,
exit_codes: vec![Some(0), Some(0), Some(0)],
parameters: BTreeMap::new(),
},
BenchmarkResult {
Expand All @@ -334,20 +362,24 @@ fn test_markup_export_manual_s() {
wall_clock_time: 0.11,
user_time: 0.11,
system_time: 0.,
memory_usage_byte: 1024,
exit_code: Some(0),
},
BenchmarkRun {
wall_clock_time: 0.12,
user_time: 0.12,
system_time: 0.,
memory_usage_byte: 1024,
exit_code: Some(0),
},
BenchmarkRun {
wall_clock_time: 0.13,
user_time: 0.13,
system_time: 0.,
memory_usage_byte: 1024,
exit_code: Some(0),
},
],
memory_usage_byte: None,
exit_codes: vec![Some(0), Some(0), Some(0)],
parameters: BTreeMap::new(),
},
];
Expand Down
Loading

0 comments on commit ab811dd

Please sign in to comment.