From e79767e8f18587fbd28faf9021d8b80fed1a4cb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Sun, 17 Sep 2023 12:59:59 +0200 Subject: [PATCH] Improve output of codegen diff Add function size statistics, to quickly see what functions got larger/smaller. --- collector/src/bin/collector.rs | 2 +- collector/src/codegen.rs | 35 +++++++++++++++++++++++++++------- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/collector/src/bin/collector.rs b/collector/src/bin/collector.rs index 08b86a3bd..21c1c4ebf 100644 --- a/collector/src/bin/collector.rs +++ b/collector/src/bin/collector.rs @@ -732,7 +732,7 @@ fn main_result() -> anyhow::Result { let mut benchmark_groups = get_runtime_benchmark_groups(&runtime_benchmark_dir, Some(group))?; - let group = benchmark_groups.pop().unwrap(); + let group = benchmark_groups.pop().expect("Benchmark group not found"); assert!(benchmark_groups.is_empty()); codegen_diff(codegen_type, toolchain1, toolchain2, group)?; diff --git a/collector/src/codegen.rs b/collector/src/codegen.rs index db382c2ec..b3f27aa13 100644 --- a/collector/src/codegen.rs +++ b/collector/src/codegen.rs @@ -1,5 +1,5 @@ use std::collections::HashMap; -use std::io::IsTerminal; +use std::io::{IsTerminal, Write}; use std::path::Path; use std::process::Command; @@ -58,8 +58,9 @@ pub fn codegen_diff( .context("Cannot generate codegen using compiler 1")?; let codegen2 = get_codegen(&toolchain2, &group.path, codegen_type, *toolchain2_index) - .context("Cannot generate codegen using compiler 1")?; + .context("Cannot generate codegen using compiler 2")?; if codegen1.trim() != codegen2.trim() { + log::debug!("Analysed function {}", function.name); return Ok(Some(CodegenDiff::new(function, codegen1, codegen2))); } } @@ -98,6 +99,7 @@ pub fn codegen_diff( let mut output = std::io::stdout().lock(); let use_color = output.is_terminal(); + write_stats(&mut output, &diffs).context("Cannot write stats")?; for diff in diffs { write_diff(&mut output, use_color, &diff).context("Cannot write diff")?; } @@ -157,11 +159,30 @@ impl<'a> CodegenDiff<'a> { } } -fn write_diff( - writer: &mut W, - use_color: bool, - diff: &CodegenDiff, -) -> anyhow::Result<()> { +fn write_stats(writer: &mut W, diffs: &[CodegenDiff]) -> anyhow::Result<()> { + writeln!(writer, "Function size stats:")?; + for diff in diffs { + let size_before = diff.codegen1.len(); + let size_after = diff.codegen2.len(); + if size_before == size_after { + continue; + } + let percent = (size_after as f64 / size_before as f64) - 1.0; + let percent = percent * 100.0; + writeln!( + writer, + "{}: {size_before} -> {size_after} ({}{:.2}%)", + diff.function.name, + if percent.is_sign_positive() { "+" } else { "-" }, + percent.abs() + )?; + } + writer.write_all(b"\n")?; + + Ok(()) +} + +fn write_diff(writer: &mut W, use_color: bool, diff: &CodegenDiff) -> anyhow::Result<()> { use console::Style; let text_diff = TextDiff::from_lines(&diff.codegen1, &diff.codegen2);