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