Merge "Dump the stats for count/gauge/value metrics." into pi-dev

This commit is contained in:
TreeHugger Robot
2018-03-14 16:45:49 +00:00
committed by Android (Google) Code Review
6 changed files with 56 additions and 3 deletions

View File

@@ -99,6 +99,24 @@ CountMetricProducer::~CountMetricProducer() {
VLOG("~CountMetricProducer() called");
}
void CountMetricProducer::dumpStatesLocked(FILE* out, bool verbose) const {
if (mCurrentSlicedCounter == nullptr ||
mCurrentSlicedCounter->size() == 0) {
return;
}
fprintf(out, "CountMetric %lld dimension size %lu\n", (long long)mMetricId,
(unsigned long)mCurrentSlicedCounter->size());
if (verbose) {
for (const auto& it : *mCurrentSlicedCounter) {
fprintf(out, "\t(what)%s\t(condition)%s %lld\n",
it.first.getDimensionKeyInWhat().toString().c_str(),
it.first.getDimensionKeyInCondition().toString().c_str(),
(unsigned long long)it.second);
}
}
}
void CountMetricProducer::onSlicedConditionMayChangeLocked(const uint64_t eventTime) {
VLOG("Metric %lld onSlicedConditionMayChange", (long long)mMetricId);
}

View File

@@ -67,7 +67,7 @@ private:
// Internal function to calculate the current used bytes.
size_t byteSizeLocked() const override;
void dumpStatesLocked(FILE* out, bool verbose) const override{};
void dumpStatesLocked(FILE* out, bool verbose) const override;
void dropDataLocked(const uint64_t dropTimeNs) override;

View File

@@ -126,6 +126,24 @@ GaugeMetricProducer::~GaugeMetricProducer() {
}
}
void GaugeMetricProducer::dumpStatesLocked(FILE* out, bool verbose) const {
if (mCurrentSlicedBucket == nullptr ||
mCurrentSlicedBucket->size() == 0) {
return;
}
fprintf(out, "GaugeMetric %lld dimension size %lu\n", (long long)mMetricId,
(unsigned long)mCurrentSlicedBucket->size());
if (verbose) {
for (const auto& it : *mCurrentSlicedBucket) {
fprintf(out, "\t(what)%s\t(condition)%s %d atoms\n",
it.first.getDimensionKeyInWhat().toString().c_str(),
it.first.getDimensionKeyInCondition().toString().c_str(),
(int)it.second.size());
}
}
}
void GaugeMetricProducer::onDumpReportLocked(const uint64_t dumpTimeNs,
ProtoOutputStream* protoOutput) {
VLOG("gauge metric %lld report now...", (long long)mMetricId);

View File

@@ -106,7 +106,7 @@ private:
// Internal function to calculate the current used bytes.
size_t byteSizeLocked() const override;
void dumpStatesLocked(FILE* out, bool verbose) const override{};
void dumpStatesLocked(FILE* out, bool verbose) const override;
void dropDataLocked(const uint64_t dropTimeNs) override;

View File

@@ -243,6 +243,23 @@ void ValueMetricProducer::onDataPulled(const std::vector<std::shared_ptr<LogEven
}
}
void ValueMetricProducer::dumpStatesLocked(FILE* out, bool verbose) const {
if (mCurrentSlicedBucket.size() == 0) {
return;
}
fprintf(out, "ValueMetric %lld dimension size %lu\n", (long long)mMetricId,
(unsigned long)mCurrentSlicedBucket.size());
if (verbose) {
for (const auto& it : mCurrentSlicedBucket) {
fprintf(out, "\t(what)%s\t(condition)%s (value)%lld\n",
it.first.getDimensionKeyInWhat().toString().c_str(),
it.first.getDimensionKeyInCondition().toString().c_str(),
(unsigned long long)it.second.sum);
}
}
}
bool ValueMetricProducer::hitGuardRailLocked(const MetricDimensionKey& newKey) {
// ===========GuardRail==============
// 1. Report the tuple count if the tuple count > soft limit

View File

@@ -99,7 +99,7 @@ private:
// Internal function to calculate the current used bytes.
size_t byteSizeLocked() const override;
void dumpStatesLocked(FILE* out, bool verbose) const override{};
void dumpStatesLocked(FILE* out, bool verbose) const override;
// Util function to flush the old packet.
void flushIfNeededLocked(const uint64_t& eventTime) override;