diff --git a/Cargo.lock b/Cargo.lock index 09f7cd7c..9604895a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -952,6 +952,7 @@ version = "0.6.0" dependencies = [ "clap", "clash_lib", + "dhat", ] [[package]] @@ -1578,6 +1579,22 @@ dependencies = [ "syn 2.0.77", ] +[[package]] +name = "dhat" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98cd11d84628e233de0ce467de10b8633f4ddaecafadefc86e13b84b8739b827" +dependencies = [ + "backtrace", + "lazy_static", + "mintex", + "parking_lot", + "rustc-hash 1.1.0", + "serde", + "serde_json", + "thousands", +] + [[package]] name = "dhcproto" version = "0.12.0" @@ -3220,6 +3237,12 @@ dependencies = [ "adler2", ] +[[package]] +name = "mintex" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9bec4598fddb13cc7b528819e697852653252b760f1228b7642679bf2ff2cd07" + [[package]] name = "mio" version = "0.8.11" @@ -5183,6 +5206,12 @@ dependencies = [ "syn 2.0.77", ] +[[package]] +name = "thousands" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3bf63baf9f5039dadc247375c29eb13706706cfde997d0330d05aa63a77d8820" + [[package]] name = "thread_local" version = "1.1.8" diff --git a/Cargo.toml b/Cargo.toml index f67ef84f..73e028a7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ opt-level = "s" codegen-units = 1 lto = true strip = true +debug = 1 [patch.crates-io] tokio-rustls = { git = "https://github.com/Watfaq/tokio-rustls.git", rev = "6b9af8ac7bb5abc159d9a67e9ddbf84127559a4a"} diff --git a/clash/Cargo.toml b/clash/Cargo.toml index b07f02c6..56a92fc3 100644 --- a/clash/Cargo.toml +++ b/clash/Cargo.toml @@ -12,7 +12,11 @@ tracing = ["clash_lib/tracing"] bench = ["clash_lib/bench"] onion = ["clash_lib/onion"] +dhat-heap = ["dep:dhat"] + [dependencies] clap = { version = "4.5.19", features = ["derive"] } -clash_lib = { path = "../clash_lib", version = "*", default-features = false } \ No newline at end of file +clash_lib = { path = "../clash_lib", version = "*", default-features = false } + +dhat = { version = "0.3.3", optional = true } \ No newline at end of file diff --git a/clash/src/main.rs b/clash/src/main.rs index 541cc731..bb2be8dc 100644 --- a/clash/src/main.rs +++ b/clash/src/main.rs @@ -1,3 +1,7 @@ +#[cfg(feature = "dhat-heap")] +#[global_allocator] +static ALLOC: dhat::Alloc = dhat::Alloc; + extern crate clash_lib as clash; use clap::Parser; @@ -45,6 +49,9 @@ struct Cli { } fn main() { + #[cfg(feature = "dhat-heap")] + let _profiler = dhat::Profiler::new_heap(); + let cli = Cli::parse(); if cli.version { @@ -81,6 +88,7 @@ fn main() { } } } + match clash::start(clash::Options { config: clash::Config::File(file), cwd: cli.directory.map(|x| x.to_string_lossy().to_string()),