Fix run-xunit-perf.cmd for local use
[platform/upstream/coreclr.git] / tests / scripts / run-xunit-perf.cmd
1 @rem Licensed to the .NET Foundation under one or more agreements.
2 @rem The .NET Foundation licenses this file to you under the MIT license.
3 @rem See the LICENSE file in the project root for more information.
4
5 @setlocal
6 @echo off
7 Setlocal EnableDelayedExpansion
8
9 rem Set defaults for the file extension, architecture and configuration
10 set CORECLR_REPO=%CD%
11 set TEST_FILE_EXT=exe
12 set TEST_ARCH=x64
13 set TEST_ARCHITECTURE=x64
14 set TEST_CONFIG=Release
15
16 goto :ARGLOOP
17
18
19 :SETUP
20
21 IF /I [%TEST_ARCHITECTURE%] == [x86jit32] (
22     set TEST_ARCH=x86
23 ) ELSE (
24     set TEST_ARCH=%TEST_ARCHITECTURE%
25 )
26
27 set CORECLR_OVERLAY=%CORECLR_REPO%\bin\tests\Windows_NT.%TEST_ARCH%.%TEST_CONFIG%\Tests\Core_Root
28 set RUNLOG=%CORECLR_REPO%\bin\Logs\perfrun.log
29
30 if NOT EXIST %CORECLR_OVERLAY% (
31   echo Can't find test overlay directory '%CORECLR_OVERLAY%'
32   echo Please build and run Release CoreCLR tests
33   exit /B 1
34 )
35
36 @echo --- setting up sandbox
37
38 if exist sandbox rd /s /q sandbox
39 if exist sandbox echo ERROR: Failed to remove the sandbox folder& exit /b 1
40 if not exist sandbox mkdir sandbox
41 if not exist sandbox echo ERROR: Failed to create the sandbox folder& exit /b 1
42 pushd sandbox
43
44 @rem stage stuff we need
45
46 @rem xunit and perf
47 "%CORECLR_REPO%\Tools\dotnetcli\dotnet.exe" restore "%CORECLR_REPO%\tests\src\Common\PerfHarness\project.json"
48 "%CORECLR_REPO%\Tools\dotnetcli\dotnet.exe" publish "%CORECLR_REPO%\tests\src\Common\PerfHarness\project.json" -c Release -o %CORECLR_REPO%\sandbox
49 xcopy /sy %CORECLR_REPO%\packages\Microsoft.Diagnostics.Tracing.TraceEvent\1.0.0-alpha-experimental\lib\native\* . >> %RUNLOG%
50 xcopy /sy %CORECLR_REPO%\bin\tests\Windows_NT.%TEST_ARCH%.%TEST_CONFIG%\Tests\Core_Root\* . >> %RUNLOG%
51
52 @rem find and stage the tests
53 for /R %CORECLR_PERF% %%T in (*.%TEST_FILE_EXT%) do (
54   call :DOIT %%T
55 )
56
57 @rem optionally upload results to benchview
58 if not [%BENCHVIEW_PATH%] == [] (
59   py "%BENCHVIEW_PATH%\submission.py" measurement.json ^
60                                     --build ..\build.json ^
61                                     --machine-data ..\machinedata.json ^
62                                     --metadata ..\submission-metadata.json ^
63                                     --group "CoreCLR" ^
64                                     --type "%RUN_TYPE%" ^
65                                     --config-name "%TEST_CONFIG%" ^
66                                     --config Configuration "%TEST_CONFIG%" ^
67                                     --config OS "Windows_NT" ^
68                                     --arch "%TEST_ARCHITECTURE%" ^
69                                     --machinepool "PerfSnake"
70   py "%BENCHVIEW_PATH%\upload.py" submission.json --container coreclr
71 )
72
73 goto :EOF
74
75 :DOIT
76 set BENCHNAME=%~n1
77 set BENCHDIR=%~p1
78 set PERFOUT=perf-%BENCHNAME%
79 set XMLOUT=%PERFOUT%-summary.xml
80
81 echo --- Running %BENCHNAME%
82
83 @rem copy benchmark and any input files
84
85 xcopy /s %1 . >> %RUNLOG%
86 xcopy /s %BENCHDIR%*.txt . >> %RUNLOG%
87
88 set CORE_ROOT=%CORECLR_REPO%\sandbox
89
90 @rem setup additional environment variables
91 if DEFINED TEST_ENV (
92     if EXIST !TEST_ENV! (
93         call %TEST_ENV%
94     )
95 )
96
97 corerun.exe PerfHarness.dll %CORECLR_REPO%\sandbox\%BENCHNAME%.%TEST_FILE_EXT% --perf:runid Perf > %BENCHNAME%.out
98
99 @rem optionally generate results for benchview
100 if not [%BENCHVIEW_PATH%] == [] (
101   py "%BENCHVIEW_PATH%\measurement.py" xunit "Perf-%BENCHNAME%.xml" --better desc --drop-first-value --append
102   REM Save off the results to the root directory for recovery later in Jenkins
103   xcopy Perf-%BENCHNAME%*.xml %CORECLR_REPO%\
104   xcopy Perf-%BENCHNAME%*.etl %CORECLR_REPO%\
105 ) else (
106   type %XMLOUT% | findstr "test name"
107   type %XMLOUT% | findstr Duration
108   type %XMLOUT% | findstr InstRetired
109 )
110
111 goto :EOF
112
113 :ARGLOOP
114 IF /I [%1] == [-testBinLoc] (
115 set CORECLR_PERF=%CORECLR_REPO%\%2
116 shift
117 shift
118 goto :ARGLOOP
119 )
120 IF /I [%1] == [-runtype] (
121 set RUN_TYPE=%2
122 shift
123 shift
124 goto :ARGLOOP
125 )
126 IF /I [%1] == [-library] (
127 set TEST_FILE_EXT=dll
128 shift
129 goto :ARGLOOP
130 )
131 IF /I [%1] == [-uploadtobenchview] (
132 set BENCHVIEW_PATH=%2
133 shift
134 shift
135 goto :ARGLOOP
136 )
137 IF /I [%1] == [-arch] (
138 set TEST_ARCHITECTURE=%2
139 shift
140 shift
141 goto :ARGLOOP
142 )
143 IF /I [%1] == [-testEnv] (
144 set TEST_ENV=%2
145 shift
146 shift
147 goto :ARGLOOP
148 )
149 IF /I [%1] == [-configuration] (
150 set TEST_CONFIG=%2
151 shift
152 shift
153 goto :ARGLOOP
154 )
155 if /I [%1] == [-?] (
156 goto :USAGE
157 )
158 if /I [%1] == [-help] (
159 goto :USAGE
160 )
161
162 if [%CORECLR_PERF%] == [] (
163 goto :USAGE
164 )
165
166 goto :SETUP
167
168 :USAGE
169 echo run-xunit-perf.cmd -testBinLoc ^<path_to_tests^> [-library] [-arch] ^<x86^|x64^> [-configuration] ^<Release^|Debug^> [-uploadToBenchview] ^<path_to_benchview_tools^> [-runtype] ^<rolling^|private^>
170
171 echo For the path to the tests you can pass a parent directory and the script will grovel for
172 echo all tests in subdirectories and run them.
173 echo The library flag denotes whether the tests are build as libraries (.dll) or an executable (.exe)
174 echo Architecture defaults to x64 and configuration defaults to release.
175 echo -uploadtoBenchview is used to specify a path to the Benchview tooling and when this flag is
176 echo set we will upload the results of the tests to the coreclr container in benchviewupload.
177 echo Runtype sets the runtype that we upload to Benchview, rolling for regular runs, and private for
178 echo PRs.
179
180 goto :EOF