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