Remove the RCSID macro
[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=%d.%06d, min=%d.%06d, max=%d.%06d\n",
257             fsOpNames[a_opIdx], a_opTimeP->numOps, a_opTimeP->numSuccesses,
258             a_opTimeP->sumTime.tv_sec, a_opTimeP->sumTime.tv_usec,
259             a_opTimeP->minTime.tv_sec, a_opTimeP->minTime.tv_usec,
260             a_opTimeP->maxTime.tv_sec, 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=%d.%06d, min=%d.%06d, max=%d.%06d\n",
291             xferOpNames[a_opIdx], a_xferP->numXfers, a_xferP->numSuccesses,
292             a_xferP->sumTime.tv_sec, a_xferP->sumTime.tv_usec,
293             a_xferP->minTime.tv_sec, a_xferP->minTime.tv_usec,
294             a_xferP->maxTime.tv_sec, 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%10d epoch\n", a_detP->epoch);
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     numLongs = a_fs_Results->data.AFS_CollData_len;
372     if (numLongs != fullPerfLongs) {
373         fprintf(fs_outFD,
374                 " ** Data size mismatch in full performance collection!\n");
375         fprintf(fs_outFD, " ** Expecting %d, got %d\n", fullPerfLongs,
376                 numLongs);
377         return;
378     }
379
380     probeTime = a_fs_Results->probeTime;
381     printableTime = ctime(&probeTime);
382     printableTime[strlen(printableTime) - 1] = '\0';
383     fullPerfP = (struct fs_stats_FullPerfStats *)
384         (a_fs_Results->data.AFS_CollData_val);
385
386     fprintf(fs_outFD,
387             "AFS_XSTATSCOLL_FULL_PERF_INFO (coll %d) for FS %s\n[Probe %d, %s]\n\n",
388             a_fs_Results->collectionNumber, a_fs_Results->connP->hostName,
389             a_fs_Results->probeNum, printableTime);
390
391     Print_fs_OverallPerfInfo(&(fullPerfP->overall));
392     Print_fs_DetailedPerfInfo(&(fullPerfP->det));
393
394 }                               /*Print_fs_FullPerfInfo */
395
396
397 /*------------------------------------------------------------------------
398  * afsmon_fsOutput()
399  *
400  * Description:
401  *      Prints the contents of xstat_fs_Results to an output file. The 
402  *      output is either in a compact (longs only) format or a detailed
403  *      format giving the names of each of the datums. Output is appended.
404  *
405  * Arguments:
406  *      Name of output file.
407  *      Flag to indicate if detailed output is required.
408  *
409  * Returns:
410  *      Nothing.
411  *
412  * Environment:
413  *      All the info we need is nestled into xstat_fs_Results.
414  *
415  * Side Effects:
416  *      As advertised.
417  *------------------------------------------------------------------------*/
418 int
419 afsmon_fsOutput(char *a_outfile,        /* ptr to output file name */
420                 int a_detOutput)        /* detailed output ? */
421 {
422
423     static char rn[] = "afsmon_fsOutput";       /* routine name */
424     char *printTime;            /* ptr to time string */
425     char *hostname;             /* fileserner name */
426     afs_int32 numLongs;         /* longwords in result */
427     afs_int32 *currLong;        /* ptr to longwords in result */
428     int i;
429     time_t probeTime;
430
431     if (afsmon_debug) {
432         fprintf(debugFD, "[ %s ] Called, a_outfile= %s, a_detOutput= %d\n",
433                 rn, a_outfile, a_detOutput);
434         fflush(debugFD);
435     }
436
437     fs_outFD = fopen(a_outfile, "a");
438     if (fs_outFD == (FILE *) 0) {
439         sprintf(errMsg, "[ %s ] failed to open output file %s", rn,
440                 a_outfile);
441         afsmon_Exit(1);
442     }
443
444     /* get the probe time and strip the \n at the end */
445     probeTime = xstat_fs_Results.probeTime;
446     printTime = ctime(&probeTime);
447     printTime[strlen(printTime) - 1] = '\0';
448     hostname = xstat_fs_Results.connP->hostName;
449
450     /* print "time hostname FS" */
451     fprintf(fs_outFD, "\n%s %s FS ", printTime, hostname);
452
453     /* if probe failed print -1 and return */
454     if (xstat_fs_Results.probeOK) {
455         fprintf(fs_outFD, "-1\n");
456         fclose(fs_outFD);
457         return (0);
458     }
459
460     /* print out the probe information as  long words */
461     numLongs = xstat_fs_Results.data.AFS_CollData_len;
462     currLong = (afs_int32 *) (xstat_fs_Results.data.AFS_CollData_val);
463
464     for (i = 0; i < numLongs; i++) {
465         fprintf(fs_outFD, "%d ", *currLong++);
466     }
467     fprintf(fs_outFD, "\n\n");
468
469     /* print detailed information */
470     if (a_detOutput) {
471         Print_fs_FullPerfInfo(&xstat_fs_Results);
472         fflush(fs_outFD);
473     }
474
475     if (fclose(fs_outFD))
476         if (afsmon_debug) {
477             fprintf(debugFD, "[ %s ] failed to close %s\n", rn, a_outfile);
478             fflush(debugFD);
479         }
480
481     return (0);
482 }
483
484 /*___________________________________________________________________________
485                         CM STATS
486  *__________________________________________________________________________*/
487
488
489
490 /*------------------------------------------------------------------------
491  * Print_cm_UpDownStats
492  *
493  * Description:
494  *      Print the up/downtime stats for the given class of server records
495  *      provided.
496  *
497  * Arguments:
498  *      a_upDownP : Ptr to the server up/down info.
499  *
500  * Returns:
501  *      Nothing.
502  *
503  * Environment:
504  *      Nothing interesting.
505  *
506  * Side Effects:
507  *      As advertised.
508  *------------------------------------------------------------------------*/
509
510 void
511 Print_cm_UpDownStats(struct afs_stats_SrvUpDownInfo *a_upDownP) /*Ptr to server up/down info */
512 {                               /*Print_cm_UpDownStats */
513
514     /*
515      * First, print the simple values.
516      */
517     fprintf(cm_outFD, "\t\t%10d numTtlRecords\n", a_upDownP->numTtlRecords);
518     fprintf(cm_outFD, "\t\t%10d numUpRecords\n", a_upDownP->numUpRecords);
519     fprintf(cm_outFD, "\t\t%10d numDownRecords\n", a_upDownP->numDownRecords);
520     fprintf(cm_outFD, "\t\t%10d sumOfRecordAges\n",
521             a_upDownP->sumOfRecordAges);
522     fprintf(cm_outFD, "\t\t%10d ageOfYoungestRecord\n",
523             a_upDownP->ageOfYoungestRecord);
524     fprintf(cm_outFD, "\t\t%10d ageOfOldestRecord\n",
525             a_upDownP->ageOfOldestRecord);
526     fprintf(cm_outFD, "\t\t%10d numDowntimeIncidents\n",
527             a_upDownP->numDowntimeIncidents);
528     fprintf(cm_outFD, "\t\t%10d numRecordsNeverDown\n",
529             a_upDownP->numRecordsNeverDown);
530     fprintf(cm_outFD, "\t\t%10d maxDowntimesInARecord\n",
531             a_upDownP->maxDowntimesInARecord);
532     fprintf(cm_outFD, "\t\t%10d sumOfDowntimes\n", a_upDownP->sumOfDowntimes);
533     fprintf(cm_outFD, "\t\t%10d shortestDowntime\n",
534             a_upDownP->shortestDowntime);
535     fprintf(cm_outFD, "\t\t%10d longestDowntime\n",
536             a_upDownP->longestDowntime);
537
538     /*
539      * Now, print the array values.
540      */
541     fprintf(cm_outFD, "\t\tDowntime duration distribution:\n");
542     fprintf(cm_outFD, "\t\t\t%8d: 0 min .. 10 min\n",
543             a_upDownP->downDurations[0]);
544     fprintf(cm_outFD, "\t\t\t%8d: 10 min .. 30 min\n",
545             a_upDownP->downDurations[1]);
546     fprintf(cm_outFD, "\t\t\t%8d: 30 min .. 1 hr\n",
547             a_upDownP->downDurations[2]);
548     fprintf(cm_outFD, "\t\t\t%8d: 1 hr .. 2 hr\n",
549             a_upDownP->downDurations[3]);
550     fprintf(cm_outFD, "\t\t\t%8d: 2 hr .. 4 hr\n",
551             a_upDownP->downDurations[4]);
552     fprintf(cm_outFD, "\t\t\t%8d: 4 hr .. 8 hr\n",
553             a_upDownP->downDurations[5]);
554     fprintf(cm_outFD, "\t\t\t%8d: > 8 hr\n", a_upDownP->downDurations[6]);
555
556     fprintf(cm_outFD, "\t\tDowntime incident distribution:\n");
557     fprintf(cm_outFD, "\t\t\t%8d: 0 times\n", a_upDownP->downIncidents[0]);
558     fprintf(cm_outFD, "\t\t\t%8d: 1 time\n", a_upDownP->downIncidents[1]);
559     fprintf(cm_outFD, "\t\t\t%8d: 2 .. 5 times\n",
560             a_upDownP->downIncidents[2]);
561     fprintf(cm_outFD, "\t\t\t%8d: 6 .. 10 times\n",
562             a_upDownP->downIncidents[3]);
563     fprintf(cm_outFD, "\t\t\t%8d: 10 .. 50 times\n",
564             a_upDownP->downIncidents[4]);
565     fprintf(cm_outFD, "\t\t\t%8d: > 50 times\n", a_upDownP->downIncidents[5]);
566
567 }                               /*Print_cm_UpDownStats */
568
569
570 /*------------------------------------------------------------------------
571  * Print_cm_OverallPerfInfo
572  *
573  * Description:
574  *      Print out overall performance numbers.
575  *
576  * Arguments:
577  *      a_ovP : Ptr to the overall performance numbers.
578  *
579  * Returns:
580  *      Nothing.
581  *
582  * Environment:
583  *      All the info we need is nestled into xstat_cm_Results.
584  *
585  * Side Effects:
586  *      As advertised.
587  *------------------------------------------------------------------------*/
588
589 void
590 Print_cm_OverallPerfInfo(struct afs_stats_CMPerf *a_ovP)
591 {                               /*Print_cm_OverallPerfInfo */
592
593     fprintf(cm_outFD, "\t%10d numPerfCalls\n", a_ovP->numPerfCalls);
594
595     fprintf(cm_outFD, "\t%10d epoch\n", a_ovP->epoch);
596     fprintf(cm_outFD, "\t%10d numCellsVisible\n", a_ovP->numCellsVisible);
597     fprintf(cm_outFD, "\t%10d numCellsContacted\n", a_ovP->numCellsContacted);
598     fprintf(cm_outFD, "\t%10d dlocalAccesses\n", a_ovP->dlocalAccesses);
599     fprintf(cm_outFD, "\t%10d vlocalAccesses\n", a_ovP->vlocalAccesses);
600     fprintf(cm_outFD, "\t%10d dremoteAccesses\n", a_ovP->dremoteAccesses);
601     fprintf(cm_outFD, "\t%10d vremoteAccesses\n", a_ovP->vremoteAccesses);
602     fprintf(cm_outFD, "\t%10d cacheNumEntries\n", a_ovP->cacheNumEntries);
603     fprintf(cm_outFD, "\t%10d cacheBlocksTotal\n", a_ovP->cacheBlocksTotal);
604     fprintf(cm_outFD, "\t%10d cacheBlocksInUse\n", a_ovP->cacheBlocksInUse);
605     fprintf(cm_outFD, "\t%10d cacheBlocksOrig\n", a_ovP->cacheBlocksOrig);
606     fprintf(cm_outFD, "\t%10d cacheMaxDirtyChunks\n",
607             a_ovP->cacheMaxDirtyChunks);
608     fprintf(cm_outFD, "\t%10d cacheCurrDirtyChunks\n",
609             a_ovP->cacheCurrDirtyChunks);
610     fprintf(cm_outFD, "\t%10d dcacheHits\n", a_ovP->dcacheHits);
611     fprintf(cm_outFD, "\t%10d vcacheHits\n", a_ovP->vcacheHits);
612     fprintf(cm_outFD, "\t%10d dcacheMisses\n", a_ovP->dcacheMisses);
613     fprintf(cm_outFD, "\t%10d vcacheMisses\n", a_ovP->vcacheMisses);
614     fprintf(cm_outFD, "\t%10d cacheFilesReused\n", a_ovP->cacheFilesReused);
615     fprintf(cm_outFD, "\t%10d vcacheXAllocs\n", a_ovP->vcacheXAllocs);
616
617     fprintf(cm_outFD, "\t%10d bufAlloced\n", a_ovP->bufAlloced);
618     fprintf(cm_outFD, "\t%10d bufHits\n", a_ovP->bufHits);
619     fprintf(cm_outFD, "\t%10d bufMisses\n", a_ovP->bufMisses);
620     fprintf(cm_outFD, "\t%10d bufFlushDirty\n", a_ovP->bufFlushDirty);
621
622     fprintf(cm_outFD, "\t%10d LargeBlocksActive\n", a_ovP->LargeBlocksActive);
623     fprintf(cm_outFD, "\t%10d LargeBlocksAlloced\n",
624             a_ovP->LargeBlocksAlloced);
625     fprintf(cm_outFD, "\t%10d SmallBlocksActive\n", a_ovP->SmallBlocksActive);
626     fprintf(cm_outFD, "\t%10d SmallBlocksAlloced\n",
627             a_ovP->SmallBlocksAlloced);
628     fprintf(cm_outFD, "\t%10d OutStandingMemUsage\n",
629             a_ovP->OutStandingMemUsage);
630     fprintf(cm_outFD, "\t%10d OutStandingAllocs\n", a_ovP->OutStandingAllocs);
631     fprintf(cm_outFD, "\t%10d CallBackAlloced\n", a_ovP->CallBackAlloced);
632     fprintf(cm_outFD, "\t%10d CallBackFlushes\n", a_ovP->CallBackFlushes);
633
634     fprintf(cm_outFD, "\t%10d srvRecords\n", a_ovP->srvRecords);
635     fprintf(cm_outFD, "\t%10d srvNumBuckets\n", a_ovP->srvNumBuckets);
636     fprintf(cm_outFD, "\t%10d srvMaxChainLength\n", a_ovP->srvMaxChainLength);
637     fprintf(cm_outFD, "\t%10d srvMaxChainLengthHWM\n",
638             a_ovP->srvMaxChainLengthHWM);
639     fprintf(cm_outFD, "\t%10d srvRecordsHWM\n", a_ovP->srvRecordsHWM);
640
641     fprintf(cm_outFD, "\t%10d sysName_ID\n", a_ovP->sysName_ID);
642
643     fprintf(cm_outFD, "\tFile Server up/downtimes, same cell:\n");
644     Print_cm_UpDownStats(&(a_ovP->fs_UpDown[0]));
645
646     fprintf(cm_outFD, "\tFile Server up/downtimes, diff cell:\n");
647     Print_cm_UpDownStats(&(a_ovP->fs_UpDown[1]));
648
649     fprintf(cm_outFD, "\tVL Server up/downtimes, same cell:\n");
650     Print_cm_UpDownStats(&(a_ovP->vl_UpDown[0]));
651
652     fprintf(cm_outFD, "\tVL Server up/downtimes, diff cell:\n");
653     Print_cm_UpDownStats(&(a_ovP->vl_UpDown[1]));
654
655 }                               /*Print_cm_OverallPerfInfo */
656
657
658 /*------------------------------------------------------------------------
659  * Print_cm_PerfInfo
660  *
661  * Description:
662  *      Print out the AFSCB_XSTATSCOLL_PERF_INFO collection we just
663  *      received.
664  *
665  * Arguments:
666  *      None.
667  *
668  * Returns:
669  *      Nothing.
670  *
671  * Environment:
672  *      All the info we need is nestled into xstat_cm_Results.
673  *
674  * Side Effects:
675  *      As advertised.
676  *------------------------------------------------------------------------*/
677
678 void
679 Print_cm_PerfInfo(void)
680 {                               /*Print_cm_PerfInfo */
681     static afs_int32 perfLongs = (sizeof(struct afs_stats_CMPerf) >> 2);        /*Correct # longs to rcv */
682     afs_int32 numLongs;         /*# longwords received */
683     struct afs_stats_CMPerf *perfP;     /*Ptr to performance stats */
684     char *printableTime;        /*Ptr to printable time string */
685     time_t probeTime;
686
687     numLongs = xstat_cm_Results.data.AFSCB_CollData_len;
688     if (numLongs != perfLongs) {
689         fprintf(cm_outFD,
690                 " ** Data size mismatch in performance collection!\n");
691         fprintf(cm_outFD, "** Expecting %d, got %d\n", perfLongs, numLongs);
692         return;
693     }
694
695     probeTime = xstat_cm_Results.probeTime;
696     printableTime = ctime(&probeTime);
697     printableTime[strlen(printableTime) - 1] = '\0';
698     perfP = (struct afs_stats_CMPerf *)
699         (xstat_cm_Results.data.AFSCB_CollData_val);
700
701     fprintf(cm_outFD,
702             "AFSCB_XSTATSCOLL_PERF_INFO (coll %d) for CM %s\n[Probe %d, %s]\n\n",
703             xstat_cm_Results.collectionNumber,
704             xstat_cm_Results.connP->hostName, xstat_cm_Results.probeNum,
705             printableTime);
706
707     Print_cm_OverallPerfInfo(perfP);
708
709 }                               /*Print_cm_PerfInfo */
710
711
712 /*------------------------------------------------------------------------
713  * Print_cm_OpTiming
714  *
715  * Description:
716  *      Print out the contents of an FS RPC op timing structure.
717  *
718  * Arguments:
719  *      a_opIdx   : Index of the AFS operation we're printing number on.
720  *      a_opNames : Ptr to table of operaton names.
721  *      a_opTimeP : Ptr to the op timing structure to print.
722  *
723  * Returns:
724  *      Nothing.
725  *
726  * Environment:
727  *      Nothing interesting.
728  *
729  * Side Effects:
730  *      As advertised.
731  *------------------------------------------------------------------------*/
732
733 void
734 Print_cm_OpTiming(int a_opIdx, char *a_opNames[],
735                   struct afs_stats_opTimingData *a_opTimeP)
736 {                               /*Print_cm_OpTiming */
737
738     fprintf(cm_outFD,
739             "%15s: %d ops (%d OK); sum=%d.%06d, min=%d.%06d, max=%d.%06d\n",
740             a_opNames[a_opIdx], a_opTimeP->numOps, a_opTimeP->numSuccesses,
741             a_opTimeP->sumTime.tv_sec, a_opTimeP->sumTime.tv_usec,
742             a_opTimeP->minTime.tv_sec, a_opTimeP->minTime.tv_usec,
743             a_opTimeP->maxTime.tv_sec, a_opTimeP->maxTime.tv_usec);
744
745 }                               /*Print_cm_OpTiming */
746
747
748 /*------------------------------------------------------------------------
749  * Print_cm_XferTiming
750  *
751  * Description:
752  *      Print out the contents of a data transfer structure.
753  *
754  * Arguments:
755  *      a_opIdx : Index of the AFS operation we're printing number on.
756  *      a_xferP : Ptr to the data transfer structure to print.
757  *
758  * Returns:
759  *      Nothing.
760  *
761  * Environment:
762  *      Nothing interesting.
763  *
764  * Side Effects:
765  *      As advertised.
766  *------------------------------------------------------------------------*/
767
768 void
769 Print_cm_XferTiming(int a_opIdx, char *a_opNames[], 
770                     struct afs_stats_xferData *a_xferP)
771 {                               /*Print_cm_XferTiming */
772
773     fprintf(cm_outFD,
774             "%s: %d xfers (%d OK), time sum=%d.%06d, min=%d.%06d, max=%d.%06d\n",
775             a_opNames[a_opIdx], a_xferP->numXfers, a_xferP->numSuccesses,
776             a_xferP->sumTime.tv_sec, a_xferP->sumTime.tv_usec,
777             a_xferP->minTime.tv_sec, a_xferP->minTime.tv_usec,
778             a_xferP->maxTime.tv_sec, a_xferP->maxTime.tv_usec);
779     fprintf(cm_outFD, "\t[bytes: sum=%d, min=%d, max=%d]\n",
780             a_xferP->sumBytes, a_xferP->minBytes, a_xferP->maxBytes);
781     fprintf(cm_outFD,
782             "\t[buckets: 0: %d, 1: %d, 2: %d, 3: %d, 4: %d, 5: %d 6: %d, 7: %d, 8: %d]\n",
783             a_xferP->count[0], a_xferP->count[1], a_xferP->count[2],
784             a_xferP->count[3], a_xferP->count[4], a_xferP->count[5],
785             a_xferP->count[6], a_xferP->count[7], a_xferP->count[8]);
786
787 }                               /*Print_cm_XferTiming */
788
789
790 /*------------------------------------------------------------------------
791  * Print_cm_ErrInfo
792  *
793  * Description:
794  *      Print out the contents of an FS RPC error info structure.
795  *
796  * Arguments:
797  *      a_opIdx   : Index of the AFS operation we're printing.
798  *      a_opNames : Ptr to table of operation names.
799  *      a_opErrP  : Ptr to the op timing structure to print.
800  *
801  * Returns:
802  *      Nothing.
803  *
804  * Environment:
805  *      Nothing interesting.
806  *
807  * Side Effects:
808  *      As advertised.
809  *------------------------------------------------------------------------*/
810
811 void
812 Print_cm_ErrInfo(int a_opIdx, char *a_opNames[],
813                  struct afs_stats_RPCErrors *a_opErrP)
814 {                               /*Print_cm_ErrInfo */
815
816     fprintf(cm_outFD,
817             "%15s: %d server, %d network, %d prot, %d vol, %d busies, %d other\n",
818             a_opNames[a_opIdx], a_opErrP->err_Server, a_opErrP->err_Network,
819             a_opErrP->err_Protection, a_opErrP->err_Volume,
820             a_opErrP->err_VolumeBusies, a_opErrP->err_Other);
821
822 }                               /*Print_cm_ErrInfo */
823
824
825 /*------------------------------------------------------------------------
826  * Print_cm_RPCPerfInfo
827  *
828  * Description:
829  *      Print out a set of RPC performance numbers.
830  *
831  * Arguments:
832  *      a_rpcP : Ptr to RPC perf numbers to print.
833  *
834  * Returns:
835  *      Nothing.
836  *
837  * Environment:
838  *      Nothing interesting.
839  *
840  * Side Effects:
841  *      As advertised.
842  *------------------------------------------------------------------------*/
843
844 void
845 Print_cm_RPCPerfInfo(struct afs_stats_RPCOpInfo *a_rpcP)
846 {                               /*Print_cm_RPCPerfInfo */
847
848     int currIdx;                /*Loop variable */
849
850     /*
851      * Print the contents of each of the opcode-related arrays.
852      */
853     fprintf(cm_outFD, "FS Operation Timings:\n---------------------\n");
854     for (currIdx = 0; currIdx < AFS_STATS_NUM_FS_RPC_OPS; currIdx++)
855         Print_cm_OpTiming(currIdx, fsOpNames, &(a_rpcP->fsRPCTimes[currIdx]));
856
857     fprintf(cm_outFD, "\nError Info:\n-----------\n");
858     for (currIdx = 0; currIdx < AFS_STATS_NUM_FS_RPC_OPS; currIdx++)
859         Print_cm_ErrInfo(currIdx, fsOpNames, &(a_rpcP->fsRPCErrors[currIdx]));
860
861     fprintf(cm_outFD, "\nTransfer timings:\n-----------------\n");
862     for (currIdx = 0; currIdx < AFS_STATS_NUM_FS_XFER_OPS; currIdx++)
863         Print_cm_XferTiming(currIdx, xferOpNames,
864                             &(a_rpcP->fsXferTimes[currIdx]));
865
866     fprintf(cm_outFD, "\nCM Operation Timings:\n---------------------\n");
867     for (currIdx = 0; currIdx < AFS_STATS_NUM_CM_RPC_OPS; currIdx++)
868         Print_cm_OpTiming(currIdx, cmOpNames, &(a_rpcP->cmRPCTimes[currIdx]));
869
870 }                               /*Print_cm_RPCPerfInfo */
871
872
873 /*------------------------------------------------------------------------
874  * Print_cm_FullPerfInfo
875  *
876  * Description:
877  *      Print out a set of full performance numbers.
878  *
879  * Arguments:
880  *      None.
881  *
882  * Returns:
883  *      Nothing.
884  *
885  * Environment:
886  *      Nothing interesting.
887  *
888  * Side Effects:
889  *      As advertised.
890  *------------------------------------------------------------------------*/
891
892 void
893 Print_cm_FullPerfInfo(void)
894 {                               /*Print_cm_FullPerfInfo */
895
896     struct afs_stats_AuthentInfo *authentP;     /*Ptr to authentication stats */
897     struct afs_stats_AccessInfo *accessinfP;    /*Ptr to access stats */
898     static afs_int32 fullPerfLongs = (sizeof(struct afs_stats_CMFullPerf) >> 2);        /*Correct #longs */
899     afs_int32 numLongs;         /*# longs actually received */
900     struct afs_stats_CMFullPerf *fullP; /*Ptr to full perf info */
901     time_t probeTime;
902     char *printableTime;        /*Ptr to printable time string */
903
904     numLongs = xstat_cm_Results.data.AFSCB_CollData_len;
905     if (numLongs != fullPerfLongs) {
906         fprintf(cm_outFD,
907                 " ** Data size mismatch in performance collection!\n");
908         fprintf(cm_outFD, " ** Expecting %d, got %d\n", fullPerfLongs,
909                 numLongs);
910         return;
911     }
912
913     probeTime = xstat_cm_Results.probeTime;
914     printableTime = ctime(&probeTime);
915     printableTime[strlen(printableTime) - 1] = '\0';
916     fullP = (struct afs_stats_CMFullPerf *)
917         (xstat_cm_Results.data.AFSCB_CollData_val);
918
919     fprintf(cm_outFD,
920             "AFSCB_XSTATSCOLL_FULL_PERF_INFO (coll %d) for CM %s\n[Probe %d, %s]\n\n",
921             xstat_cm_Results.collectionNumber,
922             xstat_cm_Results.connP->hostName, xstat_cm_Results.probeNum,
923             printableTime);
924
925     /*
926      * Print the overall numbers first, followed by all of the RPC numbers,
927      * then each of the other groupings.
928      */
929     fprintf(cm_outFD,
930             "Overall Performance Info:\n-------------------------\n");
931     Print_cm_OverallPerfInfo(&(fullP->perf));
932     fprintf(cm_outFD, "\n");
933     Print_cm_RPCPerfInfo(&(fullP->rpc));
934
935     authentP = &(fullP->authent);
936     fprintf(cm_outFD, "\nAuthentication info:\n--------------------\n");
937     fprintf(cm_outFD,
938             "\t%d PAGS, %d records (%d auth, %d unauth), %d max in PAG, chain max: %d\n",
939             authentP->curr_PAGs, authentP->curr_Records,
940             authentP->curr_AuthRecords, authentP->curr_UnauthRecords,
941             authentP->curr_MaxRecordsInPAG, authentP->curr_LongestChain);
942     fprintf(cm_outFD, "\t%d PAG creations, %d tkt updates\n",
943             authentP->PAGCreations, authentP->TicketUpdates);
944     fprintf(cm_outFD,
945             "\t[HWMs: %d PAGS, %d records, %d max in PAG, chain max: %d]\n",
946             authentP->HWM_PAGs, authentP->HWM_Records,
947             authentP->HWM_MaxRecordsInPAG, authentP->HWM_LongestChain);
948
949     accessinfP = &(fullP->accessinf);
950     fprintf(cm_outFD,
951             "\n[Un]replicated accesses:\n------------------------\n");
952     fprintf(cm_outFD,
953             "\t%d unrep, %d rep, %d reps accessed, %d max reps/ref, %d first OK\n\n",
954             accessinfP->unreplicatedRefs, accessinfP->replicatedRefs,
955             accessinfP->numReplicasAccessed, accessinfP->maxReplicasPerRef,
956             accessinfP->refFirstReplicaOK);
957
958     /* There really isn't any authorship info
959      * authorP = &(fullP->author); */
960
961 }                               /*Print_cm_FullPerfInfo */
962
963 /*------------------------------------------------------------------------
964  * afsmon_cmOutput()
965  *
966  * Description:
967  *      Prints the contents of xstat_cm_Results to an output file. The 
968  *      output is either in a compact (longs only) format or a detailed
969  *      format giving the names of each of the datums. Output is appended.
970  *
971  * Arguments:
972  *      Name of output file.
973  *      Flag to indicate if detailed output is required.
974  *
975  * Returns:
976  *      Nothing.
977  *
978  * Environment:
979  *      All the info we need is nestled into xstat_cm_Results.
980  *
981  * Side Effects:
982  *      As advertised.
983  *------------------------------------------------------------------------*/
984 int
985 afsmon_cmOutput(char *a_outfile,                /* ptr to output file name */
986                 int a_detOutput)                /* detailed output ? */
987 {
988
989     static char rn[] = "afsmon_cmOutput";       /* routine name */
990     char *printTime;            /* ptr to time string */
991     char *hostname;             /* fileserner name */
992     afs_int32 numLongs;         /* longwords in result */
993     afs_int32 *currLong;        /* ptr to longwords in result */
994     int i;
995     time_t probeTime;
996
997     if (afsmon_debug) {
998         fprintf(debugFD, "[ %s ] Called, a_outfile= %s, a_detOutput= %d\n",
999                 rn, a_outfile, a_detOutput);
1000         fflush(debugFD);
1001     }
1002
1003     /* need to lock this file before writing */
1004     cm_outFD = fopen(a_outfile, "a");
1005     if (cm_outFD == (FILE *) 0) {
1006         sprintf(errMsg, "[ %s ] failed to open output file %s", rn,
1007                 a_outfile);
1008         afsmon_Exit(1);
1009     }
1010
1011     /* get the probe time and strip the \n at the end */
1012     probeTime = xstat_cm_Results.probeTime;
1013     printTime = ctime(&probeTime);
1014     printTime[strlen(printTime) - 1] = '\0';
1015     hostname = xstat_cm_Results.connP->hostName;
1016
1017     /* print "time hostname CM" prefix  */
1018     fprintf(cm_outFD, "\n%s %s CM ", printTime, hostname);
1019
1020     /* if probe failed print -1 and vanish */
1021     if (xstat_cm_Results.probeOK) {
1022         fprintf(cm_outFD, "-1\n");
1023         fclose(cm_outFD);
1024         return (0);
1025     }
1026
1027     /* print out the probe information as  long words */
1028     numLongs = xstat_cm_Results.data.AFSCB_CollData_len;
1029     currLong = (afs_int32 *) (xstat_cm_Results.data.AFSCB_CollData_val);
1030
1031     for (i = 0; i < numLongs; i++) {
1032         fprintf(cm_outFD, "%d ", *currLong++);
1033     }
1034     fprintf(cm_outFD, "\n\n");
1035
1036     /* print out detailed statistics */
1037     if (a_detOutput) {
1038         Print_cm_FullPerfInfo();
1039         fflush(cm_outFD);
1040     }
1041
1042     if (fclose(cm_outFD))
1043         if (afsmon_debug) {
1044             fprintf(debugFD, "[ %s ] failed to close %s\n", rn, a_outfile);
1045             fflush(debugFD);
1046         }
1047
1048     return (0);
1049 }