Skip to content

Commit

Permalink
feat: ein t hours allows to specify the amount of worker threads. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Sep 21, 2022
1 parent 30712dc commit 20259da
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
14 changes: 12 additions & 2 deletions gitoxide-core/src/hours/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ pub struct Context<W> {
pub file_stats: bool,
/// Collect how many lines in files have been added, removed and modified (without rename tracking).
pub line_stats: bool,
/// The amount of threads to use. If unset, use all cores, if 0 use al physical cores.
pub threads: Option<usize>,
/// Omit unifying identities by name and email which can lead to the same author appear multiple times
/// due to using different names or email addresses.
pub omit_unify_identities: bool,
Expand All @@ -41,6 +43,7 @@ pub fn estimate<W, P>(
file_stats,
line_stats,
omit_unify_identities,
threads,
mut out,
}: Context<W>,
) -> anyhow::Result<()>
Expand All @@ -52,6 +55,14 @@ where
let commit_id = repo.rev_parse_single(rev_spec)?.detach();
let mut string_heap = BTreeSet::<&'static [u8]>::new();
let needs_stats = file_stats || line_stats;
let threads = {
let t = threads.unwrap_or_else(num_cpus::get);
(t == 0)
.then(num_cpus::get_physical)
.unwrap_or(t)
.saturating_sub(1 /*main thread*/)
.max(1)
};

let (commit_authors, stats, is_shallow, skipped_merge_commits) = {
let stat_progress = needs_stats.then(|| progress.add_child("extract stats")).map(|mut p| {
Expand Down Expand Up @@ -125,10 +136,9 @@ where

let (tx_tree_id, stat_threads) = needs_stats
.then(|| {
let num_threads = num_cpus::get().saturating_sub(1 /*main thread*/).max(1);
let (tx, rx) =
crossbeam_channel::unbounded::<(u32, Option<git::hash::ObjectId>, git::hash::ObjectId)>();
let stat_workers = (0..num_threads)
let stat_workers = (0..threads)
.map(|_| {
scope.spawn({
let commit_counter = stat_counter.clone();
Expand Down
2 changes: 2 additions & 0 deletions src/porcelain/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub fn main() -> Result<()> {
working_dir,
rev_spec,
no_bots,
threads,
file_stats,
line_stats,
show_pii,
Expand All @@ -60,6 +61,7 @@ pub fn main() -> Result<()> {
hours::Context {
show_pii,
ignore_bots: no_bots,
threads,
file_stats,
line_stats,
omit_unify_identities,
Expand Down
3 changes: 3 additions & 0 deletions src/porcelain/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ pub struct EstimateHours {
/// Note that this implies the work to be done for file-stats, so it should be set as well.
#[clap(short = 'l', long)]
pub line_stats: bool,
/// The amount of threads to use. If unset, use all cores, if 0 use al physical cores.
#[clap(short = 't', long)]
pub threads: Option<usize>,
/// Show personally identifiable information before the summary. Includes names and email addresses.
#[clap(short = 'p', long)]
pub show_pii: bool,
Expand Down

0 comments on commit 20259da

Please sign in to comment.