00001 #ifndef __XRDXROOTDMONITOR__
00002 #define __XRDXROOTDMONITOR__
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <inttypes.h>
00016 #include <time.h>
00017 #include <netinet/in.h>
00018 #include <sys/types.h>
00019
00020 #include "XrdNet/XrdNetPeer.hh"
00021 #include "XrdSys/XrdSysPthread.hh"
00022 #include "XrdXrootd/XrdXrootdMonData.hh"
00023 #include "XProtocol/XPtypes.hh"
00024
00025
00026
00027
00028
00029 #define XROOTD_MON_ALL 1
00030 #define XROOTD_MON_FILE 2
00031 #define XROOTD_MON_IO 4
00032 #define XROOTD_MON_INFO 8
00033 #define XROOTD_MON_STAGE 16
00034 #define XROOTD_MON_USER 32
00035 #define XROOTD_MON_PATH (XROOTD_MON_IO | XROOTD_MON_FILE)
00036
00037 class XrdScheduler;
00038
00039 class XrdXrootdMonitor
00040 {
00041 public:
00042 friend class XrdXrootdMonitorDummy;
00043
00044
00045
00046 inline void Add_rd(kXR_unt32 dictid,
00047 kXR_int32 rlen,
00048 kXR_int64 offset)
00049 {Add_io(dictid, rlen, offset);}
00050
00051 inline void Add_wr(kXR_unt32 dictid,
00052 kXR_int32 wlen,
00053 kXR_int64 offset)
00054 {unsigned int temp = ~ntohl(wlen)+1;
00055 Add_io(dictid,
00056 (kXR_int32)htonl(temp), offset);
00057 }
00058
00059 void appID(char *id);
00060
00061 static XrdXrootdMonitor *Alloc(int force=0);
00062
00063 void Close(kXR_unt32 dictid, long long rTot, long long wTot);
00064
00065 void Disc(kXR_unt32 dictid, int csec);
00066
00067 static void Defaults(char *dest1, int m1, char *dest2, int m2);
00068 static void Defaults(int msz, int wsz, int flush);
00069
00070 void Dup(XrdXrootdMonTrace *mrec);
00071
00072 static int Init(XrdScheduler *sp, XrdSysError *errp);
00073
00074 static kXR_unt32 Map(const char code,const char *uname,const char *path);
00075
00076 void Open(kXR_unt32 dictid, off_t fsize);
00077
00078 static time_t Tick();
00079
00080 static void unAlloc(XrdXrootdMonitor *monp);
00081
00082 static XrdXrootdMonitor *altMon;
00083 static char monIO;
00084 static char monINFO;
00085 static char monFILE;
00086 static char monSTAGE;
00087 static char monUSER;
00088
00089 XrdXrootdMonitor();
00090
00091 private:
00092 ~XrdXrootdMonitor();
00093
00094 inline void Add_io(kXR_unt32 dictid, kXR_int32 buflen,
00095 kXR_int64 offset);
00096 unsigned char do_Shift(long long xTot, unsigned int &xVal);
00097 static void fillHeader(XrdXrootdMonHeader *hdr,
00098 const char id, int size);
00099 void Flush();
00100 void Mark();
00101 static int Send(int mmode, void *buff, int size);
00102 static void startClock();
00103
00104 static XrdScheduler *Sched;
00105 static XrdSysError *eDest;
00106 static XrdSysMutex windowMutex;
00107 static int monFD;
00108 static char *Dest1;
00109 static int monMode1;
00110 static struct sockaddr InetAddr1;
00111 static char *Dest2;
00112 static int monMode2;
00113 static struct sockaddr InetAddr2;
00114 XrdXrootdMonBuff *monBuff;
00115 static int monBlen;
00116 int nextEnt;
00117 static int lastEnt;
00118 static int autoFlush;
00119 static int FlushTime;
00120 static kXR_int32 startTime;
00121 kXR_int32 lastWindow;
00122 static kXR_int32 currWindow;
00123 static kXR_int32 sizeWindow;
00124 static int isEnabled;
00125 static int numMonitor;
00126 };
00127
00128
00129
00130
00131
00132
00133
00134
00135 void XrdXrootdMonitor::Add_io(kXR_unt32 dictid,kXR_int32 blen,kXR_int64 offset)
00136 {if (lastWindow != currWindow) Mark();
00137 else if (nextEnt == lastEnt) Flush();
00138 monBuff->info[nextEnt].arg0.val = offset;
00139 monBuff->info[nextEnt].arg1.buflen = blen;
00140 monBuff->info[nextEnt++].arg2.dictid = dictid;
00141 }
00142 #endif