-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Hash lookups are way to slow to use for logging. Switch to tags with a boolean enable bit. This is a better log tag management approach, anyway, since we can now see all tags in one place. * Remove a number of println! in favor of logs. Test runtime is significantly faster now.
- Loading branch information
Showing
11 changed files
with
123 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,41 @@ | ||
use std::fmt::Display; | ||
use std::{borrow::Borrow, collections::HashSet, hash::Hash}; | ||
|
||
pub trait Logger { | ||
fn log<S: Borrow<str> + Eq + Hash + Display, F>(&self, tag: S, msg: F) | ||
where | ||
F: Fn() -> String; | ||
fn log<F: Fn() -> String>(&self, tag: Tag, msg: F); | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct PrintLogger { | ||
tags: HashSet<String>, | ||
#[derive(Debug, Clone, Default)] | ||
pub struct PrintLogger; | ||
|
||
#[derive(Debug)] | ||
pub enum Tag { | ||
Activate, | ||
Enter, | ||
Flow, | ||
Load, | ||
Local, | ||
Mem, | ||
Op, | ||
Host, | ||
Spec, | ||
|
||
Stack, | ||
LabelStack, | ||
ValStack, | ||
DumpStack, | ||
DumpLabelStack, | ||
DumpValStack, | ||
} | ||
|
||
impl Default for PrintLogger { | ||
fn default() -> Self { | ||
let mut tags = HashSet::default(); | ||
tags.insert("SPEC".to_owned()); | ||
tags.insert("LOAD".to_owned()); | ||
tags.insert("HOST".to_owned()); | ||
Self { tags } | ||
impl Tag { | ||
fn enabled(&self) -> bool { | ||
matches!(self, Tag::Load | Tag::Spec | Tag::Host) | ||
} | ||
} | ||
|
||
impl Logger for PrintLogger { | ||
fn log<S: Borrow<str> + Eq + Hash + Display, F>(&self, tag: S, msg: F) | ||
where | ||
F: Fn() -> String, | ||
{ | ||
if self.tags.contains(tag.borrow()) { | ||
fn log<F: Fn() -> String>(&self, tag: Tag, msg: F) { | ||
if tag.enabled() { | ||
let msg = msg(); | ||
println!("[{}] {}", tag, msg) | ||
println!("[{:?}] {}", tag, msg) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.