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