-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Much more accurate
cpu_usage
timing (#3913)
`frame.info.cpu_usage` now includes time for tessellation and rendering, but excludes vsync and context switching.
- Loading branch information
Showing
12 changed files
with
124 additions
and
64 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#![allow(dead_code)] // not everything is used on wasm | ||
|
||
use web_time::Instant; | ||
|
||
pub struct Stopwatch { | ||
total_time_ns: u128, | ||
|
||
/// None = not running | ||
start: Option<Instant>, | ||
} | ||
|
||
impl Stopwatch { | ||
pub fn new() -> Self { | ||
Self { | ||
total_time_ns: 0, | ||
start: None, | ||
} | ||
} | ||
|
||
pub fn start(&mut self) { | ||
assert!(self.start.is_none()); | ||
self.start = Some(Instant::now()); | ||
} | ||
|
||
pub fn pause(&mut self) { | ||
let start = self.start.take().unwrap(); | ||
let duration = start.elapsed(); | ||
self.total_time_ns += duration.as_nanos(); | ||
} | ||
|
||
pub fn resume(&mut self) { | ||
assert!(self.start.is_none()); | ||
self.start = Some(Instant::now()); | ||
} | ||
|
||
pub fn total_time_ns(&self) -> u128 { | ||
if let Some(start) = self.start { | ||
// Running | ||
let duration = start.elapsed(); | ||
self.total_time_ns + duration.as_nanos() | ||
} else { | ||
// Paused | ||
self.total_time_ns | ||
} | ||
} | ||
|
||
pub fn total_time_sec(&self) -> f32 { | ||
self.total_time_ns() as f32 * 1e-9 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters