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

Replace calls to dbg! with log::debug! + env_logger #89

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ image = { version = "0.24.9", default-features = false, features = ["webp"] }
serde = { version = "1.0.203", features = ["derive"] }
ron = "0.8"
log = "0.4"
env_logger = "0.11.5"
rust-i18n = "3.1.2"

[target.'cfg(target_arch = "wasm32")'.dependencies]
Expand Down
3 changes: 3 additions & 0 deletions raphael-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ solvers = { path = "../solvers" }
game-data = { path = "../game_data" }

clap = { version = "4.4.11", features = ["derive", "wrap_help"] }

log = "0.4"
env_logger = "0.11.5"
2 changes: 2 additions & 0 deletions raphael-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ struct Args {
}

fn main() {
env_logger::init();

let args = Args::parse();

let recipe = RECIPES
Expand Down
1 change: 1 addition & 0 deletions simulator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ rand = "0.8.5"
[dependencies]
bitfield-struct = "0.8.0"
serde = { version = "1.0.203", features = ["derive"] }
log = "0.4"
6 changes: 3 additions & 3 deletions simulator/tests/adversarial_tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use log::debug;
use simulator::{Action, ActionMask, Condition, Settings, SimulationState};

const SETTINGS: Settings = Settings {
max_cp: 1000,
max_durability: 80,
Expand Down Expand Up @@ -228,7 +228,7 @@ fn test_exhaustive() {
.collect();
let state = SimulationState::from_macro(&SETTINGS, &actions);
if let Ok(state) = state {
dbg!(&actions);
debug!("Testing actions: {:?}", &actions);
assert_eq!(
state.quality,
guaranteed_quality(SETTINGS, &actions).unwrap()
Expand Down Expand Up @@ -259,7 +259,7 @@ fn test_fuzz() {
.take(STEPS)
.collect();
if let Ok(state) = SimulationState::from_macro(&SETTINGS, &actions) {
dbg!(&actions);
debug!("Testing actions: {:?}", &actions);
assert_eq!(
state.quality,
guaranteed_quality(SETTINGS, &actions).unwrap()
Expand Down
1 change: 1 addition & 0 deletions solvers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ simulator = { path = "../simulator" }
radix-heap = "0.4.2"
rustc-hash = "1.1.0"
bitfield-struct = "0.8.0"
log = "0.4"

[dev-dependencies]
rand = "0.8.5"
14 changes: 11 additions & 3 deletions solvers/examples/macro_solver_example.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
use simulator::{Action, ActionMask, Settings, SimulationState};
use solvers::MacroSolver;

use log::debug;

fn main() {
dbg!(std::mem::size_of::<SimulationState>());
dbg!(std::mem::align_of::<SimulationState>());
debug!(
"SimulationState size: {} bytes, alignment: {} bytes",
std::mem::size_of::<SimulationState>(),
std::mem::align_of::<SimulationState>()
);

// Ra'Kaznar Lapidary Hammer
// 4462 Craftsmanship, 4391 Control
Expand Down Expand Up @@ -32,5 +37,8 @@ fn main() {
.quality;
let steps = actions.len();
let duration: i16 = actions.iter().map(|action| action.time_cost()).sum();
dbg!(quality, steps, duration);
debug!(
"Solution stats - quality: {}, steps: {}, duration: {}",
quality, steps, duration
);
}
14 changes: 11 additions & 3 deletions solvers/src/finish_solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use rustc_hash::FxHashMap as HashMap;

use super::actions::{DURABILITY_ACTIONS, PROGRESS_ACTIONS};

use log::debug;

const SEARCH_ACTIONS: ActionMask = PROGRESS_ACTIONS
.union(DURABILITY_ACTIONS)
.remove(Action::DelicateSynthesis);
Expand Down Expand Up @@ -53,8 +55,11 @@ pub struct FinishSolver {

impl FinishSolver {
pub fn new(settings: Settings) -> FinishSolver {
dbg!(std::mem::size_of::<ReducedState>());
dbg!(std::mem::align_of::<ReducedState>());
debug!(
"ReducedState size: {} bytes, alignment: {} bytes",
std::mem::size_of::<ReducedState>(),
std::mem::align_of::<ReducedState>()
);
FinishSolver {
settings,
max_progress: HashMap::default(),
Expand Down Expand Up @@ -105,6 +110,9 @@ impl FinishSolver {

impl Drop for FinishSolver {
fn drop(&mut self) {
dbg!(self.max_progress.len());
debug!(
"FinishSolver max_progress cache size: {}",
self.max_progress.len()
);
}
}
3 changes: 2 additions & 1 deletion solvers/src/macro_solver/fast_lower_bound.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use log::debug;
use radix_heap::RadixHeapMap;
use simulator::{Action, ActionMask, Combo, Condition, Settings, SimulationState};

Expand Down Expand Up @@ -61,7 +62,7 @@ pub fn fast_lower_bound(
}
}

dbg!(quality_lower_bound);
debug!("Quality lower bound: {}", quality_lower_bound);
std::cmp::min(settings.max_quality, quality_lower_bound)
}

Expand Down
7 changes: 6 additions & 1 deletion solvers/src/macro_solver/pareto_front/effect_pareto_front.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use log::debug;
use rustc_hash::FxHashMap;
use simulator::{Combo, SimulationState};

Expand Down Expand Up @@ -93,6 +94,10 @@ impl EffectParetoFront {
impl Drop for EffectParetoFront {
fn drop(&mut self) {
let pareto_entries: usize = self.buckets.values().map(|value| value.len()).sum();
dbg!(self.buckets.len(), pareto_entries);
debug!(
"Effect pareto front stats - buckets: {}, entries: {}",
self.buckets.len(),
pareto_entries
);
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use log::debug;
use rustc_hash::FxHashMap;
use simulator::{Combo, Effects, SimulationState};

Expand Down Expand Up @@ -69,6 +70,10 @@ impl QualityParetoFront {
impl Drop for QualityParetoFront {
fn drop(&mut self) {
let pareto_entries: usize = self.buckets.values().map(|value| value.len()).sum();
dbg!(self.buckets.len(), pareto_entries);
debug!(
"Quality pareto front stats - buckets: {}, entries: {}",
self.buckets.len(),
pareto_entries
);
}
}
7 changes: 6 additions & 1 deletion solvers/src/macro_solver/search_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use crate::utils::Backtracking;

use super::pareto_front::{EffectParetoFront, QualityParetoFront};

use log::debug;

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct SearchScore {
pub quality: u16,
Expand Down Expand Up @@ -84,7 +86,10 @@ impl SearchQueue {
}
dropped += self.buckets.pop_first().unwrap().1.len();
}
dbg!(self.minimum_score, dropped);
debug!(
"Updated minimum score to {:?}, dropped {} nodes",
self.minimum_score, dropped
);
}

pub fn push(
Expand Down
4 changes: 3 additions & 1 deletion solvers/src/macro_solver/solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use crate::{FinishSolver, QualityUpperBoundSolver, StepLowerBoundSolver};

use std::vec::Vec;

use log::debug;

const FULL_SEARCH_ACTIONS: ActionMask = PROGRESS_ACTIONS
.union(QUALITY_ACTIONS)
.union(DURABILITY_ACTIONS);
Expand Down Expand Up @@ -194,7 +196,7 @@ impl<'a> MacroSolver<'a> {
}

if let Some(solution) = solution {
dbg!(&solution.actions);
debug!("Found solution actions: {:?}", &solution.actions);
Some(solution.actions)
} else {
None
Expand Down
15 changes: 11 additions & 4 deletions solvers/src/quality_upper_bound_solver/solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use rustc_hash::FxHashMap as HashMap;

use super::state::ReducedState;

use log::debug;

const FULL_SEARCH_ACTIONS: ActionMask = PROGRESS_ACTIONS
.union(QUALITY_ACTIONS)
.add(Action::WasteNot)
Expand Down Expand Up @@ -36,8 +38,11 @@ pub struct QualityUpperBoundSolver {

impl QualityUpperBoundSolver {
pub fn new(settings: Settings, backload_progress: bool, unsound_branch_pruning: bool) -> Self {
dbg!(std::mem::size_of::<ReducedState>());
dbg!(std::mem::align_of::<ReducedState>());
debug!(
"ReducedState size: {} bytes, alignment: {} bytes",
std::mem::size_of::<ReducedState>(),
std::mem::align_of::<ReducedState>()
);

let initial_state = SimulationState::new(&settings);
let mut durability_cost = 100;
Expand Down Expand Up @@ -228,6 +233,7 @@ fn waste_not_min_cp(

#[cfg(test)]
mod tests {
use log::error;
use rand::Rng;
use simulator::{Combo, Effects, SimulationState};

Expand All @@ -237,7 +243,7 @@ mod tests {
let state = SimulationState::from_macro(&settings, actions).unwrap();
let result =
QualityUpperBoundSolver::new(settings, false, false).quality_upper_bound(state);
dbg!(result);
debug!("Quality upper bound result: {}", result);
result
}

Expand Down Expand Up @@ -731,7 +737,8 @@ mod tests {
Err(_) => 0,
};
if state_upper_bound < child_upper_bound {
dbg!(state, action, state_upper_bound, child_upper_bound);
error!("Monotonicity violation - state: {:?}, action: {:?}, state_ub: {}, child_ub: {}",
state, action, state_upper_bound, child_upper_bound);
panic!("Parent's upper bound is less than child's upper bound");
}
}
Expand Down
14 changes: 10 additions & 4 deletions solvers/src/step_lower_bound_solver/solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::{
branch_pruning::is_progress_only_state,
utils::{ParetoFrontBuilder, ParetoFrontId, ParetoValue},
};
use log::debug;
use simulator::*;

use rustc_hash::FxHashMap as HashMap;
Expand Down Expand Up @@ -32,8 +33,11 @@ impl StepLowerBoundSolver {
backload_progress: bool,
unsound_branch_pruning: bool,
) -> Self {
dbg!(std::mem::size_of::<ReducedState>());
dbg!(std::mem::align_of::<ReducedState>());
debug!(
"ReducedState size: {} bytes, alignment: {} bytes",
std::mem::size_of::<ReducedState>(),
std::mem::align_of::<ReducedState>()
);
let mut bonus_durability_restore = 0;
if settings.is_action_allowed::<ImmaculateMend>() {
bonus_durability_restore =
Expand Down Expand Up @@ -209,6 +213,7 @@ impl StepLowerBoundSolver {

#[cfg(test)]
mod tests {
use log::error;
use rand::Rng;
use simulator::{Action, ActionMask, Combo, Effects, SimulationState};

Expand All @@ -217,7 +222,7 @@ mod tests {
fn solve(settings: Settings, actions: &[Action]) -> u8 {
let state = SimulationState::from_macro(&settings, actions).unwrap();
let result = StepLowerBoundSolver::new(settings, false, false).step_lower_bound(state);
dbg!(result);
debug!("Step lower bound result: {}", result);
result
}

Expand Down Expand Up @@ -713,7 +718,8 @@ mod tests {
Err(_) => u8::MAX,
};
if state_lower_bound > child_lower_bound.saturating_add(1) {
dbg!(state, action, state_lower_bound, child_lower_bound);
error!("Monotonicity violation - state: {:?}, action: {:?}, state_lb: {}, child_lb: {}",
state, action, state_lower_bound, child_lower_bound);
panic!("Parent's step lower bound is greater than child's step lower bound");
}
}
Expand Down
3 changes: 2 additions & 1 deletion solvers/src/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod pareto_front_builder;
use log::debug;
pub use pareto_front_builder::{ParetoFrontBuilder, ParetoFrontId, ParetoValue};

pub struct NamedTimer {
Expand Down Expand Up @@ -87,6 +88,6 @@ impl<T: Copy> Backtracking<T> {

impl<T: Copy> Drop for Backtracking<T> {
fn drop(&mut self) {
dbg!(self.entries.len());
debug!("Backtracking entries length: {}", self.entries.len());
}
}
9 changes: 4 additions & 5 deletions solvers/src/utils/pareto_front_builder.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use log::debug;

#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub struct ParetoValue<T, U> {
pub first: T,
Expand Down Expand Up @@ -252,11 +254,8 @@ where
U: Copy + std::cmp::Ord + std::default::Default,
{
fn drop(&mut self) {
dbg!(
self.buffer.capacity(),
self.fronts_generated,
self.storage.len()
);
debug!("Pareto front builder stats - buffer capacity: {}, fronts generated: {}, storage length: {}",
self.buffer.capacity(), self.fronts_generated, self.storage.len());
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use std::time::Duration;

use serde::{de::DeserializeOwned, Deserialize, Serialize};

use log::debug;

#[cfg(not(target_arch = "wasm32"))]
use std::time::Instant;
#[cfg(target_arch = "wasm32")]
Expand Down Expand Up @@ -375,14 +377,14 @@ impl MacroSolverApp {
self.solver_progress = progress;
}
SolverEvent::IntermediateSolution(_) | SolverEvent::FinalSolution(_) => {
dbg!(update);
debug!("Unexpected progress update: {:?}", update);
}
}
}
if let Some(update) = self.data_update.solution_update.take() {
match update {
SolverEvent::Progress(_) => {
dbg!(update);
debug!("Unexpected solution update: {:?}", update);
}
SolverEvent::IntermediateSolution(actions) => {
self.actions = actions;
Expand Down
4 changes: 4 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#[cfg(not(target_arch = "wasm32"))]
fn main() -> eframe::Result<()> {
env_logger::init();

let native_options = eframe::NativeOptions {
viewport: egui::ViewportBuilder::default()
.with_inner_size([400.0, 300.0])
Expand All @@ -18,6 +20,8 @@ fn main() -> eframe::Result<()> {

#[cfg(target_arch = "wasm32")]
fn main() {
env_logger::init();

// Redirect `log` message to `console.log` and friends:
eframe::WebLogger::init(log::LevelFilter::Debug).ok();

Expand Down
Loading