mirror of
https://github.com/martinvonz/jj.git
synced 2024-12-27 06:27:43 +00:00
cli: remove jj bench
commands
I haven't used these in a long time. Not including it reduces the binary size from 16.8 MB to 15.1 MiB.
This commit is contained in:
parent
43f0cddb1c
commit
18c0b97d9d
2 changed files with 1 additions and 142 deletions
|
@ -40,7 +40,6 @@ clap = { version = "4.0.9", features = ["derive", "deprecated"] }
|
|||
clap_complete = "4.0.2"
|
||||
clap_mangen = "0.2.2"
|
||||
config = { version = "0.13.2", default-features = false, features = ["toml"] }
|
||||
criterion = "0.4.0"
|
||||
dirs = "4.0.0"
|
||||
git2 = "0.15.0"
|
||||
hex = "0.4.3"
|
||||
|
|
142
src/commands.rs
142
src/commands.rs
|
@ -19,12 +19,10 @@ use std::io::{Read, Seek, SeekFrom, Write};
|
|||
use std::ops::Range;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::Arc;
|
||||
use std::time::Instant;
|
||||
use std::{fs, io};
|
||||
|
||||
use chrono::{FixedOffset, TimeZone, Utc};
|
||||
use clap::{ArgGroup, ArgMatches, CommandFactory, FromArgMatches, Subcommand};
|
||||
use criterion::Criterion;
|
||||
use itertools::Itertools;
|
||||
use jujutsu_lib::backend::{BackendError, CommitId, Timestamp, TreeValue};
|
||||
use jujutsu_lib::commit::Commit;
|
||||
|
@ -33,7 +31,7 @@ use jujutsu_lib::dag_walk::topo_order_reverse;
|
|||
use jujutsu_lib::diff::{Diff, DiffHunk};
|
||||
use jujutsu_lib::files::DiffLine;
|
||||
use jujutsu_lib::git::{GitFetchError, GitRefUpdate};
|
||||
use jujutsu_lib::index::{HexPrefix, IndexEntry};
|
||||
use jujutsu_lib::index::IndexEntry;
|
||||
use jujutsu_lib::matchers::{EverythingMatcher, Matcher};
|
||||
use jujutsu_lib::op_store::{RefTarget, WorkspaceId};
|
||||
use jujutsu_lib::operation::Operation;
|
||||
|
@ -117,8 +115,6 @@ enum Commands {
|
|||
#[command(subcommand)]
|
||||
Git(GitCommands),
|
||||
#[command(subcommand)]
|
||||
Bench(BenchCommands),
|
||||
#[command(subcommand)]
|
||||
Debug(DebugCommands),
|
||||
}
|
||||
|
||||
|
@ -921,47 +917,6 @@ struct GitImportArgs {}
|
|||
#[derive(clap::Args, Clone, Debug)]
|
||||
struct GitExportArgs {}
|
||||
|
||||
/// Commands for benchmarking internal operations
|
||||
#[derive(Subcommand, Clone, Debug)]
|
||||
enum BenchCommands {
|
||||
#[command(name = "commonancestors")]
|
||||
CommonAncestors(BenchCommonAncestorsArgs),
|
||||
#[command(name = "isancestor")]
|
||||
IsAncestor(BenchIsAncestorArgs),
|
||||
#[command(name = "walkrevs")]
|
||||
WalkRevs(BenchWalkRevsArgs),
|
||||
#[command(name = "resolveprefix")]
|
||||
ResolvePrefix(BenchResolvePrefixArgs),
|
||||
}
|
||||
|
||||
/// Find the common ancestor(s) of a set of commits
|
||||
#[derive(clap::Args, Clone, Debug)]
|
||||
struct BenchCommonAncestorsArgs {
|
||||
revision1: String,
|
||||
revision2: String,
|
||||
}
|
||||
|
||||
/// Checks if the first commit is an ancestor of the second commit
|
||||
#[derive(clap::Args, Clone, Debug)]
|
||||
struct BenchIsAncestorArgs {
|
||||
ancestor: String,
|
||||
descendant: String,
|
||||
}
|
||||
|
||||
/// Walk revisions that are ancestors of the second argument but not ancestors
|
||||
/// of the first
|
||||
#[derive(clap::Args, Clone, Debug)]
|
||||
struct BenchWalkRevsArgs {
|
||||
unwanted: String,
|
||||
wanted: String,
|
||||
}
|
||||
|
||||
/// Resolve a commit ID prefix
|
||||
#[derive(clap::Args, Clone, Debug)]
|
||||
struct BenchResolvePrefixArgs {
|
||||
prefix: String,
|
||||
}
|
||||
|
||||
/// Low-level commands not intended for users
|
||||
#[derive(Subcommand, Clone, Debug)]
|
||||
#[command(hide = true)]
|
||||
|
@ -3586,100 +3541,6 @@ fn cmd_debug(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn run_bench<R, O>(ui: &mut Ui, id: &str, mut routine: R) -> io::Result<()>
|
||||
where
|
||||
R: (FnMut() -> O) + Copy,
|
||||
O: Debug,
|
||||
{
|
||||
let mut criterion = Criterion::default();
|
||||
let before = Instant::now();
|
||||
let result = routine();
|
||||
let after = Instant::now();
|
||||
writeln!(
|
||||
ui,
|
||||
"First run took {:?} and produced: {:?}",
|
||||
after.duration_since(before),
|
||||
result
|
||||
)?;
|
||||
criterion.bench_function(id, |bencher: &mut criterion::Bencher| {
|
||||
bencher.iter(routine);
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn cmd_bench(
|
||||
ui: &mut Ui,
|
||||
command: &CommandHelper,
|
||||
subcommand: &BenchCommands,
|
||||
) -> Result<(), CommandError> {
|
||||
match subcommand {
|
||||
BenchCommands::CommonAncestors(command_matches) => {
|
||||
let workspace_command = command.workspace_helper(ui)?;
|
||||
let commit1 = workspace_command.resolve_single_rev(&command_matches.revision1)?;
|
||||
let commit2 = workspace_command.resolve_single_rev(&command_matches.revision2)?;
|
||||
let index = workspace_command.repo().index();
|
||||
let routine =
|
||||
|| index.common_ancestors(&[commit1.id().clone()], &[commit2.id().clone()]);
|
||||
run_bench(
|
||||
ui,
|
||||
&format!(
|
||||
"commonancestors-{}-{}",
|
||||
&command_matches.revision1, &command_matches.revision2
|
||||
),
|
||||
routine,
|
||||
)?;
|
||||
}
|
||||
BenchCommands::IsAncestor(command_matches) => {
|
||||
let workspace_command = command.workspace_helper(ui)?;
|
||||
let ancestor_commit =
|
||||
workspace_command.resolve_single_rev(&command_matches.ancestor)?;
|
||||
let descendant_commit =
|
||||
workspace_command.resolve_single_rev(&command_matches.descendant)?;
|
||||
let index = workspace_command.repo().index();
|
||||
let routine = || index.is_ancestor(ancestor_commit.id(), descendant_commit.id());
|
||||
run_bench(
|
||||
ui,
|
||||
&format!(
|
||||
"isancestor-{}-{}",
|
||||
&command_matches.ancestor, &command_matches.descendant
|
||||
),
|
||||
routine,
|
||||
)?;
|
||||
}
|
||||
BenchCommands::WalkRevs(command_matches) => {
|
||||
let workspace_command = command.workspace_helper(ui)?;
|
||||
let unwanted_commit =
|
||||
workspace_command.resolve_single_rev(&command_matches.unwanted)?;
|
||||
let wanted_commit = workspace_command.resolve_single_rev(&command_matches.wanted)?;
|
||||
let index = workspace_command.repo().index();
|
||||
let routine = || {
|
||||
index
|
||||
.walk_revs(
|
||||
&[wanted_commit.id().clone()],
|
||||
&[unwanted_commit.id().clone()],
|
||||
)
|
||||
.count()
|
||||
};
|
||||
run_bench(
|
||||
ui,
|
||||
&format!(
|
||||
"walkrevs-{}-{}",
|
||||
&command_matches.unwanted, &command_matches.wanted
|
||||
),
|
||||
routine,
|
||||
)?;
|
||||
}
|
||||
BenchCommands::ResolvePrefix(command_matches) => {
|
||||
let workspace_command = command.workspace_helper(ui)?;
|
||||
let prefix = HexPrefix::new(command_matches.prefix.clone()).unwrap();
|
||||
let index = workspace_command.repo().index();
|
||||
let routine = || index.resolve_prefix(&prefix);
|
||||
run_bench(ui, &format!("resolveprefix-{}", prefix.hex()), routine)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn format_timestamp(timestamp: &Timestamp) -> String {
|
||||
let utc = Utc
|
||||
.timestamp(
|
||||
|
@ -4567,7 +4428,6 @@ pub fn run_command(
|
|||
Commands::Workspace(sub_args) => cmd_workspace(ui, command_helper, sub_args),
|
||||
Commands::Sparse(sub_args) => cmd_sparse(ui, command_helper, sub_args),
|
||||
Commands::Git(sub_args) => cmd_git(ui, command_helper, sub_args),
|
||||
Commands::Bench(sub_args) => cmd_bench(ui, command_helper, sub_args),
|
||||
Commands::Debug(sub_args) => cmd_debug(ui, command_helper, sub_args),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue