File tree Expand file tree Collapse file tree 5 files changed +31
-6
lines changed Expand file tree Collapse file tree 5 files changed +31
-6
lines changed Original file line number Diff line number Diff line change @@ -377,7 +377,7 @@ private void DownloadMissingPackages()
377377
378378 private void AnalyseSolutions ( IEnumerable < string > solutions )
379379 {
380- Parallel . ForEach ( solutions , new ParallelOptions { MaxDegreeOfParallelism = 4 } , solutionFile =>
380+ Parallel . ForEach ( solutions , new ParallelOptions { MaxDegreeOfParallelism = options . Threads } , solutionFile =>
381381 {
382382 try
383383 {
Original file line number Diff line number Diff line change 1+ using System ;
12using System . Linq ;
23using System . Collections . Generic ;
4+ using Semmle . Util ;
35
46namespace Semmle . Extraction . CSharp . DependencyFetching
57{
@@ -49,6 +51,11 @@ public interface IDependencyOptions
4951 /// <param name="path">The path to query.</param>
5052 /// <returns>True iff the path matches an exclusion.</returns>
5153 bool ExcludesFile ( string path ) ;
54+
55+ /// <summary>
56+ /// The number of threads to use.
57+ /// </summary>
58+ int Threads { get ; }
5259 }
5360
5461 public class DependencyOptions : IDependencyOptions
@@ -71,5 +78,7 @@ public class DependencyOptions : IDependencyOptions
7178
7279 public bool ExcludesFile ( string path ) =>
7380 Excludes . Any ( path . Contains ) ;
81+
82+ public int Threads { get ; set ; } = EnvironmentVariables . GetDefaultNumberOfThreads ( ) ;
7483 }
7584}
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ public abstract class CommonOptions : ICommandLineOptions
1313 /// <summary>
1414 /// The specified number of threads, or the default if unspecified.
1515 /// </summary>
16- public int Threads { get ; private set ; } = System . Environment . ProcessorCount ;
16+ public int Threads { get ; private set ; } = EnvironmentVariables . GetDefaultNumberOfThreads ( ) ;
1717
1818 /// <summary>
1919 /// The verbosity used in output and logging.
Original file line number Diff line number Diff line change @@ -41,16 +41,13 @@ public interface ICommandLineOptions
4141 public static class OptionsExtensions
4242 {
4343 private static readonly string [ ] ExtractorOptions = new [ ] { "trap_compression" , "cil" } ;
44- private static string ? GetExtractorOption ( string name ) =>
45- Environment . GetEnvironmentVariable ( $ "CODEQL_EXTRACTOR_CSHARP_OPTION_{ name . ToUpper ( ) } ") ;
46-
4744 private static List < string > GetExtractorOptions ( )
4845 {
4946 var extractorOptions = new List < string > ( ) ;
5047
5148 foreach ( var option in ExtractorOptions )
5249 {
53- var value = GetExtractorOption ( option ) ;
50+ var value = EnvironmentVariables . GetExtractorOption ( option ) ;
5451 if ( ! string . IsNullOrEmpty ( value ) )
5552 {
5653 extractorOptions . Add ( $ "--{ option } :{ value } ") ;
Original file line number Diff line number Diff line change 1+ using System ;
2+
3+ namespace Semmle . Util
4+ {
5+ public class EnvironmentVariables
6+ {
7+ public static string ? GetExtractorOption ( string name ) =>
8+ Environment . GetEnvironmentVariable ( $ "CODEQL_EXTRACTOR_CSHARP_OPTION_{ name . ToUpper ( ) } ") ;
9+
10+ public static int GetDefaultNumberOfThreads ( )
11+ {
12+ if ( ! int . TryParse ( Environment . GetEnvironmentVariable ( "CODEQL_THREADS" ) , out var threads ) || threads == - 1 )
13+ {
14+ threads = Environment . ProcessorCount ;
15+ }
16+ return threads ;
17+ }
18+ }
19+ }
You can’t perform that action at this time.
0 commit comments