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 bool gVerboseLogging = false;
23 double gCalibrationTimeSeconds = 1.0;
24 double gTestTimeSeconds = 10.0;
25 int gTestTrials = 3;
26 bool gNoFinish = false;
27 bool gEnableAllTraceTests = false;
28 bool gStartTraceAfterSetup = false;
29
30 // Default to three warmup loops. There's no science to this. More than two loops was experimentally
31 // helpful on a Windows NVIDIA setup when testing with Vulkan and native trace tests.
32 int gWarmupLoops = 3;
33 } // namespace angle
34
35 namespace
36 {
ReadIntArgument(const char * arg)37 int ReadIntArgument(const char *arg)
38 {
39 std::stringstream strstr;
40 strstr << arg;
41
42 int value;
43 strstr >> value;
44 return value;
45 }
46
47 // The same as --screenshot-dir, but used by Chrome tests.
48 constexpr char kRenderTestDirArg[] = "--render-test-output-dir=";
49 } // namespace
50
51 using namespace angle;
52
ANGLEProcessPerfTestArgs(int * argc,char ** argv)53 void ANGLEProcessPerfTestArgs(int *argc, char **argv)
54 {
55 int argcOutCount = 0;
56
57 for (int argIndex = 0; argIndex < *argc; argIndex++)
58 {
59 if (strcmp("--one-frame-only", argv[argIndex]) == 0)
60 {
61 gStepsPerTrial = 1;
62 gWarmupLoops = 0;
63 }
64 else if (strcmp("--enable-trace", argv[argIndex]) == 0)
65 {
66 gEnableTrace = true;
67 }
68 else if (strcmp("--trace-file", argv[argIndex]) == 0 && argIndex < *argc - 1)
69 {
70 gTraceFile = argv[argIndex + 1];
71 // Skip an additional argument.
72 argIndex++;
73 }
74 else if (strcmp("--calibration", argv[argIndex]) == 0)
75 {
76 gCalibration = true;
77 }
78 else if (strcmp("--steps-per-trial", argv[argIndex]) == 0 && argIndex < *argc - 1)
79 {
80 gStepsPerTrial = ReadIntArgument(argv[argIndex + 1]);
81 // Skip an additional argument.
82 argIndex++;
83 }
84 else if (strcmp("--max-steps-performed", argv[argIndex]) == 0 && argIndex < *argc - 1)
85 {
86 gMaxStepsPerformed = ReadIntArgument(argv[argIndex + 1]);
87 gWarmupLoops = 0;
88 gTestTrials = 1;
89 gTestTimeSeconds = 36000;
90 // Skip an additional argument.
91 argIndex++;
92 }
93 else if (strcmp("--screenshot-dir", argv[argIndex]) == 0 && argIndex < *argc - 1)
94 {
95 gScreenShotDir = argv[argIndex + 1];
96 argIndex++;
97 }
98 else if (strcmp("--verbose-logging", argv[argIndex]) == 0 ||
99 strcmp("--verbose", argv[argIndex]) == 0 || strcmp("-v", argv[argIndex]) == 0)
100 {
101 gVerboseLogging = true;
102 }
103 else if (strcmp("--warmup-loops", argv[argIndex]) == 0)
104 {
105 gWarmupLoops = ReadIntArgument(argv[argIndex + 1]);
106 // Skip an additional argument.
107 argIndex++;
108 }
109 else if (strcmp("--no-warmup", argv[argIndex]) == 0)
110 {
111 gWarmupLoops = 0;
112 }
113 else if (strncmp(kRenderTestDirArg, argv[argIndex], strlen(kRenderTestDirArg)) == 0)
114 {
115 gScreenShotDir = argv[argIndex] + strlen(kRenderTestDirArg);
116 }
117 else if (strcmp("--calibration-time", argv[argIndex]) == 0)
118 {
119 gCalibrationTimeSeconds = ReadIntArgument(argv[argIndex + 1]);
120 // Skip an additional argument.
121 argIndex++;
122 }
123 else if (strcmp("--test-time", argv[argIndex]) == 0)
124 {
125 gTestTimeSeconds = ReadIntArgument(argv[argIndex + 1]);
126 // Skip an additional argument.
127 argIndex++;
128 }
129 else if (strcmp("--trials", argv[argIndex]) == 0)
130 {
131 gTestTrials = ReadIntArgument(argv[argIndex + 1]);
132 // Skip an additional argument.
133 argIndex++;
134 }
135 else if (strcmp("--no-finish", argv[argIndex]) == 0)
136 {
137 gNoFinish = true;
138 }
139 else if (strcmp("--enable-all-trace-tests", argv[argIndex]) == 0)
140 {
141 gEnableAllTraceTests = true;
142 }
143 else if (strcmp("--start-trace-after-setup", argv[argIndex]) == 0)
144 {
145 gStartTraceAfterSetup = true;
146 }
147 else
148 {
149 argv[argcOutCount++] = argv[argIndex];
150 }
151 }
152
153 *argc = argcOutCount;
154 }
155