XRootD
Loading...
Searching...
No Matches
XrdBwmLogger Class Reference

#include <XrdBwmLogger.hh>

+ Collaboration diagram for XrdBwmLogger:

Classes

struct  Info
 

Public Member Functions

 XrdBwmLogger (const char *Target)
 
 ~XrdBwmLogger ()
 
void Event (Info &eInfo)
 
const char * Prog ()
 
void sendEvents (void)
 
int Start (XrdSysError *eobj)
 

Detailed Description

Definition at line 40 of file XrdBwmLogger.hh.


Class Documentation

◆ XrdBwmLogger::Info

struct XrdBwmLogger::Info

Definition at line 44 of file XrdBwmLogger.hh.

+ Collaboration diagram for XrdBwmLogger::Info:
Class Members
time_t ATime
time_t BTime
time_t CTime
int ESec
char Flow
const char * lclNode
const char * Lfn
int numqIn
int numqOut
int numqXeq
const char * rmtNode
long long Size
const char * Tident

Constructor & Destructor Documentation

◆ XrdBwmLogger()

XrdBwmLogger::XrdBwmLogger ( const char * Target)

Definition at line 79 of file XrdBwmLogger.cc.

80{
81
82// Set common variables
83//
84 theTarget = strdup(Target);
85 eDest = 0;
86 theProg = 0;
87 msgFirst = msgLast = msgFree = 0;
88 tid = 0;
89 msgFD = 0;
90 endIT = 0;
91 theEOL= '\n';
92 msgsInQ = 0;
93}

◆ ~XrdBwmLogger()

XrdBwmLogger::~XrdBwmLogger ( )

Definition at line 99 of file XrdBwmLogger.cc.

100{
101 XrdBwmLoggerMsg *tp;
102
103// Kill the notification thread. This may cause a msg block to be orphaned
104// but, in practice, this object does not really get deleted after being
105// started. So, the problem is moot.
106//
107 endIT = 1;
108 if (tid) XrdSysThread::Kill(tid);
109
110// Release all queued message bocks
111//
112 qMut.Lock();
113 while ((tp = msgFirst)) {msgFirst = tp->next; delete tp;}
114 if (theTarget) free(theTarget);
115 if (msgFD >= 0) close(msgFD);
116 if (theProg) delete theProg;
117 qMut.UnLock();
118
119// Release all free message blocks
120//
121 fMut.Lock();
122 while ((tp = msgFree)) {msgFree = tp->next; delete tp;}
123 fMut.UnLock();
124}
#define close(a)
Definition XrdPosix.hh:43
XrdBwmLoggerMsg * next
static int Kill(pthread_t tid)

References close, XrdSysThread::Kill(), and XrdBwmLoggerMsg::next.

+ Here is the call graph for this function:

Member Function Documentation

◆ Event()

void XrdBwmLogger::Event ( Info & eInfo)

Definition at line 130 of file XrdBwmLogger.cc.

131{
132 static int warnings = 0;
133 XrdBwmLoggerMsg *tp;
134
135// Get a message block
136//
137 if (!(tp = getMsg()))
138 {if ((++warnings & 0xff) == 1)
139 eDest->Emsg("Notify", "Ran out of logger message objects;",
140 eInfo.Tident, "event not logged.");
141 return;
142 }
143
144// Format the message
145//
146 tp->Tlen = snprintf(tp->Text, XrdBwmLoggerMsg::msgSize,
147 "<stats id=\"bwm\"><tid>%s</tid><lfn>%s</lfn>"
148 "<lcl>%s</lcl><rmt>%s</rmt><flow>%c</flow>"
149 "<at>%lld</at><bt>%lld</bt><ct>%lld</ct>"
150 "<iq>%d</iq><oq>%d</oq><xq>%d</xq>"
151 "<sz>%lld<sz><esec>%d</esec></stats>%c",
152 eInfo.Tident, eInfo.Lfn, eInfo.lclNode, eInfo.rmtNode,
153 eInfo.Flow, (long long) eInfo.ATime,
154 (long long) eInfo.BTime, (long long) eInfo.CTime,
155 eInfo.numqIn, eInfo.numqOut, eInfo.numqXeq, eInfo.Size,
156 eInfo.ESec, theEOL);
157
158// Either log this or put the message on the queue and return
159//
160 tp->next = 0;
161 qMut.Lock();
162 if (msgLast) {msgLast->next = tp; msgLast = tp;}
163 else msgFirst = msgLast = tp;
164 qMut.UnLock();
165 qSem.Post();
166}
char Text[msgSize]
static const int msgSize

References XrdBwmLogger::Info::ATime, XrdBwmLogger::Info::BTime, XrdBwmLogger::Info::CTime, XrdBwmLogger::Info::ESec, XrdBwmLogger::Info::Flow, XrdBwmLogger::Info::lclNode, XrdBwmLogger::Info::Lfn, XrdBwmLoggerMsg::msgSize, XrdBwmLoggerMsg::next, XrdBwmLogger::Info::numqIn, XrdBwmLogger::Info::numqOut, XrdBwmLogger::Info::numqXeq, XrdBwmLogger::Info::rmtNode, XrdBwmLogger::Info::Size, XrdBwmLoggerMsg::Text, XrdBwmLogger::Info::Tident, and XrdBwmLoggerMsg::Tlen.

◆ Prog()

const char * XrdBwmLogger::Prog ( )
inline

Definition at line 62 of file XrdBwmLogger.hh.

62{return theTarget;}

◆ sendEvents()

void XrdBwmLogger::sendEvents ( void )

Definition at line 172 of file XrdBwmLogger.cc.

173{
174 XrdBwmLoggerMsg *tp;
175 const char *theData[2] = {0,0};
176 int theDlen[2] = {0,0};
177
178// This is an endless loop that just gets things off the event queue and
179// send them out. This allows us to only hang a simgle thread should the
180// receiver get blocked, instead of the whole process.
181//
182 while(1)
183 {qSem.Wait();
184 qMut.Lock();
185 if (endIT) break;
186 if ((tp = msgFirst) && !(msgFirst = tp->next)) msgLast = 0;
187 qMut.UnLock();
188 if (tp)
189 {if (!theProg) Feed(tp->Text, tp->Tlen);
190 else {theData[0] = tp->Text; theDlen[0] = tp->Tlen;
191 theProg->Feed(theData, theDlen);
192
193 }
194 retMsg(tp);
195 }
196 }
197 qMut.UnLock();
198}

References XrdBwmLoggerMsg::next, XrdBwmLoggerMsg::Text, and XrdBwmLoggerMsg::Tlen.

Referenced by XrdBwmLoggerSend().

+ Here is the caller graph for this function:

◆ Start()

int XrdBwmLogger::Start ( XrdSysError * eobj)

Definition at line 204 of file XrdBwmLogger.cc.

205{
206 int rc;
207
208// Set the error object pointer
209//
210 eDest = eobj;
211
212// Check if we need to create a socket to a path
213//
214 if (!strcmp("*", theTarget)) {msgFD = -1; theEOL = '\0';}
215 else if (*theTarget == '>')
216 {XrdNetSocket *msgSock;
217 if (!(msgSock = XrdNetSocket::Create(eobj, theTarget+1, 0, 0660,
218 XRDNET_FIFO))) return -1;
219 msgFD = msgSock->Detach();
220 delete msgSock;
221 }
222 else {// Allocate a new program object if we don't have one
223 //
224 if (theProg) return 0;
225 theProg = new XrdOucProg(eobj);
226
227 // Setup the program
228 //
229 if (theProg->Setup(theTarget, eobj)) return -1;
230 if ((rc = theProg->Start()))
231 {eobj->Emsg("Logger", rc, "start event collector"); return -1;}
232 }
233
234// Now start a thread to get messages and send them to the collector
235//
236 if ((rc = XrdSysThread::Run(&tid, XrdBwmLoggerSend, static_cast<void *>(this),
237 0, "Log message sender")))
238 {eobj->Emsg("Logger", rc, "create log message sender thread");
239 return -1;
240 }
241
242// All done
243//
244 return 0;
245}
void * XrdBwmLoggerSend(void *pp)
#define XRDNET_FIFO
Definition XrdNetOpts.hh:83
static XrdNetSocket * Create(XrdSysError *Say, const char *path, const char *fn, mode_t mode, int isudp=0)
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
static int Run(pthread_t *, void *(*proc)(void *), void *arg, int opts=0, const char *desc=0)

References XrdNetSocket::Create(), XrdNetSocket::Detach(), XrdSysError::Emsg(), XrdSysThread::Run(), XrdBwmLoggerSend(), and XRDNET_FIFO.

+ Here is the call graph for this function:

The documentation for this class was generated from the following files: