You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: speedscope.rs
    path of file: ./repos/rbspy/src/ui
    
    the code of the file until where you have to start completion: use std::collections::HashMap;
use std::io::Write;
use std::time::SystemTime;

use crate::core::process::Pid;
use crate::core::types::{StackFrame, StackTrace};

use anyhow::Result;

/*
 * This file contains code to export rbspy profiles for use in https://speedscope.app
 *
 * The TypeScript definitions that define this file format can be found here:
 * https://github.com/jlfwong/speedscope/blob/9d13d9/src/lib/file-format-spec.ts
 *
 * From the TypeScript definition, a JSON schema is generated. The latest
 * schema
    
    pub fn record(&mut self, stack: &StackTrace) -> Result<()> {
        let mut frame_indices: Vec<usize> = stack
            .trace
            .iter()
            .map(|frame| {
                let frames = &mut self.frames;
                *self.frame_to_index.entry(frame.clone()).or_insert_with(|| {
                    let len = frames.len();
                    frames.push(Frame::new(&frame));
                    len
                })
            })
            .collect();
        frame_indices.reverse();

        self.samples
            .entry(stack.pid)
            .or_insert_with(|| vec![])
            .push(frame_indices);

        if let Some(time) = stack.time {
            if let Some(prev_time) = self.prev_time {
                let delta = time.duration_since(prev_time)?;
                self.weights.push(delta.as_secs_f64());
            } else {
                // drop first sample, since we have no delta to compare against
                self.weights.push(0.0);
            }
            self.prev_time = stack.time;
        } else {
            // support for import from old profiles that have no timestamps
            self.weights.push(1.0);
        }

        Ok(())
    }