Struct Profiler

Source
pub struct Profiler { /* private fields */ }
Expand description

A single tree of profile data.

Implementations§

Source§

impl Profiler

Source

pub fn new(name: &'static str) -> Profiler

Create a new profiler with the given name for the root node.

Examples found in repository?
examples/explicit.rs (line 4)
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
Hide additional examples
examples/noguard.rs (line 4)
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}
Source

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?
examples/explicit.rs (line 10)
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}
Source

pub fn enter_noguard(&self, name: &'static str)

Enter a profile node for name.

Examples found in repository?
examples/noguard.rs (line 10)
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}
Source

pub fn leave(&self)

Leave the current profile node.

Examples found in repository?
examples/noguard.rs (line 12)
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}
Source

pub fn print_timing(&self)

Print out the current timing information in a very naive way.

Examples found in repository?
examples/explicit.rs (line 44)
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
Hide additional examples
examples/implicit.rs (line 43)
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}
examples/noguard.rs (line 50)
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}
Source

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.

Source

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 NaNs.

Examples found in repository?
examples/explicit.rs (line 39)
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
Hide additional examples
examples/noguard.rs (line 45)
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}
Source

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?
examples/explicit.rs (line 7)
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
Hide additional examples
examples/noguard.rs (line 7)
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}
Source

pub fn disable(&self)

Disable the profiler.

All calls until enable will do nothing.

Source

pub fn enable(&self)

Enable the profiler.

Calls will take effect until disable is called.

Source

pub fn toggle(&self)

Toggle the profiler enabledness.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.