mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 21:05:08 +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
5
.gitignore
vendored
5
.gitignore
vendored
|
@ -6,6 +6,11 @@ github_search*.jsonl
|
||||||
schemastore
|
schemastore
|
||||||
.venv*
|
.venv*
|
||||||
scratch.py
|
scratch.py
|
||||||
|
perf.data
|
||||||
|
perf.data.old
|
||||||
|
flamegraph.svg
|
||||||
|
# Additional target directories that don't invalidate the main compile cache when changing linker settings
|
||||||
|
/target*
|
||||||
|
|
||||||
###
|
###
|
||||||
# Rust.gitignore
|
# Rust.gitignore
|
||||||
|
|
|
@ -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)]
|
#[allow(clippy::struct_excessive_bools, clippy::module_name_repetitions)]
|
||||||
pub struct CheckArgs {
|
pub struct CheckArgs {
|
||||||
/// List of files or directories to check.
|
/// List of files or directories to check.
|
||||||
|
|
|
@ -159,7 +159,7 @@ fn format(files: &[PathBuf]) -> Result<ExitStatus> {
|
||||||
Ok(ExitStatus::Success)
|
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();
|
let (cli, overrides) = args.partition();
|
||||||
|
|
||||||
// Construct the "default" settings. These are used when no `pyproject.toml`
|
// Construct the "default" settings. These are used when no `pyproject.toml`
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
|
use ruff::logging::{set_up_logging, LogLevel};
|
||||||
|
use ruff_cli::check;
|
||||||
|
|
||||||
mod generate_all;
|
mod generate_all;
|
||||||
mod generate_cli_help;
|
mod generate_cli_help;
|
||||||
|
@ -27,6 +29,7 @@ struct Args {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Subcommand)]
|
#[derive(Subcommand)]
|
||||||
|
#[allow(clippy::large_enum_variant)]
|
||||||
enum Command {
|
enum Command {
|
||||||
/// Run all code and documentation generation steps.
|
/// Run all code and documentation generation steps.
|
||||||
GenerateAll(generate_all::Args),
|
GenerateAll(generate_all::Args),
|
||||||
|
@ -48,6 +51,16 @@ enum Command {
|
||||||
PrintTokens(print_tokens::Args),
|
PrintTokens(print_tokens::Args),
|
||||||
/// Run round-trip source code generation on a given Python file.
|
/// Run round-trip source code generation on a given Python file.
|
||||||
RoundTrip(round_trip::Args),
|
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<()> {
|
fn main() -> Result<()> {
|
||||||
|
@ -64,6 +77,17 @@ fn main() -> Result<()> {
|
||||||
Command::PrintCST(args) => print_cst::main(args)?,
|
Command::PrintCST(args) => print_cst::main(args)?,
|
||||||
Command::PrintTokens(args) => print_tokens::main(args)?,
|
Command::PrintTokens(args) => print_tokens::main(args)?,
|
||||||
Command::RoundTrip(args) => round_trip::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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue