aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_prof
diff options
context:
space:
mode:
authorSergey Parilin <[email protected]>2019-04-03 14:05:55 +0100
committerSergey Parilin <[email protected]>2019-04-03 14:05:55 +0100
commitcc2212f3cbf72daf10a094e2293334f196f8c75c (patch)
tree2e91ebd22871229417f6bcea2851f1d075d78a56 /crates/ra_prof
parentb74449e9952846a8ea66c3507e52c24348d6dbc9 (diff)
added some docs to public functions
Diffstat (limited to 'crates/ra_prof')
-rw-r--r--crates/ra_prof/src/lib.rs47
1 files changed, 46 insertions, 1 deletions
diff --git a/crates/ra_prof/src/lib.rs b/crates/ra_prof/src/lib.rs
index abddff960..1cc8e361d 100644
--- a/crates/ra_prof/src/lib.rs
+++ b/crates/ra_prof/src/lib.rs
@@ -9,6 +9,20 @@ use std::iter::FromIterator;
9use std::sync::RwLock; 9use std::sync::RwLock;
10use lazy_static::lazy_static; 10use lazy_static::lazy_static;
11 11
12/// Set profiling filter. It specifies descriptions allowed to profile.
13/// This is helpful when call stack has too many nested profiling scopes.
14/// Additionally filter can specify maximum depth of profiling scopes nesting.
15///
16/// #Example
17/// ```
18/// use ra_prof::set_filter;
19/// use ra_prof::Filter;
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);
24/// ```
25///
12pub fn set_filter(f: Filter) { 26pub fn set_filter(f: Filter) {
13 let set = HashSet::from_iter(f.allowed.iter().cloned()); 27 let set = HashSet::from_iter(f.allowed.iter().cloned());
14 let mut old = FILTER.write().unwrap(); 28 let mut old = FILTER.write().unwrap();
@@ -16,6 +30,37 @@ pub fn set_filter(f: Filter) {
16 *old = filter_data; 30 *old = filter_data;
17} 31}
18 32
33/// This function starts a profiling scope in the current execution stack with a given description.
34/// It returns a Profile structure and measure elapsed time between this method invocation and Profile structure drop.
35/// It supports nested profiling scopes in case when this function invoked multiple times at the execution stack. In this case the profiling information will be nested at the output.
36/// Profiling information is being printed in the stderr.
37///
38/// #Example
39/// ```
40/// use ra_prof::profile;
41/// use ra_prof::set_filter;
42/// use ra_prof::Filter;
43///
44/// let allowed = vec!["profile1".to_string(), "profile2".to_string()];
45/// let f = Filter::new(2, allowed);
46/// set_filter(f);
47/// profiling_function1();
48///
49/// fn profiling_function1() {
50/// let _p = profile("profile1");
51/// profiling_function2();
52/// }
53///
54/// fn profiling_function2() {
55/// let _p = profile("profile2");
56/// }
57/// ```
58/// This will print in the stderr the following:
59/// ```text
60/// 0ms - profile
61/// 0ms - profile2
62/// ```
63///
19pub fn profile(desc: &str) -> Profiler { 64pub fn profile(desc: &str) -> Profiler {
20 PROFILE_STACK.with(|stack| { 65 PROFILE_STACK.with(|stack| {
21 let mut stack = stack.borrow_mut(); 66 let mut stack = stack.borrow_mut();
@@ -137,7 +182,7 @@ mod tests {
137 #[test] 182 #[test]
138 fn test_basic_profile() { 183 fn test_basic_profile() {
139 let s = vec!["profile1".to_string(), "profile2".to_string()]; 184 let s = vec!["profile1".to_string(), "profile2".to_string()];
140 let f = Filter { depth: 2, allowed: s }; 185 let f = Filter::new(2, s);
141 set_filter(f); 186 set_filter(f);
142 profiling_function1(); 187 profiling_function1();
143 } 188 }