Add debug logging and log stats on shortest path found

ida_star
Wilfred Hughes 2021-09-04 10:46:51 +07:00
parent 2cb1f02f62
commit 86a330c44e
5 changed files with 97 additions and 4 deletions

@ -28,6 +28,9 @@ Removed the unused `--lang` argument.
Difftastic now handles writing to a closed pipe (SIGPIPE) gracefully
rather than crashing.
Difftastic now has some debugging logs available. `RUST_LOG=trace`
will show information on the route found during graph solving.
## 0.7
### Git integration

73
Cargo.lock generated

@ -43,6 +43,12 @@ version = "1.0.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e70cc2f62c6ce1868963827bd677764c62d07c3d9a3e1fb1177ee1a9ab199eb2"
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "clap"
version = "2.33.3"
@ -103,7 +109,9 @@ dependencies = [
"itertools",
"lazy_static",
"libc",
"log",
"pretty_assertions",
"pretty_env_logger",
"regex",
"rustc-hash",
"strsim 0.10.0",
@ -118,6 +126,19 @@ version = "1.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
[[package]]
name = "env_logger"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36"
dependencies = [
"atty",
"humantime",
"log",
"regex",
"termcolor",
]
[[package]]
name = "hermit-abi"
version = "0.1.19"
@ -127,6 +148,15 @@ dependencies = [
"libc",
]
[[package]]
name = "humantime"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f"
dependencies = [
"quick-error",
]
[[package]]
name = "itertools"
version = "0.8.2"
@ -148,6 +178,15 @@ version = "0.2.99"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a7f823d141fe0a24df1e23b4af4e3c7ba9e5966ec514ea068c93024aa7deb765"
[[package]]
name = "log"
version = "0.4.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710"
dependencies = [
"cfg-if",
]
[[package]]
name = "memchr"
version = "2.4.0"
@ -175,6 +214,16 @@ dependencies = [
"output_vt100",
]
[[package]]
name = "pretty_env_logger"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "926d36b9553851b8b0005f1275891b392ee4d2d833852c417ed025477350fb9d"
dependencies = [
"env_logger",
"log",
]
[[package]]
name = "proc-macro2"
version = "1.0.28"
@ -184,6 +233,12 @@ dependencies = [
"unicode-xid",
]
[[package]]
name = "quick-error"
version = "1.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0"
[[package]]
name = "quote"
version = "1.0.9"
@ -249,6 +304,15 @@ dependencies = [
"winapi",
]
[[package]]
name = "termcolor"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4"
dependencies = [
"winapi-util",
]
[[package]]
name = "textwrap"
version = "0.11.0"
@ -308,6 +372,15 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-util"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
dependencies = [
"winapi",
]
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"

@ -30,6 +30,8 @@ lazy_static = "1.4.0"
atty = "0.2.14"
tree-sitter = "0.19.5"
libc = "0.2.99"
log = "0.4.14"
pretty_env_logger = "0.4.0"
[dev-dependencies]
pretty_assertions = "0.6.1"

@ -230,15 +230,24 @@ fn shortest_path(start: Vertex) -> Vec<(Edge, Vertex)> {
}
}
info!(
"Found predecessors for {} syntax nodes.",
predecessors.len()
);
let mut current = end;
let mut res: Vec<(Edge, Vertex)> = vec![];
let mut route: Vec<(Edge, Vertex)> = vec![];
let mut cost = 0;
while let Some(Some((node, edge))) = predecessors.remove(&current) {
res.push((edge, node.clone()));
route.push((edge, node.clone()));
cost += edge.cost();
current = node;
}
info!("Found found a path of {} with cost {}.", route.len(), cost);
res.reverse();
res
route.reverse();
route
}
const NOVEL_TREE_THRESHOLD: u64 = 20;

@ -23,6 +23,10 @@ use crate::lines::{join_overlapping, visible_groups, MaxLine};
use crate::syntax::{change_positions, init_info, matching_lines};
use crate::tree_sitter_parser as tsp;
extern crate pretty_env_logger;
#[macro_use]
extern crate log;
fn configure_color() {
if atty::is(Stream::Stdout) || env::var("GIT_PAGER_IN_USE").is_ok() {
// Always enable colour if stdout is a TTY or if the git pager is active.
@ -147,6 +151,8 @@ fn reset_sigpipe() {
}
fn main() {
pretty_env_logger::init();
reset_sigpipe();
configure_color();
let arena = Arena::new();