summaryrefslogtreecommitdiff
path: root/tests/scripts/run-xunit-perf.cmd
blob: bad1f93a404e2958eb23655df9d92836885b71a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
@rem Licensed to the .NET Foundation under one or more agreements.
@rem The .NET Foundation licenses this file to you under the MIT license.
@rem See the LICENSE file in the project root for more information.

@setlocal
@echo off
Setlocal EnableDelayedExpansion

rem Set defaults for the file extension, architecture and configuration
set CORECLR_REPO=%CD%
set TEST_FILE_EXT=exe
set TEST_ARCH=x64
set TEST_ARCHITECTURE=x64
set TEST_CONFIG=Release

goto :ARGLOOP


:SETUP

IF /I [%TEST_ARCHITECTURE%] == [x86jit32] (
    set TEST_ARCH=x86
) ELSE (
    set TEST_ARCH=%TEST_ARCHITECTURE%
)

set CORECLR_OVERLAY=%CORECLR_REPO%\bin\tests\Windows_NT.%TEST_ARCH%.%TEST_CONFIG%\Tests\Core_Root
set RUNLOG=%CORECLR_REPO%\bin\Logs\perfrun.log

if NOT EXIST %CORECLR_OVERLAY% (
  echo Can't find test overlay directory '%CORECLR_OVERLAY%'
  echo Please build and run Release CoreCLR tests
  exit /B 1
)

@echo --- setting up sandbox

if exist sandbox rd /s /q sandbox
if exist sandbox echo ERROR: Failed to remove the sandbox folder& exit /b 1
if not exist sandbox mkdir sandbox
if not exist sandbox echo ERROR: Failed to create the sandbox folder& exit /b 1
pushd sandbox

@rem stage stuff we need

@rem xunit and perf
"%CORECLR_REPO%\Tools\dotnetcli\dotnet.exe" restore "%CORECLR_REPO%\tests\src\Common\PerfHarness\project.json"
"%CORECLR_REPO%\Tools\dotnetcli\dotnet.exe" publish "%CORECLR_REPO%\tests\src\Common\PerfHarness\project.json" -c Release -o %CORECLR_REPO%\sandbox
xcopy /sy %CORECLR_REPO%\packages\Microsoft.Diagnostics.Tracing.TraceEvent\1.0.0-alpha-experimental\lib\native\* . >> %RUNLOG%
xcopy /sy %CORECLR_REPO%\bin\tests\Windows_NT.%TEST_ARCH%.%TEST_CONFIG%\Tests\Core_Root\* . >> %RUNLOG%

@rem find and stage the tests
for /R %CORECLR_PERF% %%T in (*.%TEST_FILE_EXT%) do (
  call :DOIT %%T
)

@rem optionally upload results to benchview
if not [%BENCHVIEW_PATH%] == [] (
  py "%BENCHVIEW_PATH%\submission.py" measurement.json ^
                                    --build ..\build.json ^
                                    --machine-data ..\machinedata.json ^
                                    --metadata ..\submission-metadata.json ^
                                    --group "CoreCLR" ^
                                    --type "%RUN_TYPE%" ^
                                    --config-name "%TEST_CONFIG%" ^
                                    --config Configuration "%TEST_CONFIG%" ^
                                    --config OS "Windows_NT" ^
                                    --arch "%TEST_ARCHITECTURE%" ^
                                    --machinepool "PerfSnake"
  py "%BENCHVIEW_PATH%\upload.py" submission.json --container coreclr
)

goto :EOF

:DOIT
set BENCHNAME=%~n1
set BENCHDIR=%~p1
set PERFOUT=perf-%BENCHNAME%
set XMLOUT=%PERFOUT%-summary.xml

echo --- Running %BENCHNAME%

@rem copy benchmark and any input files

xcopy /s %1 . >> %RUNLOG%
xcopy /s %BENCHDIR%*.txt . >> %RUNLOG%

set CORE_ROOT=%CORECLR_REPO%\sandbox

@rem setup additional environment variables
if DEFINED TEST_ENV (
    if EXIST !TEST_ENV! (
        call %TEST_ENV%
    )
)

corerun.exe PerfHarness.dll %WORKSPACE%\sandbox\%BENCHNAME%.%TEST_FILE_EXT% --perf:runid Perf > %BENCHNAME%.out

@rem optionally generate results for benchview
if not [%BENCHVIEW_PATH%] == [] (
  py "%BENCHVIEW_PATH%\measurement.py" xunit "Perf-%BENCHNAME%.xml" --better desc --drop-first-value --append
  REM Save off the results to the root directory for recovery later in Jenkins
  xcopy Perf-%BENCHNAME%*.xml %CORECLR_REPO%\
  xcopy Perf-%BENCHNAME%*.etl %CORECLR_REPO%\
) else (
  type %XMLOUT% | findstr "test name"
  type %XMLOUT% | findstr Duration
  type %XMLOUT% | findstr InstRetired
)

goto :EOF

:ARGLOOP
IF /I [%1] == [-testBinLoc] (
set CORECLR_PERF=%CORECLR_REPO%\%2
shift
shift
goto :ARGLOOP
)
IF /I [%1] == [-runtype] (
set RUN_TYPE=%2
shift
shift
goto :ARGLOOP
)
IF /I [%1] == [-library] (
set TEST_FILE_EXT=dll
shift
goto :ARGLOOP
)
IF /I [%1] == [-uploadtobenchview] (
set BENCHVIEW_PATH=%2
shift
shift
goto :ARGLOOP
)
IF /I [%1] == [-arch] (
set TEST_ARCHITECTURE=%2
shift
shift
goto :ARGLOOP
)
IF /I [%1] == [-testEnv] (
set TEST_ENV=%2
shift
shift
goto :ARGLOOP
)
IF /I [%1] == [-configuration] (
set TEST_CONFIG=%2
shift
shift
goto :ARGLOOP
)
if /I [%1] == [-?] (
goto :USAGE
)
if /I [%1] == [-help] (
goto :USAGE
)

if [%CORECLR_PERF%] == [] (
goto :USAGE
)

goto :SETUP

:USAGE
echo run-xunit-perf.cmd -testBinLoc ^<path_to_tests^> [-library] [-arch] ^<x86^|x64^> [-configuration] ^<Release^|Debug^> [-uploadToBenchview] ^<path_to_benchview_tools^> [-runtype] ^<rolling^|private^>

echo For the path to the tests you can pass a parent directory and the script will grovel for
echo all tests in subdirectories and run them.
echo The library flag denotes whether the tests are build as libraries (.dll) or an executable (.exe)
echo Architecture defaults to x64 and configuration defaults to release.
echo -uploadtoBenchview is used to specify a path to the Benchview tooling and when this flag is
echo set we will upload the results of the tests to the coreclr container in benchviewupload.
echo Runtype sets the runtype that we upload to Benchview, rolling for regular runs, and private for
echo PRs.

goto :EOF