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