|
xrootd
|
00001 #ifndef __XRDXROOTDMONITOR__ 00002 #define __XRDXROOTDMONITOR__ 00003 /******************************************************************************/ 00004 /* */ 00005 /* X r d X r o o t d M o n i t o r . h h */ 00006 /* */ 00007 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University */ 00008 /* All Rights Reserved */ 00009 /* Produced by Andrew Hanushevsky for Stanford University under contract */ 00010 /* DE-AC03-76-SFO0515 with the Department of Energy */ 00011 /******************************************************************************/ 00012 00013 #include <inttypes.h> 00014 #include <time.h> 00015 #include <netinet/in.h> 00016 #include <sys/types.h> 00017 00018 #include "XrdNet/XrdNetPeer.hh" 00019 #include "XrdSys/XrdSysPthread.hh" 00020 #include "XrdXrootd/XrdXrootdMonData.hh" 00021 #include "XProtocol/XPtypes.hh" 00022 00023 /******************************************************************************/ 00024 /* X r d M o n i t o r */ 00025 /******************************************************************************/ 00026 00027 #define XROOTD_MON_ALL 1 00028 #define XROOTD_MON_FILE 2 00029 #define XROOTD_MON_IO 4 00030 #define XROOTD_MON_INFO 8 00031 #define XROOTD_MON_STAGE 16 00032 #define XROOTD_MON_USER 32 00033 #define XROOTD_MON_AUTH 64 00034 #define XROOTD_MON_PATH (XROOTD_MON_IO | XROOTD_MON_FILE) 00035 #define XROOTD_MON_REDR 128 00036 #define XROOTD_MON_IOV 256 00037 00038 class XrdScheduler; 00039 00040 class XrdXrootdMonitor 00041 { 00042 public: 00043 friend class XrdXrootdMonitorDummy; // Avoid stupid gcc warnings 00044 00045 // All values for Add_xx() must be passed in network byte order 00046 // 00047 inline void Add_rd(kXR_unt32 dictid, 00048 kXR_int32 rlen, 00049 kXR_int64 offset) 00050 {Add_io(dictid, rlen, offset);} 00051 00052 inline void Add_rv(kXR_unt32 dictid, 00053 kXR_int32 rlen, 00054 kXR_int16 vcnt, 00055 kXR_char vseq) 00056 {if (lastWindow != currWindow) Mark(); 00057 else if (nextEnt == lastEnt) Flush(); 00058 monBuff->info[nextEnt].arg0.id[0] = XROOTD_MON_READV; 00059 monBuff->info[nextEnt].arg0.id[1] = vseq; 00060 monBuff->info[nextEnt].arg0.sVal[1] = vcnt; 00061 monBuff->info[nextEnt].arg0.rTot[1] = 0; 00062 monBuff->info[nextEnt].arg1.buflen = rlen; 00063 monBuff->info[nextEnt++].arg2.dictid = dictid; 00064 } 00065 00066 inline void Add_wr(kXR_unt32 dictid, 00067 kXR_int32 wlen, 00068 kXR_int64 offset) 00069 {Add_io(dictid,(kXR_int32)htonl(-wlen),offset);} 00070 00071 void appID(char *id); 00072 00073 static XrdXrootdMonitor *Alloc(int force=0); 00074 00075 void Close(kXR_unt32 dictid, long long rTot, long long wTot); 00076 00077 void Disc(kXR_unt32 dictid, int csec); 00078 00079 static void Defaults(char *dest1, int m1, char *dest2, int m2); 00080 static void Defaults(int msz, int rsz, int wsz, 00081 int flush, int flash); 00082 00083 void Dup(XrdXrootdMonTrace *mrec); 00084 00085 static int Init(XrdScheduler *sp, XrdSysError *errp); 00086 00087 static kXR_unt32 Map(const char code,const char *uname,const char *path); 00088 00089 void Open(kXR_unt32 dictid, off_t fsize); 00090 00091 static time_t Tick(); 00092 00093 static void unAlloc(XrdXrootdMonitor *monp); 00094 00095 static XrdXrootdMonitor *altMon; 00096 static char monIO; 00097 static char monINFO; 00098 static char monFILE; 00099 static char monREDR; 00100 static char monSTAGE; 00101 static char monUSER; 00102 static char monAUTH; 00103 00104 XrdXrootdMonitor(); 00105 00106 private: 00107 ~XrdXrootdMonitor(); 00108 00109 inline void Add_io(kXR_unt32 dictid, kXR_int32 buflen, 00110 kXR_int64 offset); 00111 unsigned char do_Shift(long long xTot, unsigned int &xVal); 00112 static void fillHeader(XrdXrootdMonHeader *hdr, 00113 const char id, int size); 00114 void Flush(); 00115 void Mark(); 00116 static int Send(int mmode, void *buff, int size); 00117 static void startClock(); 00118 00119 static XrdScheduler *Sched; 00120 static XrdSysError *eDest; 00121 static XrdSysMutex windowMutex; 00122 static int monFD; 00123 static char *Dest1; 00124 static int monMode1; 00125 static struct sockaddr InetAddr1; 00126 static char *Dest2; 00127 static int monMode2; 00128 static struct sockaddr InetAddr2; 00129 XrdXrootdMonBuff *monBuff; 00130 static int monBlen; 00131 int nextEnt; 00132 static int lastEnt; 00133 static int autoFlash; 00134 static int autoFlush; 00135 static int FlushTime; 00136 static kXR_int32 startTime; 00137 kXR_int32 lastWindow; 00138 static kXR_int32 currWindow; 00139 static kXR_int32 sizeWindow; 00140 static int isEnabled; 00141 static int numMonitor; 00142 static int monRlen; 00143 }; 00144 00145 /******************************************************************************/ 00146 /* I n l i n e F u n c t i o n s */ 00147 /******************************************************************************/ 00148 /******************************************************************************/ 00149 /* A d d _ i o */ 00150 /******************************************************************************/ 00151 00152 void XrdXrootdMonitor::Add_io(kXR_unt32 dictid,kXR_int32 blen,kXR_int64 offset) 00153 {if (lastWindow != currWindow) Mark(); 00154 else if (nextEnt == lastEnt) Flush(); 00155 monBuff->info[nextEnt].arg0.val = offset; 00156 monBuff->info[nextEnt].arg1.buflen = blen; 00157 monBuff->info[nextEnt++].arg2.dictid = dictid; 00158 } 00159 #endif
1.7.5