1 // Stress.cpp : Defines the entry point for the console application.
11 int GetConsoleInput(HANDLE hStdin);
13 int main(int argc, char* argv[])
19 int NewSessionDeadlock;
20 int NewSessionDeadlockCount;
27 char WorkingDirectory[512];
28 char LoggingDrive[512];
29 char EnvVariable[512];
40 NewSessionDeadlock = 0;
41 SecondsToRun = 30 * 60;
42 memset(HostName, '\0', sizeof(HostName));
43 memset(command, '\0', sizeof(command));
44 strcpy(LoggingDrive, "C");
47 for (i = 0; i < argc; i++)
49 if (!stricmp(argv[i], "-e"))
53 if (!stricmp(argv[i], "-s"))
55 SecondsDelay = atoi(argv[i+1]);
57 if (!stricmp(argv[i], "-h"))
59 strcpy(HostName, argv[i+1]);
61 if (!stricmp(argv[i], "-d"))
63 strcpy(LoggingDrive, argv[i+1]);
64 if (strlen(LoggingDrive) == 1)
65 strcat(LoggingDrive,":");
67 if (!stricmp(argv[i], "-m"))
69 SecondsToRun = atoi(argv[i+1]) * 60;
71 if (!stricmp(argv[i], "-n"))
73 NewSessionDeadlock = 1;
74 NewSessionDeadlockCount = atoi(argv[i+1]);
75 if (NewSessionDeadlockCount == 0)
76 NewSessionDeadlockCount = 20;
78 if (!stricmp(argv[i], "-?") || !stricmp(argv[i], "/?") ||
79 !stricmp(argv[i], "?") || !stricmp(argv[i], "help"))
86 hStdin = GetStdHandle(STD_INPUT_HANDLE);
88 sprintf(command, "fs trace -on");
90 sprintf(command, "fs trace -reset");
93 GetCurrentDirectory(sizeof(WorkingDirectory), WorkingDirectory);
94 if (WorkingDirectory[0] != LoggingDrive[0])
95 WorkingDirectory[0] = LoggingDrive[0];
96 sprintf(command, "rmdir /Q /S %s\\DumpAfsLogDir", WorkingDirectory);
98 sprintf(LogName, "%s\\DumpAfsLogDir", WorkingDirectory);
99 sprintf(command, "mkdir %s\\DumpAfsLogDir", WorkingDirectory);
100 rc = system(command);
103 SecondsToRun += StartTime;
109 sprintf(command, "fs minidump");
110 rc = system(command);
111 ExpandEnvironmentStrings("%windir%", EnvVariable, sizeof(EnvVariable));
112 strcat(EnvVariable, "\\TEMP\\afsd.dmp");
113 sprintf(command, "copy /Y %s %s\\DumpAfsLogDir", EnvVariable, WorkingDirectory);
114 printf("%s\n", command);
115 rc = system(command);
116 sprintf(command, "rename %s\\DumpAfsLogDir\\afsd.dmp afsd_%05d.dmp", WorkingDirectory, Count);
117 printf("%s\n", command);
118 rc = system(command);
122 sprintf(command, "fs trace -dump");
123 rc = system(command);
124 ExpandEnvironmentStrings("%windir%", EnvVariable, sizeof(EnvVariable));
125 strcat(EnvVariable, "\\TEMP\\afsd.log");
126 sprintf(command, "copy /Y %s %s\\DumpAfsLogDir", EnvVariable, WorkingDirectory);
127 printf("%s\n", command);
128 rc = system(command);
129 // sprintf(command, "crlf.pl -d %s\\DumpAfsLogDir\\afsd.log", WorkingDirectory);
130 // printf("%s\n", command);
131 // rc = system(command);
132 sprintf(command, "rename %s\\DumpAfsLogDir\\afsd.log afsd_%05d.log", WorkingDirectory, Count);
133 printf("%s\n\n", command);
134 rc = system(command);
136 if (strlen(HostName) != 0)
138 sprintf(command, "cmdebug %s -long | grep refcnt > %s\\DumpAfsLogDir\\refcnt_%05d.log",
139 HostName, WorkingDirectory, Count);
140 printf("%s\n", command);
141 rc = system(command);
143 sprintf(FileName, "%s\\DumpAfsLogDir\\afsd_%05d.log", WorkingDirectory, Count);
145 if (NewSessionDeadlock)
147 fp = fopen(FileName, "r");
150 while (fgets(Buffer, 512, fp))
152 // if (pPtr = strstr(Buffer, "RecordRacingRevoke"))
154 // if (pPtr = strstr(Buffer, "activeCalls "))
156 // pPtr += strlen("activeCalls ");
157 // if (atoi(pPtr) > 0)
159 // SetEvent(ShutDownEventHandle);
164 if (pPtr = strstr(Buffer, "New Session lsn "))
166 printf("%s", Buffer);
167 pPtr += strlen("New Session lsn " );
168 if (atoi(pPtr) > NewSessionDeadlockCount)
173 // if (pPtr = strstr(Buffer, "Racing revoke scp"))
175 // SetEvent(ShutDownEventHandle);
186 if (StartTime > (time_t)SecondsToRun)
188 printf("Type Q to stop DumpAfsLog\n");
189 SecondsToDelay = StartTime + SecondsDelay;
193 if (StartTime > (time_t)SecondsToDelay)
195 rc = GetConsoleInput(hStdin);
198 rc = GetConsoleInput(hStdin);
201 sprintf(command, "fs trace -off");
202 rc = system(command);
210 printf("usage: wintorture [options]\n");
211 printf("where options can be:\n");
212 printf("\t-d <drive> Local drive letter where to place log files\n");
213 printf("\t-e Enable fs minidump\n");
214 printf("\t-h <host> Local host name. Used to run cmdebug\n");
215 printf("\t-m <min> Number of minutes to run this program\n");
216 // printf("\t-n <num> Stop processing on \"New Session lsn XX\" deadlock\n");
217 printf("\t-s <sec> Seconds delay between dumping AFS logs\n");
218 printf("\t 15 seconds delay is the default\n");
221 int GetConsoleInput(HANDLE hStdin)
223 INPUT_RECORD InputRecord[128];
224 DWORD InputRecordCount;
230 InputRecordCount = 0;
232 if (!(rc = PeekConsoleInput(hStdin, InputRecord, 128, &InputRecordCount)))
234 if (InputRecordCount == 0)
236 rc = ReadConsoleInput(hStdin, InputRecord, 128, &InputRecordCount);
237 for (i = 0; i < (int)InputRecordCount; i++)
239 switch(InputRecord[i].EventType)
242 if (InputRecord[i].Event.KeyEvent.bKeyDown)
244 ReadChar = InputRecord[i].Event.KeyEvent.uChar.AsciiChar;
245 if ((ReadChar == 'q') || (ReadChar == 'Q'))
247 printf("Stop request received\n");