Loading cmds/statsd/src/StatsLogProcessor.h +1 −0 Original line number Diff line number Diff line Loading @@ -272,6 +272,7 @@ private: FRIEND_TEST(MetricActivationE2eTest, TestCountMetric); FRIEND_TEST(MetricActivationE2eTest, TestCountMetricWithOneDeactivation); FRIEND_TEST(MetricActivationE2eTest, TestCountMetricWithTwoDeactivations); FRIEND_TEST(MetricActivationE2eTest, TestCountMetricWithSameDeactivation); FRIEND_TEST(MetricActivationE2eTest, TestCountMetricWithTwoMetricsTwoDeactivations); FRIEND_TEST(DurationMetricE2eTest, TestOneBucket); Loading cmds/statsd/src/guardrail/StatsdStats.h +6 −0 Original line number Diff line number Diff line Loading @@ -170,6 +170,12 @@ public: // Vendor pulled atom start id. static const int32_t kVendorPulledAtomStartTag = 150000; // Beginning of range for timestamp truncation. static const int32_t kTimestampTruncationStartTag = 300000; // End of range for timestamp truncation. static const int32_t kTimestampTruncationEndTag = 304999; // Max accepted atom id. static const int32_t kMaxAtomTag = 200000; Loading cmds/statsd/src/metrics/EventMetricProducer.cpp +3 −10 Original line number Diff line number Diff line Loading @@ -146,16 +146,9 @@ void EventMetricProducer::onMatchedLogEventInternalLocked( uint64_t wrapperToken = mProto->start(FIELD_TYPE_MESSAGE | FIELD_COUNT_REPEATED | FIELD_ID_DATA); const bool truncateTimestamp = android::util::AtomsInfo::kNotTruncatingTimestampAtomWhiteList.find(event.GetTagId()) == android::util::AtomsInfo::kNotTruncatingTimestampAtomWhiteList.end(); if (truncateTimestamp) { mProto->write(FIELD_TYPE_INT64 | FIELD_ID_ELAPSED_TIMESTAMP_NANOS, (long long)truncateTimestampNsToFiveMinutes(event.GetElapsedTimestampNs())); } else { mProto->write(FIELD_TYPE_INT64 | FIELD_ID_ELAPSED_TIMESTAMP_NANOS, (long long)event.GetElapsedTimestampNs()); } const int64_t elapsedTimeNs = truncateTimestampIfNecessary( event.GetTagId(), event.GetElapsedTimestampNs()); mProto->write(FIELD_TYPE_INT64 | FIELD_ID_ELAPSED_TIMESTAMP_NANOS, (long long) elapsedTimeNs); uint64_t eventToken = mProto->start(FIELD_TYPE_MESSAGE | FIELD_ID_ATOMS); event.ToProto(*mProto); Loading cmds/statsd/src/metrics/GaugeMetricProducer.cpp +2 −7 Original line number Diff line number Diff line Loading @@ -283,14 +283,9 @@ void GaugeMetricProducer::onDumpReportLocked(const int64_t dumpTimeNs, writeFieldValueTreeToStream(mAtomId, *(atom.mFields), protoOutput); protoOutput->end(atomsToken); } const bool truncateTimestamp = android::util::AtomsInfo::kNotTruncatingTimestampAtomWhiteList.find( mAtomId) == android::util::AtomsInfo::kNotTruncatingTimestampAtomWhiteList.end(); for (const auto& atom : bucket.mGaugeAtoms) { const int64_t elapsedTimestampNs = truncateTimestamp ? truncateTimestampNsToFiveMinutes(atom.mElapsedTimestamps) : atom.mElapsedTimestamps; const int64_t elapsedTimestampNs = truncateTimestampIfNecessary(mAtomId, atom.mElapsedTimestamps); protoOutput->write( FIELD_TYPE_INT64 | FIELD_COUNT_REPEATED | FIELD_ID_ELAPSED_ATOM_TIMESTAMP, (long long)elapsedTimestampNs); Loading cmds/statsd/src/metrics/MetricProducer.cpp +8 −3 Original line number Diff line number Diff line Loading @@ -124,7 +124,8 @@ void MetricProducer::addActivation(int activationTrackerIndex, const ActivationT std::make_shared<Activation>(activationType, ttl_seconds * NS_PER_SEC); mEventActivationMap.emplace(activationTrackerIndex, activation); if (-1 != deactivationTrackerIndex) { mEventDeactivationMap.emplace(deactivationTrackerIndex, activation); auto& deactivationList = mEventDeactivationMap[deactivationTrackerIndex]; deactivationList.push_back(activation); } } Loading Loading @@ -155,7 +156,9 @@ void MetricProducer::cancelEventActivationLocked(int deactivationTrackerIndex) { if (it == mEventDeactivationMap.end()) { return; } it->second->state = ActivationState::kNotActive; for (auto activationToCancelIt : it->second) { activationToCancelIt->state = ActivationState::kNotActive; } } void MetricProducer::loadActiveMetricLocked(const ActiveMetric& activeMetric, Loading @@ -171,7 +174,9 @@ void MetricProducer::loadActiveMetricLocked(const ActiveMetric& activeMetric, continue; } auto& activation = it->second; if (activeEventActivation.state() == ActiveEventActivation::ACTIVE) { // If the event activation does not have a state, assume it is active. if (!activeEventActivation.has_state() || activeEventActivation.state() == ActiveEventActivation::ACTIVE) { // We don't want to change the ttl for future activations, so we set the start_ns // such that start_ns + ttl_ns == currentTimeNs + remaining_ttl_nanos activation->start_ns = Loading Loading
cmds/statsd/src/StatsLogProcessor.h +1 −0 Original line number Diff line number Diff line Loading @@ -272,6 +272,7 @@ private: FRIEND_TEST(MetricActivationE2eTest, TestCountMetric); FRIEND_TEST(MetricActivationE2eTest, TestCountMetricWithOneDeactivation); FRIEND_TEST(MetricActivationE2eTest, TestCountMetricWithTwoDeactivations); FRIEND_TEST(MetricActivationE2eTest, TestCountMetricWithSameDeactivation); FRIEND_TEST(MetricActivationE2eTest, TestCountMetricWithTwoMetricsTwoDeactivations); FRIEND_TEST(DurationMetricE2eTest, TestOneBucket); Loading
cmds/statsd/src/guardrail/StatsdStats.h +6 −0 Original line number Diff line number Diff line Loading @@ -170,6 +170,12 @@ public: // Vendor pulled atom start id. static const int32_t kVendorPulledAtomStartTag = 150000; // Beginning of range for timestamp truncation. static const int32_t kTimestampTruncationStartTag = 300000; // End of range for timestamp truncation. static const int32_t kTimestampTruncationEndTag = 304999; // Max accepted atom id. static const int32_t kMaxAtomTag = 200000; Loading
cmds/statsd/src/metrics/EventMetricProducer.cpp +3 −10 Original line number Diff line number Diff line Loading @@ -146,16 +146,9 @@ void EventMetricProducer::onMatchedLogEventInternalLocked( uint64_t wrapperToken = mProto->start(FIELD_TYPE_MESSAGE | FIELD_COUNT_REPEATED | FIELD_ID_DATA); const bool truncateTimestamp = android::util::AtomsInfo::kNotTruncatingTimestampAtomWhiteList.find(event.GetTagId()) == android::util::AtomsInfo::kNotTruncatingTimestampAtomWhiteList.end(); if (truncateTimestamp) { mProto->write(FIELD_TYPE_INT64 | FIELD_ID_ELAPSED_TIMESTAMP_NANOS, (long long)truncateTimestampNsToFiveMinutes(event.GetElapsedTimestampNs())); } else { mProto->write(FIELD_TYPE_INT64 | FIELD_ID_ELAPSED_TIMESTAMP_NANOS, (long long)event.GetElapsedTimestampNs()); } const int64_t elapsedTimeNs = truncateTimestampIfNecessary( event.GetTagId(), event.GetElapsedTimestampNs()); mProto->write(FIELD_TYPE_INT64 | FIELD_ID_ELAPSED_TIMESTAMP_NANOS, (long long) elapsedTimeNs); uint64_t eventToken = mProto->start(FIELD_TYPE_MESSAGE | FIELD_ID_ATOMS); event.ToProto(*mProto); Loading
cmds/statsd/src/metrics/GaugeMetricProducer.cpp +2 −7 Original line number Diff line number Diff line Loading @@ -283,14 +283,9 @@ void GaugeMetricProducer::onDumpReportLocked(const int64_t dumpTimeNs, writeFieldValueTreeToStream(mAtomId, *(atom.mFields), protoOutput); protoOutput->end(atomsToken); } const bool truncateTimestamp = android::util::AtomsInfo::kNotTruncatingTimestampAtomWhiteList.find( mAtomId) == android::util::AtomsInfo::kNotTruncatingTimestampAtomWhiteList.end(); for (const auto& atom : bucket.mGaugeAtoms) { const int64_t elapsedTimestampNs = truncateTimestamp ? truncateTimestampNsToFiveMinutes(atom.mElapsedTimestamps) : atom.mElapsedTimestamps; const int64_t elapsedTimestampNs = truncateTimestampIfNecessary(mAtomId, atom.mElapsedTimestamps); protoOutput->write( FIELD_TYPE_INT64 | FIELD_COUNT_REPEATED | FIELD_ID_ELAPSED_ATOM_TIMESTAMP, (long long)elapsedTimestampNs); Loading
cmds/statsd/src/metrics/MetricProducer.cpp +8 −3 Original line number Diff line number Diff line Loading @@ -124,7 +124,8 @@ void MetricProducer::addActivation(int activationTrackerIndex, const ActivationT std::make_shared<Activation>(activationType, ttl_seconds * NS_PER_SEC); mEventActivationMap.emplace(activationTrackerIndex, activation); if (-1 != deactivationTrackerIndex) { mEventDeactivationMap.emplace(deactivationTrackerIndex, activation); auto& deactivationList = mEventDeactivationMap[deactivationTrackerIndex]; deactivationList.push_back(activation); } } Loading Loading @@ -155,7 +156,9 @@ void MetricProducer::cancelEventActivationLocked(int deactivationTrackerIndex) { if (it == mEventDeactivationMap.end()) { return; } it->second->state = ActivationState::kNotActive; for (auto activationToCancelIt : it->second) { activationToCancelIt->state = ActivationState::kNotActive; } } void MetricProducer::loadActiveMetricLocked(const ActiveMetric& activeMetric, Loading @@ -171,7 +174,9 @@ void MetricProducer::loadActiveMetricLocked(const ActiveMetric& activeMetric, continue; } auto& activation = it->second; if (activeEventActivation.state() == ActiveEventActivation::ACTIVE) { // If the event activation does not have a state, assume it is active. if (!activeEventActivation.has_state() || activeEventActivation.state() == ActiveEventActivation::ACTIVE) { // We don't want to change the ttl for future activations, so we set the start_ns // such that start_ns + ttl_ns == currentTimeNs + remaining_ttl_nanos activation->start_ns = Loading