reverie/reverie-examples/strace/main.rs
Vladimir Makaev be457c2dc3 Migrate from structopt to clap3
Summary:
See rationale in the linked task
I was planning to build a new CLI and decided to follow CLI Foundation recommentation. Since hermit is effectively not released it's a good time to migrate now which hasn't been hard mostly followed the fastmods on the task and and some manual fixes of the remaining code

Reviewed By: jasonwhite

Differential Revision: D39953166

fbshipit-source-id: 6e917c6a8ea2ee8258e7e6068e9c9e787ebf0989
2022-10-03 12:18:55 -07:00

55 lines
1.4 KiB
Rust

/*
* Copyright (c) 2018-2019, Trustees of Indiana University
* ("University Works" via Baojun Wang)
* Copyright (c) 2018-2019, Ryan Newton
* ("Traditional Works of Scholarship")
* Copyright (c) 2020-, 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.
*/
mod config;
mod filter;
mod global_state;
mod tool;
use clap::Parser;
use config::Config;
use filter::Filter;
use reverie::Error;
use reverie_util::CommonToolArguments;
use tool::Strace;
/// A tool to trace system calls.
#[derive(Parser, Debug)]
struct Opts {
#[clap(flatten)]
common: CommonToolArguments,
/// The set of syscalls to trace. By default, all syscalls are traced. If
/// this is used, then only the specified syscalls are traced. By limiting
/// the set of traced syscalls, we can reduce the overhead of the tracer.
#[clap(long)]
trace: Vec<Filter>,
}
#[tokio::main]
async fn main() -> Result<(), Error> {
let args = Opts::from_args();
let config = Config {
filters: args.trace,
};
let log_guard = args.common.init_tracing();
let tracer = reverie_ptrace::TracerBuilder::<Strace>::new(args.common.into())
.config(config)
.spawn()
.await?;
let (status, _) = tracer.wait().await?;
drop(log_guard); // Flush logs before exiting.
status.raise_or_exit()
}