Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions doc/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ auto-generated from a Go data structure that specifies the JSON output format.
output format can most easily be be seen by diffing this file against a desired tag, starting with
"v0.13.0". Such changes are therefore no longer mentioned specially below.

## Changes in v0.18.2 (on `release_0_18`)

* Bug 527 - **IMPORTANT FIX.** Parse non-integral volumes coming from Slurm, notably average disk
traffic volumes.

## Changes in v0.18.1 (on `release_0_18`)

* Bug 516 - **IMPORTANT FUNCTIONALITY.** Introduce `global.hostname-only` as a better way of managing
Expand Down
33 changes: 28 additions & 5 deletions src/slurmjobs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,20 +520,43 @@ fn parse_duration(mut val: &str) -> u64 {
fn parse_volume_kb(val: &str) -> u64 {
if val != "" {
let (val, scale) = if let Some(suffix) = val.strip_suffix('K') {
(suffix, 1024)
(suffix, 1024.0)
} else if let Some(suffix) = val.strip_suffix('M') {
(suffix, 1024 * 1024)
(suffix, 1024.0 * 1024.0)
} else if let Some(suffix) = val.strip_suffix('G') {
(suffix, 1024 * 1024 * 1024)
(suffix, 1024.0 * 1024.0 * 1024.0)
} else if let Some(suffix) = val.strip_suffix('T') {
(suffix, 1024.0 * 1024.0 * 1024.0 * 1024.0)
} else if let Some(suffix) = val.strip_suffix('P') {
(suffix, 1024.0 * 1024.0 * 1024.0 * 1024.0 * 1024.0)
} else {
(val, 1)
(val, 1.0)
};
(val.parse::<u64>().unwrap_or(0) * scale).div_ceil(1024)
((val.parse::<f64>().unwrap_or(0.0) * scale) / 1024.0).ceil() as u64
} else {
0
}
}

#[test]
pub fn test_parse_volume_kb() {
let m = 1024;
let g = 1024 * 1024;
let t = 1024 * 1024 * 1024;
let p = 1024 * 1024 * 1024 * 1024;
assert!(parse_volume_kb("1") == 1);
assert!(parse_volume_kb("1K") == 1);
assert!(parse_volume_kb("1.5K") == 2);
assert!(parse_volume_kb("1M") == m);
assert!(parse_volume_kb("1.5M") == m + m / 2);
assert!(parse_volume_kb("1G") == g);
assert!(parse_volume_kb("1.5G") == g + g / 2);
assert!(parse_volume_kb("1T") == t);
assert!(parse_volume_kb("1.5T") == t + t / 2);
assert!(parse_volume_kb("1P") == p);
assert!(parse_volume_kb("1.5P") == p + p / 2);
}

fn render_jobs_newfmt(jobs: &[Box<JobAll>]) -> output::Array {
let mut a = output::Array::new();
for j in jobs {
Expand Down
2 changes: 1 addition & 1 deletion tests/testdata/sonar_sacct_output.txt

Large diffs are not rendered by default.