|
| 1 | +use std::path::Path; |
| 2 | + |
| 3 | +use clap::{Args, Parser, Subcommand}; |
| 4 | +use runtime_tracing::{TraceEventsFileFormat, Tracer}; |
| 5 | + |
| 6 | +#[derive(Debug, Clone, Args)] |
| 7 | +struct ConvertCommand { |
| 8 | + input_file: String, |
| 9 | + output_file: String, |
| 10 | +} |
| 11 | + |
| 12 | +#[non_exhaustive] |
| 13 | +#[derive(Subcommand, Clone, Debug)] |
| 14 | +enum RuntimeTracingCliCommand { |
| 15 | + /// Convert from one trace file format to another |
| 16 | + Convert(ConvertCommand), |
| 17 | +} |
| 18 | + |
| 19 | +#[derive(Parser, Debug)] |
| 20 | +#[command(version, about, long_about = None)] |
| 21 | +struct RuntimeTracingCli { |
| 22 | + #[command(subcommand)] |
| 23 | + command: RuntimeTracingCliCommand, |
| 24 | +} |
| 25 | + |
| 26 | +fn determine_file_format_from_name(s: &str) -> Option<TraceEventsFileFormat> { |
| 27 | + if s.ends_with(".json") { |
| 28 | + Some(TraceEventsFileFormat::Json) |
| 29 | + } else { |
| 30 | + if s.ends_with(".bin") { |
| 31 | + Some(TraceEventsFileFormat::Binary) |
| 32 | + } else { |
| 33 | + None |
| 34 | + } |
| 35 | + } |
| 36 | +} |
| 37 | + |
1 | 38 | fn main() { |
2 | | - println!("Hello, world!"); |
| 39 | + let args = RuntimeTracingCli::parse(); |
| 40 | + |
| 41 | + match args.command { |
| 42 | + RuntimeTracingCliCommand::Convert(convert_command) => { |
| 43 | + let input_file_format = determine_file_format_from_name(&convert_command.input_file).unwrap(); |
| 44 | + let output_file_format = determine_file_format_from_name(&convert_command.output_file).unwrap(); |
| 45 | + let mut trace = Tracer::new("", &[]); |
| 46 | + trace.load_trace_events(Path::new(&convert_command.input_file), input_file_format).unwrap(); |
| 47 | + trace.store_trace_events(Path::new(&convert_command.output_file), output_file_format).unwrap(); |
| 48 | + } |
| 49 | + } |
3 | 50 | } |
0 commit comments