|
1 | 1 | use std::collections::HashMap;
|
2 |
| -use std::io::IsTerminal; |
| 2 | +use std::io::{IsTerminal, Write}; |
3 | 3 | use std::path::Path;
|
4 | 4 | use std::process::Command;
|
5 | 5 |
|
@@ -58,8 +58,9 @@ pub fn codegen_diff(
|
58 | 58 | .context("Cannot generate codegen using compiler 1")?;
|
59 | 59 | let codegen2 =
|
60 | 60 | get_codegen(&toolchain2, &group.path, codegen_type, *toolchain2_index)
|
61 |
| - .context("Cannot generate codegen using compiler 1")?; |
| 61 | + .context("Cannot generate codegen using compiler 2")?; |
62 | 62 | if codegen1.trim() != codegen2.trim() {
|
| 63 | + log::debug!("Analysed function {}", function.name); |
63 | 64 | return Ok(Some(CodegenDiff::new(function, codegen1, codegen2)));
|
64 | 65 | }
|
65 | 66 | }
|
@@ -98,6 +99,7 @@ pub fn codegen_diff(
|
98 | 99 |
|
99 | 100 | let mut output = std::io::stdout().lock();
|
100 | 101 | let use_color = output.is_terminal();
|
| 102 | + write_stats(&mut output, &diffs).context("Cannot write stats")?; |
101 | 103 | for diff in diffs {
|
102 | 104 | write_diff(&mut output, use_color, &diff).context("Cannot write diff")?;
|
103 | 105 | }
|
@@ -157,11 +159,30 @@ impl<'a> CodegenDiff<'a> {
|
157 | 159 | }
|
158 | 160 | }
|
159 | 161 |
|
160 |
| -fn write_diff<W: std::io::Write>( |
161 |
| - writer: &mut W, |
162 |
| - use_color: bool, |
163 |
| - diff: &CodegenDiff, |
164 |
| -) -> anyhow::Result<()> { |
| 162 | +fn write_stats<W: Write>(writer: &mut W, diffs: &[CodegenDiff]) -> anyhow::Result<()> { |
| 163 | + writeln!(writer, "Function size stats:")?; |
| 164 | + for diff in diffs { |
| 165 | + let size_before = diff.codegen1.len(); |
| 166 | + let size_after = diff.codegen2.len(); |
| 167 | + if size_before == size_after { |
| 168 | + continue; |
| 169 | + } |
| 170 | + let percent = (size_after as f64 / size_before as f64) - 1.0; |
| 171 | + let percent = percent * 100.0; |
| 172 | + writeln!( |
| 173 | + writer, |
| 174 | + "{}: {size_before} -> {size_after} ({}{:.2}%)", |
| 175 | + diff.function.name, |
| 176 | + if percent.is_sign_positive() { "+" } else { "-" }, |
| 177 | + percent.abs() |
| 178 | + )?; |
| 179 | + } |
| 180 | + writer.write_all(b"\n")?; |
| 181 | + |
| 182 | + Ok(()) |
| 183 | +} |
| 184 | + |
| 185 | +fn write_diff<W: Write>(writer: &mut W, use_color: bool, diff: &CodegenDiff) -> anyhow::Result<()> { |
165 | 186 | use console::Style;
|
166 | 187 |
|
167 | 188 | let text_diff = TextDiff::from_lines(&diff.codegen1, &diff.codegen2);
|
|
0 commit comments