1 // Stress.cpp : Defines the entry point for the console application.
13 int getopt(int, char**, char*);
16 int main(int argc, char* argv[])
28 char TopDirectory[512];
29 char CurrentDirectory[256];
30 PROCESS_INFORMATION ProcInfo;
31 STARTUPINFO StartupInfo;
33 WIN32_FIND_DATA FindFileData;
41 for (i = 0; i < 500; i++)
49 memset(command, '\0', sizeof(command));
50 memset(TopDirectory, '\0', sizeof(TopDirectory));
52 while ((opt = getopt(argc, argv, "A:a:BbC:c:D:d:EeF:f:I:i:L:l:M:m:N:n:P:p:SsTtU:u:Vv")) != EOF)
60 strcpy(TopDirectory, optarg);
64 SecondsDelay = atoi(optarg);
68 ProcessCount = atoi(optarg);
101 for (LogID = 0; LogID < 100; LogID++)
103 sprintf(CurrentDirectory, ".\\Log%05d", LogID);
104 fHandle = FindFirstFile(CurrentDirectory, &FindFileData);
105 if (fHandle == INVALID_HANDLE_VALUE)
111 printf("\nUnable to get a LogID.\n");
117 printf("\nYou must use the -f switch\n\n");
123 printf("\nYou must use the -d switch\n\n");
127 if (ProcessCount > 500)
129 printf("\nA max of 500 processes allowed\n\n");
134 GetStartupInfo(&StartupInfo);
135 memset(&StartupInfo, '\0', sizeof(StartupInfo));
136 for (i = 0; i < ProcessCount; i++)
138 memset(command, '\0', sizeof(command));
139 for (k = 0; k < argc; k++)
141 strcat(command, argv[k]);
142 strcat(command, " ");
143 if (!stricmp(argv[k], "-f"))
146 memset(temp, '\0', sizeof(temp));
147 sprintf(temp, "%s%05d", argv[k], DirCount);
148 strcat(command, temp);
149 strcat(command, " ");
153 sprintf(temp, " -g %d", LogID);
154 strcat(command, temp);
155 StartupInfo.dwFlags = STARTF_USESHOWWINDOW;
156 StartupInfo.wShowWindow = SW_SHOWMINIMIZED;
157 if (CreateProcess(".\\wintorture.exe", command, NULL, NULL, FALSE, CREATE_NEW_CONSOLE, NULL, NULL, &StartupInfo, &ProcInfo))
158 hArray[i] = ProcInfo.hProcess;
159 Sleep(SecondsDelay * 1000);
169 printf("usage: stress [options]\n");
170 printf("where options can be:\n");
171 printf("\t-a <sec> Seconds delay between starting detached processes\n");
172 printf("\t-b Create a chronological log\n");
173 printf("\t-c <txt> Specifies the script txt file to use\n");
174 printf("\t-d <num> Number of detached processes to run\n");
175 printf("\t-e End thread processing on an error.\n");
176 printf("\t-f <name> Target directory name\n");
178 printf("\t-l <path> Interpert as an AFS locker or AFS submount\n");
179 #endif /* HAVE_HESOID */
180 printf("\t-i <num> Number of iterations of the stress test to run.\n");
181 printf("\t This option will override the -m option.\n");
182 printf("\t-m <num> The number of minutes to run\n");
183 printf("\t-n <num> The number of threads to run\n");
184 printf("\t-p <path> UNC path to second directory\n");
185 printf("\t-s Output stats\n");
186 printf("\t-t Do AFS trace logging\n");
187 printf("\t-u <UNC> UNC path to target directory\n");
188 printf("\t-v Turn on verbose mode\n");
189 printf("\nNOTE: The switches are not case sensitive. You\n");
190 printf("\n may use either upper or lower case letters.\n\n");
193 char *_progname(char *nargv0)
197 tmp = strrchr(nargv0, '/');
205 #define BADCH (int)'?'
206 #define BADARG (int)':'
209 int getopt(int nargc, char *nargv[], char *ostr)
211 static char *__progname = 0;
212 static char *place = EMSG; /* option letter processing */
213 char *oli; /* option letter list index */
215 __progname = __progname?__progname:_progname(*nargv);
217 if (optreset || !*place)
220 if (optind >= nargc || *(place = nargv[optind]) != '-')
225 if (place[1] && *++place == '-' && place[1] == '\0')
232 if ((optopt = (int)*place++) == (int)':' || !(oli = strchr(ostr, optopt)))
234 if (optopt == (int)'-')
238 if (opterr && *ostr != ':')
239 (void)fprintf(stderr, "%s: illegal option -- %c\n", __progname, optopt);
252 else if (nargc <= ++optind)
258 (void)fprintf(stderr, "%s: option requires an argument -- %c\n", __progname, optopt);
262 optarg = nargv[optind];