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