mirror of
https://github.com/facebookexperimental/reverie.git
synced 2025-01-23 13:10:04 +00:00
9a942d055f
Summary: Removes usage of the `associated_type_defaults` unstable feature, but does not actually disable the feature yet. This brings us one step closer to removing all usage of unstable nightly features, which will allow publishing a crate on https://crates.io. Reviewed By: rrnewton Differential Revision: D41388745 fbshipit-source-id: f347a577857a713fe3088a556cbf37ffe92e5553
71 lines
1.6 KiB
Rust
71 lines
1.6 KiB
Rust
/*
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under the BSD-style license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
use std::io;
|
|
use std::path::PathBuf;
|
|
use std::sync::Mutex;
|
|
use std::time::SystemTime;
|
|
|
|
use reverie::GlobalTool;
|
|
use reverie::Pid;
|
|
use serde::Deserialize;
|
|
use serde::Serialize;
|
|
|
|
use crate::event::ThreadExit;
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct Program {
|
|
/// The path to the program.
|
|
name: PathBuf,
|
|
|
|
/// The program arguments.
|
|
args: Vec<String>,
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub struct GlobalState {
|
|
epoch: SystemTime,
|
|
events: Mutex<Vec<ThreadExit>>,
|
|
}
|
|
|
|
impl Default for GlobalState {
|
|
fn default() -> Self {
|
|
Self {
|
|
epoch: SystemTime::now(),
|
|
events: Default::default(),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[reverie::global_tool]
|
|
impl GlobalTool for GlobalState {
|
|
type Request = ThreadExit;
|
|
type Response = ();
|
|
type Config = ();
|
|
|
|
async fn receive_rpc(&self, _pid: Pid, event: ThreadExit) {
|
|
let mut events = self.events.lock().unwrap();
|
|
events.push(event);
|
|
}
|
|
}
|
|
|
|
impl GlobalState {
|
|
/// Writes out a chrome trace file to the given writer.
|
|
pub fn chrome_trace<W: io::Write>(&self, writer: &mut W) -> serde_json::Result<()> {
|
|
let events = self.events.lock().unwrap();
|
|
let mut json: Vec<serde_json::Value> = Vec::new();
|
|
|
|
for event in events.iter() {
|
|
event.trace_event(self.epoch, &mut json);
|
|
}
|
|
|
|
let json = serde_json::Value::Array(json);
|
|
|
|
serde_json::to_writer(writer, &json)
|
|
}
|
|
}
|