39 const char* buffer = this->
buffer_.data();
42 while (buffer[0] !=
'\0') {
44 while (buffer[length] !=
':')
48 while (buffer[0] !=
'\n')
54 bool wasCapitalized =
false;
55 for (
size_t i = 0; i < fieldName.size(); i++) {
56 if (!isalnum(fieldName[i]) && fieldName[i] !=
'_')
58 else if (isupper(fieldName[i])) {
59 if (i > 0 && fieldName[i - 1] !=
'_' && islower(fieldName[i - 1]) && !wasCapitalized) {
60 fieldName.insert(i,
"_");
63 fieldName[i] = tolower(fieldName[i]);
64 wasCapitalized =
true;
66 wasCapitalized =
false;
68 while (fieldName.back() ==
'_')
69 fieldName.erase(fieldName.size() - 1);
70 while (fieldName.front() ==
'_')
84 auto itr = std::find(this->fieldNames_.begin(), this->fieldNames_.end(), fieldName[1]);
85 if (itr != this->fieldNames_.end()) {
88 return {
static_cast<size_t>(std::distance(this->fieldNames_.begin(), itr))};
100 return {name,
"Memory metric: " + this->fieldNames_[index], unit};
104 std::vector<FieldInfo> info;
105 for (
size_t i = 0; i < this->
fieldNames_.size(); i++)
106 info.push_back(this->fieldInfoAtIndex(i));
118 const char* buffer = this->
buffer_.data();
119 while (buffer[0] !=
'\0') {
120 while (buffer[0] !=
':')
124 while (buffer[0] ==
' ')
148 while (buffer[0] !=
'\n')
156 if (interests.none())
159 std::copy_n(current, this->fieldNames_.size(), diff);
Object used to describe a field (or metric)
std::vector< std::string > FieldName
Type used for field names (an array of strings)
bool readFile(std::ifstream &file, std::vector< char > &buffer, const std::string_view &path)
Attempts to read file into buffer.
Namespace for sources of metrics objects and operations.
static constexpr std::string_view filePath
Memory metrics file path.
std::vector< DataValueType >::const_iterator ConstIterator
Const iterator type of MetricsDataArray.
static constexpr std::string_view defaultUnit
Metric unit.
uint64_t parseUint(const char *&buffer) noexcept
Fast and unsafe unsigned integer parser.
static constexpr std::string_view sourcePrefix
Metrics name source prefix.
const FieldInfo fieldInfoAtIndex(size_t index) const noexcept override final
Get details about a specific field.
std::vector< std::string > fieldNames_
Metrics names.
const std::string fieldNameSourcePrefix() const noexcept override final
Get the prefix by which all field names should begin with.
const std::vector< size_t > indexesOfFieldName(const FieldName &fieldName, Interests *interests=nullptr) const noexcept override final
Search for fields associated to a specific name.
void parseFields()
File parser function.
std::vector< char > buffer_
Buffer to put file contents into.
static constexpr std::array fieldUnitsAssociation
Metric units associations.
size_t fieldCount() const noexcept override final
Get the number of field the source has.
std::ifstream file_
File descriptor.
int64_t DataValueType
Type of fetched raw metrics.
bool none() const
Checks wether all bit are false.
void computeDiff(const Interests &interests, DiffArray::Iterator diff, DataArray::ConstIterator current, DataArray::ConstIterator previous, double factor=1) noexcept override final
Compute the variation (in appropriate unit) of metrics.
Boolean array to keep track of which fields a source has to fetch metrics for.
std::vector< DiffValueType >::iterator Iterator
Iterator type of MetricsDiffArray.
const std::vector< FieldInfo > allFieldsInfo() const noexcept override final
Get all fields details, field which share a common name should appear only once.
void fetchData(const Interests &interests, DataArray::Iterator current) override final
Fetch the latest metrics.
bool resetFile(std::ifstream &file, std::vector< char > &buffer, const std::string_view &path)
Attempts to open a file and set buffer size accordingly.
SourceProcMeminfo()
Private default constructor.
std::string findUnit(const std::string &name, const std::array< KeyUnit, N > &keyUnitAssociation, const std::string_view &defaultUnit)
Tries to associate a field name with a unit, falling back on the default unit if none matches...
std::vector< DataValueType >::iterator Iterator
Iterator type of MetricsDataArray.