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()
377
377
378
378
private void AnalyseSolutions ( IEnumerable < string > solutions )
379
379
{
380
- Parallel . ForEach ( solutions , new ParallelOptions { MaxDegreeOfParallelism = 4 } , solutionFile =>
380
+ Parallel . ForEach ( solutions , new ParallelOptions { MaxDegreeOfParallelism = options . Threads } , solutionFile =>
381
381
{
382
382
try
383
383
{
Original file line number Diff line number Diff line change
1
+ using System ;
1
2
using System . Linq ;
2
3
using System . Collections . Generic ;
4
+ using Semmle . Util ;
3
5
4
6
namespace Semmle . Extraction . CSharp . DependencyFetching
5
7
{
@@ -49,6 +51,11 @@ public interface IDependencyOptions
49
51
/// <param name="path">The path to query.</param>
50
52
/// <returns>True iff the path matches an exclusion.</returns>
51
53
bool ExcludesFile ( string path ) ;
54
+
55
+ /// <summary>
56
+ /// The number of threads to use.
57
+ /// </summary>
58
+ int Threads { get ; }
52
59
}
53
60
54
61
public class DependencyOptions : IDependencyOptions
@@ -71,5 +78,7 @@ public class DependencyOptions : IDependencyOptions
71
78
72
79
public bool ExcludesFile ( string path ) =>
73
80
Excludes . Any ( path . Contains ) ;
81
+
82
+ public int Threads { get ; set ; } = EnvironmentVariables . GetDefaultNumberOfThreads ( ) ;
74
83
}
75
84
}
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ public abstract class CommonOptions : ICommandLineOptions
13
13
/// <summary>
14
14
/// The specified number of threads, or the default if unspecified.
15
15
/// </summary>
16
- public int Threads { get ; private set ; } = System . Environment . ProcessorCount ;
16
+ public int Threads { get ; private set ; } = EnvironmentVariables . GetDefaultNumberOfThreads ( ) ;
17
17
18
18
/// <summary>
19
19
/// The verbosity used in output and logging.
Original file line number Diff line number Diff line change @@ -41,16 +41,13 @@ public interface ICommandLineOptions
41
41
public static class OptionsExtensions
42
42
{
43
43
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
-
47
44
private static List < string > GetExtractorOptions ( )
48
45
{
49
46
var extractorOptions = new List < string > ( ) ;
50
47
51
48
foreach ( var option in ExtractorOptions )
52
49
{
53
- var value = GetExtractorOption ( option ) ;
50
+ var value = EnvironmentVariables . GetExtractorOption ( option ) ;
54
51
if ( ! string . IsNullOrEmpty ( value ) )
55
52
{
56
53
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