diff --git a/CIME/baselines/performance.py b/CIME/baselines/performance.py index 71d357cedf6..98bb170436d 100644 --- a/CIME/baselines/performance.py +++ b/CIME/baselines/performance.py @@ -428,9 +428,11 @@ def read_baseline_file(baseline_file): Value stored in baseline file without comments. """ with open(baseline_file) as fd: - lines = [x.strip().split(" ")[-1] for x in fd.readlines() if not x.startswith("#")] + lines = [ + x.strip().split(" ")[-1] for x in fd.readlines() if not x.startswith("#") + ] - return "\n".join(lines) + return lines[-1] def _perf_compare_throughput_baseline(case, baseline, tolerance): @@ -474,7 +476,7 @@ def _perf_compare_throughput_baseline(case, baseline, tolerance): below_tolerance = diff < tolerance info = "Throughput changed by {:.2f}%: baseline={:.3f} sypd, tolerance={:d}%, current={:.3f} sypd".format( - diff * 100, baseline, int(tolerance * 100), current + diff * 100, baseline, int(tolerance * 100), current ) if below_tolerance: comment = "TPUTCOMP: " + info @@ -531,8 +533,8 @@ def _perf_compare_memory_baseline(case, baseline, tolerance): if diff is not None: below_tolerance = diff < tolerance - info = "Memory usage highwater changed by {:.2f}%: baseline={:.3f} sypd, tolerance={:d}%, current={:.3f} sypd".format( - diff * 100, baseline, int(tolerance * 100), current + info = "Memory usage highwater changed by {:.2f}%: baseline={:.3f} MB, tolerance={:d}%, current={:.3f} MB".format( + diff * 100, baseline, int(tolerance * 100), current ) if below_tolerance: comment = "MEMCOMP: " + info diff --git a/CIME/tests/test_unit_baselines_performance.py b/CIME/tests/test_unit_baselines_performance.py index 1422f3412b8..f3ad551d1f4 100644 --- a/CIME/tests/test_unit_baselines_performance.py +++ b/CIME/tests/test_unit_baselines_performance.py @@ -155,16 +155,18 @@ def test_get_cpl_mem_usage(self, isfile): def test_read_baseline_file_multi_line(self): with mock.patch( "builtins.open", - mock.mock_open(read_data="#comment about data\n1000.0\n2000.0\n"), + mock.mock_open( + read_data="sha:1df0 date:2023 1000.0\nsha:3b05 date:2023 2000.0" + ), ) as mock_file: baseline = performance.read_baseline_file("/tmp/cpl-mem.log") mock_file.assert_called_with("/tmp/cpl-mem.log") - assert baseline == "1000.0\n2000.0" + assert baseline == "2000.0" def test_read_baseline_file_content(self): with mock.patch( - "builtins.open", mock.mock_open(read_data="1000.0") + "builtins.open", mock.mock_open(read_data="sha:1df0 date:2023 1000.0") ) as mock_file: baseline = performance.read_baseline_file("/tmp/cpl-mem.log") @@ -176,14 +178,12 @@ def test_read_baseline_file(self): baseline = performance.read_baseline_file("/tmp/cpl-mem.log") mock_file.assert_called_with("/tmp/cpl-mem.log") - assert baseline == "" def test_write_baseline_file(self): with mock.patch("builtins.open", mock.mock_open()) as mock_file: performance.write_baseline_file("/tmp/cpl-tput.log", "1000") - mock_file.assert_called_with("/tmp/cpl-tput.log", "w") - mock_file.return_value.write.assert_called_with("1000") + mock_file.assert_called_with("/tmp/cpl-tput.log", "a") @mock.patch("CIME.baselines.performance.get_cpl_throughput") @mock.patch("CIME.baselines.performance.get_latest_cpl_logs") @@ -368,7 +368,7 @@ def test_perf_compare_throughput_baseline_no_tolerance( assert below_tolerance assert ( comment - == "TPUTCOMP: Computation time changed by -0.80% relative to baseline" + == "TPUTCOMP: Throughput changed by -0.80%: baseline=500.000 sypd, tolerance=10%, current=504.000 sypd" ) @mock.patch("CIME.baselines.performance._perf_get_throughput") @@ -399,7 +399,8 @@ def test_perf_compare_throughput_baseline_above_threshold( assert not below_tolerance assert ( - comment == "Error: TPUTCOMP: Computation time increase > 5% from baseline" + comment + == "Error: TPUTCOMP: Throughput changed by 49.60%: baseline=1000.000 sypd, tolerance=5%, current=504.000 sypd" ) @mock.patch("CIME.baselines.performance._perf_get_throughput") @@ -431,7 +432,7 @@ def test_perf_compare_throughput_baseline( assert below_tolerance assert ( comment - == "TPUTCOMP: Computation time changed by -0.80% relative to baseline" + == "TPUTCOMP: Throughput changed by -0.80%: baseline=500.000 sypd, tolerance=5%, current=504.000 sypd" ) @mock.patch("CIME.baselines.performance.get_cpl_mem_usage") @@ -466,7 +467,7 @@ def test_perf_compare_memory_baseline_no_baseline( assert below_tolerance assert ( comment - == "MEMCOMP: Memory usage highwater has changed by 0.00% relative to baseline" + == "MEMCOMP: Memory usage highwater changed by 0.00%: baseline=0.000 MB, tolerance=5%, current=1003.000 MB" ) @mock.patch("CIME.baselines.performance.get_cpl_mem_usage") @@ -557,7 +558,7 @@ def test_perf_compare_memory_baseline_no_tolerance( assert below_tolerance assert ( comment - == "MEMCOMP: Memory usage highwater has changed by 0.30% relative to baseline" + == "MEMCOMP: Memory usage highwater changed by 0.30%: baseline=1000.000 MB, tolerance=10%, current=1003.000 MB" ) @mock.patch("CIME.baselines.performance.get_cpl_mem_usage") @@ -592,7 +593,7 @@ def test_perf_compare_memory_baseline_above_threshold( assert not below_tolerance assert ( comment - == "Error: Memory usage increase >5% from baseline's 1000.000000 to 2003.000000" + == "Error: MEMCOMP: Memory usage highwater changed by 100.30%: baseline=1000.000 MB, tolerance=5%, current=2003.000 MB" ) @mock.patch("CIME.baselines.performance.get_cpl_mem_usage") @@ -627,7 +628,7 @@ def test_perf_compare_memory_baseline( assert below_tolerance assert ( comment - == "MEMCOMP: Memory usage highwater has changed by 0.30% relative to baseline" + == "MEMCOMP: Memory usage highwater changed by 0.30%: baseline=1000.000 MB, tolerance=5%, current=1003.000 MB" ) def test_get_latest_cpl_logs_found_multiple(self):