1
1
using GC . Infrastructure . Core . Configurations . ASPNetBenchmarks ;
2
2
using GC . Infrastructure . Core . TraceCollection ;
3
+ using System . Linq ;
3
4
using System . Text ;
4
5
5
6
namespace GC . Infrastructure . Core . CommandBuilders
@@ -10,162 +11,84 @@ public static (string, string) Build(ASPNetBenchmarksConfiguration configuration
10
11
{
11
12
string processName = "crank" ;
12
13
StringBuilder commandStringBuilder = new ( ) ;
13
-
14
- // Load the base configuration.
15
14
commandStringBuilder . Append ( benchmarkNameToCommand . Value ) ;
16
15
16
+ List < KeyValuePair < string , string > > keyValueArgsList = new ( ) ;
17
+
17
18
// Environment Variables.
18
19
// Add the environment variables from the configuration.
19
- Dictionary < string , string > environmentVariables = new ( ) ;
20
- foreach ( var env in configuration . Environment ! . environment_variables )
21
- {
22
- environmentVariables [ env . Key ] = env . Value ;
23
- }
20
+ var environmentVariables = ServerRunCommandBuilder . OverrideDictionary (
21
+ configuration . Environment ! . environment_variables ! ,
22
+ run . Value ! . environment_variables ! ) ;
24
23
25
- // Add overrides, if available.
26
- if ( run . Value . environment_variables != null )
27
- {
28
- foreach ( var env in run . Value . environment_variables )
29
- {
30
- environmentVariables [ env . Key ] = env . Value ;
31
- }
32
- }
24
+ keyValueArgsList . AddRange (
25
+ ServerRunCommandBuilder . GenerateKeyValuePairListForEnvironmentVariables ( environmentVariables ) ) ;
33
26
34
- foreach ( var env in environmentVariables )
27
+ // Check if the log file is specified, also add the fact that we want to retrieve the log file back.
28
+ // This log file should be named in concordance with the name of the run and the benchmark.
29
+ string ? fileNameOfLog = environmentVariables ! . GetValueOrDefault ( "DOTNET_GCLogFile" , null ) ;
30
+ if ( ! String . IsNullOrEmpty ( fileNameOfLog ) )
35
31
{
36
- string variable = env . Value ;
37
-
38
- // Check if the log file is specified, also add the fact that we want to retrieve the log file back.
39
- // This log file should be named in concordance with the name of the run and the benchmark.
40
- if ( string . CompareOrdinal ( env . Key , "DOTNET_GCLogFile" ) == 0 )
41
- {
42
- string fileNameOfLog = Path . GetFileName ( env . Value ) ;
43
- commandStringBuilder . Append ( $ " --application.options.downloadFiles \" *{ fileNameOfLog } .log\" ") ;
44
- commandStringBuilder . Append ( $ " --application.options.downloadFilesOutput \" { Path . Combine ( configuration . Output ! . Path , run . Key , $ "{ benchmarkNameToCommand . Key } _GCLog") } \" ") ;
45
- }
46
-
47
- commandStringBuilder . Append ( $ " --application.environmentVariables { env . Key } ={ variable } ") ;
32
+ string gcLogDownloadPath = Path . Combine ( configuration . Output ! . Path , run . Key , $ "{ benchmarkNameToCommand . Key } _GCLog") ;
33
+ keyValueArgsList . AddRange (
34
+ ServerRunCommandBuilder . GenerateKeyValuePairListForGCLog ( fileNameOfLog , gcLogDownloadPath ) ) ;
48
35
}
49
36
50
37
// Trace Collection.
51
38
// If the TraceConfiguration Key is specified in the yaml and
52
39
if ( configuration . TraceConfigurations != null && ! string . Equals ( configuration . TraceConfigurations . Type , "none" , StringComparison . OrdinalIgnoreCase ) )
53
40
{
54
41
CollectType collectType = TraceCollector . StringToCollectTypeMap [ configuration . TraceConfigurations . Type ] ;
55
- string collectionCommand = TraceCollector . WindowsCollectTypeMap [ collectType ] ;
56
- collectionCommand = collectionCommand . Replace ( " " , ";" ) . Replace ( "/" , "" ) ;
57
-
58
- string traceFileSuffix = ".etl.zip" ;
59
- // Add specific commands.
60
- if ( os == OS . Windows )
61
- {
62
- commandStringBuilder . Append ( " --application.collect true " ) ;
63
- commandStringBuilder . Append ( " --application.collectStartup true " ) ;
64
- commandStringBuilder . Append ( $ " --application.collectArguments \" { collectionCommand } \" ") ;
65
- }
66
-
67
- else
68
- {
69
- if ( configuration . TraceConfigurations . Type != "gc" )
70
- {
71
- throw new ArgumentException ( $ "{ nameof ( ASPNetBenchmarksCommandBuilder ) } : Currently only GCCollectOnly traces are allowed for Linux.") ;
72
- }
73
-
74
- else
75
- {
76
- traceFileSuffix = ".nettrace" ;
77
- commandStringBuilder . Append ( " --application.dotnetTrace true " ) ;
78
- commandStringBuilder . Append ( " --application.dotnetTraceProviders gc-collect " ) ;
79
- }
80
- }
81
-
82
- // Add name of output.
83
- commandStringBuilder . Append ( $ " --application.options.traceOutput { Path . Combine ( configuration . Output . Path , run . Key , ( benchmarkNameToCommand . Key + "." + collectType ) ) + traceFileSuffix } ") ;
84
- }
42
+ string traceFileSuffix = os == OS . Windows ? ".etl.zip" : ".nettrace" ;
43
+ string tracePath = Path . Combine ( configuration . Output . Path , run . Key , ( benchmarkNameToCommand . Key + "." + collectType ) ) + traceFileSuffix ;
85
44
86
- string frameworkVersion = configuration . Environment . framework_version ;
87
- // Override the framework version if it's specified at the level of the run.
88
- if ( ! string . IsNullOrEmpty ( run . Value . framework_version ) )
89
- {
90
- frameworkVersion = run . Value . framework_version ;
45
+ keyValueArgsList . AddRange (
46
+ ServerRunCommandBuilder . GenerateKeyValuePairListForTrace ( configuration . TraceConfigurations . Type , tracePath , os ) ) ;
91
47
}
92
- commandStringBuilder . Append ( $ " --application.framework { frameworkVersion } ") ;
93
48
94
- string artifactsToUpload = run . Value . corerun ! ;
49
+ // Override the framework version if it's specified at the level of the run.
50
+ string frameworkVersion = string . IsNullOrEmpty ( run . Value . framework_version ) ?
51
+ configuration . Environment . framework_version : run . Value . framework_version ;
52
+ keyValueArgsList . AddRange (
53
+ ServerRunCommandBuilder . GenerateKeyValuePairListForFramework ( frameworkVersion ) ) ;
95
54
96
55
// If the corerun specified is a directory, upload the entire directory.
97
56
// Else, we upload just the file.
98
- if ( Directory . Exists ( run . Value . corerun ! ) )
99
- {
100
- artifactsToUpload = Path . Combine ( artifactsToUpload , "*.*" ) ;
101
- }
102
- commandStringBuilder . Append ( $ " --application.options.outputFiles { artifactsToUpload } ") ;
57
+ keyValueArgsList . AddRange (
58
+ ServerRunCommandBuilder . GenerateKeyValuePairListForUploadFiles ( run . Value . corerun ) ) ;
103
59
104
60
// Get the logs.
105
- commandStringBuilder . Append ( " --application.options.downloadOutput true " ) ;
106
- commandStringBuilder . Append ( $ " --application.options.downloadOutputOutput { Path . Combine ( configuration . Output . Path , run . Key , $ "{ benchmarkNameToCommand . Key } _{ run . Key } .output.log") } ") ;
107
-
108
- commandStringBuilder . Append ( " --application.options.downloadBuildLog true " ) ;
109
- commandStringBuilder . Append ( $ " --application.options.downloadBuildLogOutput { Path . Combine ( configuration . Output . Path , run . Key , $ "{ benchmarkNameToCommand . Key } _{ run . Key } .build.log") } ") ;
110
-
111
- commandStringBuilder . Append ( $ " --json { Path . Combine ( configuration . Output . Path , run . Key , $ "{ benchmarkNameToCommand . Key } _{ run . Key } .json") } ") ;
61
+ string logDownloadPathWithoutExtension = Path . Combine (
62
+ configuration . Output . Path , run . Key , $ "{ benchmarkNameToCommand . Key } _{ run . Key } ") ;
63
+ keyValueArgsList . AddRange (
64
+ ServerRunCommandBuilder . GenerateKeyValuePairListForGettingLogs ( logDownloadPathWithoutExtension ) ) ;
112
65
113
66
// Add the extra metrics by including the configuration.
114
- commandStringBuilder . Append ( $ " --config { Path . Combine ( "Commands" , "RunCommand" , "BaseSuite" , "PercentileBasedMetricsConfiguration.yml" ) } ") ;
115
-
116
- // Add any additional arguments specified.
117
- if ( ! string . IsNullOrEmpty ( configuration . benchmark_settings . additional_arguments ) )
118
- {
119
- commandStringBuilder . Append ( $ " { configuration . benchmark_settings . additional_arguments } ") ;
120
- }
121
-
122
- string commandString = commandStringBuilder . ToString ( ) ;
67
+ string configPath = Path . Combine ( "Commands" , "RunCommand" , "BaseSuite" , "PercentileBasedMetricsConfiguration.yml" ) ;
68
+ keyValueArgsList . AddRange (
69
+ ServerRunCommandBuilder . GenerateKeyValuePairListForConfig ( configPath ) ) ;
123
70
124
71
// Apply overrides.
125
72
if ( ! string . IsNullOrEmpty ( configuration . benchmark_settings . override_arguments ) )
126
73
{
127
- List < KeyValuePair < string , string > > overrideCommands = GetCrankArgsAsList ( configuration . benchmark_settings . override_arguments ) ;
128
- if ( overrideCommands . Count > 0 )
129
- {
130
- // Take the current commands and first replace all the keys that match the override commands.
131
- // Subsequently, add the new overrides and then convert the key-value pair list back to a string.
132
- List < KeyValuePair < string , string > > currentCommands = GetCrankArgsAsList ( commandString ) ;
133
- foreach ( var item in overrideCommands )
134
- {
135
- var existing = currentCommands . Where ( kv => kv . Key == item . Key ) . ToList ( ) ;
136
- foreach ( var kv in existing )
137
- {
138
- if ( kv . Key != null )
139
- {
140
- currentCommands . Remove ( kv ) ;
141
- }
142
- }
143
-
144
- currentCommands . Add ( item ) ;
145
- }
146
-
147
- commandString = string . Join ( " " , currentCommands . Select ( c => $ "--{ c . Key } { c . Value } ") ) ;
148
- }
149
- }
74
+ List < KeyValuePair < string , string > > overrideCommands = ServerRunCommandBuilder . GetCrankArgsAsList (
75
+ configuration . benchmark_settings . override_arguments ) ;
150
76
151
- return ( processName , commandString ) ;
152
- }
77
+ keyValueArgsList = ServerRunCommandBuilder . OverrideKeyValuePairList (
78
+ keyValueArgsList , overrideCommands ) ;
79
+ }
153
80
154
- internal static List < KeyValuePair < string , string > > GetCrankArgsAsList ( string input )
155
- {
156
- var keyValuePairs = new List < KeyValuePair < string , string > > ( ) ;
157
- var splitStr = input . Split ( new [ ] { "--" } , StringSplitOptions . RemoveEmptyEntries ) ;
81
+ // Add key-Value arguments to commandStringBuilder
82
+ commandStringBuilder . Append ( ServerRunCommandBuilder . ConvertKeyValueArgsListToString ( keyValueArgsList ) ) ;
158
83
159
- foreach ( var item in splitStr )
84
+ // Add any additional arguments specified.
85
+ if ( ! string . IsNullOrEmpty ( configuration . benchmark_settings . additional_arguments ) )
160
86
{
161
- var keyValue = item . Split ( ' ' , StringSplitOptions . RemoveEmptyEntries | StringSplitOptions . TrimEntries ) ;
162
- if ( keyValue . Length == 2 )
163
- {
164
- keyValuePairs . Add ( new KeyValuePair < string , string > ( keyValue [ 0 ] , keyValue [ 1 ] ) ) ;
165
- }
87
+ commandStringBuilder . Append ( $ " { configuration . benchmark_settings . additional_arguments } ") ;
166
88
}
167
89
168
- return keyValuePairs ;
90
+ string commandString = commandStringBuilder . ToString ( ) ;
91
+ return ( processName , commandString ) ;
169
92
}
170
93
}
171
94
}
0 commit comments