40 const char* buffer = this->
buffer_.data();
45 buffer = std::strchr(buffer,
'\n') + 1;
50 while (buffer[0] !=
'\0') {
52 while (buffer[length] !=
' ')
56 while (buffer[0] !=
'\n')
72 auto itr = std::find(this->otherFieldNames_.begin(), this->otherFieldNames_.end(), fieldName[2]);
73 if (itr != this->otherFieldNames_.end()) {
76 return {
static_cast<size_t>(std::distance(this->otherFieldNames_.begin(), itr))};
95 std::vector<size_t> indexes;
96 for (
size_t cpuIndex = 0; cpuIndex < this->cpuCount_; cpuIndex++)
105 cpuIndex = std::stoll(fieldName[2]);
109 if (cpuIndex < this->cpuCount_) {
125 if (index < this->otherFieldNames_.size()) {
140 std::vector<FieldInfo> info;
142 info.push_back(this->fieldInfoAtIndex(i));
158 const char* buffer = this->
buffer_.data();
160 if (interests.
isSet(1)) {
162 size_t remainingCPUs = this->
cpuCount_ + 1;
165 while (buffer[0] !=
' ')
167 while(buffer[0] !=
'\n') {
181 if (interests.
isSet(0)) {
183 while (buffer[0] !=
'\n')
189 while (remainingFields > 0 && buffer[0] !=
'\0') {
190 while (buffer[0] !=
' ')
194 while (buffer[0] !=
'\n')
203 if (interests.isSet(0)) {
204 for (
size_t i = 0; i < this->otherFieldNames_.size(); i++) {
205 if (i == 4 || i == 5)
208 *diff =
static_cast<DiffValueType>((*current - *previous) * factor);
215 if (interests.isSet(1)) {
216 for (
size_t cpuIndex = 0; cpuIndex < this->cpuCount_ + 1; cpuIndex++) {
220 if (currentSum == previousSum) {
222 diff[i] = static_cast<DiffValueType>(0);
228 double invSumDiff = 100.0 / (currentSum - previousSum);
230 invSumDiff *= this->cpuCount_;
232 *diff =
static_cast<DiffValueType>((*current - *previous) * invSumDiff);
Object used to describe a field (or metric)
static constexpr std::string_view fieldNameAllCoresPrefix
Metrics name category.
static constexpr std::string_view cpuField
Metrics name category.
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.
static constexpr std::array< std::string_view, cpuFieldCount > cpuFieldNames
CPU states names.
const FieldInfo fieldInfoAtIndex(size_t index) const noexcept override final
Get details about a specific field.
Namespace for sources of metrics objects and operations.
static constexpr std::string_view percentUnit
Metric unit.
std::vector< DataValueType >::const_iterator ConstIterator
Const iterator type of MetricsDataArray.
uint64_t parseUint(const char *&buffer) noexcept
Fast and unsafe unsigned integer parser.
const std::string fieldNameSourcePrefix() const noexcept override final
Get the prefix by which all field names should begin with.
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.
void fetchData(const Interests &interests, DataArray::Iterator current) override final
Fetch the latest metrics.
static constexpr std::string_view fieldNameCorePrefix
Metrics name category.
static constexpr std::string_view filePath
CPU metrics file path.
void parseFields()
File parser function.
static constexpr std::string_view sourcePrefix
Metrics name source prefix.
const std::vector< FieldInfo > allFieldsInfo() const noexcept override final
Get all fields details, field which share a common name should appear only once.
int64_t DataValueType
Type of fetched raw metrics.
bool none() const
Checks wether all bit are false.
Boolean array to keep track of which fields a source has to fetch metrics for.
static constexpr size_t cpuFieldCount
Number of fields for each CPU.
static constexpr std::string_view fieldNameOtherPrefix
Metrics name category.
std::vector< char > buffer_
Buffer to put file contents into.
std::vector< DiffValueType >::iterator Iterator
Iterator type of MetricsDiffArray.
static constexpr std::string_view defaultUnit
Metric unit.
static constexpr std::string_view fieldNameCoreDescription
Metrics name category description.
bool resetFile(std::ifstream &file, std::vector< char > &buffer, const std::string_view &path)
Attempts to open a file and set buffer size accordingly.
const std::vector< size_t > indexesOfFieldName(const FieldName &fieldName, Interests *interests=nullptr) const noexcept override final
Search for fields associated to a specific name.
static constexpr std::string_view fieldNameCoreAll
Metrics name wildcard.
std::vector< std::string > otherFieldNames_
Names of other CPU metrics.
std::vector< DataValueType >::iterator Iterator
Iterator type of MetricsDataArray.
SourceProcStat()
Private default constructor.
bool isSet(T index) const
Checks if a specific bit is true.
size_t cpuCount_
Number of CPUs.
size_t fieldCount() const noexcept override final
Get the number of field the source has.
std::ifstream file_
File descriptor.
double DiffValueType
Type of metric variation.