Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds '--compare-solvers' option #882

Merged
merged 2 commits into from
Dec 19, 2023
Merged

Adds '--compare-solvers' option #882

merged 2 commits into from
Dec 19, 2023

Conversation

dcookspi
Copy link
Collaborator

This adds the --compare-solvers option that will run all the solvers to completion and produce a short report comparing the work they did. The report is fairly basic at the moment, but it is useful when comparing solvers with different settings or tweaks. The first solver to finish is used as 'the result' to return the rest of the program.

In cases where one solver might run for a long time before finishing, the existing --timeout <seconds> option can be used to limit the solvers run time.

Examples:

> spk explain --compare-solvers somepackage
...
Unchanged            : solved in 1.720847 seconds, 54 steps (0 back), 62 builds at 36.029 builds/sec
All Impossible Checks: solved in 2.404295 seconds, 54 steps (0 back), 62 builds at 25.787 builds/sec
..

# or
> spk explain --compare-solvers anotherpackage someotherpackage
...
All Impossible Checks: solved in 4.820338 seconds, 133 steps (84 back), 446 builds at 92.525 builds/sec
Unchanged            : failed in 30.022511 seconds, 3593 steps (84 back), 10681 builds at 355.766 builds/sec
...

crates/spk-solve/src/io.rs Outdated Show resolved Hide resolved
crates/spk-solve/src/io.rs Outdated Show resolved Hide resolved
Comment on lines 964 to 1033
let mut lines = Vec::new();
let mut max_width = 0;
for (solver_kind, duration, solver, result) in solver_results.iter() {
let solved = if result.is_ok() { "solved" } else { "failed" };
let seconds = duration.as_secs_f64();
let total_builds = solver.get_total_builds();
let num_steps = solver.get_number_of_steps();
let num_steps_back = solver.get_number_of_steps_back();

let kind = format!("{solver_kind}");
let length = kind.len();
max_width = max(max_width, length);

lines.push((
kind,
solved,
seconds,
num_steps,
num_steps_back,
total_builds,
));
}

for (solver_kind, solved, seconds, num_steps, num_steps_back, total_builds) in
lines.into_iter()
{
let padding = " ".repeat(max_width - solver_kind.len());
let builds = "build".pluralize(total_builds);
let steps = "step".pluralize(num_steps);

println!("{solver_kind}{padding}: {solved} in {seconds:.6} seconds, {num_steps} {steps} ({num_steps_back} back), {total_builds} {builds} at {:.3} builds/sec", total_builds as f64 / seconds);
}

// Give the first result to finish back to the rest of the
// program as the result.
match solver_results.first() {
Some((_, _, _, result)) => match result {
Ok(s) => Ok(s.clone()),
Err(e) => Err(Error::String(format!("{e}"))),
},
None => Err(Error::String(
"Multi-solver task failed to run any tasks for comparsion.".to_string(),
)),
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be captured in a separate function easily, I think it would go a long way to clarifying and keeping the the complexity of this outer function down as much as possible

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've pulled this out into a method, and added a struct for the solver result data.

…compare the work they did.

Signed-off-by: David Gilligan-Cook <dcook@imageworks.com>
Signed-off-by: David Gilligan-Cook <dcook@imageworks.com>
@dcookspi dcookspi merged commit 91cc844 into main Dec 19, 2023
4 checks passed
@dcookspi dcookspi deleted the adds-compare-solvers branch December 19, 2023 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request SPI AOI Area of interest for SPI SPI-0.39
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants