Sha256: ad9c12d5e55f28be436b2fc7759a17d5df156ab01dcfcf59d446f9417a2b35c5

Contents?: true

Size: 903 Bytes

Versions: 31

Compression:

Stored size: 903 Bytes

Contents

use serde::ser::{Serialize, Serializer};

/// The type used for sample and marker timestamps.
///
/// Timestamps in the profile are stored in reference to the profile's [`ReferenceTimestamp`](crate::ReferenceTimestamp).
#[derive(Debug, Clone, Copy, PartialOrd, Ord, PartialEq, Eq, Hash)]
pub struct Timestamp {
    nanos: u64,
}

impl Timestamp {
    pub fn from_nanos_since_reference(nanos: u64) -> Self {
        Self { nanos }
    }

    pub fn from_millis_since_reference(millis: f64) -> Self {
        Self {
            nanos: (millis * 1_000_000.0) as u64,
        }
    }
}

impl Serialize for Timestamp {
    fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
        // In the profile JSON, timestamps are currently expressed as float milliseconds
        // since profile.meta.startTime.
        serializer.serialize_f64((self.nanos as f64) / 1_000_000.0)
    }
}

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
wasmtime-29.0.0 ./ext/cargo-vendor/fxprof-processed-profile-0.6.0/src/timestamp.rs
wasmtime-28.0.0 ./ext/cargo-vendor/fxprof-processed-profile-0.6.0/src/timestamp.rs
wasmtime-27.0.0 ./ext/cargo-vendor/fxprof-processed-profile-0.6.0/src/timestamp.rs
wasmtime-26.0.0 ./ext/cargo-vendor/fxprof-processed-profile-0.6.0/src/timestamp.rs
wasmtime-25.0.2 ./ext/cargo-vendor/fxprof-processed-profile-0.6.0/src/timestamp.rs
wasmtime-25.0.1 ./ext/cargo-vendor/fxprof-processed-profile-0.6.0/src/timestamp.rs
wasmtime-25.0.0 ./ext/cargo-vendor/fxprof-processed-profile-0.6.0/src/timestamp.rs
wasmtime-24.0.0 ./ext/cargo-vendor/fxprof-processed-profile-0.6.0/src/timestamp.rs
wasmtime-23.0.2 ./ext/cargo-vendor/fxprof-processed-profile-0.6.0/src/timestamp.rs
wasmtime-22.0.0 ./ext/cargo-vendor/fxprof-processed-profile-0.6.0/src/timestamp.rs
wasmtime-21.0.1 ./ext/cargo-vendor/fxprof-processed-profile-0.6.0/src/timestamp.rs
wasmtime-20.0.2 ./ext/cargo-vendor/fxprof-processed-profile-0.6.0/src/timestamp.rs
wasmtime-20.0.0 ./ext/cargo-vendor/fxprof-processed-profile-0.6.0/src/timestamp.rs
wasmtime-18.0.3 ./ext/cargo-vendor/fxprof-processed-profile-0.6.0/src/timestamp.rs
wasmtime-17.0.1 ./ext/cargo-vendor/fxprof-processed-profile-0.6.0/src/timestamp.rs
wasmtime-17.0.0 ./ext/cargo-vendor/fxprof-processed-profile-0.6.0/src/timestamp.rs
wasmtime-16.0.0 ./ext/cargo-vendor/fxprof-processed-profile-0.6.0/src/timestamp.rs
wasmtime-15.0.1 ./ext/cargo-vendor/fxprof-processed-profile-0.6.0/src/timestamp.rs
wasmtime-15.0.0 ./ext/cargo-vendor/fxprof-processed-profile-0.6.0/src/timestamp.rs
wasmtime-14.0.4 ./ext/cargo-vendor/fxprof-processed-profile-0.6.0/src/timestamp.rs