Merge pull request #11671 from dotnet/PerfTrigger
[platform/upstream/coreclr.git] / perf.groovy
1 // Import the utility functionality.
2
3 import jobs.generation.*;
4
5 def project = GithubProject
6 def branch = GithubBranchName
7 def projectName = Utilities.getFolderName(project)
8 def projectFolder = projectName + '/' + Utilities.getFolderName(branch)
9
10 def static getOSGroup(def os) {
11     def osGroupMap = ['Ubuntu14.04':'Linux',
12         'RHEL7.2': 'Linux',
13         'Ubuntu16.04': 'Linux',
14         'Debian8.4':'Linux',
15         'Fedora24':'Linux',
16         'OSX':'OSX',
17         'Windows_NT':'Windows_NT',
18         'FreeBSD':'FreeBSD',
19         'CentOS7.1': 'Linux',
20         'OpenSUSE13.2': 'Linux',
21         'OpenSUSE42.1': 'Linux',
22         'LinuxARMEmulator': 'Linux']
23     def osGroup = osGroupMap.get(os, null)
24     assert osGroup != null : "Could not find os group for ${os}"
25     return osGroupMap[os]
26 }
27 // Setup perflab tests runs
28 [true, false].each { isPR ->
29     ['Windows_NT'].each { os ->
30         ['x64', 'x86'].each { arch ->
31             [true, false].each { isSmoketest ->
32                 def architecture = arch
33                 def jobName = isSmoketest ? "perf_perflab_${os}_${arch}_smoketest" : "perf_perflab_${os}_${arch}"
34
35                 if (arch == 'x86jit32')
36                 {
37                     architecture = 'x86'
38                     testEnv = '-testEnv %WORKSPACE%\\tests\\x86\\compatjit_x86_testenv.cmd'
39                 }
40                 else if (arch == 'x86')
41                 {
42                     testEnv = '-testEnv %WORKSPACE%\\tests\\x86\\ryujit_x86_testenv.cmd'
43                 }
44
45                 def newJob = job(Utilities.getFullJobName(project, jobName, isPR)) {
46                     // Set the label.
47                     label('windows_clr_perf')
48                     wrappers {
49                         credentialsBinding {
50                             string('BV_UPLOAD_SAS_TOKEN', 'CoreCLR Perf BenchView Sas')
51                         }
52                     }
53
54                 if (isPR)
55                 {
56                     parameters
57                     {
58                         stringParam('BenchviewCommitName', '\${ghprbPullTitle}', 'The name that you will be used to build the full title of a run in Benchview.  The final name will be of the form <branch> private BenchviewCommitName')
59                     }
60                 }
61                 if (isSmoketest)
62                 {
63                     parameters
64                     {
65                         stringParam('XUNIT_PERFORMANCE_MAX_ITERATION', '2', 'Sets the number of iterations to two.  We want to do this so that we can run as fast as possible as this is just for smoke testing')
66                         stringParam('XUNIT_PERFORMANCE_MAX_ITERATION_INNER_SPECIFIED', '2', 'Sets the number of iterations to two.  We want to do this so that we can run as fast as possible as this is just for smoke testing')
67                     }
68                 }
69                 else
70                 {
71                     parameters
72                     {
73                         stringParam('XUNIT_PERFORMANCE_MAX_ITERATION', '21', 'Sets the number of iterations to twenty one.  We are doing this to limit the amount of data that we upload as 20 iterations is enought to get a good sample')
74                         stringParam('XUNIT_PERFORMANCE_MAX_ITERATION_INNER_SPECIFIED', '21', 'Sets the number of iterations to twenty one.  We are doing this to limit the amount of data that we upload as 20 iterations is enought to get a good sample')
75                     }
76                 }
77                 def configuration = 'Release'
78                 def runType = isPR ? 'private' : 'rolling'
79                 def benchViewName = isPR ? 'coreclr private %BenchviewCommitName%' : 'coreclr rolling %GIT_BRANCH_WITHOUT_ORIGIN% %GIT_COMMIT%'
80                 def uploadString = isSmoketest ? '' : '-uploadToBenchview'
81                     
82                     steps {
83                         // Batch
84
85                         batchFile("powershell wget https://dist.nuget.org/win-x86-commandline/latest/nuget.exe -OutFile \"%WORKSPACE%\\nuget.exe\"")
86                         batchFile("if exist \"%WORKSPACE%\\Microsoft.BenchView.JSONFormat\" rmdir /s /q \"%WORKSPACE%\\Microsoft.BenchView.JSONFormat\"")
87                         batchFile("\"%WORKSPACE%\\nuget.exe\" install Microsoft.BenchView.JSONFormat -Source http://benchviewtestfeed.azurewebsites.net/nuget -OutputDirectory \"%WORKSPACE%\" -Prerelease -ExcludeVersion")
88                         //Do this here to remove the origin but at the front of the branch name as this is a problem for BenchView
89                         //we have to do it all as one statement because cmd is called each time and we lose the set environment variable
90                         batchFile("if [%GIT_BRANCH:~0,7%] == [origin/] (set GIT_BRANCH_WITHOUT_ORIGIN=%GIT_BRANCH:origin/=%) else (set GIT_BRANCH_WITHOUT_ORIGIN=%GIT_BRANCH%)\n" +
91                         "set BENCHVIEWNAME=${benchViewName}\n" +
92                         "set BENCHVIEWNAME=%BENCHVIEWNAME:\"=%\n" +
93                         "py \"%WORKSPACE%\\Microsoft.BenchView.JSONFormat\\tools\\submission-metadata.py\" --name \"%BENCHVIEWNAME%\" --user \"dotnet-bot@microsoft.com\"\n" +
94                         "py \"%WORKSPACE%\\Microsoft.BenchView.JSONFormat\\tools\\build.py\" git --branch %GIT_BRANCH_WITHOUT_ORIGIN% --type ${runType}")
95                         batchFile("py \"%WORKSPACE%\\Microsoft.BenchView.JSONFormat\\tools\\machinedata.py\"")
96                         batchFile("set __TestIntermediateDir=int&&build.cmd ${configuration} ${architecture}")
97
98                         if (arch == 'x86jit32')
99                         {
100                             // Download package and copy compatjit into Core_Root
101                             batchFile("C:\\Tools\\nuget.exe install runtime.win7-${architecture}.Microsoft.NETCore.Jit -Source https://dotnet.myget.org/F/dotnet-core -OutputDirectory \"%WORKSPACE%\" -Prerelease -ExcludeVersion\n" +
102                             "xcopy \"%WORKSPACE%\\runtime.win7-x86.Microsoft.NETCore.Jit\\runtimes\\win7-x86\\native\\compatjit.dll\" \"%WORKSPACE%\\bin\\Product\\${os}.${architecture}.${configuration}\" /Y")
103                         }
104
105                         batchFile("tests\\runtest.cmd ${configuration} ${architecture} GenerateLayoutOnly")
106
107                         // Run with just stopwatch
108                         batchFile("tests\\scripts\\run-xunit-perf.cmd -arch ${arch} -configuration ${configuration} -testBinLoc bin\\tests\\${os}.${architecture}.${configuration}\\performance\\perflab\\Perflab -library -generateBenchviewData \"%WORKSPACE%\\Microsoft.Benchview.JSONFormat\\tools\" ${uploadString} -runtype ${runType} -stabilityPrefix \"START \"CORECLR_PERF_RUN\" /B /WAIT /HIGH /AFFINITY 0x2\"")
109                         batchFile("tests\\scripts\\run-xunit-perf.cmd -arch ${arch} -configuration ${configuration} -testBinLoc bin\\tests\\${os}.${architecture}.${configuration}\\Jit\\Performance\\CodeQuality -generateBenchviewData \"%WORKSPACE%\\Microsoft.Benchview.JSONFormat\\tools\" ${uploadString} -runtype ${runType} -stabilityPrefix \"START \"CORECLR_PERF_RUN\" /B /WAIT /HIGH /AFFINITY 0x2\"")
110                         batchFile("tests\\scripts\\run-xunit-perf.cmd -arch ${arch} -configuration ${configuration} -testBinLoc bin\\tests\\${os}.${architecture}.${configuration}\\performance\\linkbench\\linkbench -generateBenchviewData \"%WORKSPACE%\\Microsoft.Benchview.JSONFormat\\tools\" ${uploadString} -nowarmup -runtype ${runType} -scenarioTest -group ILLink")
111
112                         // Run with the full set of counters enabled
113                         batchFile("tests\\scripts\\run-xunit-perf.cmd -arch ${arch} -configuration ${configuration} -testBinLoc bin\\tests\\${os}.${architecture}.${configuration}\\performance\\perflab\\Perflab -library -generateBenchviewData \"%WORKSPACE%\\Microsoft.Benchview.JSONFormat\\tools\" ${uploadString} -runtype ${runType} -collectionFlags default+BranchMispredictions+CacheMisses+InstructionRetired+gcapi -stabilityPrefix \"START \"CORECLR_PERF_RUN\" /B /WAIT /HIGH /AFFINITY 0x2\"")
114                         batchFile("tests\\scripts\\run-xunit-perf.cmd -arch ${arch} -configuration ${configuration} -testBinLoc bin\\tests\\${os}.${architecture}.${configuration}\\Jit\\Performance\\CodeQuality -generateBenchviewData \"%WORKSPACE%\\Microsoft.Benchview.JSONFormat\\tools\" ${uploadString} -runtype ${runType} -collectionFlags default+BranchMispredictions+CacheMisses+InstructionRetired+gcapi -stabilityPrefix \"START \"CORECLR_PERF_RUN\" /B /WAIT /HIGH /AFFINITY 0x2\"")
115                     }
116                 }
117                 
118                 if (isSmoketest)
119                 {
120                     Utilities.setMachineAffinity(newJob, "Windows_NT", '20170427-elevated')
121                 }
122                 // Save machinedata.json to /artifact/bin/ Jenkins dir
123                 def archiveSettings = new ArchivalSettings()
124                 archiveSettings.addFiles('Perf-*.xml')
125                 archiveSettings.addFiles('Perf-*.etl')
126                 Utilities.addArchival(newJob, archiveSettings)
127
128                 Utilities.standardJobSetup(newJob, project, isPR, "*/${branch}")
129                 
130                 newJob.with {
131                     wrappers {
132                         timeout {
133                             absolute(240)
134                         }
135                     }
136                 }
137                 
138                 if (isPR) {
139                     TriggerBuilder builder = TriggerBuilder.triggerOnPullRequest()
140                     if (isSmoketest)
141                     {
142                         builder.setGithubContext("${os} ${arch} CoreCLR Perf Tests Correctness")
143                         builder.triggerOnlyOnComment()
144                         builder.setCustomTriggerPhrase("(?i).*test\\W+${os}\\W+${arch}\\W+perf correctness.*")
145                     }
146                     else
147                     {
148                         builder.setGithubContext("${os} ${arch} CoreCLR Perf Tests")
149                         builder.triggerOnlyOnComment()
150                         builder.setCustomTriggerPhrase("(?i).*test\\W+${os}\\W+${arch}\\W+perf.*")
151                     }
152                     builder.triggerForBranch(branch)
153                     builder.emitTrigger(newJob)
154                 }
155                 else {
156                     // Set a push trigger
157                     TriggerBuilder builder = TriggerBuilder.triggerOnCommit()
158                     builder.emitTrigger(newJob)
159                 }
160             }
161         }
162     }
163 }
164
165 // Setup throughput perflab tests runs
166 [true, false].each { isPR ->
167     ['Windows_NT'].each { os ->
168         ['x64', 'x86'].each { arch ->
169             def architecture = arch
170
171             def newJob = job(Utilities.getFullJobName(project, "perf_throughput_perflab_${os}_${arch}", isPR)) {
172                 // Set the label.
173                 label('windows_clr_perf')
174                 wrappers {
175                     credentialsBinding {
176                         string('BV_UPLOAD_SAS_TOKEN', 'CoreCLR Perf BenchView Sas')
177                     }
178                 }
179
180             if (isPR)
181             {
182                 parameters
183                 {
184                     stringParam('BenchviewCommitName', '\${ghprbPullTitle}', 'The name that you will be used to build the full title of a run in Benchview.  The final name will be of the form <branch> private BenchviewCommitName')
185                 }
186             }
187             def configuration = 'Release'
188             def runType = isPR ? 'private' : 'rolling'
189             def benchViewName = isPR ? 'coreclr-throughput private %BenchviewCommitName%' : 'coreclr-throughput rolling %GIT_BRANCH_WITHOUT_ORIGIN% %GIT_COMMIT%'
190                 
191                 steps {
192                     // Batch
193
194                     batchFile("if exist \"%WORKSPACE%\\Microsoft.BenchView.JSONFormat\" rmdir /s /q \"%WORKSPACE%\\Microsoft.BenchView.JSONFormat\"")
195                     batchFile("if exist \"%WORKSPACE%\\Microsoft.BenchView.ThroughputBenchmarks.${architecture}.${os}\" rmdir /s /q \"%WORKSPACE%\\Microsoft.BenchView.ThroughputBenchmarks.${architecture}.${os}\"")
196                     batchFile("C:\\Tools\\nuget.exe install Microsoft.BenchView.JSONFormat -Source http://benchviewtestfeed.azurewebsites.net/nuget -OutputDirectory \"%WORKSPACE%\" -Prerelease -ExcludeVersion")
197                     batchFile("C:\\Tools\\nuget.exe install Microsoft.BenchView.ThroughputBenchmarks.${architecture}.${os} -Source https://dotnet.myget.org/F/dotnet-core -OutputDirectory \"%WORKSPACE%\" -Prerelease -ExcludeVersion")
198                     //Do this here to remove the origin but at the front of the branch name as this is a problem for BenchView
199                     //we have to do it all as one statement because cmd is called each time and we lose the set environment variable
200                     batchFile("if [%GIT_BRANCH:~0,7%] == [origin/] (set GIT_BRANCH_WITHOUT_ORIGIN=%GIT_BRANCH:origin/=%) else (set GIT_BRANCH_WITHOUT_ORIGIN=%GIT_BRANCH%)\n" +
201                     "set BENCHVIEWNAME=${benchViewName}\n" +
202                     "set BENCHVIEWNAME=%BENCHVIEWNAME:\"=%\n" +
203                     "py \"%WORKSPACE%\\Microsoft.BenchView.JSONFormat\\tools\\submission-metadata.py\" --name \"${benchViewName}\" --user \"dotnet-bot@microsoft.com\"\n" +
204                     "py \"%WORKSPACE%\\Microsoft.BenchView.JSONFormat\\tools\\build.py\" git --branch %GIT_BRANCH_WITHOUT_ORIGIN% --type ${runType}")
205                     batchFile("py \"%WORKSPACE%\\Microsoft.BenchView.JSONFormat\\tools\\machinedata.py\"")
206                     batchFile("set __TestIntermediateDir=int&&build.cmd ${configuration} ${architecture} skiptests")
207                     batchFile("tests\\runtest.cmd ${configuration} ${architecture} GenerateLayoutOnly")
208                     batchFile("py -u tests\\scripts\\run-throughput-perf.py -arch ${arch} -os ${os} -configuration ${configuration} -clr_root \"%WORKSPACE%\" -assembly_root \"%WORKSPACE%\\Microsoft.BenchView.ThroughputBenchmarks.${architecture}.${os}\\lib\" -benchview_path \"%WORKSPACE%\\Microsoft.Benchview.JSONFormat\\tools\" -run_type ${runType}")
209                 }
210             }
211
212             // Save machinedata.json to /artifact/bin/ Jenkins dir
213             def archiveSettings = new ArchivalSettings()
214             archiveSettings.addFiles('throughput-*.csv')
215             Utilities.addArchival(newJob, archiveSettings)
216
217             Utilities.standardJobSetup(newJob, project, isPR, "*/${branch}")
218
219             if (isPR) {
220                 TriggerBuilder builder = TriggerBuilder.triggerOnPullRequest()
221                 builder.setGithubContext("${os} ${arch} CoreCLR Throughput Perf Tests")
222                 builder.triggerOnlyOnComment()
223                 builder.setCustomTriggerPhrase("(?i).*test\\W+${os}\\W+${arch}\\W+throughput.*")
224                 builder.triggerForBranch(branch)
225                 builder.emitTrigger(newJob)
226             }
227             else {
228                 // Set a push trigger
229                 TriggerBuilder builder = TriggerBuilder.triggerOnCommit()
230                 builder.emitTrigger(newJob)
231             }
232         }
233     }
234 }
235
236 // Create the Linux/OSX/CentOS coreclr test leg for debug and release and each scenario
237 [true, false].each { isPR ->
238     ['Ubuntu14.04'].each { os ->
239         def newJob = job(Utilities.getFullJobName(project, "perf_${os}", isPR)) {
240             
241             label('linux_clr_perf')
242                 wrappers {
243                     credentialsBinding {
244                         string('BV_UPLOAD_SAS_TOKEN', 'CoreCLR Perf BenchView Sas')
245                     }
246                 }
247             
248             if (isPR)
249             {
250                 parameters
251                 {
252                     stringParam('BenchviewCommitName', '\${ghprbPullTitle}', 'The name that you will be used to build the full title of a run in Benchview.  The final name will be of the form <branch> private BenchviewCommitName')
253                 }
254             }
255             def osGroup = getOSGroup(os)
256             def architecture = 'x64'
257             def configuration = 'Release'
258             def runType = isPR ? 'private' : 'rolling'
259             def benchViewName = isPR ? 'coreclr private \$BenchviewCommitName' : 'coreclr rolling \$GIT_BRANCH_WITHOUT_ORIGIN \$GIT_COMMIT'
260             
261             steps {
262                 shell("bash ./tests/scripts/perf-prep.sh")
263                 shell("./init-tools.sh")
264                 shell("./build.sh ${architecture} ${configuration}")
265                 shell("GIT_BRANCH_WITHOUT_ORIGIN=\$(echo \$GIT_BRANCH | sed \"s/[^/]*\\/\\(.*\\)/\\1 /\")\n" +
266                 "python3.5 \"\${WORKSPACE}/tests/scripts/Microsoft.BenchView.JSONFormat/tools/submission-metadata.py\" --name \" ${benchViewName} \" --user \"dotnet-bot@microsoft.com\"\n" +
267                 "python3.5 \"\${WORKSPACE}/tests/scripts/Microsoft.BenchView.JSONFormat/tools/build.py\" git --branch \$GIT_BRANCH_WITHOUT_ORIGIN --type ${runType}")
268                 shell("""sudo -E bash ./tests/scripts/run-xunit-perf.sh \\
269                 --testRootDir=\"\${WORKSPACE}/bin/tests/Windows_NT.${architecture}.${configuration}\" \\
270                 --testNativeBinDir=\"\${WORKSPACE}/bin/obj/${osGroup}.${architecture}.${configuration}/tests\" \\
271                 --coreClrBinDir=\"\${WORKSPACE}/bin/Product/${osGroup}.${architecture}.${configuration}\" \\
272                 --mscorlibDir=\"\${WORKSPACE}/bin/Product/${osGroup}.${architecture}.${configuration}\" \\
273                 --coreFxBinDir=\"\${WORKSPACE}/corefx\" \\
274                 --runType=\"${runType}\" \\
275                 --benchViewOS=\"${os}\" \\
276                 --uploadToBenchview""")
277             }
278         }
279
280         // Save machinedata.json to /artifact/bin/ Jenkins dir
281         def archiveSettings = new ArchivalSettings()
282         archiveSettings.addFiles('sandbox/perf-*.xml')
283         archiveSettings.addFiles('machinedata.json')
284         Utilities.addArchival(newJob, archiveSettings)
285
286         Utilities.standardJobSetup(newJob, project, isPR, "*/${branch}")
287
288         // For perf, we need to keep the run results longer
289         newJob.with {
290             // Enable the log rotator
291             logRotator {
292                 artifactDaysToKeep(7)
293                 daysToKeep(300)
294                 artifactNumToKeep(25)
295                 numToKeep(1000)
296             }
297         }
298         if (isPR) {
299             TriggerBuilder builder = TriggerBuilder.triggerOnPullRequest()
300             builder.setGithubContext("${os} Perf Tests")
301             builder.triggerOnlyOnComment()
302             builder.setCustomTriggerPhrase("(?i).*test\\W+${os}\\W+perf.*")
303             builder.triggerForBranch(branch)
304             builder.emitTrigger(newJob)
305         }
306         else {
307             // Set a push trigger
308             TriggerBuilder builder = TriggerBuilder.triggerOnCommit()
309             builder.emitTrigger(newJob)
310         }
311     } // os
312 } // isPR
313
314 // Create the Linux/OSX/CentOS coreclr test leg for debug and release and each scenario
315 [true, false].each { isPR ->
316     ['Ubuntu14.04'].each { os ->
317         def newJob = job(Utilities.getFullJobName(project, "perf_throughput_${os}", isPR)) {
318             
319             label('linux_clr_perf')
320                 wrappers {
321                     credentialsBinding {
322                         string('BV_UPLOAD_SAS_TOKEN', 'CoreCLR Perf BenchView Sas')
323                     }
324                 }
325             
326             if (isPR)
327             {
328                 parameters
329                 {
330                     stringParam('BenchviewCommitName', '\${ghprbPullTitle}', 'The name that you will be used to build the full title of a run in Benchview.  The final name will be of the form <branch> private BenchviewCommitName')
331                 }
332             }
333             def osGroup = getOSGroup(os)
334             def architecture = 'x64'
335             def configuration = 'Release'
336             def runType = isPR ? 'private' : 'rolling'
337             def benchViewName = isPR ? 'coreclr private \$BenchviewCommitName' : 'coreclr rolling \$GIT_BRANCH_WITHOUT_ORIGIN \$GIT_COMMIT'
338             
339             steps {
340                 shell("bash ./tests/scripts/perf-prep.sh --throughput")
341                 shell("./init-tools.sh")
342                 shell("./build.sh ${architecture} ${configuration}")
343                 shell("GIT_BRANCH_WITHOUT_ORIGIN=\$(echo \$GIT_BRANCH | sed \"s/[^/]*\\/\\(.*\\)/\\1 /\")\n" +
344                 "python3.5 \"\${WORKSPACE}/tests/scripts/Microsoft.BenchView.JSONFormat/tools/submission-metadata.py\" --name \" ${benchViewName} \" --user \"dotnet-bot@microsoft.com\"\n" +
345                 "python3.5 \"\${WORKSPACE}/tests/scripts/Microsoft.BenchView.JSONFormat/tools/build.py\" git --branch \$GIT_BRANCH_WITHOUT_ORIGIN --type ${runType}")
346                 shell("""sudo -E python3.5 ./tests/scripts/run-throughput-perf.py \\
347                 -arch \"${architecture}\" \\
348                 -os \"${os}\" \\
349                 -configuration \"${configuration}\" \\
350                 -clr_root \"\${WORKSPACE}\" \\
351                 -assembly_root \"\${WORKSPACE}/_/fx/bin/runtime/netcoreapp-${osGroup}-${configuration}-${architecture}\" \\
352                 -run_type \"${runType}\" \\
353                 -benchview_path \"\${WORKSPACE}/tests/scripts/Microsoft.BenchView.JSONFormat/tools\"""")
354             }
355         }
356
357         // Save machinedata.json to /artifact/bin/ Jenkins dir
358         def archiveSettings = new ArchivalSettings()
359         archiveSettings.addFiles('throughput-*.csv')
360         archiveSettings.addFiles('machinedata.json')
361         Utilities.addArchival(newJob, archiveSettings)
362
363         Utilities.standardJobSetup(newJob, project, isPR, "*/${branch}")
364
365         // For perf, we need to keep the run results longer
366         newJob.with {
367             // Enable the log rotator
368             logRotator {
369                 artifactDaysToKeep(7)
370                 daysToKeep(300)
371                 artifactNumToKeep(25)
372                 numToKeep(1000)
373             }
374         }
375         if (isPR) {
376             TriggerBuilder builder = TriggerBuilder.triggerOnPullRequest()
377             builder.setGithubContext("${os} Throughput Perf Tests")
378             builder.triggerOnlyOnComment()
379             builder.setCustomTriggerPhrase("(?i).*test\\W+${os}\\W+throughput.*")
380             builder.triggerForBranch(branch)
381             builder.emitTrigger(newJob)
382         }
383         else {
384             // Set a push trigger
385             TriggerBuilder builder = TriggerBuilder.triggerOnCommit()
386             builder.emitTrigger(newJob)
387         }
388     } // os
389 } // isPR