blob: dfa3cdb1f51a04fde8e8308e0c8434bdcf9befc7 [file] [log] [blame]
// Copyright 2020 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COBALT_SRC_LOCAL_AGGREGATION_1_1_AGGREGATION_PROCEDURES_NUMERIC_STAT_AGGREGATION_PROCEDURE_H_
#define COBALT_SRC_LOCAL_AGGREGATION_1_1_AGGREGATION_PROCEDURES_NUMERIC_STAT_AGGREGATION_PROCEDURE_H_
#include <memory>
#include <set>
#include <vector>
#include "src/lib/statusor/statusor.h"
#include "src/local_aggregation_1_1/aggregation_procedures/aggregation_procedure.h"
#include "src/logger/event_record.h"
#include "src/registry/metric_definition.pb.h"
#include "src/registry/report_definition.pb.h"
namespace cobalt::local_aggregation {
class NumericStatAggregationProcedure : public AggregationProcedure {
public:
static std::unique_ptr<NumericStatAggregationProcedure> New(const MetricDefinition &metric,
const ReportDefinition &report);
explicit NumericStatAggregationProcedure(const MetricDefinition &metric,
const ReportDefinition &report);
[[nodiscard]] bool IsDaily() const override;
lib::statusor::StatusOr<std::unique_ptr<Observation>> GenerateSingleObservation(
const std::vector<EventCodeAggregate *> &aggregates,
const std::set<std::vector<uint32_t>> &event_vectors) override;
protected:
virtual int64_t CollectValue(const std::vector<const AggregateData *> &aggregates) = 0;
};
#define PROCEDURE(type) \
class type##NumericStatAggregationProcedure : public NumericStatAggregationProcedure { \
public: \
explicit type##NumericStatAggregationProcedure(const MetricDefinition &metric, \
const ReportDefinition &report) \
: NumericStatAggregationProcedure(metric, report){}; \
\
void UpdateAggregateData(const logger::EventRecord &event_record, \
AggregateData *aggregate_data, \
EventCodeAggregate * /*aggregate*/) override; \
\
[[nodiscard]] std::string DebugString() const override { return #type " NUMERIC_STAT"; } \
\
private: \
int64_t CollectValue(const std::vector<const AggregateData *> &aggregates) override; \
};
PROCEDURE(Sum);
PROCEDURE(Min);
PROCEDURE(Max);
PROCEDURE(Mean);
PROCEDURE(Median);
class PercentileNNumericStatAggregationProcedure : public MedianNumericStatAggregationProcedure {
public:
explicit PercentileNNumericStatAggregationProcedure(const MetricDefinition &metric,
const ReportDefinition &report)
: MedianNumericStatAggregationProcedure(metric, report),
percentile_n_(report.local_aggregation_procedure_percentile_n()) {}
[[nodiscard]] std::string DebugString() const override { return "PercentileN NUMERIC_STAT"; }
private:
int64_t CollectValue(const std::vector<const AggregateData *> &aggregates) override;
uint32_t percentile_n_;
};
} // namespace cobalt::local_aggregation
#endif // COBALT_SRC_LOCAL_AGGREGATION_1_1_AGGREGATION_PROCEDURES_NUMERIC_STAT_AGGREGATION_PROCEDURE_H_