6 个版本
0.2.6 | 2023年6月3日 |
---|---|
0.2.5 | 2022年1月1日 |
0.2.4 | 2020年1月20日 |
0.2.3 | 2019年12月6日 |
0.1.0 | 2019年12月3日 |
#90 在 性能分析 分类中
69 每月下载量
在 rendology 中使用
17KB
244 行
coarse-prof
coarse-prof
允许你分层测量程序中块的耗时,使你能够了解大部分时间都花在哪里。这对于游戏开发很有用,在游戏中有很多需要在每一帧运行的事情,如物理、渲染、网络等,你可能希望识别热点,以便知道是否需要以及如何进行优化。
coarse-prof
的实现受到了 hprof 的启发。与每次帧后重置测量的 hprof
相比,这个库跟踪多个帧的平均值。此外,coarse-prof
提供了用于分析作用域的宏 profile
,这样用户就不必为作用域保护器分配名称。
使用方法
只需将以下行添加到 Cargo.toml
中的依赖项
coarse-prof = "0.2"
示例
use std::thread::sleep;
use std::time::Duration;
use coarse_prof::profile;
fn render() {
profile!("render");
// So slow!
sleep(Duration::from_millis(10));
}
// Our game's main loop
let num_frames = 100;
for i in 0..num_frames {
profile!("frame");
// Physics don't run every frame
if i % 10 == 0 {
profile!("physics");
sleep(Duration::from_millis(2));
{
profile!("collisions");
sleep(Duration::from_millis(1));
}
}
render();
}
// Print the profiling results.
coarse_prof::write(&mut std::io::stdout()).unwrap();
示例输出
frame: 100.00%, 10.40ms/call @ 96.17Hz
physics: 3.04%, 3.16ms/call @ 9.62Hz
collisions: 33.85%, 1.07ms/call @ 9.62Hz
render: 96.84%, 10.07ms/call @ 96.17Hz
依赖项
~105KB