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 namespace angle
15 {
16 bool gCalibration = false;
17 int gStepsPerTrial = 0;
18 int gMaxStepsPerformed = 0;
19 bool gEnableTrace = false;
20 const char *gTraceFile = "ANGLETrace.json";
21 const char *gScreenShotDir = nullptr;
22 int gScreenShotFrame = 1;
23 bool gVerboseLogging = false;
24 double gCalibrationTimeSeconds = 1.0;
25 double gMaxTrialTimeSeconds = 10.0;
26 int gTestTrials = 3;
27 bool gNoFinish = false;
28 bool gEnableAllTraceTests = false;
29 bool gRetraceMode = false;
30 bool gMinimizeGPUWork = false;
31 bool gTraceTestValidation = false;
32 const char *gPerfCounters = nullptr;
33
34 // Default to three warmup loops. There's no science to this. More than two loops was experimentally
35 // helpful on a Windows NVIDIA setup when testing with Vulkan and native trace tests.
36 int gWarmupLoops = 3;
37 int gWarmupSteps = std::numeric_limits<int>::max();
38 } // namespace angle
39
40 namespace
41 {
ReadIntArgument(const char * arg)42 int ReadIntArgument(const char *arg)
43 {
44 std::stringstream strstr;
45 strstr << arg;
46
47 int value;
48 strstr >> value;
49 return value;
50 }
51
52 // The same as --screenshot-dir, but used by Chrome tests.
53 constexpr char kRenderTestDirArg[] = "--render-test-output-dir=";
54 } // namespace
55
56 using namespace angle;
57
ANGLEProcessPerfTestArgs(int * argc,char ** argv)58 void ANGLEProcessPerfTestArgs(int *argc, char **argv)
59 {
60 for (int argIndex = 0; argIndex < *argc; argIndex++)
61 {
62 if (strcmp("--one-frame-only", argv[argIndex]) == 0)
63 {
64 gStepsPerTrial = 1;
65 gWarmupLoops = 0;
66 }
67 else if (strcmp("--enable-trace", argv[argIndex]) == 0)
68 {
69 gEnableTrace = true;
70 }
71 else if (strcmp("--trace-file", argv[argIndex]) == 0 && argIndex < *argc - 1)
72 {
73 gTraceFile = argv[argIndex + 1];
74 // Skip an additional argument.
75 argIndex++;
76 }
77 else if (strcmp("--calibration", argv[argIndex]) == 0)
78 {
79 gCalibration = true;
80 gTestTrials = 0;
81 }
82 else if (strcmp("--steps-per-trial", argv[argIndex]) == 0 && argIndex < *argc - 1)
83 {
84 gStepsPerTrial = ReadIntArgument(argv[argIndex + 1]);
85 // Skip an additional argument.
86 argIndex++;
87 }
88 else if (strcmp("--max-steps-performed", argv[argIndex]) == 0 && argIndex < *argc - 1)
89 {
90 gMaxStepsPerformed = ReadIntArgument(argv[argIndex + 1]);
91 gWarmupLoops = 0;
92 gTestTrials = 1;
93 gMaxTrialTimeSeconds = 36000;
94 // Skip an additional argument.
95 argIndex++;
96 }
97 else if (strcmp("--fixed-test-time", argv[argIndex]) == 0 && argIndex < *argc - 1)
98 {
99 gMaxTrialTimeSeconds = ReadIntArgument(argv[argIndex + 1]);
100 gStepsPerTrial = std::numeric_limits<int>::max();
101 gTestTrials = 1;
102 gWarmupLoops = 0;
103 // Skip an additional argument.
104 argIndex++;
105 }
106 else if (strcmp("--screenshot-dir", argv[argIndex]) == 0 && argIndex < *argc - 1)
107 {
108 gScreenShotDir = argv[argIndex + 1];
109 argIndex++;
110 }
111 else if (strcmp("--screenshot-frame", argv[argIndex]) == 0 && argIndex < *argc - 1)
112 {
113 gScreenShotFrame = ReadIntArgument(argv[argIndex + 1]);
114 argIndex++;
115 }
116 else if (strcmp("--verbose-logging", argv[argIndex]) == 0 ||
117 strcmp("--verbose", argv[argIndex]) == 0 || strcmp("-v", argv[argIndex]) == 0)
118 {
119 gVerboseLogging = true;
120 }
121 else if (strcmp("--warmup-loops", argv[argIndex]) == 0)
122 {
123 gWarmupLoops = ReadIntArgument(argv[argIndex + 1]);
124 // Skip an additional argument.
125 argIndex++;
126 }
127 else if (strcmp("--warmup-steps", argv[argIndex]) == 0)
128 {
129 gWarmupSteps = ReadIntArgument(argv[argIndex + 1]);
130 // Skip an additional argument.
131 argIndex++;
132 }
133 else if (strcmp("--no-warmup", argv[argIndex]) == 0)
134 {
135 gWarmupLoops = 0;
136 }
137 else if (strncmp(kRenderTestDirArg, argv[argIndex], strlen(kRenderTestDirArg)) == 0)
138 {
139 gScreenShotDir = argv[argIndex] + strlen(kRenderTestDirArg);
140 }
141 else if (strcmp("--calibration-time", argv[argIndex]) == 0)
142 {
143 gCalibrationTimeSeconds = ReadIntArgument(argv[argIndex + 1]);
144 // Skip an additional argument.
145 argIndex++;
146 }
147 else if (strcmp("--max-trial-time", argv[argIndex]) == 0)
148 {
149 gMaxTrialTimeSeconds = ReadIntArgument(argv[argIndex + 1]);
150 // Skip an additional argument.
151 argIndex++;
152 }
153 else if (strcmp("--trials", argv[argIndex]) == 0)
154 {
155 gTestTrials = ReadIntArgument(argv[argIndex + 1]);
156 // Skip an additional argument.
157 argIndex++;
158 }
159 else if (strcmp("--no-finish", argv[argIndex]) == 0)
160 {
161 gNoFinish = true;
162 }
163 else if (strcmp("--enable-all-trace-tests", argv[argIndex]) == 0)
164 {
165 gEnableAllTraceTests = true;
166 }
167 else if (strcmp("--retrace-mode", argv[argIndex]) == 0)
168 {
169 gRetraceMode = true;
170 }
171 else if (strcmp("--minimize-gpu-work", argv[argIndex]) == 0)
172 {
173 gMinimizeGPUWork = true;
174 }
175 else if (strcmp("--validation", argv[argIndex]) == 0)
176 {
177 gTraceTestValidation = true;
178 gWarmupLoops = 0;
179 gTestTrials = 1;
180 gMaxTrialTimeSeconds = 600.0;
181 }
182 else if (strcmp("--perf-counters", argv[argIndex]) == 0 && argIndex < *argc - 1)
183 {
184 gPerfCounters = argv[argIndex + 1];
185 argIndex++;
186 }
187 }
188 }
189