mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 18:28:24 +00:00
Add cargo dev repeat
for profiling (#5144)
## Summary This adds a new subcommand that can be used as ```shell cargo build --bin ruff_dev --profile=release-debug perf record -g -F 999 target/release-debug/ruff_dev repeat --repeat 30 --exit-zero --no-cache path/to/cpython > /dev/null flamegraph --perfdata perf.data ``` ## Test Plan This is a ruff internal script. I successfully used it to profile cpython with the instructions above
This commit is contained in:
parent
be11cae619
commit
361d45f2b2
4 changed files with 31 additions and 2 deletions
|
@ -68,7 +68,7 @@ pub enum Command {
|
|||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, clap::Args)]
|
||||
#[derive(Clone, Debug, clap::Args)]
|
||||
#[allow(clippy::struct_excessive_bools, clippy::module_name_repetitions)]
|
||||
pub struct CheckArgs {
|
||||
/// List of files or directories to check.
|
||||
|
|
|
@ -159,7 +159,7 @@ fn format(files: &[PathBuf]) -> Result<ExitStatus> {
|
|||
Ok(ExitStatus::Success)
|
||||
}
|
||||
|
||||
fn check(args: CheckArgs, log_level: LogLevel) -> Result<ExitStatus> {
|
||||
pub fn check(args: CheckArgs, log_level: LogLevel) -> Result<ExitStatus> {
|
||||
let (cli, overrides) = args.partition();
|
||||
|
||||
// Construct the "default" settings. These are used when no `pyproject.toml`
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
use anyhow::Result;
|
||||
use clap::{Parser, Subcommand};
|
||||
use ruff::logging::{set_up_logging, LogLevel};
|
||||
use ruff_cli::check;
|
||||
|
||||
mod generate_all;
|
||||
mod generate_cli_help;
|
||||
|
@ -27,6 +29,7 @@ struct Args {
|
|||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
#[allow(clippy::large_enum_variant)]
|
||||
enum Command {
|
||||
/// Run all code and documentation generation steps.
|
||||
GenerateAll(generate_all::Args),
|
||||
|
@ -48,6 +51,16 @@ enum Command {
|
|||
PrintTokens(print_tokens::Args),
|
||||
/// Run round-trip source code generation on a given Python file.
|
||||
RoundTrip(round_trip::Args),
|
||||
/// Run a ruff command n times for profiling/benchmarking
|
||||
Repeat {
|
||||
#[clap(flatten)]
|
||||
args: ruff_cli::args::CheckArgs,
|
||||
#[clap(flatten)]
|
||||
log_level_args: ruff_cli::args::LogLevelArgs,
|
||||
/// Run this many times
|
||||
#[clap(long, short = 'n')]
|
||||
repeat: usize,
|
||||
},
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
|
@ -64,6 +77,17 @@ fn main() -> Result<()> {
|
|||
Command::PrintCST(args) => print_cst::main(args)?,
|
||||
Command::PrintTokens(args) => print_tokens::main(args)?,
|
||||
Command::RoundTrip(args) => round_trip::main(args)?,
|
||||
Command::Repeat {
|
||||
args,
|
||||
repeat,
|
||||
log_level_args,
|
||||
} => {
|
||||
let log_level = LogLevel::from(log_level_args);
|
||||
set_up_logging(&log_level)?;
|
||||
for _ in 0..*repeat {
|
||||
check(args.clone(), log_level)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue