virtual void AddToHistogram(const string& name,
gtl::ArraySlice<double> values) = 0;
+ // TODO(shivaniagarawal): consistency in double and float usage.
+ // Add the given `value` as Scalar with the given `name`.
+ virtual void AddScalar(const string& name, float value) = 0;
+
// Stores a protocol buffer representation of the aggregator state in the
// given `out_summary`.
// TODO(mrry): Consider separating this method from the `StatsAggregator`
}
}
+ void AddScalar(const string& name, float value) override {
+ mutex_lock l(mu_);
+ scalars_[name] = value;
+ }
+
void EncodeToProto(Summary* out_summary) override {
mutex_lock l(mu_);
for (const auto& pair : histograms_) {
histogram.EncodeToProto(value->mutable_histo(),
false /* doesn't preserve zero buckets */);
}
+ for (const auto& pair : scalars_) {
+ Summary::Value* value = out_summary->add_value();
+ value->set_tag(pair.first);
+ value->set_simple_value(pair.second);
+ }
}
private:
mutex mu_;
std::unordered_map<string, histogram::Histogram> histograms_ GUARDED_BY(mu_);
+ std::unordered_map<string, float> scalars_ GUARDED_BY(mu_);
TF_DISALLOW_COPY_AND_ASSIGN(StatsAggregatorImpl);
};