stats.c

Go to the documentation of this file.
00001 /*
00002 
00003   Copyright (C) 2000, 2001, Silicon Graphics, Inc.  All Rights Reserved.
00004 
00005   This program is free software; you can redistribute it and/or modify it
00006   under the terms of version 2.1 of the GNU Lesser General Public License 
00007   as published by the Free Software Foundation.
00008 
00009   This program is distributed in the hope that it would be useful, but
00010   WITHOUT ANY WARRANTY; without even the implied warranty of
00011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
00012 
00013   Further, this software is distributed without any warranty that it is
00014   free of the rightful claim of any third person regarding infringement 
00015   or the like.  Any license provided herein, whether implied or 
00016   otherwise, applies only to this software file.  Patent licenses, if
00017   any, provided herein do not apply to combinations of this program with 
00018   other software, or any other product whatsoever.  
00019 
00020   You should have received a copy of the GNU Lesser General Public 
00021   License along with this program; if not, write the Free Software 
00022   Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, 
00023   USA.
00024 
00025   Contact information:  Silicon Graphics, Inc., 1600 Amphitheatre Pky,
00026   Mountain View, CA 94043, or:
00027 
00028   http://www.sgi.com
00029 
00030   For further information regarding this notice, see:
00031 
00032   http://oss.sgi.com/projects/GenInfo/NoticeExplan
00033 
00034 */
00035 
00036 
00037 
00038 #pragma ident "@(#) libf/fio/stats.c    92.1    06/21/99 10:37:55"
00039 
00040 /*
00041  *      stats.c         Fortran I/O statistics support routines.  This
00042  *                      code is common between the CRAY Y-MP and the 
00043  *                      CRAY-2.  Any changes to one copy should also be
00044  *                      made in the other.
00045  */
00046 #if     !defined(_CRAYMPP) && defined(_UNICOS)
00047 #define _STATS_ENABLED
00048 #endif
00049 
00050 #ifdef  _STATS_ENABLED
00051 extern int _pstatfd;            /* file descriptor of stat pipe */
00052 #endif
00053   
00054 #include <errno.h>
00055 #if !defined(_ABSOFT)
00056 #include <malloc.h>
00057 #else
00058 #include <stdlib.h>
00059 #endif
00060 #include <string.h>
00061 #include <unistd.h>
00062 #include "fio.h"
00063 
00064 /*
00065  * _ft_stopen   - Initialize unit fields associated with statistics gathering.
00066  *                Allocate a close packet. Send Fortran open packet to procstat.
00067  *                This should be the last routine called during open processing
00068  *                to ensure that an open packet is sent only when an open 
00069  *                succeeds.
00070  *
00071  * Return value:  0 on normal exit, -1 with errno set on error.
00072  */
00073 _ft_stopen(
00074         unit    *cup,   /* unit pointer */
00075         char    *atstr) /* assign attributes associated with the file or unit */
00076 {
00077 #ifndef _STATS_ENABLED
00078                                 /* No procstat support for MPP or SPARC yet */
00079         return(0);              /* normal return */
00080 #else
00081         unum_t          unum;
00082         int             fd;             /* system file descriptor number */
00083         int             pktsiz;
00084         int             limit;
00085         int             len_name;
00086         int             len_attr;
00087         char            *cp;
00088         char            *file_name;
00089         union stat_ntry *sp;
00090         union stat_ntry open_packet;
00091 
00092         if (cup == NULL)
00093                 return(0);
00094 
00095         fd      = cup->usysfd;
00096 
00097         if (STDIN_FILENO <= fd && fd <= STDERR_FILENO)
00098                 return(0);      /* no Fortran stats for standard files for now*/
00099 
00100         file_name       = (cup->ufnm != NULL ? cup->ufnm : "(unnamed)");
00101         
00102         /*
00103          * Initialize the open packet.
00104          *
00105          * Notice that pktsiz includes the null terminator for the filename
00106          * since the size of the fname[1] field ensures room for an extra byte.
00107          */
00108         len_name        = strlen(file_name);
00109         len_attr        = (atstr == NULL) ? 0 : strlen(atstr);
00110         pktsiz  = MIN(MAXPACK,
00111                      sizeof(open_packet.fopn_pkt) +
00112                      len_name + 1 + len_attr + 1);
00113         open_packet.fopn_pkt.h.pktsiz   = pktsiz;
00114         open_packet.fopn_pkt.h.pid      = getpid();
00115         open_packet.fopn_pkt.h.typ      = FOPEN_PACK;
00116         open_packet.fopn_pkt.h.tstmp    = _rtc();
00117         open_packet.fopn_pkt.h.rsv0     = 0;
00118         open_packet.fopn_pkt.h.rsv1     = 0;
00119         open_packet.fopn_pkt.h.rsv2     = 0;
00120         open_packet.fopn_pkt.h.rsv3     = 0;
00121         open_packet.fopn_pkt.unitnum    = cup->uid;
00122         open_packet.fopn_pkt.iotype     = IO_TYPE(cup);
00123         open_packet.fopn_pkt.fstruct    = _deduce_fstruct(cup->ufs,
00124                                         (struct fdinfo*)cup->ufp.fdc,cup->ufmt);
00125         open_packet.fopn_pkt.sys_fd     = fd;
00126         open_packet.fopn_pkt.smode      = 0;
00127         open_packet.fopn_pkt.recl       = cup->urecl;
00128         open_packet.fopn_pkt.rsv1       = 0;
00129         open_packet.fopn_pkt.rsv2       = 0;
00130         open_packet.fopn_pkt.rsv3       = 0;
00131 
00132         cp      = &open_packet.fopn_pkt.strings[0];
00133         limit   = pktsiz - (cp - (char*)&open_packet);
00134 
00135         if (len_name > limit - 1)
00136                 len_name        = limit - 1;
00137         if (len_name >= 0) {    /* truncate name to max length of packet */
00138                 (void)memcpy(cp, file_name, len_name);  /* copy file name */
00139                 cp[len_name]    = '\0';
00140         }
00141         
00142         cp    += len_name + 1;          /* skip over name & null terminator */
00143         limit -= len_name + 1;
00144 
00145         if (len_attr > limit - 1)
00146                 len_attr        = limit - 1;
00147         if (len_attr >= 0) {            /* don't copy of no room or no attrs */
00148                 (void)memcpy(cp, atstr, len_attr);      /* copy assign attrs */
00149                 cp[len_attr]    = '\0';
00150         }
00151 
00152         /* 
00153          * Allocate and zero the close packet.
00154          */
00155         if ((sp = (union stat_ntry *)malloc(sizeof(union stat_ntry))) == NULL) {
00156                 errno   = FENOMEMY;
00157                 return(-1);
00158         }
00159         cup->ftstat     = sp;
00160         memset((char*)sp, 0, sizeof(*(cup->ftstat)));
00161 
00162         /*
00163          * Now send open packet.  The open has succeeded.
00164          */
00165         (void)write(    _pstatfd,
00166                         (char*)&open_packet,
00167                         open_packet.fopn_pkt.h.pktsiz);
00168 
00169         return(0);              /* normal return */
00170 #endif
00171 }
00172 /*
00173  * _ft_stclose  - Send a close packet at the end of close processing for
00174  *                a particular unit.  Then deallocate the close packet.
00175  *
00176  * Return value:  0 on normal exit, -1 with errno set otherwise.
00177  */
00178 _ft_stclose(unit *cup)
00179 {
00180 #ifndef _STATS_ENABLED
00181                                 /* No procstat support for MPP or SPARC yet */
00182         return(0);              /* normal return */
00183 #else
00184         int             pktsiz;
00185         char            *file_name;
00186         union stat_ntry *sp;
00187 
00188         if (cup->ftstat == NULL)
00189                 return(0);
00190 
00191         file_name       = (cup->ufnm != NULL ? cup->ufnm : "(unnamed)");
00192 
00193         /*
00194          * Fill in the close packet.
00195          */
00196         sp                      = cup->ftstat;
00197         pktsiz                  = sizeof(sp->fcls_pkt);
00198         sp->fcls_pkt.h.pktsiz   = pktsiz;
00199         sp->fcls_pkt.h.pid      = getpid();
00200         sp->fcls_pkt.h.typ      = FCLOSE_PACK;
00201         sp->fcls_pkt.h.tstmp    = _rtc();
00202         sp->fcls_pkt.h.rsv0     = 0;
00203         sp->fcls_pkt.h.rsv1     = 0;
00204         sp->fcls_pkt.h.rsv2     = 0;
00205         sp->fcls_pkt.h.rsv3     = 0;
00206         sp->fcls_pkt.unitnum    = cup->uid;
00207         sp->fcls_pkt.iotype     = IO_TYPE(cup);
00208         sp->fcls_pkt.sys_fd     = cup->usysfd;
00209         sp->fcls_pkt.smode      = 0;
00210         sp->fcls_pkt.rsv1       = 0;
00211         sp->fcls_pkt.rsv2       = 0;
00212         sp->fcls_pkt.rsv3       = 0;
00213         sp->fcls_pkt.rsv4       = 0;
00214         sp->fcls_pkt.rsv5       = 0;
00215         sp->fcls_pkt.rsv6       = 0;
00216         sp->fcls_pkt.rsv7       = 0;
00217 
00218         /*
00219          * fname gets the first 15 characters of the file name.  The 
00220          * complete file name can be found in the open packet.
00221          */
00222         (void) strncpy(&sp->fcls_pkt.fname[0], file_name, 15);
00223         sp->fcls_pkt.fname[15]  = '\0';
00224 
00225         /*
00226          * Now send the close packet, and then deallocate it.
00227          */
00228         (void)write(_pstatfd, (char*)sp, sp->fcls_pkt.h.pktsiz);
00229         free(sp);
00230         cup->ftstat     = NULL;
00231         
00232         return(0);
00233 #endif
00234 }

Generated on Tue Nov 17 05:54:42 2009 for Open64 (mfef90, whirl2f, and IR tools) by  doxygen 1.6.1