"serde_json",
]
-[[package]]
-name = "fs_extra"
-version = "1.1.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5f2a4a2034423744d2cc7ca2068453168dcdb82c438419e639a26bd87839c674"
-
[[package]]
name = "fsevent"
version = "2.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6"
-[[package]]
-name = "jemalloc-ctl"
-version = "0.3.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c502a5ff9dd2924f1ed32ba96e3b65735d837b4bfd978d3161b1702e66aca4b7"
-dependencies = [
- "jemalloc-sys",
- "libc",
- "paste",
-]
-
-[[package]]
-name = "jemalloc-sys"
-version = "0.3.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0d3b9f3f5c9b31aa0f5ed3260385ac205db665baa41d49bb8338008ae94ede45"
-dependencies = [
- "cc",
- "fs_extra",
- "libc",
-]
-
-[[package]]
-name = "jemallocator"
-version = "0.3.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "43ae63fcfc45e99ab3d1b29a46782ad679e98436c3169d15a167a1108a724b69"
-dependencies = [
- "jemalloc-sys",
- "libc",
-]
-
[[package]]
name = "jod-thread"
version = "0.1.2"
"winapi 0.3.9",
]
-[[package]]
-name = "paste"
-version = "0.1.18"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "45ca20c77d80be666aef2b45486da86238fabe33e38306bd3118fe4af33fa880"
-dependencies = [
- "paste-impl",
- "proc-macro-hack",
-]
-
-[[package]]
-name = "paste-impl"
-version = "0.1.18"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d95a7db200b97ef370c8e6de0088252f7e0dfff7d047a28528e47456c0fc98b6"
-dependencies = [
- "proc-macro-hack",
-]
-
[[package]]
name = "paths"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "237a5ed80e274dbc66f86bd59c1e25edc039660be53194b5fe0a482e0f2612ea"
-[[package]]
-name = "proc-macro-hack"
-version = "0.5.16"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7e0456befd48169b9f13ef0f0ad46d492cf9d2dbb918bcf38e01eed4ce3ec5e4"
-
[[package]]
name = "proc-macro2"
version = "1.0.19"
dependencies = [
"backtrace",
"cfg-if",
- "jemalloc-ctl",
- "jemallocator",
"libc",
"mimalloc",
"once_cell",
cfg-if = "0.1.10"
libc = "0.2.73"
-[target.'cfg(not(target_env = "msvc"))'.dependencies]
-jemallocator = { version = "0.3.2", optional = true }
-jemalloc-ctl = { version = "0.3.3", optional = true }
-
[features]
-jemalloc = [ "jemallocator", "jemalloc-ctl" ]
cpu_profiler = []
# Uncomment to enable for the whole crate graph
# default = [ "backtrace" ]
-# default = [ "jemalloc" ]
# default = [ "mimalloc" ]
# default = [ "cpu_profiler" ]
memory_usage::{Bytes, MemoryUsage},
};
-// We use jemalloc mainly to get heap usage statistics, actual performance
-// difference is not measures.
-#[cfg(all(feature = "jemalloc", not(target_env = "msvc")))]
-#[global_allocator]
-static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;
-
#[cfg(all(feature = "mimalloc"))]
#[global_allocator]
static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc;
//! FIXME: write short doc here
+use std::fmt;
use cfg_if::cfg_if;
-use std::fmt;
pub struct MemoryUsage {
pub allocated: Bytes,
impl MemoryUsage {
pub fn current() -> MemoryUsage {
cfg_if! {
- if #[cfg(all(feature = "jemalloc", not(target_env = "msvc")))] {
- jemalloc_ctl::epoch::advance().unwrap();
- MemoryUsage {
- allocated: Bytes(jemalloc_ctl::stats::allocated::read().unwrap()),
- resident: Bytes(jemalloc_ctl::stats::resident::read().unwrap()),
- }
- } else if #[cfg(target_os = "linux")] {
+ if #[cfg(target_os = "linux")] {
// Note: This is incredibly slow.
let alloc = unsafe { libc::mallinfo() }.uordblks as u32 as usize;
MemoryUsage { allocated: Bytes(alloc), resident: Bytes(0) }
tt = { path = "../ra_tt", package = "ra_tt" }
[features]
-jemalloc = [ "ra_prof/jemalloc" ]
mimalloc = [ "ra_prof/mimalloc" ]
FLAGS:
-o, --only Only analyze items matching this path
-h, --help Prints help information
- --memory-usage Collect memory usage statistics (requires `--features jemalloc`)
+ --memory-usage Collect memory usage statistics
--randomize Randomize order in which crates, modules, and items are processed
--parallel Run type inference in parallel
--load-output-dirs Load OUT_DIR values by running `cargo check` before analysis
FLAGS:
-h, --help Prints help information
- --memory-usage Collect memory usage statistics (requires `--features jemalloc`)
+ --memory-usage Collect memory usage statistics
--load-output-dirs Load OUT_DIR values by running `cargo check` before analysis
--with-proc-macro Use ra-proc-macro-srv for proc-macro expanding
-v, --verbose
There are also two VS Code commands which might be of interest:
-* `Rust Analyzer: Status` shows some memory-usage statistics. To take full
- advantage of it, you need to compile rust-analyzer with jemalloc support:
- ```
- $ cargo install --path crates/rust-analyzer --force --features jemalloc
- ```
-
- There's an alias for this: `cargo xtask install --server --jemalloc`.
+* `Rust Analyzer: Status` shows some memory-usage statistics.
* `Rust Analyzer: Syntax Tree` shows syntax tree of the current file/selection.
env::set_var("CC", "clang");
run!(
"cargo build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --release"
- // We'd want to add, but that requires setting the right linker somehow
- // --features=jemalloc
)?;
} else {
run!("cargo build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --release")?;
pub enum Malloc {
System,
- Jemalloc,
Mimalloc,
}
let malloc_feature = match opts.malloc {
Malloc::System => "",
- Malloc::Jemalloc => "--features jemalloc",
Malloc::Mimalloc => "--features mimalloc",
};
let res = run!("cargo install --path crates/rust-analyzer --locked --force {}", malloc_feature);
FLAGS:
--client-code Install only VS Code plugin
--server Install only the language server
- --jemalloc Use jemalloc for server
--mimalloc Use mimalloc for server
-h, --help Prints help information
"
return Ok(());
}
- let malloc = match (args.contains("--jemalloc"), args.contains("--mimalloc")) {
- (false, false) => Malloc::System,
- (true, false) => Malloc::Jemalloc,
- (false, true) => Malloc::Mimalloc,
- (true, true) => {
- eprintln!("error: Cannot use both `--jemalloc` and `--mimalloc`");
- return Ok(());
- }
- };
+ let malloc =
+ if args.contains("--mimalloc") { Malloc::Mimalloc } else { Malloc::System };
args.finish()?;