pub struct Profiler { /* private fields */ }
Expand description
A single tree of profile data.
Implementations§
Source§impl Profiler
impl Profiler
Sourcepub fn new(name: &'static str) -> Profiler
pub fn new(name: &'static str) -> Profiler
Create a new profiler with the given name for the root node.
Examples found in repository?
3fn main() {
4 let p = hprof::Profiler::new("main loop");
5
6 loop {
7 p.start_frame();
8
9 {
10 let _g = p.enter("setup");
11 std::thread::sleep_ms(1);
12 }
13 {
14 let _g = p.enter("physics");
15
16 let _g = p.enter("collision");
17 std::thread::sleep_ms(1);
18 drop(_g);
19
20 let _g = p.enter("update positions");
21 std::thread::sleep_ms(1);
22 drop(_g);
23 }
24 {
25 let _g = p.enter("render");
26
27 let _g = p.enter("cull");
28 std::thread::sleep_ms(1);
29 drop(_g);
30
31 let _g = p.enter("gpu submit");
32 std::thread::sleep_ms(2);
33 drop(_g);
34
35 let _g = p.enter("gpu wait");
36 std::thread::sleep_ms(10);
37 }
38
39 p.end_frame();
40
41 // this would usually depend on a debug flag, or use custom functionality for drawing the
42 // debug information.
43 if true {
44 p.print_timing();
45 }
46 break;
47 }
48}
More examples
3fn main() {
4 let p = hprof::Profiler::new("main loop");
5
6 loop {
7 p.start_frame();
8
9 {
10 p.enter_noguard("setup");
11 std::thread::sleep_ms(1);
12 p.leave();
13 }
14 {
15 p.enter_noguard("physics");
16
17 p.enter_noguard("collision");
18 std::thread::sleep_ms(1);
19 p.leave();
20
21 p.enter_noguard("update positions");
22 std::thread::sleep_ms(1);
23 p.leave();
24
25 p.leave();
26 }
27 {
28 p.enter_noguard("render");
29
30 p.enter_noguard("cull");
31 std::thread::sleep_ms(1);
32 p.leave();
33
34 p.enter_noguard("gpu submit");
35 std::thread::sleep_ms(2);
36 p.leave();
37
38 p.enter_noguard("gpu wait");
39 std::thread::sleep_ms(10);
40 p.leave();
41
42 p.leave();
43 }
44
45 p.end_frame();
46
47 // this would usually depend on a debug flag, or use custom functionality for drawing the
48 // debug information.
49 if true {
50 p.print_timing();
51 }
52 break;
53 }
54}
Sourcepub fn enter(&self, name: &'static str) -> ProfileGuard<'_>
pub fn enter(&self, name: &'static str) -> ProfileGuard<'_>
Enter a profile node for name
, returning a guard object that will leave
on destruction.
Examples found in repository?
3fn main() {
4 let p = hprof::Profiler::new("main loop");
5
6 loop {
7 p.start_frame();
8
9 {
10 let _g = p.enter("setup");
11 std::thread::sleep_ms(1);
12 }
13 {
14 let _g = p.enter("physics");
15
16 let _g = p.enter("collision");
17 std::thread::sleep_ms(1);
18 drop(_g);
19
20 let _g = p.enter("update positions");
21 std::thread::sleep_ms(1);
22 drop(_g);
23 }
24 {
25 let _g = p.enter("render");
26
27 let _g = p.enter("cull");
28 std::thread::sleep_ms(1);
29 drop(_g);
30
31 let _g = p.enter("gpu submit");
32 std::thread::sleep_ms(2);
33 drop(_g);
34
35 let _g = p.enter("gpu wait");
36 std::thread::sleep_ms(10);
37 }
38
39 p.end_frame();
40
41 // this would usually depend on a debug flag, or use custom functionality for drawing the
42 // debug information.
43 if true {
44 p.print_timing();
45 }
46 break;
47 }
48}
Sourcepub fn enter_noguard(&self, name: &'static str)
pub fn enter_noguard(&self, name: &'static str)
Enter a profile node for name
.
Examples found in repository?
3fn main() {
4 let p = hprof::Profiler::new("main loop");
5
6 loop {
7 p.start_frame();
8
9 {
10 p.enter_noguard("setup");
11 std::thread::sleep_ms(1);
12 p.leave();
13 }
14 {
15 p.enter_noguard("physics");
16
17 p.enter_noguard("collision");
18 std::thread::sleep_ms(1);
19 p.leave();
20
21 p.enter_noguard("update positions");
22 std::thread::sleep_ms(1);
23 p.leave();
24
25 p.leave();
26 }
27 {
28 p.enter_noguard("render");
29
30 p.enter_noguard("cull");
31 std::thread::sleep_ms(1);
32 p.leave();
33
34 p.enter_noguard("gpu submit");
35 std::thread::sleep_ms(2);
36 p.leave();
37
38 p.enter_noguard("gpu wait");
39 std::thread::sleep_ms(10);
40 p.leave();
41
42 p.leave();
43 }
44
45 p.end_frame();
46
47 // this would usually depend on a debug flag, or use custom functionality for drawing the
48 // debug information.
49 if true {
50 p.print_timing();
51 }
52 break;
53 }
54}
Sourcepub fn leave(&self)
pub fn leave(&self)
Leave the current profile node.
Examples found in repository?
3fn main() {
4 let p = hprof::Profiler::new("main loop");
5
6 loop {
7 p.start_frame();
8
9 {
10 p.enter_noguard("setup");
11 std::thread::sleep_ms(1);
12 p.leave();
13 }
14 {
15 p.enter_noguard("physics");
16
17 p.enter_noguard("collision");
18 std::thread::sleep_ms(1);
19 p.leave();
20
21 p.enter_noguard("update positions");
22 std::thread::sleep_ms(1);
23 p.leave();
24
25 p.leave();
26 }
27 {
28 p.enter_noguard("render");
29
30 p.enter_noguard("cull");
31 std::thread::sleep_ms(1);
32 p.leave();
33
34 p.enter_noguard("gpu submit");
35 std::thread::sleep_ms(2);
36 p.leave();
37
38 p.enter_noguard("gpu wait");
39 std::thread::sleep_ms(10);
40 p.leave();
41
42 p.leave();
43 }
44
45 p.end_frame();
46
47 // this would usually depend on a debug flag, or use custom functionality for drawing the
48 // debug information.
49 if true {
50 p.print_timing();
51 }
52 break;
53 }
54}
Sourcepub fn print_timing(&self)
pub fn print_timing(&self)
Print out the current timing information in a very naive way.
Examples found in repository?
3fn main() {
4 let p = hprof::Profiler::new("main loop");
5
6 loop {
7 p.start_frame();
8
9 {
10 let _g = p.enter("setup");
11 std::thread::sleep_ms(1);
12 }
13 {
14 let _g = p.enter("physics");
15
16 let _g = p.enter("collision");
17 std::thread::sleep_ms(1);
18 drop(_g);
19
20 let _g = p.enter("update positions");
21 std::thread::sleep_ms(1);
22 drop(_g);
23 }
24 {
25 let _g = p.enter("render");
26
27 let _g = p.enter("cull");
28 std::thread::sleep_ms(1);
29 drop(_g);
30
31 let _g = p.enter("gpu submit");
32 std::thread::sleep_ms(2);
33 drop(_g);
34
35 let _g = p.enter("gpu wait");
36 std::thread::sleep_ms(10);
37 }
38
39 p.end_frame();
40
41 // this would usually depend on a debug flag, or use custom functionality for drawing the
42 // debug information.
43 if true {
44 p.print_timing();
45 }
46 break;
47 }
48}
More examples
3fn main() {
4 loop {
5 hprof::start_frame();
6
7 {
8 let _g = hprof::enter("setup");
9 std::thread::sleep_ms(1);
10 }
11 {
12 let _g = hprof::enter("physics");
13
14 let _g = hprof::enter("collision");
15 std::thread::sleep_ms(1);
16 drop(_g);
17
18 let _g = hprof::enter("update positions");
19 std::thread::sleep_ms(1);
20 drop(_g);
21 }
22 {
23 let _g = hprof::enter("render");
24
25 let _g = hprof::enter("cull");
26 std::thread::sleep_ms(1);
27 drop(_g);
28
29 let _g = hprof::enter("gpu submit");
30 std::thread::sleep_ms(2);
31 drop(_g);
32
33 let _g = hprof::enter("gpu wait");
34 std::thread::sleep_ms(10);
35 drop(_g);
36 }
37
38 hprof::end_frame();
39
40 // this would usually depend on a debug flag, or use custom functionality for drawing the
41 // debug information.
42 if true {
43 hprof::profiler().print_timing();
44 }
45 break;
46 }
47}
3fn main() {
4 let p = hprof::Profiler::new("main loop");
5
6 loop {
7 p.start_frame();
8
9 {
10 p.enter_noguard("setup");
11 std::thread::sleep_ms(1);
12 p.leave();
13 }
14 {
15 p.enter_noguard("physics");
16
17 p.enter_noguard("collision");
18 std::thread::sleep_ms(1);
19 p.leave();
20
21 p.enter_noguard("update positions");
22 std::thread::sleep_ms(1);
23 p.leave();
24
25 p.leave();
26 }
27 {
28 p.enter_noguard("render");
29
30 p.enter_noguard("cull");
31 std::thread::sleep_ms(1);
32 p.leave();
33
34 p.enter_noguard("gpu submit");
35 std::thread::sleep_ms(2);
36 p.leave();
37
38 p.enter_noguard("gpu wait");
39 std::thread::sleep_ms(10);
40 p.leave();
41
42 p.leave();
43 }
44
45 p.end_frame();
46
47 // this would usually depend on a debug flag, or use custom functionality for drawing the
48 // debug information.
49 if true {
50 p.print_timing();
51 }
52 break;
53 }
54}
Sourcepub fn root(&self) -> Rc<ProfileNode>
pub fn root(&self) -> Rc<ProfileNode>
Return the root profile node for inspection.
This root will always be valid and reflect the current state of the Profiler
.
It is not advised to inspect the data between calls to start_frame
and end_frame
.
Sourcepub fn end_frame(&self)
pub fn end_frame(&self)
Finish a frame.
Logs an error if there are pending leave
calls, and later attempts to
print timing data will be met with sadness in the form of NaN
s.
Examples found in repository?
3fn main() {
4 let p = hprof::Profiler::new("main loop");
5
6 loop {
7 p.start_frame();
8
9 {
10 let _g = p.enter("setup");
11 std::thread::sleep_ms(1);
12 }
13 {
14 let _g = p.enter("physics");
15
16 let _g = p.enter("collision");
17 std::thread::sleep_ms(1);
18 drop(_g);
19
20 let _g = p.enter("update positions");
21 std::thread::sleep_ms(1);
22 drop(_g);
23 }
24 {
25 let _g = p.enter("render");
26
27 let _g = p.enter("cull");
28 std::thread::sleep_ms(1);
29 drop(_g);
30
31 let _g = p.enter("gpu submit");
32 std::thread::sleep_ms(2);
33 drop(_g);
34
35 let _g = p.enter("gpu wait");
36 std::thread::sleep_ms(10);
37 }
38
39 p.end_frame();
40
41 // this would usually depend on a debug flag, or use custom functionality for drawing the
42 // debug information.
43 if true {
44 p.print_timing();
45 }
46 break;
47 }
48}
More examples
3fn main() {
4 let p = hprof::Profiler::new("main loop");
5
6 loop {
7 p.start_frame();
8
9 {
10 p.enter_noguard("setup");
11 std::thread::sleep_ms(1);
12 p.leave();
13 }
14 {
15 p.enter_noguard("physics");
16
17 p.enter_noguard("collision");
18 std::thread::sleep_ms(1);
19 p.leave();
20
21 p.enter_noguard("update positions");
22 std::thread::sleep_ms(1);
23 p.leave();
24
25 p.leave();
26 }
27 {
28 p.enter_noguard("render");
29
30 p.enter_noguard("cull");
31 std::thread::sleep_ms(1);
32 p.leave();
33
34 p.enter_noguard("gpu submit");
35 std::thread::sleep_ms(2);
36 p.leave();
37
38 p.enter_noguard("gpu wait");
39 std::thread::sleep_ms(10);
40 p.leave();
41
42 p.leave();
43 }
44
45 p.end_frame();
46
47 // this would usually depend on a debug flag, or use custom functionality for drawing the
48 // debug information.
49 if true {
50 p.print_timing();
51 }
52 break;
53 }
54}
Sourcepub fn start_frame(&self)
pub fn start_frame(&self)
Start a frame.
Resets timing data. Logs an error if there are pending leave
calls, but there are
otherwise no ill effects.
Examples found in repository?
3fn main() {
4 let p = hprof::Profiler::new("main loop");
5
6 loop {
7 p.start_frame();
8
9 {
10 let _g = p.enter("setup");
11 std::thread::sleep_ms(1);
12 }
13 {
14 let _g = p.enter("physics");
15
16 let _g = p.enter("collision");
17 std::thread::sleep_ms(1);
18 drop(_g);
19
20 let _g = p.enter("update positions");
21 std::thread::sleep_ms(1);
22 drop(_g);
23 }
24 {
25 let _g = p.enter("render");
26
27 let _g = p.enter("cull");
28 std::thread::sleep_ms(1);
29 drop(_g);
30
31 let _g = p.enter("gpu submit");
32 std::thread::sleep_ms(2);
33 drop(_g);
34
35 let _g = p.enter("gpu wait");
36 std::thread::sleep_ms(10);
37 }
38
39 p.end_frame();
40
41 // this would usually depend on a debug flag, or use custom functionality for drawing the
42 // debug information.
43 if true {
44 p.print_timing();
45 }
46 break;
47 }
48}
More examples
3fn main() {
4 let p = hprof::Profiler::new("main loop");
5
6 loop {
7 p.start_frame();
8
9 {
10 p.enter_noguard("setup");
11 std::thread::sleep_ms(1);
12 p.leave();
13 }
14 {
15 p.enter_noguard("physics");
16
17 p.enter_noguard("collision");
18 std::thread::sleep_ms(1);
19 p.leave();
20
21 p.enter_noguard("update positions");
22 std::thread::sleep_ms(1);
23 p.leave();
24
25 p.leave();
26 }
27 {
28 p.enter_noguard("render");
29
30 p.enter_noguard("cull");
31 std::thread::sleep_ms(1);
32 p.leave();
33
34 p.enter_noguard("gpu submit");
35 std::thread::sleep_ms(2);
36 p.leave();
37
38 p.enter_noguard("gpu wait");
39 std::thread::sleep_ms(10);
40 p.leave();
41
42 p.leave();
43 }
44
45 p.end_frame();
46
47 // this would usually depend on a debug flag, or use custom functionality for drawing the
48 // debug information.
49 if true {
50 p.print_timing();
51 }
52 break;
53 }
54}