#include <chrono>
#include <string>
Go to the source code of this file.
|
std::string | LogMaskToString (int mask) |
|
bool | ParseDuration (const std::string &duration, std::chrono::steady_clock::duration &result, std::string &errmsg) |
|
◆ LogMask
◆ LogMaskToString()
std::string LogMaskToString |
( |
int |
mask | ) |
|
◆ ParseDuration()
bool ParseDuration |
( |
const std::string & |
duration, |
|
|
std::chrono::steady_clock::duration & |
result, |
|
|
std::string & |
errmsg |
|
) |
| |
Definition at line 41 of file XrdOssStatsConfig.cc.
43 if (duration.empty()) {
44 errmsg =
"cannot parse empty string as a time duration";
47 if (duration ==
"0") {
48 result = std::chrono::steady_clock::duration(0);
51 std::chrono::steady_clock::duration dur(0);
52 auto strValue = duration;
53 while (!strValue.empty()) {
57 value = std::stod(strValue, &pos);
58 }
catch (std::invalid_argument
const &exc) {
59 errmsg =
"Invalid number provided as timeout: " + strValue;
61 }
catch (std::out_of_range
const &exc) {
62 errmsg =
"Provided timeout out of representable range: " + std::string(exc.what());
66 errmsg =
"Provided timeout was negative";
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';}
75 if (strValue.size() > 1) {
76 unit[1] = strValue[1];
77 if (unit[1] >=
'0' && unit[1] <=
'9') {unit[1] =
'\0';}
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);
95 errmsg =
"Unit missing from duration: " + duration;
98 strValue = strValue.substr(strlen(unit));
Referenced by StatsFileSystem::Config().