1use clap::{Parser, Subcommand};
2use tracing::error;
3use tracing_subscriber::{EnvFilter, Layer, fmt, layer::SubscriberExt, util::SubscriberInitExt};
4
5use perf::{client, server};
6
7#[tokio::main(flavor = "current_thread")]
8async fn main() {
9 let opt = Cli::parse();
10
11 let registry = tracing_subscriber::registry();
12 #[cfg(feature = "tokio-console")]
13 let registry = registry.with(console_subscriber::spawn());
14 registry
15 .with(
16 fmt::layer().with_filter(
17 EnvFilter::try_from_default_env()
18 .or_else(|_| EnvFilter::try_new("warn"))
19 .unwrap(),
20 ),
21 )
22 .init();
23
24 let r = match opt.command {
25 Commands::Server(opt) => server::run(opt).await,
26 Commands::Client(opt) => client::run(opt).await,
27 };
28 if let Err(e) = r {
29 error!("{:#}", e);
30 }
31}
32
33#[derive(Parser)]
34#[clap(long_about = None)]
35struct Cli {
36 #[command(subcommand)]
37 command: Commands,
38}
39
40#[derive(Subcommand)]
41enum Commands {
42 Server(server::Opt),
44 Client(client::Opt),
46}