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