diff options
Diffstat (limited to 'crates/ra_prof/src/lib.rs')
-rw-r--r-- | crates/ra_prof/src/lib.rs | 23 |
1 files changed, 6 insertions, 17 deletions
diff --git a/crates/ra_prof/src/lib.rs b/crates/ra_prof/src/lib.rs index 1fac0b14a..402c719b1 100644 --- a/crates/ra_prof/src/lib.rs +++ b/crates/ra_prof/src/lib.rs | |||
@@ -15,14 +15,10 @@ use lazy_static::lazy_static; | |||
15 | /// | 15 | /// |
16 | /// #Example | 16 | /// #Example |
17 | /// ``` | 17 | /// ``` |
18 | /// use ra_prof::set_filter; | 18 | /// use ra_prof::{set_filter, Filter}; |
19 | /// use ra_prof::Filter; | 19 | /// let f = Filter::from_spec("profile1|profile2@2"); |
20 | /// let max_depth = 2; | ||
21 | /// let allowed = vec!["profile1".to_string(), "profile2".to_string()]; | ||
22 | /// let f = Filter::new( max_depth, allowed ); | ||
23 | /// set_filter(f); | 20 | /// set_filter(f); |
24 | /// ``` | 21 | /// ``` |
25 | /// | ||
26 | pub fn set_filter(f: Filter) { | 22 | pub fn set_filter(f: Filter) { |
27 | PROFILING_ENABLED.store(f.depth > 0, Ordering::SeqCst); | 23 | PROFILING_ENABLED.store(f.depth > 0, Ordering::SeqCst); |
28 | let set = HashSet::from_iter(f.allowed.iter().cloned()); | 24 | let set = HashSet::from_iter(f.allowed.iter().cloned()); |
@@ -43,12 +39,9 @@ pub fn set_filter(f: Filter) { | |||
43 | /// | 39 | /// |
44 | /// #Example | 40 | /// #Example |
45 | /// ``` | 41 | /// ``` |
46 | /// use ra_prof::profile; | 42 | /// use ra_prof::{profile, set_filter, Filter}; |
47 | /// use ra_prof::set_filter; | ||
48 | /// use ra_prof::Filter; | ||
49 | /// | 43 | /// |
50 | /// let allowed = vec!["profile1".to_string(), "profile2".to_string()]; | 44 | /// let f = Filter::from_spec("profile1|profile2@2"); |
51 | /// let f = Filter::new(2, allowed); | ||
52 | /// set_filter(f); | 45 | /// set_filter(f); |
53 | /// profiling_function1(); | 46 | /// profiling_function1(); |
54 | /// | 47 | /// |
@@ -66,7 +59,6 @@ pub fn set_filter(f: Filter) { | |||
66 | /// 0ms - profile | 59 | /// 0ms - profile |
67 | /// 0ms - profile2 | 60 | /// 0ms - profile2 |
68 | /// ``` | 61 | /// ``` |
69 | /// | ||
70 | pub fn profile(desc: &str) -> Profiler { | 62 | pub fn profile(desc: &str) -> Profiler { |
71 | assert!(!desc.is_empty()); | 63 | assert!(!desc.is_empty()); |
72 | if !PROFILING_ENABLED.load(Ordering::Relaxed) { | 64 | if !PROFILING_ENABLED.load(Ordering::Relaxed) { |
@@ -220,15 +212,12 @@ fn print(lvl: usize, msgs: &[Message], out: &mut impl Write) { | |||
220 | 212 | ||
221 | #[cfg(test)] | 213 | #[cfg(test)] |
222 | mod tests { | 214 | mod tests { |
223 | 215 | use super::*; | |
224 | use super::profile; | ||
225 | use super::set_filter; | ||
226 | use super::Filter; | ||
227 | 216 | ||
228 | #[test] | 217 | #[test] |
229 | fn test_basic_profile() { | 218 | fn test_basic_profile() { |
230 | let s = vec!["profile1".to_string(), "profile2".to_string()]; | 219 | let s = vec!["profile1".to_string(), "profile2".to_string()]; |
231 | let f = Filter::new(2, s); | 220 | let f = Filter::new(2, s, Duration::new(0, 0)); |
232 | set_filter(f); | 221 | set_filter(f); |
233 | profiling_function1(); | 222 | profiling_function1(); |
234 | } | 223 | } |