1 //
2 // Copyright 2019 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // ANGLEPerfTestArgs.cpp:
7 // Parse command line arguments for angle_perftests.
8 //
9
10 #include "ANGLEPerfTestArgs.h"
11 #include <string.h>
12 #include <sstream>
13
14 #include "common/debug.h"
15 #include "util/test_utils.h"
16
17 namespace angle
18 {
19
20 constexpr int kDefaultStepsPerTrial = 0;
21 constexpr int kDefaultTrialTimeSeconds = 0;
22 constexpr int kDefaultTestTrials = 3;
23
24 bool gCalibration = false;
25 int gStepsPerTrial = kDefaultStepsPerTrial;
26 int gMaxStepsPerformed = kDefaultMaxStepsPerformed;
27 bool gEnableTrace = false;
28 const char *gTraceFile = "ANGLETrace.json";
29 const char *gScreenshotDir = nullptr;
30 const char *gRenderTestOutputDir = nullptr;
31 bool gSaveScreenshots = false;
32 int gScreenshotFrame = kDefaultScreenshotFrame;
33 bool gVerboseLogging = false;
34 int gCalibrationTimeSeconds = 1;
35 int gTrialTimeSeconds = kDefaultTrialTimeSeconds;
36 int gTestTrials = kDefaultTestTrials;
37 bool gNoFinish = false;
38 bool gRetraceMode = false;
39 bool gMinimizeGPUWork = false;
40 bool gTraceTestValidation = false;
41 const char *gPerfCounters = nullptr;
42 const char *gUseANGLE = nullptr;
43 const char *gUseGL = nullptr;
44 bool gOffscreen = false;
45 bool gVsync = false;
46 bool gRunToKeyFrame = false;
47 bool gNoWarmup = false;
48 int gFixedTestTime = 0;
49 int gFixedTestTimeWithWarmup = 0;
50 const char *gTraceInterpreter = nullptr;
51 const char *gPrintExtensionsToFile = nullptr;
52 const char *gRequestedExtensions = nullptr;
53
54 // Default to three warmup trials. There's no science to this. More than two was experimentally
55 // helpful on a Windows NVIDIA setup when testing with Vulkan and native trace tests.
56 constexpr int kDefaultWarmupTrials = 3;
57 constexpr int kDefaultWarmupSteps = 0;
58
59 int gWarmupTrials = kDefaultWarmupTrials;
60 int gWarmupSteps = kDefaultWarmupSteps;
61
62 namespace
63 {
PerfTestArg(int * argc,char ** argv,int argIndex)64 bool PerfTestArg(int *argc, char **argv, int argIndex)
65 {
66 return ParseFlag("--run-to-key-frame", argc, argv, argIndex, &gRunToKeyFrame) ||
67 ParseFlag("--enable-trace", argc, argv, argIndex, &gEnableTrace) ||
68 ParseFlag("--calibration", argc, argv, argIndex, &gCalibration) ||
69 ParseFlag("-v", argc, argv, argIndex, &gVerboseLogging) ||
70 ParseFlag("--verbose", argc, argv, argIndex, &gVerboseLogging) ||
71 ParseFlag("--verbose-logging", argc, argv, argIndex, &gVerboseLogging) ||
72 ParseFlag("--no-warmup", argc, argv, argIndex, &gNoWarmup) ||
73 ParseFlag("--no-finish", argc, argv, argIndex, &gNoFinish) ||
74 ParseCStringArg("--trace-file", argc, argv, argIndex, &gTraceFile) ||
75 ParseCStringArg("--perf-counters", argc, argv, argIndex, &gPerfCounters) ||
76 ParseIntArg("--steps-per-trial", argc, argv, argIndex, &gStepsPerTrial) ||
77 ParseIntArg("--max-steps-performed", argc, argv, argIndex, &gMaxStepsPerformed) ||
78 ParseIntArg("--fixed-test-time", argc, argv, argIndex, &gFixedTestTime) ||
79 ParseIntArg("--fixed-test-time-with-warmup", argc, argv, argIndex,
80 &gFixedTestTimeWithWarmup) ||
81 ParseIntArg("--warmup-trials", argc, argv, argIndex, &gWarmupTrials) ||
82 ParseIntArg("--warmup-steps", argc, argv, argIndex, &gWarmupSteps) ||
83 ParseIntArg("--calibration-time", argc, argv, argIndex, &gCalibrationTimeSeconds) ||
84 ParseIntArg("--trial-time", argc, argv, argIndex, &gTrialTimeSeconds) ||
85 ParseIntArg("--max-trial-time", argc, argv, argIndex, &gTrialTimeSeconds) ||
86 ParseIntArg("--trials", argc, argv, argIndex, &gTestTrials);
87 }
88
TraceTestArg(int * argc,char ** argv,int argIndex)89 bool TraceTestArg(int *argc, char **argv, int argIndex)
90 {
91 return ParseFlag("--retrace-mode", argc, argv, argIndex, &gRetraceMode) ||
92 ParseFlag("--validation", argc, argv, argIndex, &gTraceTestValidation) ||
93 ParseFlag("--save-screenshots", argc, argv, argIndex, &gSaveScreenshots) ||
94 ParseFlag("--offscreen", argc, argv, argIndex, &gOffscreen) ||
95 ParseFlag("--vsync", argc, argv, argIndex, &gVsync) ||
96 ParseFlag("--minimize-gpu-work", argc, argv, argIndex, &gMinimizeGPUWork) ||
97 ParseCStringArg("--trace-interpreter", argc, argv, argIndex, &gTraceInterpreter) ||
98 ParseIntArg("--screenshot-frame", argc, argv, argIndex, &gScreenshotFrame) ||
99 ParseCStringArgWithHandling("--render-test-output-dir", argc, argv, argIndex,
100 &gRenderTestOutputDir, ArgHandling::Preserve) ||
101 ParseCStringArg("--screenshot-dir", argc, argv, argIndex, &gScreenshotDir) ||
102 ParseCStringArg("--use-angle", argc, argv, argIndex, &gUseANGLE) ||
103 ParseCStringArg("--use-gl", argc, argv, argIndex, &gUseGL) ||
104 ParseCStringArg("--print-extensions-to-file", argc, argv, argIndex,
105 &gPrintExtensionsToFile) ||
106 ParseCStringArg("--request-extensions", argc, argv, argIndex, &gRequestedExtensions);
107 }
108 } // namespace
109 } // namespace angle
110
111 using namespace angle;
112
ANGLEProcessPerfTestArgs(int * argc,char ** argv)113 void ANGLEProcessPerfTestArgs(int *argc, char **argv)
114 {
115 for (int argIndex = 1; argIndex < *argc;)
116 {
117 if (!PerfTestArg(argc, argv, argIndex))
118 {
119 argIndex++;
120 }
121 }
122
123 if (gCalibration)
124 {
125 gTestTrials = 0;
126 }
127
128 if (gRunToKeyFrame || gMaxStepsPerformed > 0)
129 {
130 // Ensure defaults were provided for params we're about to set
131 ASSERT(gWarmupTrials == kDefaultWarmupTrials && gTestTrials == kDefaultTestTrials &&
132 gTrialTimeSeconds == kDefaultTrialTimeSeconds);
133
134 gWarmupTrials = 0;
135 gTestTrials = 1;
136 gTrialTimeSeconds = 36000;
137 }
138
139 if (gFixedTestTime != 0)
140 {
141 // Ensure defaults were provided for params we're about to set
142 ASSERT(gTrialTimeSeconds == kDefaultTrialTimeSeconds &&
143 gStepsPerTrial == kDefaultStepsPerTrial && gTestTrials == kDefaultTestTrials &&
144 gWarmupTrials == kDefaultWarmupTrials);
145
146 gTrialTimeSeconds = gFixedTestTime;
147 gStepsPerTrial = std::numeric_limits<int>::max();
148 gTestTrials = 1;
149 gWarmupTrials = 0;
150 }
151
152 if (gFixedTestTimeWithWarmup != 0)
153 {
154 // Ensure defaults were provided for params we're about to set
155 ASSERT(gTrialTimeSeconds == kDefaultTrialTimeSeconds &&
156 gStepsPerTrial == kDefaultStepsPerTrial && gTestTrials == kDefaultTestTrials &&
157 gWarmupTrials == kDefaultWarmupTrials && gWarmupSteps == kDefaultWarmupSteps);
158
159 // This option is primarily useful for trace replays when you want to iterate once through
160 // the trace to warm caches, then run for a fixed amount of time. It is equivalent to:
161 // --trial-time X --steps-per-trial INF --trials 1 --warmup-trials 1 --warmup-steps <frames>
162 gTrialTimeSeconds = gFixedTestTimeWithWarmup;
163 gStepsPerTrial = std::numeric_limits<int>::max();
164 gTestTrials = 1;
165 gWarmupTrials = 1;
166 gWarmupSteps = kAllFrames;
167 }
168
169 if (gNoWarmup)
170 {
171 gWarmupTrials = 0;
172 }
173
174 if (gTrialTimeSeconds == 0)
175 {
176 gTrialTimeSeconds = 10;
177 }
178 else
179 {
180 gCalibrationTimeSeconds = gTrialTimeSeconds;
181 }
182 }
183
ANGLEProcessTraceTestArgs(int * argc,char ** argv)184 void ANGLEProcessTraceTestArgs(int *argc, char **argv)
185 {
186 ANGLEProcessPerfTestArgs(argc, argv);
187
188 for (int argIndex = 1; argIndex < *argc;)
189 {
190 if (!TraceTestArg(argc, argv, argIndex))
191 {
192 argIndex++;
193 }
194 }
195
196 if (gScreenshotDir)
197 {
198 // implicitly set here but not when using kRenderTestOutputDir
199 gSaveScreenshots = true;
200 }
201
202 if (gRenderTestOutputDir)
203 {
204 gScreenshotDir = gRenderTestOutputDir;
205 }
206
207 if (gTraceTestValidation)
208 {
209 gWarmupTrials = 0;
210 gTestTrials = 1;
211 gTrialTimeSeconds = 600;
212 }
213 }
214