XRootD
XrdOssStatsConfig.cc File Reference
#include "XrdVersion.hh"
#include "XrdOssStatsConfig.hh"
#include "XrdOssStatsFileSystem.hh"
#include "XrdSys/XrdSysError.hh"
#include <sstream>
+ Include dependency graph for XrdOssStatsConfig.cc:

Go to the source code of this file.

Functions

std::string LogMaskToString (int mask)
 
bool ParseDuration (const std::string &duration, std::chrono::steady_clock::duration &result, std::string &errmsg)
 
XrdOssXrdOssAddStorageSystem2 (XrdOss *curr_oss, XrdSysLogger *logger, const char *config_fn, const char *parms, XrdOucEnv *envP)
 
 XrdVERSIONINFO (XrdOssAddStorageSystem2, fsstats)
 
 XrdVERSIONINFO (XrdOssGetFileSystem, Stats)
 

Function Documentation

◆ LogMaskToString()

std::string LogMaskToString ( int  mask)

Definition at line 13 of file XrdOssStatsConfig.cc.

13  {
14  if (mask == LogMask::All) {return "all";}
15 
16  bool has_entry = false;
17  std::stringstream ss;
18  if (mask & LogMask::Debug) {
19  ss << "debug";
20  has_entry = true;
21  }
22  if (mask & LogMask::Info) {
23  ss << (has_entry ? ", " : "") << "info";
24  has_entry = true;
25  }
26  if (mask & LogMask::Warning) {
27  ss << (has_entry ? ", " : "") << "warning";
28  has_entry = true;
29  }
30  if (mask & LogMask::Error) {
31  ss << (has_entry ? ", " : "") << "error";
32  has_entry = true;
33  }
34  return ss.str();
35 }
@ Info
@ Warning

References Macaroons::All, Macaroons::Debug, Macaroons::Error, Info, and Warning.

Referenced by StatsFileSystem::Config().

+ Here is the caller graph for this function:

◆ ParseDuration()

bool ParseDuration ( const std::string &  duration,
std::chrono::steady_clock::duration &  result,
std::string &  errmsg 
)

Definition at line 41 of file XrdOssStatsConfig.cc.

41  {
42 
43  if (duration.empty()) {
44  errmsg = "cannot parse empty string as a time duration";
45  return false;
46  }
47  if (duration == "0") {
48  result = std::chrono::steady_clock::duration(0);
49  return true;
50  }
51  std::chrono::steady_clock::duration dur(0);
52  auto strValue = duration;
53  while (!strValue.empty()) {
54  std::size_t pos;
55  double value;
56  try {
57  value = std::stod(strValue, &pos);
58  } catch (std::invalid_argument const &exc) {
59  errmsg = "Invalid number provided as timeout: " + strValue;
60  return false;
61  } catch (std::out_of_range const &exc) {
62  errmsg = "Provided timeout out of representable range: " + std::string(exc.what());
63  return false;
64  }
65  if (value < 0) {
66  errmsg = "Provided timeout was negative";
67  return false;
68  }
69  strValue = strValue.substr(pos);
70  char unit[3] = {'\0', '\0', '\0'};
71  if (!strValue.empty()) {
72  unit[0] = strValue[0];
73  if (unit[0] >= '0' && unit[0] <= '9') {unit[0] = '\0';}
74  }
75  if (strValue.size() > 1) {
76  unit[1] = strValue[1];
77  if (unit[1] >= '0' && unit[1] <= '9') {unit[1] = '\0';}
78  }
79  if (!strncmp(unit, "ns", 2)) {
80  dur += std::chrono::duration_cast<typeof(dur)>(std::chrono::duration<double, std::nano>(value));
81  } else if (!strncmp(unit, "us", 2)) {
82  dur += std::chrono::duration_cast<typeof(dur)>(std::chrono::duration<double, std::micro>(value));
83  } else if (!strncmp(unit, "ms", 2)) {
84  dur += std::chrono::duration_cast<typeof(dur)>(std::chrono::duration<double, std::milli>(value));
85  } else if (!strncmp(unit, "s", 1)) {
86  dur += std::chrono::duration_cast<typeof(dur)>(std::chrono::duration<double>(value));
87  } else if (!strncmp(unit, "m", 1)) {
88  dur += std::chrono::duration_cast<typeof(dur)>(std::chrono::duration<double, std::ratio<60>>(value));
89  } else if (!strncmp(unit, "h", 1)) {
90  dur += std::chrono::duration_cast<typeof(dur)>(std::chrono::duration<double, std::ratio<3600>>(value));
91  } else if (strlen(unit) > 0) {
92  errmsg = "Unknown unit in duration: " + std::string(unit);
93  return false;
94  } else {
95  errmsg = "Unit missing from duration: " + duration;
96  return false;
97  }
98  strValue = strValue.substr(strlen(unit));
99  }
100  result = dur;
101  return true;
102 }

Referenced by StatsFileSystem::Config().

+ Here is the caller graph for this function:

◆ XrdOssAddStorageSystem2()

XrdOss* XrdOssAddStorageSystem2 ( XrdOss curr_oss,
XrdSysLogger logger,
const char *  config_fn,
const char *  parms,
XrdOucEnv envP 
)

Definition at line 110 of file XrdOssStatsConfig.cc.

115 {
116 
117  XrdSysError log(logger, "fsstats_");
118  try {
119  return new StatsFileSystem(curr_oss, logger, config_fn, envP);
120  } catch (std::runtime_error &re) {
121  log.Emsg("Initialize", "Encountered a runtime failure:", re.what());
122  return nullptr;
123  }
124 }
XrdOucEnv * envP
Definition: XrdPss.cc:109

References XrdSysError::Emsg(), and XrdProxy::envP.

+ Here is the call graph for this function:

◆ XrdVERSIONINFO() [1/2]

XrdVERSIONINFO ( XrdOssAddStorageSystem2  ,
fsstats   
)

◆ XrdVERSIONINFO() [2/2]

XrdVERSIONINFO ( XrdOssGetFileSystem  ,
Stats   
)