Sha256: d803a56ea79ea6c0260326e7b3c9c453462ac60b35ef8cb2c8ed9d10bded20a6

Contents?: true

Size: 1.41 KB

Versions: 31

Compression:

Stored size: 1.41 KB

Contents

use serde::ser::{Serialize, Serializer};
use std::time::{Duration, SystemTime, UNIX_EPOCH};

/// A timestamp which anchors the profile in absolute time.
///
/// In the profile JSON, this uses a UNIX timestamp.
///
/// All timestamps in the profile are relative to this reference timestamp.
#[derive(Debug, Clone, Copy, PartialOrd, PartialEq)]
pub struct ReferenceTimestamp {
    ms_since_unix_epoch: f64,
}

impl ReferenceTimestamp {
    /// Create a reference timestamp from a [`Duration`] since the UNIX epoch.
    pub fn from_duration_since_unix_epoch(duration: Duration) -> Self {
        Self::from_millis_since_unix_epoch(duration.as_secs_f64() * 1000.0)
    }

    /// Create a reference timestamp from milliseconds since the UNIX epoch.
    pub fn from_millis_since_unix_epoch(ms_since_unix_epoch: f64) -> Self {
        Self {
            ms_since_unix_epoch,
        }
    }

    /// Create a reference timestamp from a [`SystemTime`].
    pub fn from_system_time(system_time: SystemTime) -> Self {
        Self::from_duration_since_unix_epoch(system_time.duration_since(UNIX_EPOCH).unwrap())
    }
}

impl From<SystemTime> for ReferenceTimestamp {
    fn from(system_time: SystemTime) -> Self {
        Self::from_system_time(system_time)
    }
}

impl Serialize for ReferenceTimestamp {
    fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
        self.ms_since_unix_epoch.serialize(serializer)
    }
}

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/reference_timestamp.rs
wasmtime-28.0.0 ./ext/cargo-vendor/fxprof-processed-profile-0.6.0/src/reference_timestamp.rs
wasmtime-27.0.0 ./ext/cargo-vendor/fxprof-processed-profile-0.6.0/src/reference_timestamp.rs
wasmtime-26.0.0 ./ext/cargo-vendor/fxprof-processed-profile-0.6.0/src/reference_timestamp.rs
wasmtime-25.0.2 ./ext/cargo-vendor/fxprof-processed-profile-0.6.0/src/reference_timestamp.rs
wasmtime-25.0.1 ./ext/cargo-vendor/fxprof-processed-profile-0.6.0/src/reference_timestamp.rs
wasmtime-25.0.0 ./ext/cargo-vendor/fxprof-processed-profile-0.6.0/src/reference_timestamp.rs
wasmtime-24.0.0 ./ext/cargo-vendor/fxprof-processed-profile-0.6.0/src/reference_timestamp.rs
wasmtime-23.0.2 ./ext/cargo-vendor/fxprof-processed-profile-0.6.0/src/reference_timestamp.rs
wasmtime-22.0.0 ./ext/cargo-vendor/fxprof-processed-profile-0.6.0/src/reference_timestamp.rs
wasmtime-21.0.1 ./ext/cargo-vendor/fxprof-processed-profile-0.6.0/src/reference_timestamp.rs
wasmtime-20.0.2 ./ext/cargo-vendor/fxprof-processed-profile-0.6.0/src/reference_timestamp.rs
wasmtime-20.0.0 ./ext/cargo-vendor/fxprof-processed-profile-0.6.0/src/reference_timestamp.rs
wasmtime-18.0.3 ./ext/cargo-vendor/fxprof-processed-profile-0.6.0/src/reference_timestamp.rs
wasmtime-17.0.1 ./ext/cargo-vendor/fxprof-processed-profile-0.6.0/src/reference_timestamp.rs
wasmtime-17.0.0 ./ext/cargo-vendor/fxprof-processed-profile-0.6.0/src/reference_timestamp.rs
wasmtime-16.0.0 ./ext/cargo-vendor/fxprof-processed-profile-0.6.0/src/reference_timestamp.rs
wasmtime-15.0.1 ./ext/cargo-vendor/fxprof-processed-profile-0.6.0/src/reference_timestamp.rs
wasmtime-15.0.0 ./ext/cargo-vendor/fxprof-processed-profile-0.6.0/src/reference_timestamp.rs
wasmtime-14.0.4 ./ext/cargo-vendor/fxprof-processed-profile-0.6.0/src/reference_timestamp.rs