XRootD
XrdOssStatsConfig.hh File Reference
#include <chrono>
#include <string>
+ Include dependency graph for XrdOssStatsConfig.hh:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Enumerations

enum  LogMask {
  Debug = 0x01 ,
  Info = 0x02 ,
  Warning = 0x04 ,
  Error = 0x08 ,
  All = 0xff
}
 

Functions

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

Enumeration Type Documentation

◆ LogMask

enum LogMask
Enumerator
Debug 
Info 
Warning 
Error 
All 

Definition at line 7 of file XrdOssStatsConfig.hh.

7  {
8  Debug = 0x01,
9  Info = 0x02,
10  Warning = 0x04,
11  Error = 0x08,
12  All = 0xff
13 };
@ Info
@ Warning
@ Error
@ Debug

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 }

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: