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/src/hprof.rs | 4 +++- crates/profile/src/lib.rs | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'crates/profile/src') 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