Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wasm non-web usage of env::now #123

Merged
merged 2 commits into from
Jan 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions puffin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,17 +535,11 @@ impl GlobalProfiler {

/// Returns a high-precision, monotonically increasing nanosecond count since unix epoch.
#[inline]
#[cfg(any(not(target_arch = "wasm32"), feature = "web"))]
pub fn now_ns() -> NanoSecond {
#[cfg(target_arch = "wasm32")]
fn nanos_since_epoch() -> NanoSecond {
#[cfg(feature = "web")]
{
(js_sys::Date::new_0().get_time() * 1e6) as _
}
#[cfg(not(feature = "web"))]
{
0 // We won't get correct date-times, but that's fine.
}
(js_sys::Date::new_0().get_time() * 1e6) as _
}

#[cfg(not(target_arch = "wasm32"))]
Expand All @@ -566,6 +560,13 @@ pub fn now_ns() -> NanoSecond {
START_TIME.0 + START_TIME.1.elapsed().as_nanos() as NanoSecond
}

#[inline]
#[cfg(all(target_arch = "wasm32", not(feature = "web")))]
pub fn now_ns() -> NanoSecond {
// This should be unused.
panic!("Wasm without the `web` feature requires passing a custom source of time via `ThreadProfiler::initialize`");
}

// ----------------------------------------------------------------------------

// We currently store an Option<ProfilerScope> on the stack (None when profiling is off).
Expand Down