5ab39e4e09dc259de2fe3d1c22b46a256f49dcb9
[openafs.git] / src / afsmonitor / afsmon-output.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 /*
11  * Module:      afsmon-output.c
12  *              Outputs the xstat probe results to a file
13  *              Most of this code is taken from xstat_fs_test.c and
14  *              xstat_cm_test.c
15  *
16  *-------------------------------------------------------------------------*/
17
18 #include <stdio.h>
19 #include <time.h>
20 #include <afsconfig.h>
21 #include <afs/param.h>
22
23 #ifdef HAVE_STRING_H
24 #include <string.h>
25 #else
26 #ifdef HAVE_STRINGS_H
27 #include <strings.h>
28 #endif
29 #endif
30
31 RCSID
32     ("$Header$");
33
34 #include <afs/xstat_fs.h>
35 #include <afs/xstat_cm.h>
36
37
38
39 /* Extern Variables */
40 extern int afsmon_debug;        /* debugging on ? */
41 extern FILE *debugFD;           /* debug file FD */
42 extern char errMsg[256];        /* error message buffer */
43
44 extern int afsmon_Exit();       /* exit routine */
45
46 static FILE *fs_outFD;          /* fs output file descriptor */
47 static FILE *cm_outFD;          /* cm output file descriptor */
48
49 /* structures used by FS & CM stats print routines */
50
51 static char *fsOpNames[] = {
52     "FetchData",
53     "FetchACL",
54     "FetchStatus",
55     "StoreData",
56     "StoreACL",
57     "StoreStatus",
58     "RemoveFile",
59     "CreateFile",
60     "Rename",
61     "Symlink",
62     "Link",
63     "MakeDir",
64     "RemoveDir",
65     "SetLock",
66     "ExtendLock",
67     "ReleaseLock",
68     "GetStatistics",
69     "GiveUpCallbacks",
70     "GetVolumeInfo",
71     "GetVolumeStatus",
72     "SetVolumeStatus",
73     "GetRootVolume",
74     "CheckToken",
75     "GetTime",
76     "NGetVolumeInfo",
77     "BulkStatus",
78     "XStatsVersion",
79     "GetXStats"
80 };
81
82 static char *cmOpNames[] = {
83     "CallBack",
84     "InitCallBackState",
85     "Probe",
86     "GetLock",
87     "GetCE",
88     "XStatsVersion",
89     "GetXStats"
90 };
91
92 static char *xferOpNames[] = {
93     "FetchData",
94     "StoreData"
95 };
96
97 /*________________________________________________________________________
98                                 FS STATS ROUTINES 
99  *_______________________________________________________________________*/
100
101 /*------------------------------------------------------------------------
102  * Print_fs_OverallPerfInfo
103  *
104  * Description:
105  *      Print out overall performance numbers.
106  *
107  * Arguments:
108  *      a_ovP : Ptr to the overall performance numbers.
109  *
110  * Returns:
111  *      Nothing.
112  *
113  * Environment:
114  *      Nothing interesting.
115  *
116  * Side Effects:
117  *      As advertised.
118  *------------------------------------------------------------------------*/
119
120 void
121 Print_fs_OverallPerfInfo(a_ovP)
122      struct afs_PerfStats *a_ovP;
123
124 {                               /*Print_fs_OverallPerfInfo */
125
126     fprintf(fs_outFD, "\t%10d numPerfCalls\n\n", a_ovP->numPerfCalls);
127
128
129     /*
130      * Vnode cache section.
131      */
132     fprintf(fs_outFD, "\t%10d vcache_L_Entries\n", a_ovP->vcache_L_Entries);
133     fprintf(fs_outFD, "\t%10d vcache_L_Allocs\n", a_ovP->vcache_L_Allocs);
134     fprintf(fs_outFD, "\t%10d vcache_L_Gets\n", a_ovP->vcache_L_Gets);
135     fprintf(fs_outFD, "\t%10d vcache_L_Reads\n", a_ovP->vcache_L_Reads);
136     fprintf(fs_outFD, "\t%10d vcache_L_Writes\n\n", a_ovP->vcache_L_Writes);
137
138     fprintf(fs_outFD, "\t%10d vcache_S_Entries\n", a_ovP->vcache_S_Entries);
139     fprintf(fs_outFD, "\t%10d vcache_S_Allocs\n", a_ovP->vcache_S_Allocs);
140     fprintf(fs_outFD, "\t%10d vcache_S_Gets\n", a_ovP->vcache_S_Gets);
141     fprintf(fs_outFD, "\t%10d vcache_S_Reads\n", a_ovP->vcache_S_Reads);
142     fprintf(fs_outFD, "\t%10d vcache_S_Writes\n\n", a_ovP->vcache_S_Writes);
143
144     fprintf(fs_outFD, "\t%10d vcache_H_Entries\n", a_ovP->vcache_H_Entries);
145     fprintf(fs_outFD, "\t%10d vcache_H_Gets\n", a_ovP->vcache_H_Gets);
146     fprintf(fs_outFD, "\t%10d vcache_H_Replacements\n\n",
147             a_ovP->vcache_H_Replacements);
148
149     /*
150      * Directory package section.
151      */
152     fprintf(fs_outFD, "\t%10d dir_Buffers\n", a_ovP->dir_Buffers);
153     fprintf(fs_outFD, "\t%10d dir_Calls\n", a_ovP->dir_Calls);
154     fprintf(fs_outFD, "\t%10d dir_IOs\n\n", a_ovP->dir_IOs);
155
156     /*
157      * Rx section.
158      */
159     fprintf(fs_outFD, "\t%10d rx_packetRequests\n", a_ovP->rx_packetRequests);
160     fprintf(fs_outFD, "\t%10d rx_noPackets_RcvClass\n",
161             a_ovP->rx_noPackets_RcvClass);
162     fprintf(fs_outFD, "\t%10d rx_noPackets_SendClass\n",
163             a_ovP->rx_noPackets_SendClass);
164     fprintf(fs_outFD, "\t%10d rx_noPackets_SpecialClass\n",
165             a_ovP->rx_noPackets_SpecialClass);
166     fprintf(fs_outFD, "\t%10d rx_socketGreedy\n", a_ovP->rx_socketGreedy);
167     fprintf(fs_outFD, "\t%10d rx_bogusPacketOnRead\n",
168             a_ovP->rx_bogusPacketOnRead);
169     fprintf(fs_outFD, "\t%10d rx_bogusHost\n", a_ovP->rx_bogusHost);
170     fprintf(fs_outFD, "\t%10d rx_noPacketOnRead\n", a_ovP->rx_noPacketOnRead);
171     fprintf(fs_outFD, "\t%10d rx_noPacketBuffersOnRead\n",
172             a_ovP->rx_noPacketBuffersOnRead);
173     fprintf(fs_outFD, "\t%10d rx_selects\n", a_ovP->rx_selects);
174     fprintf(fs_outFD, "\t%10d rx_sendSelects\n", a_ovP->rx_sendSelects);
175     fprintf(fs_outFD, "\t%10d rx_packetsRead_RcvClass\n",
176             a_ovP->rx_packetsRead_RcvClass);
177     fprintf(fs_outFD, "\t%10d rx_packetsRead_SendClass\n",
178             a_ovP->rx_packetsRead_SendClass);
179     fprintf(fs_outFD, "\t%10d rx_packetsRead_SpecialClass\n",
180             a_ovP->rx_packetsRead_SpecialClass);
181     fprintf(fs_outFD, "\t%10d rx_dataPacketsRead\n",
182             a_ovP->rx_dataPacketsRead);
183     fprintf(fs_outFD, "\t%10d rx_ackPacketsRead\n", a_ovP->rx_ackPacketsRead);
184     fprintf(fs_outFD, "\t%10d rx_dupPacketsRead\n", a_ovP->rx_dupPacketsRead);
185     fprintf(fs_outFD, "\t%10d rx_spuriousPacketsRead\n",
186             a_ovP->rx_spuriousPacketsRead);
187     fprintf(fs_outFD, "\t%10d rx_packetsSent_RcvClass\n",
188             a_ovP->rx_packetsSent_RcvClass);
189     fprintf(fs_outFD, "\t%10d rx_packetsSent_SendClass\n",
190             a_ovP->rx_packetsSent_SendClass);
191     fprintf(fs_outFD, "\t%10d rx_packetsSent_SpecialClass\n",
192             a_ovP->rx_packetsSent_SpecialClass);
193     fprintf(fs_outFD, "\t%10d rx_ackPacketsSent\n", a_ovP->rx_ackPacketsSent);
194     fprintf(fs_outFD, "\t%10d rx_pingPacketsSent\n",
195             a_ovP->rx_pingPacketsSent);
196     fprintf(fs_outFD, "\t%10d rx_abortPacketsSent\n",
197             a_ovP->rx_abortPacketsSent);
198     fprintf(fs_outFD, "\t%10d rx_busyPacketsSent\n",
199             a_ovP->rx_busyPacketsSent);
200     fprintf(fs_outFD, "\t%10d rx_dataPacketsSent\n",
201             a_ovP->rx_dataPacketsSent);
202     fprintf(fs_outFD, "\t%10d rx_dataPacketsReSent\n",
203             a_ovP->rx_dataPacketsReSent);
204     fprintf(fs_outFD, "\t%10d rx_dataPacketsPushed\n",
205             a_ovP->rx_dataPacketsPushed);
206     fprintf(fs_outFD, "\t%10d rx_ignoreAckedPacket\n",
207             a_ovP->rx_ignoreAckedPacket);
208     fprintf(fs_outFD, "\t%10d rx_totalRtt_Sec\n", a_ovP->rx_totalRtt_Sec);
209     fprintf(fs_outFD, "\t%10d rx_totalRtt_Usec\n", a_ovP->rx_totalRtt_Usec);
210     fprintf(fs_outFD, "\t%10d rx_minRtt_Sec\n", a_ovP->rx_minRtt_Sec);
211     fprintf(fs_outFD, "\t%10d rx_minRtt_Usec\n", a_ovP->rx_minRtt_Usec);
212     fprintf(fs_outFD, "\t%10d rx_maxRtt_Sec\n", a_ovP->rx_maxRtt_Sec);
213     fprintf(fs_outFD, "\t%10d rx_maxRtt_Usec\n", a_ovP->rx_maxRtt_Usec);
214     fprintf(fs_outFD, "\t%10d rx_nRttSamples\n", a_ovP->rx_nRttSamples);
215     fprintf(fs_outFD, "\t%10d rx_nServerConns\n", a_ovP->rx_nServerConns);
216     fprintf(fs_outFD, "\t%10d rx_nClientConns\n", a_ovP->rx_nClientConns);
217     fprintf(fs_outFD, "\t%10d rx_nPeerStructs\n", a_ovP->rx_nPeerStructs);
218     fprintf(fs_outFD, "\t%10d rx_nCallStructs\n", a_ovP->rx_nCallStructs);
219     fprintf(fs_outFD, "\t%10d rx_nFreeCallStructs\n\n",
220             a_ovP->rx_nFreeCallStructs);
221
222     /*
223      * Host module fields.
224      */
225     fprintf(fs_outFD, "\t%10d host_NumHostEntries\n",
226             a_ovP->host_NumHostEntries);
227     fprintf(fs_outFD, "\t%10d host_HostBlocks\n", a_ovP->host_HostBlocks);
228     fprintf(fs_outFD, "\t%10d host_NonDeletedHosts\n",
229             a_ovP->host_NonDeletedHosts);
230     fprintf(fs_outFD, "\t%10d host_HostsInSameNetOrSubnet\n",
231             a_ovP->host_HostsInSameNetOrSubnet);
232     fprintf(fs_outFD, "\t%10d host_HostsInDiffSubnet\n",
233             a_ovP->host_HostsInDiffSubnet);
234     fprintf(fs_outFD, "\t%10d host_HostsInDiffNetwork\n",
235             a_ovP->host_HostsInDiffNetwork);
236     fprintf(fs_outFD, "\t%10d host_NumClients\n", a_ovP->host_NumClients);
237     fprintf(fs_outFD, "\t%10d host_ClientBlocks\n\n",
238             a_ovP->host_ClientBlocks);
239
240 }                               /*Print_fs_OverallPerfInfo */
241
242
243 /*------------------------------------------------------------------------
244  * Print_fs_OpTiming
245  *
246  * Description:
247  *      Print out the contents of an RPC op timing structure.
248  *
249  * Arguments:
250  *      a_opIdx   : Index of the AFS operation we're printing number on.
251  *      a_opTimeP : Ptr to the op timing structure to print.
252  *
253  * Returns:
254  *      Nothing.
255  *
256  * Environment:
257  *      Nothing interesting.
258  *
259  * Side Effects:
260  *      As advertised.
261  *------------------------------------------------------------------------*/
262
263 void
264 Print_fs_OpTiming(a_opIdx, a_opTimeP)
265      int a_opIdx;
266      struct fs_stats_opTimingData *a_opTimeP;
267
268 {                               /*Print_fs_OpTiming */
269
270     fprintf(fs_outFD,
271             "%15s: %d ops (%d OK); sum=%d.%06d, min=%d.%06d, max=%d.%06d\n",
272             fsOpNames[a_opIdx], a_opTimeP->numOps, a_opTimeP->numSuccesses,
273             a_opTimeP->sumTime.tv_sec, a_opTimeP->sumTime.tv_usec,
274             a_opTimeP->minTime.tv_sec, a_opTimeP->minTime.tv_usec,
275             a_opTimeP->maxTime.tv_sec, a_opTimeP->maxTime.tv_usec);
276
277 }                               /*Print_fs_OpTiming */
278
279
280 /*------------------------------------------------------------------------
281  * Print_fs_XferTiming
282  *
283  * Description:
284  *      Print out the contents of a data transfer structure.
285  *
286  * Arguments:
287  *      a_opIdx : Index of the AFS operation we're printing number on.
288  *      a_xferP : Ptr to the data transfer structure to print.
289  *
290  * Returns:
291  *      Nothing.
292  *
293  * Environment:
294  *      Nothing interesting.
295  *
296  * Side Effects:
297  *      As advertised.
298  *------------------------------------------------------------------------*/
299
300 void
301 Print_fs_XferTiming(a_opIdx, a_xferP)
302      int a_opIdx;
303      struct fs_stats_xferData *a_xferP;
304
305 {                               /*Print_fs_XferTiming */
306
307     fprintf(fs_outFD,
308             "%s: %d xfers (%d OK), time sum=%d.%06d, min=%d.%06d, max=%d.%06d\n",
309             xferOpNames[a_opIdx], a_xferP->numXfers, a_xferP->numSuccesses,
310             a_xferP->sumTime.tv_sec, a_xferP->sumTime.tv_usec,
311             a_xferP->minTime.tv_sec, a_xferP->minTime.tv_usec,
312             a_xferP->maxTime.tv_sec, a_xferP->maxTime.tv_usec);
313     fprintf(fs_outFD, "\t[bytes: sum=%d, min=%d, max=%d]\n",
314             a_xferP->sumBytes, a_xferP->minBytes, a_xferP->maxBytes);
315     fprintf(fs_outFD,
316             "\t[buckets: 0: %d, 1: %d, 2: %d, 3: %d, 4: %d, 5: %d 6: %d, 7: %d, 8: %d]\n",
317             a_xferP->count[0], a_xferP->count[1], a_xferP->count[2],
318             a_xferP->count[3], a_xferP->count[4], a_xferP->count[5],
319             a_xferP->count[6], a_xferP->count[7], a_xferP->count[8]);
320
321 }                               /*Print_fs_XferTiming */
322
323
324 /*------------------------------------------------------------------------
325  * Print_fs_DetailedPerfInfo
326  *
327  * Description:
328  *      Print out a set of detailed performance numbers.
329  *
330  * Arguments:
331  *      a_detP : Ptr to detailed perf numbers to print.
332  *
333  * Returns:
334  *      Nothing.
335  *
336  * Environment:
337  *      Nothing interesting.
338  *
339  * Side Effects:
340  *      As advertised.
341  *------------------------------------------------------------------------*/
342
343 void
344 Print_fs_DetailedPerfInfo(a_detP)
345      struct fs_stats_DetailedStats *a_detP;
346
347 {                               /*Print_fs_DetailedPerfInfo */
348
349     int currIdx;                /*Loop variable */
350
351     fprintf(fs_outFD, "\t%10d epoch\n", a_detP->epoch);
352
353     for (currIdx = 0; currIdx < FS_STATS_NUM_RPC_OPS; currIdx++)
354         Print_fs_OpTiming(currIdx, &(a_detP->rpcOpTimes[currIdx]));
355
356     for (currIdx = 0; currIdx < FS_STATS_NUM_XFER_OPS; currIdx++)
357         Print_fs_XferTiming(currIdx, &(a_detP->xferOpTimes[currIdx]));
358
359 }                               /*Print_fs_DetailedPerfInfo */
360
361
362 /*------------------------------------------------------------------------
363  * Print_fs_FullPerfInfo
364  *
365  * Description:
366  *      Print out the AFS_XSTATSCOLL_FULL_PERF_INFO collection we just
367  *      received.
368  *
369  * Arguments:
370  *      None.
371  *
372  * Returns:
373  *      Nothing.
374  *
375  * Environment:
376  *      All the info we need is nestled into xstat_fs_Results.
377  *
378  * Side Effects:
379  *      As advertised.
380  *------------------------------------------------------------------------*/
381
382 void
383 Print_fs_FullPerfInfo(a_fs_Results)
384      struct xstat_fs_ProbeResults *a_fs_Results;        /* ptr to fs results */
385 {                               /*Print_fs_FullPerfInfo */
386
387     static char rn[] = "Print_fs_FullPerfInfo"; /*Routine name */
388     static afs_int32 fullPerfLongs = (sizeof(struct fs_stats_FullPerfStats) >> 2);      /*Correct # longs to rcv */
389     afs_int32 numLongs;         /*# longwords received */
390     struct fs_stats_FullPerfStats *fullPerfP;   /*Ptr to full perf stats */
391     char *printableTime;        /*Ptr to printable time string */
392     time_t probeTime;
393
394     numLongs = a_fs_Results->data.AFS_CollData_len;
395     if (numLongs != fullPerfLongs) {
396         fprintf(fs_outFD,
397                 " ** Data size mismatch in full performance collection!\n");
398         fprintf(fs_outFD, " ** Expecting %d, got %d\n", fullPerfLongs,
399                 numLongs);
400         return;
401     }
402
403     probeTime = a_fs_Results->probeTime;
404     printableTime = ctime(&probeTime);
405     printableTime[strlen(printableTime) - 1] = '\0';
406     fullPerfP = (struct fs_stats_FullPerfStats *)
407         (a_fs_Results->data.AFS_CollData_val);
408
409     fprintf(fs_outFD,
410             "AFS_XSTATSCOLL_FULL_PERF_INFO (coll %d) for FS %s\n[Probe %d, %s]\n\n",
411             a_fs_Results->collectionNumber, a_fs_Results->connP->hostName,
412             a_fs_Results->probeNum, printableTime);
413
414     Print_fs_OverallPerfInfo(&(fullPerfP->overall));
415     Print_fs_DetailedPerfInfo(&(fullPerfP->det));
416
417 }                               /*Print_fs_FullPerfInfo */
418
419
420 /*------------------------------------------------------------------------
421  * afsmon_fsOutput()
422  *
423  * Description:
424  *      Prints the contents of xstat_fs_Results to an output file. The 
425  *      output is either in a compact (longs only) format or a detailed
426  *      format giving the names of each of the datums. Output is appended.
427  *
428  * Arguments:
429  *      Name of output file.
430  *      Flag to indicate if detailed output is required.
431  *
432  * Returns:
433  *      Nothing.
434  *
435  * Environment:
436  *      All the info we need is nestled into xstat_fs_Results.
437  *
438  * Side Effects:
439  *      As advertised.
440  *------------------------------------------------------------------------*/
441 int
442 afsmon_fsOutput(a_outfile, a_detOutput)
443      char *a_outfile;           /* ptr to output file name */
444      int a_detOutput;           /* detailed output ? */
445 {
446
447     static char rn[] = "afsmon_fsOutput";       /* routine name */
448     char *printTime;            /* ptr to time string */
449     char *hostname;             /* fileserner name */
450     afs_int32 numLongs;         /* longwords in result */
451     afs_int32 *currLong;        /* ptr to longwords in result */
452     int i;
453     time_t probeTime;
454
455     if (afsmon_debug) {
456         fprintf(debugFD, "[ %s ] Called, a_outfile= %s, a_detOutput= %d\n",
457                 rn, a_outfile, a_detOutput);
458         fflush(debugFD);
459     }
460
461     fs_outFD = fopen(a_outfile, "a");
462     if (fs_outFD == (FILE *) 0) {
463         sprintf(errMsg, "[ %s ] failed to open output file %s", rn,
464                 a_outfile);
465         afsmon_Exit(1);
466     }
467
468     /* get the probe time and strip the \n at the end */
469     probeTime = xstat_fs_Results.probeTime;
470     printTime = ctime(&probeTime);
471     printTime[strlen(printTime) - 1] = '\0';
472     hostname = xstat_fs_Results.connP->hostName;
473
474     /* print "time hostname FS" */
475     fprintf(fs_outFD, "\n%s %s FS ", printTime, hostname);
476
477     /* if probe failed print -1 and return */
478     if (xstat_fs_Results.probeOK) {
479         fprintf(fs_outFD, "-1\n");
480         fclose(fs_outFD);
481         return (0);
482     }
483
484     /* print out the probe information as  long words */
485     numLongs = xstat_fs_Results.data.AFS_CollData_len;
486     currLong = (afs_int32 *) (xstat_fs_Results.data.AFS_CollData_val);
487
488     for (i = 0; i < numLongs; i++) {
489         fprintf(fs_outFD, "%d ", *currLong++);
490     }
491     fprintf(fs_outFD, "\n\n");
492
493     /* print detailed information */
494     if (a_detOutput) {
495         Print_fs_FullPerfInfo(&xstat_fs_Results);
496         fflush(fs_outFD);
497     }
498
499     if (fclose(fs_outFD))
500         if (afsmon_debug) {
501             fprintf(debugFD, "[ %s ] failed to close %s\n", rn, a_outfile);
502             fflush(debugFD);
503         }
504
505     return (0);
506 }
507
508 /*___________________________________________________________________________
509                         CM STATS
510  *__________________________________________________________________________*/
511
512
513
514 /*------------------------------------------------------------------------
515  * Print_cm_UpDownStats
516  *
517  * Description:
518  *      Print the up/downtime stats for the given class of server records
519  *      provided.
520  *
521  * Arguments:
522  *      a_upDownP : Ptr to the server up/down info.
523  *
524  * Returns:
525  *      Nothing.
526  *
527  * Environment:
528  *      Nothing interesting.
529  *
530  * Side Effects:
531  *      As advertised.
532  *------------------------------------------------------------------------*/
533
534 void
535 Print_cm_UpDownStats(a_upDownP)
536      struct afs_stats_SrvUpDownInfo *a_upDownP; /*Ptr to server up/down info */
537
538 {                               /*Print_cm_UpDownStats */
539
540     /*
541      * First, print the simple values.
542      */
543     fprintf(cm_outFD, "\t\t%10d numTtlRecords\n", a_upDownP->numTtlRecords);
544     fprintf(cm_outFD, "\t\t%10d numUpRecords\n", a_upDownP->numUpRecords);
545     fprintf(cm_outFD, "\t\t%10d numDownRecords\n", a_upDownP->numDownRecords);
546     fprintf(cm_outFD, "\t\t%10d sumOfRecordAges\n",
547             a_upDownP->sumOfRecordAges);
548     fprintf(cm_outFD, "\t\t%10d ageOfYoungestRecord\n",
549             a_upDownP->ageOfYoungestRecord);
550     fprintf(cm_outFD, "\t\t%10d ageOfOldestRecord\n",
551             a_upDownP->ageOfOldestRecord);
552     fprintf(cm_outFD, "\t\t%10d numDowntimeIncidents\n",
553             a_upDownP->numDowntimeIncidents);
554     fprintf(cm_outFD, "\t\t%10d numRecordsNeverDown\n",
555             a_upDownP->numRecordsNeverDown);
556     fprintf(cm_outFD, "\t\t%10d maxDowntimesInARecord\n",
557             a_upDownP->maxDowntimesInARecord);
558     fprintf(cm_outFD, "\t\t%10d sumOfDowntimes\n", a_upDownP->sumOfDowntimes);
559     fprintf(cm_outFD, "\t\t%10d shortestDowntime\n",
560             a_upDownP->shortestDowntime);
561     fprintf(cm_outFD, "\t\t%10d longestDowntime\n",
562             a_upDownP->longestDowntime);
563
564     /*
565      * Now, print the array values.
566      */
567     fprintf(cm_outFD, "\t\tDowntime duration distribution:\n");
568     fprintf(cm_outFD, "\t\t\t%8d: 0 min .. 10 min\n",
569             a_upDownP->downDurations[0]);
570     fprintf(cm_outFD, "\t\t\t%8d: 10 min .. 30 min\n",
571             a_upDownP->downDurations[1]);
572     fprintf(cm_outFD, "\t\t\t%8d: 30 min .. 1 hr\n",
573             a_upDownP->downDurations[2]);
574     fprintf(cm_outFD, "\t\t\t%8d: 1 hr .. 2 hr\n",
575             a_upDownP->downDurations[3]);
576     fprintf(cm_outFD, "\t\t\t%8d: 2 hr .. 4 hr\n",
577             a_upDownP->downDurations[4]);
578     fprintf(cm_outFD, "\t\t\t%8d: 4 hr .. 8 hr\n",
579             a_upDownP->downDurations[5]);
580     fprintf(cm_outFD, "\t\t\t%8d: > 8 hr\n", a_upDownP->downDurations[6]);
581
582     fprintf(cm_outFD, "\t\tDowntime incident distribution:\n");
583     fprintf(cm_outFD, "\t\t\t%8d: 0 times\n", a_upDownP->downIncidents[0]);
584     fprintf(cm_outFD, "\t\t\t%8d: 1 time\n", a_upDownP->downIncidents[1]);
585     fprintf(cm_outFD, "\t\t\t%8d: 2 .. 5 times\n",
586             a_upDownP->downIncidents[2]);
587     fprintf(cm_outFD, "\t\t\t%8d: 6 .. 10 times\n",
588             a_upDownP->downIncidents[3]);
589     fprintf(cm_outFD, "\t\t\t%8d: 10 .. 50 times\n",
590             a_upDownP->downIncidents[4]);
591     fprintf(cm_outFD, "\t\t\t%8d: > 50 times\n", a_upDownP->downIncidents[5]);
592
593 }                               /*Print_cm_UpDownStats */
594
595
596 /*------------------------------------------------------------------------
597  * Print_cm_OverallPerfInfo
598  *
599  * Description:
600  *      Print out overall performance numbers.
601  *
602  * Arguments:
603  *      a_ovP : Ptr to the overall performance numbers.
604  *
605  * Returns:
606  *      Nothing.
607  *
608  * Environment:
609  *      All the info we need is nestled into xstat_cm_Results.
610  *
611  * Side Effects:
612  *      As advertised.
613  *------------------------------------------------------------------------*/
614
615 void
616 Print_cm_OverallPerfInfo(a_ovP)
617      struct afs_stats_CMPerf *a_ovP;
618
619 {                               /*Print_cm_OverallPerfInfo */
620
621     fprintf(cm_outFD, "\t%10d numPerfCalls\n", a_ovP->numPerfCalls);
622
623     fprintf(cm_outFD, "\t%10d epoch\n", a_ovP->epoch);
624     fprintf(cm_outFD, "\t%10d numCellsVisible\n", a_ovP->numCellsVisible);
625     fprintf(cm_outFD, "\t%10d numCellsContacted\n", a_ovP->numCellsContacted);
626     fprintf(cm_outFD, "\t%10d dlocalAccesses\n", a_ovP->dlocalAccesses);
627     fprintf(cm_outFD, "\t%10d vlocalAccesses\n", a_ovP->vlocalAccesses);
628     fprintf(cm_outFD, "\t%10d dremoteAccesses\n", a_ovP->dremoteAccesses);
629     fprintf(cm_outFD, "\t%10d vremoteAccesses\n", a_ovP->vremoteAccesses);
630     fprintf(cm_outFD, "\t%10d cacheNumEntries\n", a_ovP->cacheNumEntries);
631     fprintf(cm_outFD, "\t%10d cacheBlocksTotal\n", a_ovP->cacheBlocksTotal);
632     fprintf(cm_outFD, "\t%10d cacheBlocksInUse\n", a_ovP->cacheBlocksInUse);
633     fprintf(cm_outFD, "\t%10d cacheBlocksOrig\n", a_ovP->cacheBlocksOrig);
634     fprintf(cm_outFD, "\t%10d cacheMaxDirtyChunks\n",
635             a_ovP->cacheMaxDirtyChunks);
636     fprintf(cm_outFD, "\t%10d cacheCurrDirtyChunks\n",
637             a_ovP->cacheCurrDirtyChunks);
638     fprintf(cm_outFD, "\t%10d dcacheHits\n", a_ovP->dcacheHits);
639     fprintf(cm_outFD, "\t%10d vcacheHits\n", a_ovP->vcacheHits);
640     fprintf(cm_outFD, "\t%10d dcacheMisses\n", a_ovP->dcacheMisses);
641     fprintf(cm_outFD, "\t%10d vcacheMisses\n", a_ovP->vcacheMisses);
642     fprintf(cm_outFD, "\t%10d cacheFilesReused\n", a_ovP->cacheFilesReused);
643     fprintf(cm_outFD, "\t%10d vcacheXAllocs\n", a_ovP->vcacheXAllocs);
644
645     fprintf(cm_outFD, "\t%10d bufAlloced\n", a_ovP->bufAlloced);
646     fprintf(cm_outFD, "\t%10d bufHits\n", a_ovP->bufHits);
647     fprintf(cm_outFD, "\t%10d bufMisses\n", a_ovP->bufMisses);
648     fprintf(cm_outFD, "\t%10d bufFlushDirty\n", a_ovP->bufFlushDirty);
649
650     fprintf(cm_outFD, "\t%10d LargeBlocksActive\n", a_ovP->LargeBlocksActive);
651     fprintf(cm_outFD, "\t%10d LargeBlocksAlloced\n",
652             a_ovP->LargeBlocksAlloced);
653     fprintf(cm_outFD, "\t%10d SmallBlocksActive\n", a_ovP->SmallBlocksActive);
654     fprintf(cm_outFD, "\t%10d SmallBlocksAlloced\n",
655             a_ovP->SmallBlocksAlloced);
656     fprintf(cm_outFD, "\t%10d OutStandingMemUsage\n",
657             a_ovP->OutStandingMemUsage);
658     fprintf(cm_outFD, "\t%10d OutStandingAllocs\n", a_ovP->OutStandingAllocs);
659     fprintf(cm_outFD, "\t%10d CallBackAlloced\n", a_ovP->CallBackAlloced);
660     fprintf(cm_outFD, "\t%10d CallBackFlushes\n", a_ovP->CallBackFlushes);
661
662     fprintf(cm_outFD, "\t%10d srvRecords\n", a_ovP->srvRecords);
663     fprintf(cm_outFD, "\t%10d srvNumBuckets\n", a_ovP->srvNumBuckets);
664     fprintf(cm_outFD, "\t%10d srvMaxChainLength\n", a_ovP->srvMaxChainLength);
665     fprintf(cm_outFD, "\t%10d srvMaxChainLengthHWM\n",
666             a_ovP->srvMaxChainLengthHWM);
667     fprintf(cm_outFD, "\t%10d srvRecordsHWM\n", a_ovP->srvRecordsHWM);
668
669     fprintf(cm_outFD, "\t%10d sysName_ID\n", a_ovP->sysName_ID);
670
671     fprintf(cm_outFD, "\tFile Server up/downtimes, same cell:\n");
672     Print_cm_UpDownStats(&(a_ovP->fs_UpDown[0]));
673
674     fprintf(cm_outFD, "\tFile Server up/downtimes, diff cell:\n");
675     Print_cm_UpDownStats(&(a_ovP->fs_UpDown[1]));
676
677     fprintf(cm_outFD, "\tVL Server up/downtimes, same cell:\n");
678     Print_cm_UpDownStats(&(a_ovP->vl_UpDown[0]));
679
680     fprintf(cm_outFD, "\tVL Server up/downtimes, diff cell:\n");
681     Print_cm_UpDownStats(&(a_ovP->vl_UpDown[1]));
682
683 }                               /*Print_cm_OverallPerfInfo */
684
685
686 /*------------------------------------------------------------------------
687  * Print_cm_PerfInfo
688  *
689  * Description:
690  *      Print out the AFSCB_XSTATSCOLL_PERF_INFO collection we just
691  *      received.
692  *
693  * Arguments:
694  *      None.
695  *
696  * Returns:
697  *      Nothing.
698  *
699  * Environment:
700  *      All the info we need is nestled into xstat_cm_Results.
701  *
702  * Side Effects:
703  *      As advertised.
704  *------------------------------------------------------------------------*/
705
706 void
707 Print_cm_PerfInfo()
708 {                               /*Print_cm_PerfInfo */
709
710     static char rn[] = "Print_cm_PerfInfo";     /*Routine name */
711     static afs_int32 perfLongs = (sizeof(struct afs_stats_CMPerf) >> 2);        /*Correct # longs to rcv */
712     afs_int32 numLongs;         /*# longwords received */
713     struct afs_stats_CMPerf *perfP;     /*Ptr to performance stats */
714     char *printableTime;        /*Ptr to printable time string */
715     time_t probeTime;
716
717     numLongs = xstat_cm_Results.data.AFSCB_CollData_len;
718     if (numLongs != perfLongs) {
719         fprintf(cm_outFD,
720                 " ** Data size mismatch in performance collection!\n");
721         fprintf(cm_outFD, "** Expecting %d, got %d\n", perfLongs, numLongs);
722         return;
723     }
724
725     probeTime = xstat_cm_Results.probeTime;
726     printableTime = ctime(&probeTime);
727     printableTime[strlen(printableTime) - 1] = '\0';
728     perfP = (struct afs_stats_CMPerf *)
729         (xstat_cm_Results.data.AFSCB_CollData_val);
730
731     fprintf(cm_outFD,
732             "AFSCB_XSTATSCOLL_PERF_INFO (coll %d) for CM %s\n[Probe %d, %s]\n\n",
733             xstat_cm_Results.collectionNumber,
734             xstat_cm_Results.connP->hostName, xstat_cm_Results.probeNum,
735             printableTime);
736
737     Print_cm_OverallPerfInfo(perfP);
738
739 }                               /*Print_cm_PerfInfo */
740
741
742 /*------------------------------------------------------------------------
743  * Print_cm_OpTiming
744  *
745  * Description:
746  *      Print out the contents of an FS RPC op timing structure.
747  *
748  * Arguments:
749  *      a_opIdx   : Index of the AFS operation we're printing number on.
750  *      a_opNames : Ptr to table of operaton names.
751  *      a_opTimeP : Ptr to the op timing structure to print.
752  *
753  * Returns:
754  *      Nothing.
755  *
756  * Environment:
757  *      Nothing interesting.
758  *
759  * Side Effects:
760  *      As advertised.
761  *------------------------------------------------------------------------*/
762
763 void
764 Print_cm_OpTiming(a_opIdx, a_opNames, a_opTimeP)
765      int a_opIdx;
766      char *a_opNames[];
767      struct afs_stats_opTimingData *a_opTimeP;
768
769 {                               /*Print_cm_OpTiming */
770
771     fprintf(cm_outFD,
772             "%15s: %d ops (%d OK); sum=%d.%06d, min=%d.%06d, max=%d.%06d\n",
773             a_opNames[a_opIdx], a_opTimeP->numOps, a_opTimeP->numSuccesses,
774             a_opTimeP->sumTime.tv_sec, a_opTimeP->sumTime.tv_usec,
775             a_opTimeP->minTime.tv_sec, a_opTimeP->minTime.tv_usec,
776             a_opTimeP->maxTime.tv_sec, a_opTimeP->maxTime.tv_usec);
777
778 }                               /*Print_cm_OpTiming */
779
780
781 /*------------------------------------------------------------------------
782  * Print_cm_XferTiming
783  *
784  * Description:
785  *      Print out the contents of a data transfer structure.
786  *
787  * Arguments:
788  *      a_opIdx : Index of the AFS operation we're printing number on.
789  *      a_xferP : Ptr to the data transfer structure to print.
790  *
791  * Returns:
792  *      Nothing.
793  *
794  * Environment:
795  *      Nothing interesting.
796  *
797  * Side Effects:
798  *      As advertised.
799  *------------------------------------------------------------------------*/
800
801 void
802 Print_cm_XferTiming(a_opIdx, a_opNames, a_xferP)
803      int a_opIdx;
804      char *a_opNames[];
805      struct afs_stats_xferData *a_xferP;
806
807 {                               /*Print_cm_XferTiming */
808
809     fprintf(cm_outFD,
810             "%s: %d xfers (%d OK), time sum=%d.%06d, min=%d.%06d, max=%d.%06d\n",
811             a_opNames[a_opIdx], a_xferP->numXfers, a_xferP->numSuccesses,
812             a_xferP->sumTime.tv_sec, a_xferP->sumTime.tv_usec,
813             a_xferP->minTime.tv_sec, a_xferP->minTime.tv_usec,
814             a_xferP->maxTime.tv_sec, a_xferP->maxTime.tv_usec);
815     fprintf(cm_outFD, "\t[bytes: sum=%d, min=%d, max=%d]\n",
816             a_xferP->sumBytes, a_xferP->minBytes, a_xferP->maxBytes);
817     fprintf(cm_outFD,
818             "\t[buckets: 0: %d, 1: %d, 2: %d, 3: %d, 4: %d, 5: %d 6: %d, 7: %d, 8: %d]\n",
819             a_xferP->count[0], a_xferP->count[1], a_xferP->count[2],
820             a_xferP->count[3], a_xferP->count[4], a_xferP->count[5],
821             a_xferP->count[6], a_xferP->count[7], a_xferP->count[8]);
822
823 }                               /*Print_cm_XferTiming */
824
825
826 /*------------------------------------------------------------------------
827  * Print_cm_ErrInfo
828  *
829  * Description:
830  *      Print out the contents of an FS RPC error info structure.
831  *
832  * Arguments:
833  *      a_opIdx   : Index of the AFS operation we're printing.
834  *      a_opNames : Ptr to table of operation names.
835  *      a_opErrP  : Ptr to the op timing structure to print.
836  *
837  * Returns:
838  *      Nothing.
839  *
840  * Environment:
841  *      Nothing interesting.
842  *
843  * Side Effects:
844  *      As advertised.
845  *------------------------------------------------------------------------*/
846
847 void
848 Print_cm_ErrInfo(a_opIdx, a_opNames, a_opErrP)
849      int a_opIdx;
850      char *a_opNames[];
851      struct afs_stats_RPCErrors *a_opErrP;
852
853 {                               /*Print_cm_ErrInfo */
854
855     fprintf(cm_outFD,
856             "%15s: %d server, %d network, %d prot, %d vol, %d busies, %d other\n",
857             a_opNames[a_opIdx], a_opErrP->err_Server, a_opErrP->err_Network,
858             a_opErrP->err_Protection, a_opErrP->err_Volume,
859             a_opErrP->err_VolumeBusies, a_opErrP->err_Other);
860
861 }                               /*Print_cm_ErrInfo */
862
863
864 /*------------------------------------------------------------------------
865  * Print_cm_RPCPerfInfo
866  *
867  * Description:
868  *      Print out a set of RPC performance numbers.
869  *
870  * Arguments:
871  *      a_rpcP : Ptr to RPC perf numbers to print.
872  *
873  * Returns:
874  *      Nothing.
875  *
876  * Environment:
877  *      Nothing interesting.
878  *
879  * Side Effects:
880  *      As advertised.
881  *------------------------------------------------------------------------*/
882
883 void
884 Print_cm_RPCPerfInfo(a_rpcP)
885      struct afs_stats_RPCOpInfo *a_rpcP;
886
887 {                               /*Print_cm_RPCPerfInfo */
888
889     int currIdx;                /*Loop variable */
890
891     /*
892      * Print the contents of each of the opcode-related arrays.
893      */
894     fprintf(cm_outFD, "FS Operation Timings:\n---------------------\n");
895     for (currIdx = 0; currIdx < AFS_STATS_NUM_FS_RPC_OPS; currIdx++)
896         Print_cm_OpTiming(currIdx, fsOpNames, &(a_rpcP->fsRPCTimes[currIdx]));
897
898     fprintf(cm_outFD, "\nError Info:\n-----------\n");
899     for (currIdx = 0; currIdx < AFS_STATS_NUM_FS_RPC_OPS; currIdx++)
900         Print_cm_ErrInfo(currIdx, fsOpNames, &(a_rpcP->fsRPCErrors[currIdx]));
901
902     fprintf(cm_outFD, "\nTransfer timings:\n-----------------\n");
903     for (currIdx = 0; currIdx < AFS_STATS_NUM_FS_XFER_OPS; currIdx++)
904         Print_cm_XferTiming(currIdx, xferOpNames,
905                             &(a_rpcP->fsXferTimes[currIdx]));
906
907     fprintf(cm_outFD, "\nCM Operation Timings:\n---------------------\n");
908     for (currIdx = 0; currIdx < AFS_STATS_NUM_CM_RPC_OPS; currIdx++)
909         Print_cm_OpTiming(currIdx, cmOpNames, &(a_rpcP->cmRPCTimes[currIdx]));
910
911 }                               /*Print_cm_RPCPerfInfo */
912
913
914 /*------------------------------------------------------------------------
915  * Print_cm_FullPerfInfo
916  *
917  * Description:
918  *      Print out a set of full performance numbers.
919  *
920  * Arguments:
921  *      None.
922  *
923  * Returns:
924  *      Nothing.
925  *
926  * Environment:
927  *      Nothing interesting.
928  *
929  * Side Effects:
930  *      As advertised.
931  *------------------------------------------------------------------------*/
932
933 void
934 Print_cm_FullPerfInfo()
935 {                               /*Print_cm_FullPerfInfo */
936
937     static char rn[] = "Print_cm_FullPerfInfo"; /* routine name */
938     struct afs_stats_AuthentInfo *authentP;     /*Ptr to authentication stats */
939     struct afs_stats_AccessInfo *accessinfP;    /*Ptr to access stats */
940     static afs_int32 fullPerfLongs = (sizeof(struct afs_stats_CMFullPerf) >> 2);        /*Correct #longs */
941     afs_int32 numLongs;         /*# longs actually received */
942     struct afs_stats_CMFullPerf *fullP; /*Ptr to full perf info */
943     time_t probeTime;
944     char *printableTime;        /*Ptr to printable time string */
945
946     numLongs = xstat_cm_Results.data.AFSCB_CollData_len;
947     if (numLongs != fullPerfLongs) {
948         fprintf(cm_outFD,
949                 " ** Data size mismatch in performance collection!\n");
950         fprintf(cm_outFD, " ** Expecting %d, got %d\n", fullPerfLongs,
951                 numLongs);
952         return;
953     }
954
955     probeTime = xstat_cm_Results.probeTime;
956     printableTime = ctime(&probeTime);
957     printableTime[strlen(printableTime) - 1] = '\0';
958     fullP = (struct afs_stats_CMFullPerf *)
959         (xstat_cm_Results.data.AFSCB_CollData_val);
960
961     fprintf(cm_outFD,
962             "AFSCB_XSTATSCOLL_FULL_PERF_INFO (coll %d) for CM %s\n[Probe %d, %s]\n\n",
963             xstat_cm_Results.collectionNumber,
964             xstat_cm_Results.connP->hostName, xstat_cm_Results.probeNum,
965             printableTime);
966
967     /*
968      * Print the overall numbers first, followed by all of the RPC numbers,
969      * then each of the other groupings.
970      */
971     fprintf(cm_outFD,
972             "Overall Performance Info:\n-------------------------\n");
973     Print_cm_OverallPerfInfo(&(fullP->perf));
974     fprintf(cm_outFD, "\n");
975     Print_cm_RPCPerfInfo(&(fullP->rpc));
976
977     authentP = &(fullP->authent);
978     fprintf(cm_outFD, "\nAuthentication info:\n--------------------\n");
979     fprintf(cm_outFD,
980             "\t%d PAGS, %d records (%d auth, %d unauth), %d max in PAG, chain max: %d\n",
981             authentP->curr_PAGs, authentP->curr_Records,
982             authentP->curr_AuthRecords, authentP->curr_UnauthRecords,
983             authentP->curr_MaxRecordsInPAG, authentP->curr_LongestChain);
984     fprintf(cm_outFD, "\t%d PAG creations, %d tkt updates\n",
985             authentP->PAGCreations, authentP->TicketUpdates);
986     fprintf(cm_outFD,
987             "\t[HWMs: %d PAGS, %d records, %d max in PAG, chain max: %d]\n",
988             authentP->HWM_PAGs, authentP->HWM_Records,
989             authentP->HWM_MaxRecordsInPAG, authentP->HWM_LongestChain);
990
991     accessinfP = &(fullP->accessinf);
992     fprintf(cm_outFD,
993             "\n[Un]replicated accesses:\n------------------------\n");
994     fprintf(cm_outFD,
995             "\t%d unrep, %d rep, %d reps accessed, %d max reps/ref, %d first OK\n\n",
996             accessinfP->unreplicatedRefs, accessinfP->replicatedRefs,
997             accessinfP->numReplicasAccessed, accessinfP->maxReplicasPerRef,
998             accessinfP->refFirstReplicaOK);
999
1000     /* There really isn't any authorship info
1001      * authorP = &(fullP->author); */
1002
1003 }                               /*Print_cm_FullPerfInfo */
1004
1005 /*------------------------------------------------------------------------
1006  * afsmon_cmOutput()
1007  *
1008  * Description:
1009  *      Prints the contents of xstat_cm_Results to an output file. The 
1010  *      output is either in a compact (longs only) format or a detailed
1011  *      format giving the names of each of the datums. Output is appended.
1012  *
1013  * Arguments:
1014  *      Name of output file.
1015  *      Flag to indicate if detailed output is required.
1016  *
1017  * Returns:
1018  *      Nothing.
1019  *
1020  * Environment:
1021  *      All the info we need is nestled into xstat_cm_Results.
1022  *
1023  * Side Effects:
1024  *      As advertised.
1025  *------------------------------------------------------------------------*/
1026 int
1027 afsmon_cmOutput(a_outfile, a_detOutput)
1028      char *a_outfile;           /* ptr to output file name */
1029      int a_detOutput;           /* detailed output ? */
1030 {
1031
1032     static char rn[] = "afsmon_cmOutput";       /* routine name */
1033     char *printTime;            /* ptr to time string */
1034     char *hostname;             /* fileserner name */
1035     afs_int32 numLongs;         /* longwords in result */
1036     afs_int32 *currLong;        /* ptr to longwords in result */
1037     int i;
1038     time_t probeTime;
1039
1040     if (afsmon_debug) {
1041         fprintf(debugFD, "[ %s ] Called, a_outfile= %s, a_detOutput= %d\n",
1042                 rn, a_outfile, a_detOutput);
1043         fflush(debugFD);
1044     }
1045
1046     /* need to lock this file before writing */
1047     cm_outFD = fopen(a_outfile, "a");
1048     if (cm_outFD == (FILE *) 0) {
1049         sprintf(errMsg, "[ %s ] failed to open output file %s", rn,
1050                 a_outfile);
1051         afsmon_Exit(1);
1052     }
1053
1054     /* get the probe time and strip the \n at the end */
1055     probeTime = xstat_cm_Results.probeTime;
1056     printTime = ctime(&probeTime);
1057     printTime[strlen(printTime) - 1] = '\0';
1058     hostname = xstat_cm_Results.connP->hostName;
1059
1060     /* print "time hostname CM" prefix  */
1061     fprintf(cm_outFD, "\n%s %s CM ", printTime, hostname);
1062
1063     /* if probe failed print -1 and vanish */
1064     if (xstat_cm_Results.probeOK) {
1065         fprintf(cm_outFD, "-1\n");
1066         fclose(cm_outFD);
1067         return (0);
1068     }
1069
1070     /* print out the probe information as  long words */
1071     numLongs = xstat_cm_Results.data.AFSCB_CollData_len;
1072     currLong = (afs_int32 *) (xstat_cm_Results.data.AFSCB_CollData_val);
1073
1074     for (i = 0; i < numLongs; i++) {
1075         fprintf(cm_outFD, "%d ", *currLong++);
1076     }
1077     fprintf(cm_outFD, "\n\n");
1078
1079     /* print out detailed statistics */
1080     if (a_detOutput) {
1081         Print_cm_FullPerfInfo();
1082         fflush(cm_outFD);
1083     }
1084
1085     if (fclose(cm_outFD))
1086         if (afsmon_debug) {
1087             fprintf(debugFD, "[ %s ] failed to close %s\n", rn, a_outfile);
1088             fflush(debugFD);
1089         }
1090
1091     return (0);
1092 }