Improve tracing output

This commit is contained in:
hal8174 2025-02-17 23:08:06 +01:00
parent cebdee4ec7
commit 81edc8e67a
6 changed files with 53 additions and 24 deletions

View file

@ -1,4 +1,4 @@
use tracing::{Level, info, span, trace, warn};
use tracing::{Level, field::Empty, info, span, trace, warn};
use crate::{
LayoutResult, Layouter,
@ -22,7 +22,6 @@ impl Layouter for GeneticAlgorithm {
pathfinder: &P,
rng: &mut R,
) -> Option<crate::LayoutResult> {
assert!(self.population_new > 0);
assert!(self.population_new + self.population_keep <= self.population_size);
let _complete_span = span!(Level::TRACE, "genetic_algorithm_v1").entered();
@ -47,7 +46,8 @@ impl Layouter for GeneticAlgorithm {
let mut best_result = population[0].clone();
for g in 0..self.generations {
let _generation_span = span!(Level::TRACE, "generation", g).entered();
let generation_span =
span!(Level::TRACE, "generation", generation = g, score = Empty).entered();
{
let _mutate_span = span!(Level::TRACE, "mutate").entered();
@ -99,7 +99,8 @@ impl Layouter for GeneticAlgorithm {
if population[0].1 < best_result.1 {
best_result = population[0].clone();
}
info!("completed generation {g} best score: {}", population[0].1);
generation_span.record("score", population[0].1);
println!("completed generation {g} best score: {}", population[0].1);
}
Some(best_result.0)