osquery-1/osquery/numeric_monitoring/pre_aggregation_cache.h
Jesse Kornblum c7355b19aa Update osquery licensing wording (#5452)
Summary:
Pull Request resolved: https://github.com/facebook/osquery/pull/5452

As suggested in another diff, this diff updates the language we use to describe the osquery licensing terms. We are changing all instances of

//This source code is licensed as defined on the LICENSE file found in the root directory of this source tree.//

to

//This source code is licensed in accordance with the terms specified in the LICENSE file found in the root directory of this source tree.//

We accomplish this with a codemod:

  $ codemod -md xplat/osquery/oss --extensions cpp,h,in,py,sh,mm,ps1 "(.\s+)This source code is licensed as defined on the LICENSE file found in the(.*)root directory of this source tree\." "\1This source code is licensed in accordance with the terms specified in\2the LICENSE file found in the root directory of this source tree."

Reviewed By: fmanco

Differential Revision: D14131290

fbshipit-source-id: 52c90da342263e2a80f5a678ecd760c19cf7513e
2019-02-19 10:59:48 -08:00

77 lines
2.0 KiB
C++

/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed in accordance with the terms specified in
* the LICENSE file found in the root directory of this source tree.
*/
#pragma once
#include <unordered_map>
#include <osquery/numeric_monitoring.h>
namespace osquery {
namespace monitoring {
/**
* Monitoring system smallest unit
* Consists of watched value itself, watching time, unique name for this set of
* values and pre-aggregation type.
* Performs pre-aggregation operations @see tryToAggregate.
*/
class Point {
public:
/**
* Constructor
* Consists of watched value itself, watching time, unique name for this set
* of values and pre-aggregation type.
* @param path Path or in other words unique name for the sequence of
* monitoring values
* @param value Observed value
* @param pre_aggregation_type Pre-aggregation type for the sequence
* @param time_point Time point at which value was observed
*/
explicit Point(std::string path,
ValueType value,
PreAggregationType pre_aggregation_type,
TimePoint time_point);
/**
* Try to aggregate @param new_point into itself.
* If `pre_aggregation_type` and `path` are the same in `new_point`, the value
* of `new_point` will be aggregated with `value` from self and written to
* self `value`. `true` will be returned in this case.
* Otherwise nothing will be changed and `false` will be returned.
*/
bool tryToAggregate(const Point& new_point);
public:
std::string path_;
ValueType value_;
PreAggregationType pre_aggregation_type_;
TimePoint time_point_;
};
class PreAggregationCache {
public:
explicit PreAggregationCache() = default;
void addPoint(Point point);
std::vector<Point> takePoints();
std::size_t size() const noexcept {
return points_.size();
}
private:
std::unordered_map<std::string, std::size_t> points_index_;
std::vector<Point> points_;
};
} // namespace monitoring
} // namespace osquery