From e5c5c0a040e0c74892ea0a36c7fd50e5410879bd Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 21 Jan 2021 19:04:50 +0300 Subject: Include `countme` crate to count important data structures. --- crates/profile/Cargo.toml | 1 + crates/profile/src/hprof.rs | 4 +++- crates/profile/src/lib.rs | 7 +++++++ 3 files changed, 11 insertions(+), 1 deletion(-) (limited to 'crates/profile') diff --git a/crates/profile/Cargo.toml b/crates/profile/Cargo.toml index f7231c2b8..cc7da27f7 100644 --- a/crates/profile/Cargo.toml +++ b/crates/profile/Cargo.toml @@ -14,6 +14,7 @@ once_cell = "1.3.1" cfg-if = "1" libc = "0.2.73" la-arena = { version = "0.2.0", path = "../../lib/arena" } +countme = { version = "2.0.0-pre.2", features = ["enable"] } jemalloc-ctl = { version = "0.3.3", optional = true } [target.'cfg(target_os = "linux")'.dependencies] diff --git a/crates/profile/src/hprof.rs b/crates/profile/src/hprof.rs index 8957ea016..29d2ed518 100644 --- a/crates/profile/src/hprof.rs +++ b/crates/profile/src/hprof.rs @@ -3,6 +3,7 @@ use once_cell::sync::Lazy; use std::{ cell::RefCell, collections::{BTreeMap, HashSet}, + env, io::{stderr, Write}, sync::{ atomic::{AtomicBool, Ordering}, @@ -18,7 +19,8 @@ use crate::tree::{Idx, Tree}; /// env RA_PROFILE=foo|bar|baz // enabled only selected entries /// env RA_PROFILE=*@3>10 // dump everything, up to depth 3, if it takes more than 10 ms pub fn init() { - let spec = std::env::var("RA_PROFILE").unwrap_or_default(); + countme::enable(env::var("RA_COUNT").is_ok()); + let spec = env::var("RA_PROFILE").unwrap_or_default(); init_from(&spec); } diff --git a/crates/profile/src/lib.rs b/crates/profile/src/lib.rs index aa6ccc36c..79dba47d5 100644 --- a/crates/profile/src/lib.rs +++ b/crates/profile/src/lib.rs @@ -15,6 +15,13 @@ pub use crate::{ stop_watch::{StopWatch, StopWatchSpan}, }; +pub use countme; +/// Include `_c: Count` field in important structs to count them. +/// +/// To view the counts, run with `RA_COUNT=1`. The overhead of disabled count is +/// almost zero. +pub use countme::Count; + thread_local!(static IN_SCOPE: RefCell = RefCell::new(false)); /// Allows to check if the current code is withing some dynamic scope, can be -- cgit v1.2.3