reverie/reverie-examples/chrome-trace/main.rs
Jason White 20c7020868 Appease the copyright linter
Summary: The OSS license linter doesn't like the word "its".

Reviewed By: johnhurt

Differential Revision: D36856385

fbshipit-source-id: 909037d96de8976f08004497d28b77838f8c6870
2022-06-02 11:51:06 -07:00

61 lines
1.5 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.
*/
//! Runs a process, gathering metadata about all of the processes that were ran
//! and displays it as a tree using Graphviz.
mod event;
mod global_state;
mod tool;
use tool::ChromeTrace;
use structopt::StructOpt;
use anyhow::Context;
use reverie::Error;
use reverie_util::CommonToolArguments;
use std::fs;
use std::io;
use std::path::PathBuf;
/// A tool to render a summary of the process tree.
#[derive(Debug, StructOpt)]
struct Args {
#[structopt(flatten)]
common: CommonToolArguments,
/// The path to write out Chrome trace file. This can be loaded with
/// `chrome://tracing`.
#[structopt(long)]
out: Option<PathBuf>,
}
#[tokio::main]
async fn main() -> Result<(), Error> {
let args = Args::from_args();
let log_guard = args.common.init_tracing();
let tracer = reverie_ptrace::TracerBuilder::<ChromeTrace>::new(args.common.into())
.spawn()
.await?;
let (status, global_state) = tracer.wait().await?;
if let Some(path) = args.out {
let mut f = io::BufWriter::new(fs::File::create(path)?);
global_state
.chrome_trace(&mut f)
.context("failed to generate Chrome trace")?;
}
// Flush logs before exiting.
drop(log_guard);
status.raise_or_exit()
}