MetroCollect  2.3.4
MetricsDiffArray.cc
Go to the documentation of this file.
1 //
2 // MetricsDiffArray.cc
3 //
4 // Created on July 18th 2018
5 //
6 // Copyright 2018 CFM (www.cfm.fr)
7 //
8 // Licensed under the Apache License, Version 2.0 (the "License");
9 // you may not use this file except in compliance with the License.
10 // You may obtain a copy of the License at
11 //
12 // http://www.apache.org/licenses/LICENSE-2.0
13 //
14 // Unless required by applicable law or agreed to in writing, software
15 // distributed under the License is distributed on an "AS IS" BASIS,
16 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 // See the License for the specific language governing permissions and
18 // limitations under the License.
19 //
20 
21 #include "MetricsDiffArray.h"
22 
23 
24 namespace MetroCollect {
26 
27  MetricsDiffArray::MetricsDiffArray(MetricsSource::SourceInterests sourceInterests) noexcept : MetricsArray(sourceInterests) { }
28 
29 
30  const std::chrono::system_clock::time_point& MetricsDiffArray::startTime() const noexcept {
31  return this->startTime_;
32  }
33 
34  const std::chrono::system_clock::time_point& MetricsDiffArray::endTime() const noexcept {
35  return this->endTime_;
36  }
37 
39  this->startTime_ = previous.timestamp();
40  this->endTime_ = current.timestamp();
41  this->timestamp_ = this->startTime_ + (this->endTime_ - this->startTime_) / 2;
42 
43  this->sources_.forEach([&](auto& source, size_t sourceIndex) {
44  if ((*this->sourceInterests_)[sourceIndex].any())
45  source.computeDiff((*this->sourceInterests_)[sourceIndex], this->sourceIterators_[sourceIndex].first,
46  static_cast<typename MetricsArray<DataValueType>::ConstIterator>(current.sourceIterators_[sourceIndex].first),
47  static_cast<typename MetricsArray<DataValueType>::ConstIterator>(previous.sourceIterators_[sourceIndex].first),
48  factor);
49  });
50  }
51 }
std::chrono::system_clock::time_point startTime_
Time of earlier metrics.
std::shared_ptr< std::vector< MetricsSource::Interests > > SourceInterests
Type used to store and share interests of multiple sources.
void computeDiff(MetricsArray< DataValueType > &current, MetricsArray< DataValueType > &previous, double factor) noexcept
Compute and store the differences between two Metrics Data Arrays.
Generic class to store and manage metrics.
Definition: MetricsArray.h:40
const std::chrono::system_clock::time_point & endTime() const noexcept
Get time of latest metrics.
const std::chrono::system_clock::time_point & startTime() const noexcept
Get time of earlier metrics.
std::chrono::system_clock::time_point endTime_
Time of latest metrics.
MetricsDiffArray() noexcept
Construct a new Metrics Diff Array object.