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