6 extern int CurrentLoop;
7 extern HANDLE ChronMutexHandle;
8 extern HANDLE MutexHandle;
9 extern HANDLE FileMutexHandle;
11 void LogStats(char *FileName, int ToLog, int Iteration, int NumberOfProcesses, int NumberOfThreads,
12 char *HostName, int ProcessNumber, struct cmd_struct CommandInfo[],
13 char *CommandLine, char *TargetDirectory)
15 struct cmd_struct TotalCommandInfo[CMD_MAX_CMD + 1];
19 unsigned grand_total = 0;
27 newtime = localtime(&aclock);
28 strcpy(AsciiTime, asctime(newtime));
29 AsciiTime[strlen(AsciiTime) - 1] = '\0';
33 fp = fopen(FileName, "a+");
35 for (j = 0; j <= CMD_MAX_CMD; j++)
37 TotalCommandInfo[j].count = 0;
38 TotalCommandInfo[j].min_sec = 0;
39 TotalCommandInfo[j].ErrorTime = 0;
40 TotalCommandInfo[j].max_sec = 0;
41 TotalCommandInfo[j].MilliSeconds = 0;
42 TotalCommandInfo[j].total_sec = 0;
43 TotalCommandInfo[j].total_sum_of_squares = 0;
44 TotalCommandInfo[j].ErrorCount = 0;
45 TotalCommandInfo[j].ErrorTime = 0;
48 for (i = 0; i <= CMD_MAX_CMD; i++)
50 TotalCommandInfo[i].count += CommandInfo[i].count;
51 TotalCommandInfo[i].total_sec += CommandInfo[i].total_sec;
52 TotalCommandInfo[i].ErrorCount += CommandInfo[i].ErrorCount;
53 TotalCommandInfo[i].ErrorTime += CommandInfo[i].ErrorTime;
54 grand_total += CommandInfo[i].total_sec;
55 if (!TotalCommandInfo[i].min_sec || (TotalCommandInfo[i].min_sec > CommandInfo[i].min_sec))
56 TotalCommandInfo[i].min_sec = CommandInfo[i].min_sec;
57 if (TotalCommandInfo[i].min_sec == 1000)
58 TotalCommandInfo[i].min_sec = 0;
59 if (TotalCommandInfo[i].max_sec < CommandInfo[i].max_sec)
60 TotalCommandInfo[i].max_sec = CommandInfo[i].max_sec;
62 if (ProcessNumber > -1)
64 fprintf(fp, "Iteration %d Statistics\n", Iteration);
67 else if (ProcessNumber == -1)
69 fprintf(fp, "Process Statistics for Iteration %d\n", Iteration);
72 else if (ProcessNumber == -2)
74 fprintf(fp, "Test Statistics for all processes - %d Iterations \n", Iteration);
77 fprintf(fp, "Date: %s\n", AsciiTime);
79 fprintf(fp, "Total Time: %d seconds (%4.1f minutes)\n", grand_total, grand_total/60.0);
81 if ((ProcessNumber == -2) || (ProcessNumber == -1))
83 fprintf(fp, "Number of Processes: %d\n", NumberOfProcesses);
84 fprintf(fp, "Number of Threads/Process: %d\n", NumberOfThreads);
89 if (strlen(TargetDirectory) != 0)
91 fprintf(fp, "Target directory: %s\n", TargetDirectory);
94 if (strlen(CommandLine) != 0)
96 fprintf(fp, "Command Line: %s\n", CommandLine);
99 fprintf(fp, "\n Command: Count Min Latency Max Latency Ave Latency Cost Seconds Error Error \n");
100 fprintf(fp, " (seconds) (seconds) (seconds) Count seconds\n");
104 for (i = LineCount; i < 12; i++)
107 for (i = 0; i <= CMD_MAX_CMD; i++)
109 fprintf(fp, "%-30s %8d %8d %10d %10.2f %5.1f%% %10d %8d %8d %s\n",
111 TotalCommandInfo[i].count,
112 TotalCommandInfo[i].min_sec,
113 TotalCommandInfo[i].max_sec,
114 (TotalCommandInfo[i].count ? (float)TotalCommandInfo[i].total_sec/(float)TotalCommandInfo[i].count : 0),
115 (grand_total ? 100.0*TotalCommandInfo[i].total_sec/grand_total : 0),
116 TotalCommandInfo[i].total_sec,
117 TotalCommandInfo[i].ErrorCount,
118 TotalCommandInfo[i].ErrorTime,
119 cmd_names[i].ms_api);
126 void LogMessage(int ProcessNumber, char *HostName, char *FileName, char *message, int LogID)
128 char NewMessage[1024];
130 char NewFileName[256];
131 char WorkingDirectory[512];
141 rc = WaitForSingleObject(ChronMutexHandle, 4 * 1000);
142 if ((rc == WAIT_OBJECT_0) || (rc == WAIT_TIMEOUT))
147 newtime = localtime(&aclock);
148 strcpy(AsciiTime, asctime(newtime));
149 AsciiTime[strlen(AsciiTime) - 1] = '\0';
150 GetCurrentDirectory(sizeof(WorkingDirectory), WorkingDirectory);
151 sprintf(NewMessage, "%s - %s", AsciiTime, message);
152 sprintf(NewFileName, "%s\\log%05d\\%s\\%s", WorkingDirectory, LogID, HostName, FileName);
153 fp = fopen(NewFileName, "a+");
156 fprintf(fp, "%s", NewMessage);
161 sprintf(NewMessage, "%s %s:%d- %s", AsciiTime, HostName, ProcessNumber, message);
162 sprintf(NewFileName, "%s\\log%05d\\Chron.log", WorkingDirectory, LogID);
163 fp = fopen(NewFileName, "a+");
164 fprintf(fp, "%s", NewMessage);
166 ReleaseMutex(ChronMutexHandle);
170 void DumpAFSLog(char *HostName, int LogID)
172 char EnvVariable[512];
173 char WorkingDirectory[512];
177 WaitForSingleObject(FileMutexHandle, 4 * 1000);
178 memset(WorkingDirectory, '\0', sizeof(WorkingDirectory));
179 GetCurrentDirectory(sizeof(WorkingDirectory), WorkingDirectory);
180 sprintf(command, "fs trace -dump > .\\test\\%s", HostName);
181 rc = system(command);
182 rc = GetWindowsDirectory(EnvVariable, sizeof(EnvVariable));
183 strcat(EnvVariable, "\\TEMP\\afsd.log");
184 sprintf(command, "move %s %s\\log%05d\\%s > .\\test\\%s", EnvVariable, WorkingDirectory, LogID, HostName, HostName);
185 rc = system(command);
186 sprintf(command, "rename %s\\log%05d\\%s\\afsd.log afsd_%s_iteration%d.log",
187 WorkingDirectory, LogID, HostName, HostName, CurrentLoop);
188 rc = system(command);
189 ReleaseMutex(FileMutexHandle);
192 int UpdateMasterLog(char *FileName, struct cmd_struct CommandInfo[])
197 struct cmd_struct TotalCommandInfo[CMD_MAX_CMD + 1];
199 WaitForSingleObject(FileMutexHandle, 4 * 1000);
201 for (i = 0; i <= CMD_MAX_CMD; i++)
203 TotalCommandInfo[i].count = 0;
204 TotalCommandInfo[i].min_sec = 0;
205 TotalCommandInfo[i].max_sec = 0;
206 TotalCommandInfo[i].MilliSeconds = 0;
207 TotalCommandInfo[i].total_sec = 0;
208 TotalCommandInfo[i].ErrorCount = 0;
209 TotalCommandInfo[i].ErrorTime = 0;
210 TotalCommandInfo[i].total_sum_of_squares = 0;
213 fp = fopen(FileName, "r");
216 for (i = 0; i <= CMD_MAX_CMD; i++)
218 fgets(Buffer, 16, fp);
219 TotalCommandInfo[i].count = atoi(Buffer);
220 fgets(Buffer, 16, fp);
221 TotalCommandInfo[i].min_sec = atoi(Buffer);
222 fgets(Buffer, 16, fp);
223 TotalCommandInfo[i].max_sec = atoi(Buffer);
224 fgets(Buffer, 16, fp);
225 TotalCommandInfo[i].total_sec = atoi(Buffer);
226 fgets(Buffer, 16, fp);
227 TotalCommandInfo[i].total_sum_of_squares = atoi(Buffer);
228 fgets(Buffer, 16, fp);
229 TotalCommandInfo[i].ErrorCount = atoi(Buffer);
230 fgets(Buffer, 16, fp);
231 TotalCommandInfo[i].ErrorTime = atoi(Buffer);
236 for (i = 0; i <= CMD_MAX_CMD; i++)
238 TotalCommandInfo[i].count += CommandInfo[i].count;
239 if (!TotalCommandInfo[i].min_sec || (TotalCommandInfo[i].min_sec > CommandInfo[i].min_sec))
240 TotalCommandInfo[i].min_sec = CommandInfo[i].min_sec;
241 if (TotalCommandInfo[i].max_sec < CommandInfo[i].max_sec)
242 TotalCommandInfo[i].max_sec = CommandInfo[i].max_sec;
243 TotalCommandInfo[i].total_sec += CommandInfo[i].total_sec;
244 TotalCommandInfo[i].total_sum_of_squares += CommandInfo[i].total_sum_of_squares;
245 TotalCommandInfo[i].ErrorCount += CommandInfo[i].ErrorCount;
246 TotalCommandInfo[i].ErrorTime += CommandInfo[i].ErrorTime;
250 fp = fopen(FileName, "w");
251 for (i = 0; i <= CMD_MAX_CMD; i++)
253 fprintf(fp, "%ld\n", TotalCommandInfo[i].count);
254 fprintf(fp, "%ld\n", TotalCommandInfo[i].min_sec);
255 fprintf(fp, "%ld\n", TotalCommandInfo[i].max_sec);
256 fprintf(fp, "%ld\n", TotalCommandInfo[i].total_sec);
257 fprintf(fp, "%ld\n", TotalCommandInfo[i].total_sum_of_squares);
258 fprintf(fp, "%ld\n", TotalCommandInfo[i].ErrorCount);
259 fprintf(fp, "%ld\n", TotalCommandInfo[i].ErrorTime);
262 ReleaseMutex(FileMutexHandle);
266 int BuildMasterStatLog(char *FileName, char*MoveFileName, int NumberOfProcesses,
267 int NumberOfThreads, char *CommandLine, int Iterations,
268 char *TargetDirectory, int ProcessNumber)
273 struct cmd_struct TotalCommandInfo[CMD_MAX_CMD + 1];
275 for (i = 0; i <= CMD_MAX_CMD; i++)
277 TotalCommandInfo[i].count = 0;
278 TotalCommandInfo[i].min_sec = 0;
279 TotalCommandInfo[i].MilliSeconds = 0;
280 TotalCommandInfo[i].max_sec = 0;
281 TotalCommandInfo[i].total_sec = 0;
282 TotalCommandInfo[i].total_sum_of_squares = 0;
283 TotalCommandInfo[i].ErrorCount = 0;
284 TotalCommandInfo[i].ErrorTime = 0;
287 fp = fopen(FileName, "r");
290 for (i = 0; i <= CMD_MAX_CMD; i++)
292 if (fgets(Buffer, 16, fp) != NULL)
293 TotalCommandInfo[i].count = atoi(Buffer);
294 if (fgets(Buffer, 16, fp) != NULL)
295 TotalCommandInfo[i].min_sec = atoi(Buffer);
296 if (fgets(Buffer, 16, fp) != NULL)
297 TotalCommandInfo[i].max_sec = atoi(Buffer);
298 if (fgets(Buffer, 16, fp) != NULL)
299 TotalCommandInfo[i].total_sec = atoi(Buffer);
300 if (fgets(Buffer, 16, fp) != NULL)
301 TotalCommandInfo[i].total_sum_of_squares = atoi(Buffer);
302 if (fgets(Buffer, 16, fp) != NULL)
303 TotalCommandInfo[i].ErrorCount = atoi(Buffer);
304 if (fgets(Buffer, 16, fp) != NULL)
305 TotalCommandInfo[i].ErrorTime = atoi(Buffer);
308 MoveFile(FileName, MoveFileName);
311 fp = fopen(FileName, "w");
313 LogStats(FileName, 1, Iterations, NumberOfProcesses, NumberOfThreads, "", ProcessNumber, TotalCommandInfo,
314 CommandLine, TargetDirectory);