Sha256: 3bb4751787db041652a7911bd357b5eb857c4f815d23319eff0bbf79e1fcdc33

Contents?: true

Size: 1.56 KB

Versions: 31

Compression:

Stored size: 1.56 KB

Contents

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

use crate::cpu_delta::CpuDelta;
use crate::Timestamp;

#[derive(Debug, Clone, Default)]
pub struct SampleTable {
    sample_weights: Vec<i32>,
    sample_timestamps: Vec<Timestamp>,
    sample_stack_indexes: Vec<Option<usize>>,
    sample_cpu_deltas: Vec<CpuDelta>,
}

impl SampleTable {
    pub fn new() -> Self {
        Default::default()
    }

    pub fn add_sample(
        &mut self,
        timestamp: Timestamp,
        stack_index: Option<usize>,
        cpu_delta: CpuDelta,
        weight: i32,
    ) {
        self.sample_weights.push(weight);
        self.sample_timestamps.push(timestamp);
        self.sample_stack_indexes.push(stack_index);
        self.sample_cpu_deltas.push(cpu_delta);
    }

    pub fn modify_last_sample(&mut self, timestamp: Timestamp, weight: i32) {
        *self.sample_weights.last_mut().unwrap() += weight;
        *self.sample_timestamps.last_mut().unwrap() = timestamp;
    }
}

impl Serialize for SampleTable {
    fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
        let len = self.sample_timestamps.len();
        let mut map = serializer.serialize_map(None)?;
        map.serialize_entry("length", &len)?;
        map.serialize_entry("stack", &self.sample_stack_indexes)?;
        map.serialize_entry("time", &self.sample_timestamps)?;
        map.serialize_entry("weight", &self.sample_weights)?;
        map.serialize_entry("weightType", &"samples")?;
        map.serialize_entry("threadCPUDelta", &self.sample_cpu_deltas)?;
        map.end()
    }
}

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