XRootD
XrdXrootdMonFile Class Reference

#include <XrdXrootdMonFile.hh>

+ Inheritance diagram for XrdXrootdMonFile:
+ Collaboration diagram for XrdXrootdMonFile:

Public Member Functions

 XrdXrootdMonFile ()
 
 ~XrdXrootdMonFile ()
 
void DoIt ()
 

Static Public Member Functions

static void Close (XrdXrootdFileStats *fsP, bool isDisc=false)
 
static void Defaults (int intv, int opts, int iocnt, int fbsz)
 
static void Disc (unsigned int usrID)
 
static bool Init ()
 
static void Open (XrdXrootdFileStats *fsP, const char *Path, unsigned int uDID, bool isRW)
 

Detailed Description

Definition at line 42 of file XrdXrootdMonFile.hh.

Constructor & Destructor Documentation

◆ XrdXrootdMonFile()

XrdXrootdMonFile::XrdXrootdMonFile ( )
inline

Definition at line 59 of file XrdXrootdMonFile.hh.

59 : XrdJob("monitor fstat") {}
XrdJob(const char *desc="")
Definition: XrdJob.hh:51

Referenced by Init().

+ Here is the caller graph for this function:

◆ ~XrdXrootdMonFile()

XrdXrootdMonFile::~XrdXrootdMonFile ( )
inline

Definition at line 60 of file XrdXrootdMonFile.hh.

60 {}

Member Function Documentation

◆ Close()

void XrdXrootdMonFile::Close ( XrdXrootdFileStats *  fsP,
bool  isDisc = false 
)
static

Definition at line 111 of file XrdXrootdMonFile.cc.

112 {
113  XrdXrootdMonFileCLS cRec;
114  char *cP;
115  int iEnt, iMap, iSlot;
116 
117 // If this object was registered for I/O reporting, deregister it. Then mark
118 // it as closed on the f-stream.
119 //
120  if (fsP->MonEnt != -1 && fsP->MonEnt != noSlot)
121  {iEnt = fsP->MonEnt & 0xffff;
122  iMap = iEnt >> XrdXrootdMonFMap::fmShft;
123  iSlot = iEnt & XrdXrootdMonFMap::fmMask;
124  fmMutex.Lock();
125  if (fmMap[iMap].Free(iSlot)) fmUse[iMap]--;
126  if (iMap == fmHWM) while(fmHWM >= 0 && !fmUse[fmHWM]) fmHWM--;
127  fmMutex.UnLock();
128  }
129  fsP->MonEnt = -1;
130 
131 // Insert a close record header (mostly precomputed)
132 //
134  cRec.Hdr.recFlag = crecFlag;
135  if (isDisc) cRec.Hdr.recFlag |= XrdXrootdMonFileHdr::forced;
136  cRec.Hdr.recSize = crecNLen;
137  cRec.Hdr.fileID = fsP->FileID;
138 
139 // Insert the I/O bytes
140 //
141  cRec.Xfr.read = htonll(fsP->xfr.read);
142  cRec.Xfr.readv = htonll(fsP->xfr.readv);
143  cRec.Xfr.write = htonll(fsP->xfr.write);
144 
145 // Insert ops if so wanted
146 //
147  if (fsOPS)
148  {cRec.Ops.read = htonl (fsP->ops.read);
149  if (fsP->ops.read)
150  {cRec.Ops.rdMin = htonl (fsP->ops.rdMin);
151  cRec.Ops.rdMax = htonl (fsP->ops.rdMax);
152  } else {
153  cRec.Ops.rdMin = cRec.Ops.rdMax = 0;
154  }
155  cRec.Ops.readv = htonl (fsP->ops.readv);
156  cRec.Ops.rsegs = htonll(fsP->ops.rsegs);
157  if (fsP->ops.readv)
158  {cRec.Ops.rsMin = htons (fsP->ops.rsMin);
159  cRec.Ops.rsMax = htons (fsP->ops.rsMax);
160  cRec.Ops.rvMin = htonl (fsP->ops.rvMin);
161  cRec.Ops.rvMax = htonl (fsP->ops.rvMax);
162  } else {
163  cRec.Ops.rsMin = cRec.Ops.rsMax = 0;
164  cRec.Ops.rvMin = cRec.Ops.rvMax = 0;
165  }
166  cRec.Ops.write = htonl (fsP->ops.write);
167  if (fsP->ops.write)
168  {cRec.Ops.wrMin = htonl (fsP->ops.wrMin);
169  cRec.Ops.wrMax = htonl (fsP->ops.wrMax);
170  } else {
171  cRec.Ops.wrMin = cRec.Ops.wrMax = 0;
172  }
173  }
174 
175 // Record sum of squares if so needed
176 //
177  if (fsSSQ)
178  {XrdXrootdMonDouble xval;
179  xval.dreal = fsP->ssq.read;
180  cRec.Ssq.read.dlong = htonll(xval.dlong);
181  xval.dreal = fsP->ssq.readv;
182  cRec.Ssq.readv.dlong = htonll(xval.dlong);
183  xval.dreal = fsP->ssq.rsegs;
184  cRec.Ssq.rsegs.dlong = htonll(xval.dlong);
185  xval.dreal = fsP->ssq.write;
186  cRec.Ssq.write.dlong = htonll(xval.dlong);
187  }
188 
189 // Get a pointer to the next slot (the buffer gets locked)
190 //
191  cP = GetSlot(crecSize);
192  memcpy(cP, &cRec, crecSize);
193  bfMutex.UnLock();
194 }
XrdXrootdMonDouble write
XrdXrootdMonDouble read
XrdXrootdMonDouble readv
XrdXrootdMonStatXFR Xfr
XrdXrootdMonStatOPS Ops
XrdXrootdMonDouble rsegs
XrdXrootdMonStatSSQ Ssq
XrdXrootdMonFileHdr Hdr
XrdXrootdMonStatXFR xfr
XrdXrootdMonStatOPS ops
struct XrdXrootdFileStats::@176 ssq
static const int fmShft
static const int fmMask

References XrdXrootdMonDouble::dlong, XrdXrootdMonDouble::dreal, XrdXrootdFileStats::FileID, XrdXrootdMonFMap::fmMask, XrdXrootdMonFMap::fmShft, XrdXrootdMonFileHdr::forced, XrdXrootdMonFileCLS::Hdr, XrdXrootdMonFileHdr::isClose, XrdSysMutex::Lock(), XrdXrootdFileStats::MonEnt, XrdXrootdFileStats::ops, XrdXrootdMonFileCLS::Ops, XrdXrootdMonStatOPS::rdMax, XrdXrootdMonStatOPS::rdMin, XrdXrootdMonStatOPS::read, XrdXrootdMonStatSSQ::read, XrdXrootdMonStatXFR::read, XrdXrootdMonStatOPS::readv, XrdXrootdMonStatSSQ::readv, XrdXrootdMonStatXFR::readv, XrdXrootdMonFileHdr::recFlag, XrdXrootdMonFileHdr::recSize, XrdXrootdMonFileHdr::recType, XrdXrootdMonStatOPS::rsegs, XrdXrootdMonStatSSQ::rsegs, XrdXrootdMonStatOPS::rsMax, XrdXrootdMonStatOPS::rsMin, XrdXrootdMonStatOPS::rvMax, XrdXrootdMonStatOPS::rvMin, XrdXrootdFileStats::ssq, XrdXrootdMonFileCLS::Ssq, XrdSysMutex::UnLock(), XrdXrootdMonStatOPS::write, XrdXrootdMonStatSSQ::write, XrdXrootdMonStatXFR::write, XrdXrootdMonStatOPS::wrMax, XrdXrootdMonStatOPS::wrMin, XrdXrootdFileStats::xfr, and XrdXrootdMonFileCLS::Xfr.

Referenced by XrdXrootdFileTable::Del(), and XrdXrootdFileTable::Recycle().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Defaults()

void XrdXrootdMonFile::Defaults ( int  intv,
int  opts,
int  iocnt,
int  fbsz 
)
static

Definition at line 200 of file XrdXrootdMonFile.cc.

201 {
202 
203 // Set the reporting interval and I/O counter
204 //
205  repTime = intv;
206  xfrCnt = xfrcnt;
207  xfrRem = xfrcnt;
208 
209 // Set the buffer size. The configuration accepts 1024 to 65535 bytes, but the
210 // buffer goes out as one datagram, so limit it to the largest UDP payload.
211 //
212  fBsz = (fbsz <= 0 ? 65472
213  : std::clamp(fbsz, 1024, XrdXrootdMonitor::maxDgram));
214 
215 // Expand out the options
216 //
217  fsXFR = (opts & XROOTD_MON_FSXFR) != 0;
218  fsLFN = (opts & XROOTD_MON_FSLFN) != 0;
219  fsOPS = (opts & (XROOTD_MON_FSOPS | XROOTD_MON_FSSSQ)) != 0;
220  fsSSQ = (opts & XROOTD_MON_FSSSQ) != 0;
221 
222 // Set monitoring level
223 //
224  if (fsSSQ) fsLVL = XrdXrootdFileStats::monSsq;
225  else if (fsOPS) fsLVL = XrdXrootdFileStats::monOps;
226  else if (intv) fsLVL = XrdXrootdFileStats::monOn;
227  else fsLVL = XrdXrootdFileStats::monOff;
228 }
struct myOpts opts
#define XROOTD_MON_FSSSQ
#define XROOTD_MON_FSLFN
#define XROOTD_MON_FSOPS
#define XROOTD_MON_FSXFR
static constexpr int maxDgram

References XrdXrootdMonitor::maxDgram, XrdXrootdFileStats::monOff, XrdXrootdFileStats::monOn, XrdXrootdFileStats::monOps, XrdXrootdFileStats::monSsq, opts, XROOTD_MON_FSLFN, XROOTD_MON_FSOPS, XROOTD_MON_FSSSQ, and XROOTD_MON_FSXFR.

Referenced by XrdXrootdMonitor::Defaults().

+ Here is the caller graph for this function:

◆ Disc()

void XrdXrootdMonFile::Disc ( unsigned int  usrID)
static

Definition at line 234 of file XrdXrootdMonFile.cc.

235 {
236  static short drecSize = htons(sizeof(XrdXrootdMonFileDSC));
238 
239 // Get a pointer to the next slot (the buffer gets locked)
240 //
241  dP = (XrdXrootdMonFileDSC *)GetSlot(sizeof(XrdXrootdMonFileDSC));
242 
243 // Fill out the record. It's pretty simple
244 //
246  dP->Hdr.recFlag = 0;
247  dP->Hdr.recSize = drecSize;
248  dP->Hdr.userID = usrID;
249  bfMutex.UnLock();
250 }
XrdXrootdMonFileHdr Hdr

References XrdXrootdMonFileDSC::Hdr, XrdXrootdMonFileHdr::isDisc, XrdXrootdMonFileHdr::recFlag, XrdXrootdMonFileHdr::recSize, XrdXrootdMonFileHdr::recType, and XrdSysMutex::UnLock().

Referenced by XrdXrootdProtocol::Recycle().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DoIt()

void XrdXrootdMonFile::DoIt ( )
virtual

Implements XrdJob.

Definition at line 256 of file XrdXrootdMonFile.cc.

257 {
258 
259 // First check if we need to report all the I/O stats
260 //
261  xfrRem--;
262  if (!xfrRem) DoXFR();
263 
264 // Check if we should flush the buffer
265 //
266  bfMutex.Lock();
267  if (repNext) Flush();
268  bfMutex.UnLock();
269 
270 // Reschedule ourselves
271 //
272  XrdXrootdMonInfo::Sched->Schedule((XrdJob *)this, time(0)+repTime);
273 }
Definition: XrdJob.hh:43
void Schedule(XrdJob *jp)
XrdScheduler * Sched

References XrdSysMutex::Lock(), XrdXrootdMonInfo::Sched, XrdScheduler::Schedule(), and XrdSysMutex::UnLock().

+ Here is the call graph for this function:

◆ Init()

bool XrdXrootdMonFile::Init ( )
static

Definition at line 351 of file XrdXrootdMonFile.cc.

352 {
353  XrdXrootdMonFile *mfP;
354  int alignment, pagsz = getpagesize();
355 
356 // Allocate a socket buffer
357 //
358  alignment = (fBsz < pagsz ? 1024 : pagsz);
359  if (posix_memalign((void **)&repBuff, alignment, fBsz))
360  {XrdXrootdMonInfo::eDest->Emsg("MonFile", "Unable to allocate monitor buffer.");
361  return false;
362  }
363 
364 // Set the header (always present)
365 //
366  repHdr = (XrdXrootdMonHeader *)repBuff;
367  repHdr->code = XROOTD_MON_MAPFSTA;
368  repHdr->pseq = 0;
370 
371 // Set the time record (always present)
372 //
373  repTOD = (XrdXrootdMonFileTOD *)(repBuff + sizeof(XrdXrootdMonHeader));
376  repTOD->Hdr.recSize = htons(sizeof(XrdXrootdMonFileTOD));
377  repTOD->sID = static_cast<kXR_int64>(XrdXrootdMonInfo::mySID);
378 
379 // Establish first real record in the buffer (always fixed)
380 //
381  repFirst = repBuff+sizeof(XrdXrootdMonHeader)+sizeof(XrdXrootdMonFileTOD);
382 
383 // Calculate the end nut the next slot always starts with a null pointer
384 //
385  repLast = repBuff+fBsz-1;
386  repNext = 0;
387 
388 // Compute the longest lfn that an open record can carry, not counting its
389 // null byte. The record must fit an empty buffer, and its size must fit the
390 // 16-bit recSize field. Records are a multiple of 8 bytes long, so use the
391 // largest multiple of 8 that fits. The fixed part is minRecSz plus the user
392 // dictid. Defaults() keeps fBsz at 1024 or more, so this is always positive.
393 //
394  int maxSlot = repLast - repFirst;
395  if (maxSlot > 32767) maxSlot = 32767;
396  maxText = (maxSlot & ~7) - (minRecSz + (int)sizeof(kXR_unt32)) - 1;
397 
398 // Calculate the close record size and the initial flags
399 //
400  crecSize = sizeof(XrdXrootdMonFileHdr) + sizeof(XrdXrootdMonStatXFR);
401  if (fsSSQ || fsOPS)
402  {crecSize += sizeof(XrdXrootdMonStatOPS);
403  crecFlag = XrdXrootdMonFileHdr::hasOPS;
404  } else crecFlag = 0;
405  if (fsSSQ)
406  {crecSize += sizeof(XrdXrootdMonStatSSQ);
407  crecFlag |= XrdXrootdMonFileHdr::hasSSQ;
408  }
409  crecNLen = htons(static_cast<short>(crecSize));
410 
411 // Preformat the i/o record
412 //
414  xfrRec.Hdr.recFlag = 0;
415  xfrRec.Hdr.recSize = htons(static_cast<short>(sizeof(xfrRec)));
416 
417 // Calculate the tod record size
418 //
419  trecNLen = htons(static_cast<short>(sizeof(XrdXrootdMonFileTOD)));
420 
421 // Allocate an instance of ourselves so we can schedule ourselves
422 //
423  mfP = new XrdXrootdMonFile();
424 
425 // Schedule an the flushes
426 //
427  XrdXrootdMonInfo::Sched->Schedule((XrdJob *)mfP, time(0)+repTime);
428  return true;
429 }
long long kXR_int64
Definition: XPtypes.hh:98
unsigned int kXR_unt32
Definition: XPtypes.hh:90
XrdXrootdMonFileHdr Hdr
const kXR_char XROOTD_MON_MAPFSTA
XrdXrootdMonFileHdr Hdr
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
Definition: XrdSysError.cc:116
XrdSysError * eDest

References XrdXrootdMonFile(), XrdXrootdMonHeader::code, XrdXrootdMonInfo::eDest, XrdSysError::Emsg(), XrdXrootdMonFileHdr::hasOPS, XrdXrootdMonFileHdr::hasSID, XrdXrootdMonFileHdr::hasSSQ, XrdXrootdMonFileTOD::Hdr, XrdXrootdMonFileXFR::Hdr, XrdXrootdMonFileHdr::isTime, XrdXrootdMonFileHdr::isXfr, XrdXrootdMonInfo::mySID, XrdXrootdMonHeader::pseq, XrdXrootdMonFileHdr::recFlag, XrdXrootdMonFileHdr::recSize, XrdXrootdMonFileHdr::recType, XrdXrootdMonInfo::Sched, XrdScheduler::Schedule(), XrdXrootdMonFileTOD::sID, XrdXrootdMonInfo::startTime, XrdXrootdMonHeader::stod, and XROOTD_MON_MAPFSTA.

Referenced by XrdXrootdMonitor::Init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Open()

void XrdXrootdMonFile::Open ( XrdXrootdFileStats *  fsP,
const char *  Path,
unsigned int  uDID,
bool  isRW 
)
static

Definition at line 501 of file XrdXrootdMonFile.cc.

503 {
505  int i = 0, sNum = -1, rLen, tLen = 0;
506 
507 // Assign the path a dictionary id if not assigned via file monitoring
508 //
509  if (fsP->FileID == 0) fsP->FileID = XrdXrootdMonitor::GetDictID();
510 
511 // Add this open to the map table if we are doing I/O stats.
512 //
513  if (fsXFR)
514  {fmMutex.Lock();
515  for (i = 0; i < mapUse; i++)
516  if (fmUse[i] < XrdXrootdMonFMap::fmSize)
517  {if ((sNum = fmMap[i].Insert(fsP)) >= 0)
518  {fmUse[i]++;
519  if (i > fmHWM) fmHWM = i;
520  break;
521  }
522  }
523  fmMutex.UnLock();
524  }
525 
526 // Generate the cookie (real or virtual) to find the entry in the map table.
527 // If the file has no entry (no xfr option, or the map is full), use noSlot.
528 // Supply the monitoring options for efficiency.
529 //
530  fsP->MonEnt = (sNum < 0 ? noSlot
531  : (sNum | (i << XrdXrootdMonFMap::fmShft)) & 0xffff);
532  fsP->monLvl = fsLVL;
533  fsP->xfrXeq = 0;
534 
535 // Compute the size of this record
536 //
537  rLen = minRecSz;
538  if (fsLFN)
539  {tLen = strlen(Path);
540  if (tLen > maxText) tLen = maxText;
541  rLen = (rLen + sizeof(kXR_unt32) + tLen + 1 + 7) & ~7;
542  }
543 
544 // Get a pointer to the next slot (the buffer gets locked)
545 //
546  oP = (XrdXrootdMonFileOPN *)GetSlot(rLen);
547 
548 // Fill out the record
549 //
551  oP->Hdr.recFlag = (isRW ? XrdXrootdMonFileHdr::hasRW : 0);
552  oP->Hdr.recSize = htons(static_cast<short>(rLen));
553  oP->Hdr.fileID = fsP->FileID;
554  oP->fsz = htonll(fsP->fSize);
555 
556 // Append user and path if so wanted (sizes have been verified).
557 // The lfn is null padded up to the end of the record.
558 //
559  if (fsLFN)
561  oP->ufn.user = uDID;
562  XrdXrootdMonitor::CopyText(oP->ufn.lfn, rLen - minRecSz - sizeof(kXR_unt32), Path, tLen);
563  }
564  bfMutex.UnLock();
565 }
XrdOucString Path
XrdXrootdMonFileLFN ufn
XrdXrootdMonFileHdr Hdr
static const int fmSize
static int CopyText(char *buff, int room, const char *text, int tLen)
static kXR_unt32 GetDictID(bool hbo=false)

References XrdXrootdMonitor::CopyText(), XrdXrootdFileStats::FileID, XrdXrootdMonFMap::fmShft, XrdXrootdMonFMap::fmSize, XrdXrootdFileStats::fSize, XrdXrootdMonFileOPN::fsz, XrdXrootdMonitor::GetDictID(), XrdXrootdMonFileHdr::hasLFN, XrdXrootdMonFileHdr::hasRW, XrdXrootdMonFileOPN::Hdr, XrdXrootdMonFileHdr::isOpen, XrdXrootdMonFileLFN::lfn, XrdSysMutex::Lock(), XrdXrootdFileStats::MonEnt, XrdXrootdFileStats::monLvl, Path, XrdXrootdMonFileHdr::recFlag, XrdXrootdMonFileHdr::recSize, XrdXrootdMonFileHdr::recType, XrdXrootdMonFileOPN::ufn, XrdSysMutex::UnLock(), XrdXrootdMonFileLFN::user, and XrdXrootdFileStats::xfrXeq.

+ Here is the call graph for this function:

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