History

feat: `ein t hours` allows to specify the amount of worker threads. (#536)

Sebastian Thiel committed 4 years ago

Commit 20259da1 parent 30712dc3 files · +17 −2Browse files

Unified · Split

3 files
  1. gitoxide-core/src/hours/mod.rs +12 −2
  2. src/porcelain/main.rs +2 −0
  3. src/porcelain/options.rs +3 −0
gitoxide-core/src/hours/mod.rs+12−2
@@ -18,6 +18,8 @@ pub struct Context<W> { · 17 unmodified lines
1818 pub file_stats: bool,
1919 /// Collect how many lines in files have been added, removed and modified (without rename tracking).
2020 pub line_stats: bool,
21+ /// The amount of threads to use. If unset, use all cores, if 0 use al physical cores.
22+ pub threads: Option<usize>,
2123 /// Omit unifying identities by name and email which can lead to the same author appear multiple times
2224 /// due to using different names or email addresses.
2325 pub omit_unify_identities: bool,
@@ -41,6 +43,7 @@ pub fn estimate<W, P>( · 17 unmodified lines
4143 file_stats,
4244 line_stats,
4345 omit_unify_identities,
46+ threads,
4447 mut out,
4548 }: Context<W>,
4649 ) -> anyhow::Result<()>
@@ -52,6 +55,14 @@ where · 5 unmodified lines
5255 let commit_id = repo.rev_parse_single(rev_spec)?.detach();
5356 let mut string_heap = BTreeSet::<&'static [u8]>::new();
5457 let needs_stats = file_stats || line_stats;
58+ let threads = {
59+ let t = threads.unwrap_or_else(num_cpus::get);
60+ (t == 0)
61+ .then(num_cpus::get_physical)
62+ .unwrap_or(t)
63+ .saturating_sub(1 /*main thread*/)
64+ .max(1)
65+ };
5566
5667 let (commit_authors, stats, is_shallow, skipped_merge_commits) = {
5768 let stat_progress = needs_stats.then(|| progress.add_child("extract stats")).map(|mut p| {
@@ -125,10 +136,9 @@ where · 67 unmodified lines
125136
126137 let (tx_tree_id, stat_threads) = needs_stats
127138 .then(|| {
128− let num_threads = num_cpus::get().saturating_sub(1 /*main thread*/).max(1);
129139 let (tx, rx) =
130140 crossbeam_channel::unbounded::<(u32, Option<git::hash::ObjectId>, git::hash::ObjectId)>();
131− let stat_workers = (0..num_threads)
141+ let stat_workers = (0..threads)
132142 .map(|_| {
133143 scope.spawn({
134144 let commit_counter = stat_counter.clone();
src/porcelain/main.rs+2−0
@@ -40,6 +40,7 @@ pub fn main() -> Result<()> { · 39 unmodified lines
4040 working_dir,
4141 rev_spec,
4242 no_bots,
43+ threads,
4344 file_stats,
4445 line_stats,
4546 show_pii,
@@ -60,6 +61,7 @@ pub fn main() -> Result<()> { · 14 unmodified lines
6061 hours::Context {
6162 show_pii,
6263 ignore_bots: no_bots,
64+ threads,
6365 file_stats,
6466 line_stats,
6567 omit_unify_identities,
src/porcelain/options.rs+3−0
@@ -109,6 +109,9 @@ pub struct EstimateHours { · 108 unmodified lines
109109 /// Note that this implies the work to be done for file-stats, so it should be set as well.
110110 #[clap(short = 'l', long)]
111111 pub line_stats: bool,
112+ /// The amount of threads to use. If unset, use all cores, if 0 use al physical cores.
113+ #[clap(short = 't', long)]
114+ pub threads: Option<usize>,
112115 /// Show personally identifiable information before the summary. Includes names and email addresses.
113116 #[clap(short = 'p', long)]
114117 pub show_pii: bool,