diff --git a/Cargo.toml b/Cargo.toml index b6f855cb..688eb9f3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,10 +40,16 @@ tracing-subscriber = { version = "0.3.17", optional = true, features = ["env-fil walkdir = "2.3.3" [features] -default = ["compare", "tracing"] +default = ["compare"] compare = [] tracing = ["dep:opentelemetry", "dep:opentelemetry-otlp", "dep:opentelemetry-semantic-conventions", "dep:tokio", "dep:tracing", "dep:tracing-opentelemetry", "dep:tracing-subscriber"] -[profile.release] +[profile.release-lto] +inherits = "release" lto = true strip = "symbols" + +[profile.perf] +inherits = "release" +lto = true +debug = true diff --git a/scripts/callgrind.bash b/scripts/callgrind.bash new file mode 100755 index 00000000..4046e370 --- /dev/null +++ b/scripts/callgrind.bash @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +# +set -euo pipefail +IFS=$'\n\t' +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +cd "$DIR/../" + +RUSTFLAGS="-C opt-level=0" cargo build --no-default-features +valgrind --tool=callgrind --callgrind-out-file=callgrind.out target/debug/compare + +echo "You probably want to run:" +echo "callgrind_annotate --auto=yes callgrind.out" diff --git a/scripts/perf.bash b/scripts/perf.bash new file mode 100755 index 00000000..c7f9969a --- /dev/null +++ b/scripts/perf.bash @@ -0,0 +1,18 @@ +#!/usr/bin/env bash +# +set -euo pipefail +IFS=$'\n\t' +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +: ${PROFILE:="perf"} + +cd "$DIR/../" + +cargo build --profile "$PROFILE" --no-default-features +perf record --freq=2000 --call-graph dwarf --output=perf.data target/${PROFILE}/compare +# Convert to a format firefox will read +# flags to consider --show-info +perf script -F +pid --input perf.data > perf.firefox + +echo "You probably want to go to https://profiler.firefox.com/" +echo "Either that or run hotspot" diff --git a/src/main.rs b/src/main.rs index 33879e9f..03269cfa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,6 @@ #![feature(round_char_boundary)] -#[cfg(feature = "compare")] use std::io::Read; -#[cfg(feature = "compare")] use ::organic::parser::document; #[cfg(feature = "compare")] use organic::compare_document; @@ -37,14 +35,10 @@ fn main() -> Result<(), Box> { #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn main_body() -> Result<(), Box> { - #[cfg(not(feature = "compare"))] - let org_contents = ""; - #[cfg(feature = "compare")] let org_contents = read_stdin_to_string()?; run_compare(org_contents) } -#[cfg(feature = "compare")] fn read_stdin_to_string() -> Result> { let mut stdin_contents = String::new(); std::io::stdin() @@ -79,7 +73,9 @@ fn run_compare>(org_contents: P) -> Result<(), Box>(_org_contents: P) -> Result<(), Box> { - println!("This program was built with compare disabled. Doing nothing."); +fn run_compare>(org_contents: P) -> Result<(), Box> { + eprintln!("This program was built with compare disabled. Dumping the AST from rust."); + let (remaining, rust_parsed) = document(org_contents.as_ref()).expect("Org Parse failure"); + println!("{:#?}", rust_parsed); Ok(()) }