summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2024-01-07 22:48:53 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2024-01-07 22:48:53 +0000
commit777896d3fa9a3d4d3b2a468920c1f2ca1579fef5 (patch)
treead21b5a6a8186dc350fc3e49300fe20bf6fcffbb
parent448ee280f8da54b47ceb61afb4c98397846003a1 (diff)
parenta730024491cd273a32cee2d4de0bb14af5737918 (diff)
downloadStatsD-777896d3fa9a3d4d3b2a468920c1f2ca1579fef5.tar.gz
Snap for 11282912 from a730024491cd273a32cee2d4de0bb14af5737918 to mainline-mediaprovider-release
Change-Id: I5b4e8386d31a3214fba9687deb81fcb11d0b01db
-rw-r--r--lib/libstatssocket/utils.h1
-rw-r--r--statsd/Android.bp117
-rw-r--r--statsd/benchmark/db_benchmark.cpp2
-rw-r--r--statsd/benchmark/duration_metric_benchmark.cpp41
-rw-r--r--statsd/benchmark/filter_value_benchmark.cpp2
-rw-r--r--statsd/benchmark/get_dimensions_for_condition_benchmark.cpp2
-rw-r--r--statsd/benchmark/metric_util.cpp381
-rw-r--r--statsd/benchmark/metric_util.h140
-rw-r--r--statsd/benchmark/stats_write_benchmark.cpp20
-rw-r--r--statsd/src/HashableDimensionKey.h21
-rw-r--r--statsd/src/StatsLogProcessor.cpp12
-rw-r--r--statsd/src/StatsLogProcessor.h45
-rw-r--r--statsd/src/StatsService.cpp3
-rw-r--r--statsd/src/StatsService.h2
-rw-r--r--statsd/src/anomaly/AlarmMonitor.cpp6
-rw-r--r--statsd/src/anomaly/AlarmMonitor.h8
-rw-r--r--statsd/src/anomaly/AlarmTracker.cpp2
-rw-r--r--statsd/src/anomaly/AlarmTracker.h3
-rw-r--r--statsd/src/anomaly/AnomalyTracker.cpp33
-rw-r--r--statsd/src/anomaly/AnomalyTracker.h31
-rw-r--r--statsd/src/anomaly/DurationAnomalyTracker.cpp8
-rw-r--r--statsd/src/anomaly/DurationAnomalyTracker.h7
-rw-r--r--statsd/src/anomaly/subscriber_util.h2
-rw-r--r--statsd/src/condition/CombinationConditionTracker.cpp2
-rw-r--r--statsd/src/condition/CombinationConditionTracker.h4
-rw-r--r--statsd/src/condition/ConditionTracker.h4
-rw-r--r--statsd/src/condition/SimpleConditionTracker.cpp2
-rw-r--r--statsd/src/condition/SimpleConditionTracker.h4
-rw-r--r--statsd/src/config/ConfigKey.cpp2
-rw-r--r--statsd/src/config/ConfigKey.h15
-rw-r--r--statsd/src/config/ConfigKeyWithPackage.h2
-rw-r--r--statsd/src/config/ConfigManager.h4
-rw-r--r--statsd/src/external/PullResultReceiver.h4
-rw-r--r--statsd/src/external/StatsCallbackPuller.cpp2
-rw-r--r--statsd/src/external/StatsCallbackPuller.h4
-rw-r--r--statsd/src/external/StatsPuller.cpp2
-rw-r--r--statsd/src/external/StatsPuller.h7
-rw-r--r--statsd/src/external/StatsPullerManager.cpp12
-rw-r--r--statsd/src/external/StatsPullerManager.h21
-rw-r--r--statsd/src/guardrail/StatsdStats.cpp38
-rw-r--r--statsd/src/guardrail/StatsdStats.h87
-rw-r--r--statsd/src/guardrail/stats_log_enums.proto1
-rw-r--r--statsd/src/logd/LogEventQueue.cpp13
-rw-r--r--statsd/src/logd/LogEventQueue.h10
-rw-r--r--statsd/src/metrics/CountMetricProducer.cpp8
-rw-r--r--statsd/src/metrics/CountMetricProducer.h17
-rw-r--r--statsd/src/metrics/DurationMetricProducer.cpp6
-rw-r--r--statsd/src/metrics/DurationMetricProducer.h28
-rw-r--r--statsd/src/metrics/EventMetricProducer.h10
-rw-r--r--statsd/src/metrics/GaugeMetricProducer.cpp15
-rw-r--r--statsd/src/metrics/GaugeMetricProducer.h26
-rw-r--r--statsd/src/metrics/MetricProducer.cpp12
-rw-r--r--statsd/src/metrics/MetricProducer.h39
-rw-r--r--statsd/src/metrics/MetricsManager.cpp13
-rw-r--r--statsd/src/metrics/MetricsManager.h27
-rw-r--r--statsd/src/metrics/NumericValueMetricProducer.h2
-rw-r--r--statsd/src/metrics/RestrictedEventMetricProducer.h4
-rw-r--r--statsd/src/metrics/ValueMetricProducer.cpp8
-rw-r--r--statsd/src/metrics/ValueMetricProducer.h17
-rw-r--r--statsd/src/metrics/duration_helper/DurationTracker.h24
-rw-r--r--statsd/src/metrics/duration_helper/MaxDurationTracker.cpp12
-rw-r--r--statsd/src/metrics/duration_helper/MaxDurationTracker.h15
-rw-r--r--statsd/src/metrics/duration_helper/OringDurationTracker.cpp15
-rw-r--r--statsd/src/metrics/duration_helper/OringDurationTracker.h22
-rw-r--r--statsd/src/metrics/parsing_utils/config_update_utils.cpp2
-rw-r--r--statsd/src/metrics/parsing_utils/config_update_utils.h10
-rw-r--r--statsd/src/metrics/parsing_utils/metrics_manager_util.cpp26
-rw-r--r--statsd/src/metrics/parsing_utils/metrics_manager_util.h43
-rw-r--r--statsd/src/packages/PackageInfoListener.h9
-rw-r--r--statsd/src/packages/UidMap.cpp16
-rw-r--r--statsd/src/packages/UidMap.h29
-rw-r--r--statsd/src/shell/ShellSubscriber.h2
-rw-r--r--statsd/src/socket/StatsSocketListener.cpp11
-rw-r--r--statsd/src/socket/StatsSocketListener.h3
-rw-r--r--statsd/src/state/StateManager.cpp4
-rw-r--r--statsd/src/state/StateManager.h8
-rw-r--r--statsd/src/state/StateTracker.cpp8
-rw-r--r--statsd/src/state/StateTracker.h6
-rw-r--r--statsd/src/stats_log.proto7
-rw-r--r--statsd/src/stats_log_util.cpp2
-rw-r--r--statsd/src/stats_log_util.h4
-rw-r--r--statsd/src/statsd_config.proto2
-rw-r--r--statsd/src/storage/StorageManager.h5
-rw-r--r--statsd/src/utils/DbUtils.h15
-rw-r--r--statsd/src/utils/MultiConditionTrigger.cpp2
-rw-r--r--statsd/src/utils/ShardOffsetProvider.h1
-rw-r--r--statsd/tests/SocketListener_test.cpp7
-rw-r--r--statsd/tests/anomaly/AnomalyTracker_test.cpp14
-rw-r--r--statsd/tests/e2e/GaugeMetric_e2e_push_test.cpp172
-rw-r--r--statsd/tests/guardrail/StatsdStats_test.cpp10
-rw-r--r--statsd/tests/indexed_priority_queue_test.cpp2
-rw-r--r--statsd/tests/log_event/LogEventQueue_test.cpp124
-rw-r--r--statsd/tests/metrics/metrics_test_helper.h12
-rw-r--r--statsd/tests/metrics/parsing_utils/metrics_manager_util_test.cpp59
-rw-r--r--statsd/tests/statsd_test_util.h48
95 files changed, 973 insertions, 1139 deletions
diff --git a/lib/libstatssocket/utils.h b/lib/libstatssocket/utils.h
index be1339e1..1eada991 100644
--- a/lib/libstatssocket/utils.h
+++ b/lib/libstatssocket/utils.h
@@ -18,6 +18,7 @@
#include <stddef.h>
#include <stdint.h>
+#include <sys/cdefs.h>
__BEGIN_DECLS
diff --git a/statsd/Android.bp b/statsd/Android.bp
index 616b112f..d1b4a2e9 100644
--- a/statsd/Android.bp
+++ b/statsd/Android.bp
@@ -231,13 +231,61 @@ cc_binary {
min_sdk_version: "30",
}
+
+cc_defaults {
+ name: "statsd_test_defaults",
+ defaults: ["statsd_defaults"],
+ srcs: [
+ // atom_field_options.proto needs field_options.proto, but that is
+ // not included in libprotobuf-cpp-lite, so compile it here.
+ ":libprotobuf-internal-protos",
+ ":libstats_internal_protos",
+
+ "src/shell/shell_data.proto",
+ "src/stats_log.proto",
+ ],
+ cflags: [
+ "-Wall",
+ "-Werror",
+ "-Wno-enum-compare",
+ "-Wno-missing-field-initializers",
+ "-Wno-unused-function",
+ "-Wno-unused-parameter",
+ "-Wno-unused-variable",
+ ],
+ static_libs: [
+ "libgmock",
+ "libstatslog_statsdtest",
+ "libstatssocket_private",
+ ],
+ proto: {
+ type: "lite",
+ include_dirs: [
+ "external/protobuf/src",
+ "frameworks/proto_logging/stats",
+ ],
+ static: true,
+ },
+}
+
+cc_library_static {
+ name: "libstats_test_utils",
+ defaults: ["statsd_test_defaults"],
+ srcs: [
+ "tests/statsd_test_util.cpp",
+ ],
+ tidy_timeout_srcs: [
+ "tests/statsd_test_util.cpp",
+ ],
+}
+
// ==============
// statsd_test
// ==============
cc_test {
name: "statsd_test",
- defaults: ["statsd_defaults"],
+ defaults: ["statsd_test_defaults"],
test_suites: [
"device-tests",
"mts-statsd",
@@ -256,16 +304,6 @@ cc_test {
},
},
- cflags: [
- "-Wall",
- "-Werror",
- "-Wno-enum-compare",
- "-Wno-missing-field-initializers",
- "-Wno-unused-function",
- "-Wno-unused-parameter",
- "-Wno-unused-variable",
- ],
-
require_root: true,
tidy_timeout_srcs: [
@@ -300,19 +338,11 @@ cc_test {
"tests/metrics/parsing_utils/config_update_utils_test.cpp",
"tests/metrics/parsing_utils/metrics_manager_util_test.cpp",
"tests/state/StateTracker_test.cpp",
- "tests/statsd_test_util.cpp",
"tests/StatsLogProcessor_test.cpp",
"tests/UidMap_test.cpp",
],
srcs: [
- // atom_field_options.proto needs field_options.proto, but that is
- // not included in libprotobuf-cpp-lite, so compile it here.
- ":libprotobuf-internal-protos",
- ":libstats_internal_protos",
-
- "src/shell/shell_data.proto",
- "src/stats_log.proto",
"tests/AlarmMonitor_test.cpp",
"tests/anomaly/AlarmTracker_test.cpp",
"tests/anomaly/AnomalyTracker_test.cpp",
@@ -370,7 +400,6 @@ cc_test {
"tests/MetricsManager_test.cpp",
"tests/shell/ShellSubscriber_test.cpp",
"tests/state/StateTracker_test.cpp",
- "tests/statsd_test_util.cpp",
"tests/statsd_test_util_test.cpp",
"tests/SocketListener_test.cpp",
"tests/StatsLogProcessor_test.cpp",
@@ -382,20 +411,10 @@ cc_test {
],
static_libs: [
- "libgmock",
"libstatsgtestmatchers",
- "libstatslog_statsdtest",
- "libstatssocket_private",
+ "libstats_test_utils",
],
- proto: {
- type: "lite",
- include_dirs: [
- "external/protobuf/src",
- "frameworks/proto_logging/stats",
- ],
- static: true,
- },
min_sdk_version: "30",
}
@@ -406,14 +425,9 @@ cc_test {
cc_benchmark {
name: "statsd_benchmark",
- defaults: ["statsd_defaults"],
+ defaults: ["statsd_test_defaults"],
srcs: [
- // atom_field_options.proto needs field_options.proto, but that is
- // not included in libprotobuf-cpp-lite, so compile it here.
- ":libprotobuf-internal-protos",
- ":libstats_internal_protos",
-
"benchmark/data_structures_benchmark.cpp",
"benchmark/db_benchmark.cpp",
"benchmark/duration_metric_benchmark.cpp",
@@ -423,43 +437,18 @@ cc_benchmark {
"benchmark/log_event_benchmark.cpp",
"benchmark/log_event_filter_benchmark.cpp",
"benchmark/main.cpp",
- "benchmark/metric_util.cpp",
"benchmark/stats_write_benchmark.cpp",
"benchmark/loss_info_container_benchmark.cpp",
- "src/stats_log.proto",
],
- proto: {
- type: "lite",
- include_dirs: [
- "external/protobuf/src",
- "frameworks/proto_logging/stats",
- ],
- },
-
cflags: [
- "-Wall",
- "-Werror",
- "-Wno-unused-parameter",
- "-Wno-unused-variable",
- "-Wno-unused-function",
-
// Bug: http://b/29823425 Disable -Wvarargs for Clang update to r271374
"-Wno-varargs",
],
static_libs: [
- "libplatformprotos",
- "libstatssocket_private",
- ],
-
- shared_libs: [
- "libprotobuf-cpp-lite",
- "libstatslog",
- ],
-
- header_libs: [
- "libgtest_prod_headers",
+ "libgtest",
+ "libstats_test_utils",
],
}
diff --git a/statsd/benchmark/db_benchmark.cpp b/statsd/benchmark/db_benchmark.cpp
index ebe751a2..b9b16949 100644
--- a/statsd/benchmark/db_benchmark.cpp
+++ b/statsd/benchmark/db_benchmark.cpp
@@ -15,7 +15,7 @@
*/
#include "benchmark/benchmark.h"
-#include "metric_util.h"
+#include "tests/statsd_test_util.h"
#include "utils/DbUtils.h"
using namespace std;
diff --git a/statsd/benchmark/duration_metric_benchmark.cpp b/statsd/benchmark/duration_metric_benchmark.cpp
index 2d315d93..a87b5eed 100644
--- a/statsd/benchmark/duration_metric_benchmark.cpp
+++ b/statsd/benchmark/duration_metric_benchmark.cpp
@@ -14,12 +14,13 @@
* limitations under the License.
*/
#include <vector>
-#include "benchmark/benchmark.h"
+
#include "FieldValue.h"
#include "HashableDimensionKey.h"
+#include "benchmark/benchmark.h"
#include "logd/LogEvent.h"
#include "stats_log_util.h"
-#include "metric_util.h"
+#include "tests/statsd_test_util.h"
namespace android {
namespace os {
@@ -39,15 +40,15 @@ static StatsdConfig CreateDurationMetricConfig_NoLink_AND_CombinationCondition(
auto scheduledJobPredicate = CreateScheduledJobPredicate();
auto dimensions = scheduledJobPredicate.mutable_simple_predicate()->mutable_dimensions();
- dimensions->set_field(android::util::SCHEDULED_JOB_STATE_CHANGED);
+ dimensions->set_field(util::SCHEDULED_JOB_STATE_CHANGED);
dimensions->add_child()->set_field(2); // job name field.
auto screenIsOffPredicate = CreateScreenIsOffPredicate();
auto isSyncingPredicate = CreateIsSyncingPredicate();
auto syncDimension = isSyncingPredicate.mutable_simple_predicate()->mutable_dimensions();
- *syncDimension = CreateAttributionUidAndTagDimensions(android::util::SYNC_STATE_CHANGED,
- {Position::FIRST});
+ *syncDimension =
+ CreateAttributionUidAndTagDimensions(util::SYNC_STATE_CHANGED, {Position::FIRST});
if (addExtraDimensionInCondition) {
syncDimension->add_child()->set_field(2 /* name field*/);
}
@@ -68,10 +69,10 @@ static StatsdConfig CreateDurationMetricConfig_NoLink_AND_CombinationCondition(
metric->set_condition(combinationPredicate->id());
metric->set_aggregation_type(aggregationType);
auto dimensionWhat = metric->mutable_dimensions_in_what();
- dimensionWhat->set_field(android::util::SCHEDULED_JOB_STATE_CHANGED);
+ dimensionWhat->set_field(util::SCHEDULED_JOB_STATE_CHANGED);
dimensionWhat->add_child()->set_field(2); // job name field.
- *metric->mutable_dimensions_in_condition() = CreateAttributionUidAndTagDimensions(
- android::util::SYNC_STATE_CHANGED, {Position::FIRST});
+ *metric->mutable_dimensions_in_condition() =
+ CreateAttributionUidAndTagDimensions(util::SYNC_STATE_CHANGED, {Position::FIRST});
return config;
}
@@ -87,14 +88,13 @@ static StatsdConfig CreateDurationMetricConfig_Link_AND_CombinationCondition(
auto scheduledJobPredicate = CreateScheduledJobPredicate();
auto dimensions = scheduledJobPredicate.mutable_simple_predicate()->mutable_dimensions();
- *dimensions = CreateAttributionUidDimensions(
- android::util::SCHEDULED_JOB_STATE_CHANGED, {Position::FIRST});
+ *dimensions =
+ CreateAttributionUidDimensions(util::SCHEDULED_JOB_STATE_CHANGED, {Position::FIRST});
dimensions->add_child()->set_field(2); // job name field.
auto isSyncingPredicate = CreateIsSyncingPredicate();
auto syncDimension = isSyncingPredicate.mutable_simple_predicate()->mutable_dimensions();
- *syncDimension = CreateAttributionUidDimensions(
- android::util::SYNC_STATE_CHANGED, {Position::FIRST});
+ *syncDimension = CreateAttributionUidDimensions(util::SYNC_STATE_CHANGED, {Position::FIRST});
if (addExtraDimensionInCondition) {
syncDimension->add_child()->set_field(2 /* name field*/);
}
@@ -116,16 +116,15 @@ static StatsdConfig CreateDurationMetricConfig_Link_AND_CombinationCondition(
metric->set_what(scheduledJobPredicate.id());
metric->set_condition(combinationPredicate->id());
metric->set_aggregation_type(aggregationType);
- *metric->mutable_dimensions_in_what() = CreateAttributionUidDimensions(
- android::util::SCHEDULED_JOB_STATE_CHANGED, {Position::FIRST});
+ *metric->mutable_dimensions_in_what() =
+ CreateAttributionUidDimensions(util::SCHEDULED_JOB_STATE_CHANGED, {Position::FIRST});
auto links = metric->add_links();
links->set_condition(isSyncingPredicate.id());
*links->mutable_fields_in_what() =
- CreateAttributionUidDimensions(
- android::util::SCHEDULED_JOB_STATE_CHANGED, {Position::FIRST});
+ CreateAttributionUidDimensions(util::SCHEDULED_JOB_STATE_CHANGED, {Position::FIRST});
*links->mutable_fields_in_condition() =
- CreateAttributionUidDimensions(android::util::SYNC_STATE_CHANGED, {Position::FIRST});
+ CreateAttributionUidDimensions(util::SYNC_STATE_CHANGED, {Position::FIRST});
return config;
}
@@ -208,8 +207,8 @@ static void BM_DurationMetricNoLink(benchmark::State& state) {
sortLogEventsByTimestamp(&events);
while (state.KeepRunning()) {
- auto processor = CreateStatsLogProcessor(
- bucketStartTimeNs / NS_PER_SEC, config, cfgKey);
+ auto processor =
+ CreateStatsLogProcessor(bucketStartTimeNs, bucketStartTimeNs, config, cfgKey);
for (const auto& event : events) {
processor->OnLogEvent(event.get());
}
@@ -299,8 +298,8 @@ static void BM_DurationMetricLink(benchmark::State& state) {
sortLogEventsByTimestamp(&events);
while (state.KeepRunning()) {
- auto processor = CreateStatsLogProcessor(
- bucketStartTimeNs / NS_PER_SEC, config, cfgKey);
+ auto processor =
+ CreateStatsLogProcessor(bucketStartTimeNs, bucketStartTimeNs, config, cfgKey);
for (const auto& event : events) {
processor->OnLogEvent(event.get());
}
diff --git a/statsd/benchmark/filter_value_benchmark.cpp b/statsd/benchmark/filter_value_benchmark.cpp
index 743ccc4e..06420706 100644
--- a/statsd/benchmark/filter_value_benchmark.cpp
+++ b/statsd/benchmark/filter_value_benchmark.cpp
@@ -19,9 +19,9 @@
#include "HashableDimensionKey.h"
#include "benchmark/benchmark.h"
#include "logd/LogEvent.h"
-#include "metric_util.h"
#include "stats_event.h"
#include "stats_log_util.h"
+#include "tests/statsd_test_util.h"
namespace android {
namespace os {
diff --git a/statsd/benchmark/get_dimensions_for_condition_benchmark.cpp b/statsd/benchmark/get_dimensions_for_condition_benchmark.cpp
index 7a455650..99570667 100644
--- a/statsd/benchmark/get_dimensions_for_condition_benchmark.cpp
+++ b/statsd/benchmark/get_dimensions_for_condition_benchmark.cpp
@@ -19,9 +19,9 @@
#include "HashableDimensionKey.h"
#include "benchmark/benchmark.h"
#include "logd/LogEvent.h"
-#include "metric_util.h"
#include "stats_event.h"
#include "stats_log_util.h"
+#include "tests/statsd_test_util.h"
namespace android {
namespace os {
diff --git a/statsd/benchmark/metric_util.cpp b/statsd/benchmark/metric_util.cpp
deleted file mode 100644
index a1e978ac..00000000
--- a/statsd/benchmark/metric_util.cpp
+++ /dev/null
@@ -1,381 +0,0 @@
-// Copyright (C) 2017 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#include "metric_util.h"
-
-#include "stats_event.h"
-
-namespace android {
-namespace os {
-namespace statsd {
-
-AtomMatcher CreateSimpleAtomMatcher(const string& name, int atomId) {
- AtomMatcher atom_matcher;
- atom_matcher.set_id(StringToId(name));
- auto simple_atom_matcher = atom_matcher.mutable_simple_atom_matcher();
- simple_atom_matcher->set_atom_id(atomId);
- return atom_matcher;
-}
-
-AtomMatcher CreateScheduledJobStateChangedAtomMatcher(const string& name,
- ScheduledJobStateChanged::State state) {
- AtomMatcher atom_matcher;
- atom_matcher.set_id(StringToId(name));
- auto simple_atom_matcher = atom_matcher.mutable_simple_atom_matcher();
- simple_atom_matcher->set_atom_id(android::util::SCHEDULED_JOB_STATE_CHANGED);
- auto field_value_matcher = simple_atom_matcher->add_field_value_matcher();
- field_value_matcher->set_field(3); // State field.
- field_value_matcher->set_eq_int(state);
- return atom_matcher;
-}
-
-AtomMatcher CreateStartScheduledJobAtomMatcher() {
- return CreateScheduledJobStateChangedAtomMatcher("ScheduledJobStart",
- ScheduledJobStateChanged::STARTED);
-}
-
-AtomMatcher CreateFinishScheduledJobAtomMatcher() {
- return CreateScheduledJobStateChangedAtomMatcher("ScheduledJobFinish",
- ScheduledJobStateChanged::FINISHED);
-}
-
-AtomMatcher CreateScreenBrightnessChangedAtomMatcher() {
- AtomMatcher atom_matcher;
- atom_matcher.set_id(StringToId("ScreenBrightnessChanged"));
- auto simple_atom_matcher = atom_matcher.mutable_simple_atom_matcher();
- simple_atom_matcher->set_atom_id(android::util::SCREEN_BRIGHTNESS_CHANGED);
- return atom_matcher;
-}
-
-AtomMatcher CreateUidProcessStateChangedAtomMatcher() {
- AtomMatcher atom_matcher;
- atom_matcher.set_id(StringToId("UidProcessStateChanged"));
- auto simple_atom_matcher = atom_matcher.mutable_simple_atom_matcher();
- simple_atom_matcher->set_atom_id(android::util::UID_PROCESS_STATE_CHANGED);
- return atom_matcher;
-}
-
-AtomMatcher CreateWakelockStateChangedAtomMatcher(const string& name,
- WakelockStateChanged::State state) {
- AtomMatcher atom_matcher;
- atom_matcher.set_id(StringToId(name));
- auto simple_atom_matcher = atom_matcher.mutable_simple_atom_matcher();
- simple_atom_matcher->set_atom_id(android::util::WAKELOCK_STATE_CHANGED);
- auto field_value_matcher = simple_atom_matcher->add_field_value_matcher();
- field_value_matcher->set_field(4); // State field.
- field_value_matcher->set_eq_int(state);
- return atom_matcher;
-}
-
-AtomMatcher CreateAcquireWakelockAtomMatcher() {
- return CreateWakelockStateChangedAtomMatcher("AcquireWakelock", WakelockStateChanged::ACQUIRE);
-}
-
-AtomMatcher CreateReleaseWakelockAtomMatcher() {
- return CreateWakelockStateChangedAtomMatcher("ReleaseWakelock", WakelockStateChanged::RELEASE);
-}
-
-AtomMatcher CreateScreenStateChangedAtomMatcher(
- const string& name, android::view::DisplayStateEnum state) {
- AtomMatcher atom_matcher;
- atom_matcher.set_id(StringToId(name));
- auto simple_atom_matcher = atom_matcher.mutable_simple_atom_matcher();
- simple_atom_matcher->set_atom_id(android::util::SCREEN_STATE_CHANGED);
- auto field_value_matcher = simple_atom_matcher->add_field_value_matcher();
- field_value_matcher->set_field(1); // State field.
- field_value_matcher->set_eq_int(state);
- return atom_matcher;
-}
-
-AtomMatcher CreateScreenTurnedOnAtomMatcher() {
- return CreateScreenStateChangedAtomMatcher("ScreenTurnedOn",
- android::view::DisplayStateEnum::DISPLAY_STATE_ON);
-}
-
-AtomMatcher CreateScreenTurnedOffAtomMatcher() {
- return CreateScreenStateChangedAtomMatcher("ScreenTurnedOff",
- ::android::view::DisplayStateEnum::DISPLAY_STATE_OFF);
-}
-
-AtomMatcher CreateSyncStateChangedAtomMatcher(
- const string& name, SyncStateChanged::State state) {
- AtomMatcher atom_matcher;
- atom_matcher.set_id(StringToId(name));
- auto simple_atom_matcher = atom_matcher.mutable_simple_atom_matcher();
- simple_atom_matcher->set_atom_id(android::util::SYNC_STATE_CHANGED);
- auto field_value_matcher = simple_atom_matcher->add_field_value_matcher();
- field_value_matcher->set_field(3); // State field.
- field_value_matcher->set_eq_int(state);
- return atom_matcher;
-}
-
-AtomMatcher CreateSyncStartAtomMatcher() {
- return CreateSyncStateChangedAtomMatcher("SyncStart", SyncStateChanged::ON);
-}
-
-AtomMatcher CreateSyncEndAtomMatcher() {
- return CreateSyncStateChangedAtomMatcher("SyncEnd", SyncStateChanged::OFF);
-}
-
-AtomMatcher CreateActivityForegroundStateChangedAtomMatcher(
- const string& name, ActivityForegroundStateChanged::State state) {
- AtomMatcher atom_matcher;
- atom_matcher.set_id(StringToId(name));
- auto simple_atom_matcher = atom_matcher.mutable_simple_atom_matcher();
- simple_atom_matcher->set_atom_id(android::util::ACTIVITY_FOREGROUND_STATE_CHANGED);
- auto field_value_matcher = simple_atom_matcher->add_field_value_matcher();
- field_value_matcher->set_field(4); // Activity field.
- field_value_matcher->set_eq_int(state);
- return atom_matcher;
-}
-
-AtomMatcher CreateMoveToBackgroundAtomMatcher() {
- return CreateActivityForegroundStateChangedAtomMatcher(
- "MoveToBackground", ActivityForegroundStateChanged::BACKGROUND);
-}
-
-AtomMatcher CreateMoveToForegroundAtomMatcher() {
- return CreateActivityForegroundStateChangedAtomMatcher(
- "MoveToForeground", ActivityForegroundStateChanged::FOREGROUND);
-}
-
-Predicate CreateScheduledJobPredicate() {
- Predicate predicate;
- predicate.set_id(StringToId("ScheduledJobRunningPredicate"));
- predicate.mutable_simple_predicate()->set_start(StringToId("ScheduledJobStart"));
- predicate.mutable_simple_predicate()->set_stop(StringToId("ScheduledJobFinish"));
- return predicate;
-}
-
-Predicate CreateBatterySaverModePredicate() {
- Predicate predicate;
- predicate.set_id(StringToId("BatterySaverIsOn"));
- predicate.mutable_simple_predicate()->set_start(StringToId("BatterySaverModeStart"));
- predicate.mutable_simple_predicate()->set_stop(StringToId("BatterySaverModeStop"));
- return predicate;
-}
-
-Predicate CreateScreenIsOnPredicate() {
- Predicate predicate;
- predicate.set_id(StringToId("ScreenIsOn"));
- predicate.mutable_simple_predicate()->set_start(StringToId("ScreenTurnedOn"));
- predicate.mutable_simple_predicate()->set_stop(StringToId("ScreenTurnedOff"));
- return predicate;
-}
-
-Predicate CreateScreenIsOffPredicate() {
- Predicate predicate;
- predicate.set_id(1111123);
- predicate.mutable_simple_predicate()->set_start(StringToId("ScreenTurnedOff"));
- predicate.mutable_simple_predicate()->set_stop(StringToId("ScreenTurnedOn"));
- return predicate;
-}
-
-Predicate CreateHoldingWakelockPredicate() {
- Predicate predicate;
- predicate.set_id(StringToId("HoldingWakelock"));
- predicate.mutable_simple_predicate()->set_start(StringToId("AcquireWakelock"));
- predicate.mutable_simple_predicate()->set_stop(StringToId("ReleaseWakelock"));
- return predicate;
-}
-
-Predicate CreateIsSyncingPredicate() {
- Predicate predicate;
- predicate.set_id(33333333333333);
- predicate.mutable_simple_predicate()->set_start(StringToId("SyncStart"));
- predicate.mutable_simple_predicate()->set_stop(StringToId("SyncEnd"));
- return predicate;
-}
-
-Predicate CreateIsInBackgroundPredicate() {
- Predicate predicate;
- predicate.set_id(StringToId("IsInBackground"));
- predicate.mutable_simple_predicate()->set_start(StringToId("MoveToBackground"));
- predicate.mutable_simple_predicate()->set_stop(StringToId("MoveToForeground"));
- return predicate;
-}
-
-void addPredicateToPredicateCombination(const Predicate& predicate,
- Predicate* combinationPredicate) {
- combinationPredicate->mutable_combination()->add_predicate(predicate.id());
-}
-
-FieldMatcher CreateAttributionUidDimensions(const int atomId,
- const std::vector<Position>& positions) {
- FieldMatcher dimensions;
- dimensions.set_field(atomId);
- for (const auto position : positions) {
- auto child = dimensions.add_child();
- child->set_field(1);
- child->set_position(position);
- child->add_child()->set_field(1);
- }
- return dimensions;
-}
-
-FieldMatcher CreateAttributionUidAndTagDimensions(const int atomId,
- const std::vector<Position>& positions) {
- FieldMatcher dimensions;
- dimensions.set_field(atomId);
- for (const auto position : positions) {
- auto child = dimensions.add_child();
- child->set_field(1);
- child->set_position(position);
- child->add_child()->set_field(1);
- child->add_child()->set_field(2);
- }
- return dimensions;
-}
-
-FieldMatcher CreateDimensions(const int atomId, const std::vector<int>& fields) {
- FieldMatcher dimensions;
- dimensions.set_field(atomId);
- for (const int field : fields) {
- dimensions.add_child()->set_field(field);
- }
- return dimensions;
-}
-
-void writeAttribution(AStatsEvent* statsEvent, const vector<int>& attributionUids,
- const vector<string>& attributionTags) {
- vector<const char*> cTags(attributionTags.size());
- for (int i = 0; i < cTags.size(); i++) {
- cTags[i] = attributionTags[i].c_str();
- }
-
- AStatsEvent_writeAttributionChain(statsEvent,
- reinterpret_cast<const uint32_t*>(attributionUids.data()),
- cTags.data(), attributionUids.size());
-}
-
-void parseStatsEventToLogEvent(AStatsEvent* statsEvent, LogEvent* logEvent) {
- AStatsEvent_build(statsEvent);
-
- size_t size;
- uint8_t* buf = AStatsEvent_getBuffer(statsEvent, &size);
- logEvent->parseBuffer(buf, size);
-
- AStatsEvent_release(statsEvent);
-}
-
-std::unique_ptr<LogEvent> CreateScreenStateChangedEvent(
- uint64_t timestampNs, const android::view::DisplayStateEnum state) {
- AStatsEvent* statsEvent = AStatsEvent_obtain();
- AStatsEvent_setAtomId(statsEvent, util::SCREEN_STATE_CHANGED);
- AStatsEvent_overwriteTimestamp(statsEvent, timestampNs);
- AStatsEvent_writeInt32(statsEvent, state);
-
- std::unique_ptr<LogEvent> logEvent = std::make_unique<LogEvent>(/*uid=*/0, /*pid=*/0);
- parseStatsEventToLogEvent(statsEvent, logEvent.get());
- return logEvent;
-}
-
-std::unique_ptr<LogEvent> CreateScheduledJobStateChangedEvent(
- const vector<int>& attributionUids, const vector<string>& attributionTags,
- const string& jobName, const ScheduledJobStateChanged::State state, uint64_t timestampNs) {
- AStatsEvent* statsEvent = AStatsEvent_obtain();
- AStatsEvent_setAtomId(statsEvent, util::SCHEDULED_JOB_STATE_CHANGED);
- AStatsEvent_overwriteTimestamp(statsEvent, timestampNs);
-
- writeAttribution(statsEvent, attributionUids, attributionTags);
- AStatsEvent_writeString(statsEvent, jobName.c_str());
- AStatsEvent_writeInt32(statsEvent, state);
-
- std::unique_ptr<LogEvent> logEvent = std::make_unique<LogEvent>(/*uid=*/0, /*pid=*/0);
- parseStatsEventToLogEvent(statsEvent, logEvent.get());
- return logEvent;
-}
-
-std::unique_ptr<LogEvent> CreateStartScheduledJobEvent(uint64_t timestampNs,
- const vector<int>& attributionUids,
- const vector<string>& attributionTags,
- const string& jobName) {
- return CreateScheduledJobStateChangedEvent(attributionUids, attributionTags, jobName,
- ScheduledJobStateChanged::STARTED, timestampNs);
-}
-
-// Create log event when scheduled job finishes.
-std::unique_ptr<LogEvent> CreateFinishScheduledJobEvent(uint64_t timestampNs,
- const vector<int>& attributionUids,
- const vector<string>& attributionTags,
- const string& jobName) {
- return CreateScheduledJobStateChangedEvent(attributionUids, attributionTags, jobName,
- ScheduledJobStateChanged::FINISHED, timestampNs);
-}
-
-std::unique_ptr<LogEvent> CreateSyncStateChangedEvent(uint64_t timestampNs,
- const vector<int>& attributionUids,
- const vector<string>& attributionTags,
- const string& name,
- const SyncStateChanged::State state) {
- AStatsEvent* statsEvent = AStatsEvent_obtain();
- AStatsEvent_setAtomId(statsEvent, util::SYNC_STATE_CHANGED);
- AStatsEvent_overwriteTimestamp(statsEvent, timestampNs);
-
- writeAttribution(statsEvent, attributionUids, attributionTags);
- AStatsEvent_writeString(statsEvent, name.c_str());
- AStatsEvent_writeInt32(statsEvent, state);
-
- std::unique_ptr<LogEvent> logEvent = std::make_unique<LogEvent>(/*uid=*/0, /*pid=*/0);
- parseStatsEventToLogEvent(statsEvent, logEvent.get());
- return logEvent;
-}
-
-std::unique_ptr<LogEvent> CreateSyncStartEvent(uint64_t timestampNs,
- const vector<int>& attributionUids,
- const vector<string>& attributionTags,
- const string& name) {
- return CreateSyncStateChangedEvent(timestampNs, attributionUids, attributionTags, name,
- SyncStateChanged::ON);
-}
-
-std::unique_ptr<LogEvent> CreateSyncEndEvent(uint64_t timestampNs,
- const vector<int>& attributionUids,
- const vector<string>& attributionTags,
- const string& name) {
- return CreateSyncStateChangedEvent(timestampNs, attributionUids, attributionTags, name,
- SyncStateChanged::OFF);
-}
-
-sp<StatsLogProcessor> CreateStatsLogProcessor(const long timeBaseSec, const StatsdConfig& config,
- const ConfigKey& key) {
- sp<UidMap> uidMap = new UidMap();
- sp<StatsPullerManager> pullerManager = new StatsPullerManager();
- sp<AlarmMonitor> anomalyAlarmMonitor;
- sp<AlarmMonitor> periodicAlarmMonitor;
- sp<StatsLogProcessor> processor = new StatsLogProcessor(
- uidMap, pullerManager, anomalyAlarmMonitor, periodicAlarmMonitor,
- timeBaseSec * NS_PER_SEC, [](const ConfigKey&) { return true; },
- [](const int&, const vector<int64_t>&) { return true; },
- [](const ConfigKey&, const string&, const vector<int64_t>&) {},
- std::make_shared<LogEventFilter>());
- processor->OnConfigUpdated(timeBaseSec * NS_PER_SEC, key, config);
- return processor;
-}
-
-void sortLogEventsByTimestamp(std::vector<std::unique_ptr<LogEvent>> *events) {
- std::sort(events->begin(), events->end(),
- [](const std::unique_ptr<LogEvent>& a, const std::unique_ptr<LogEvent>& b) {
- return a->GetElapsedTimestampNs() < b->GetElapsedTimestampNs();
- });
-}
-
-int64_t StringToId(const string& str) {
- return static_cast<int64_t>(std::hash<std::string>()(str));
-}
-
-
-} // namespace statsd
-} // namespace os
-} // namespace android
diff --git a/statsd/benchmark/metric_util.h b/statsd/benchmark/metric_util.h
deleted file mode 100644
index 693bf459..00000000
--- a/statsd/benchmark/metric_util.h
+++ /dev/null
@@ -1,140 +0,0 @@
-// Copyright (C) 2017 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#pragma once
-
-#include "src/stats_log.pb.h"
-#include "src/statsd_config.pb.h"
-#include "src/StatsLogProcessor.h"
-#include "src/logd/LogEvent.h"
-#include "stats_event.h"
-#include "statslog.h"
-
-namespace android {
-namespace os {
-namespace statsd {
-
-// Create AtomMatcher proto to simply match a specific atom type.
-AtomMatcher CreateSimpleAtomMatcher(const string& name, int atomId);
-
-// Create AtomMatcher proto for scheduled job state changed.
-AtomMatcher CreateScheduledJobStateChangedAtomMatcher();
-
-// Create AtomMatcher proto for starting a scheduled job.
-AtomMatcher CreateStartScheduledJobAtomMatcher();
-
-// Create AtomMatcher proto for a scheduled job is done.
-AtomMatcher CreateFinishScheduledJobAtomMatcher();
-
-// Create AtomMatcher proto for screen brightness state changed.
-AtomMatcher CreateScreenBrightnessChangedAtomMatcher();
-
-// Create AtomMatcher proto for acquiring wakelock.
-AtomMatcher CreateAcquireWakelockAtomMatcher();
-
-// Create AtomMatcher proto for releasing wakelock.
-AtomMatcher CreateReleaseWakelockAtomMatcher() ;
-
-// Create AtomMatcher proto for screen turned on.
-AtomMatcher CreateScreenTurnedOnAtomMatcher();
-
-// Create AtomMatcher proto for screen turned off.
-AtomMatcher CreateScreenTurnedOffAtomMatcher();
-
-// Create AtomMatcher proto for app sync turned on.
-AtomMatcher CreateSyncStartAtomMatcher();
-
-// Create AtomMatcher proto for app sync turned off.
-AtomMatcher CreateSyncEndAtomMatcher();
-
-// Create AtomMatcher proto for app sync moves to background.
-AtomMatcher CreateMoveToBackgroundAtomMatcher();
-
-// Create AtomMatcher proto for app sync moves to foreground.
-AtomMatcher CreateMoveToForegroundAtomMatcher();
-
-// Create Predicate proto for screen is off.
-Predicate CreateScreenIsOffPredicate();
-
-// Create Predicate proto for a running scheduled job.
-Predicate CreateScheduledJobPredicate();
-
-// Create Predicate proto for holding wakelock.
-Predicate CreateHoldingWakelockPredicate();
-
-// Create a Predicate proto for app syncing.
-Predicate CreateIsSyncingPredicate();
-
-// Create a Predicate proto for app is in background.
-Predicate CreateIsInBackgroundPredicate();
-
-// Add a predicate to the predicate combination.
-void addPredicateToPredicateCombination(const Predicate& predicate, Predicate* combination);
-
-// Create dimensions from primitive fields.
-FieldMatcher CreateDimensions(const int atomId, const std::vector<int>& fields);
-
-// Create dimensions by attribution uid and tag.
-FieldMatcher CreateAttributionUidAndTagDimensions(const int atomId,
- const std::vector<Position>& positions);
-
-// Create dimensions by attribution uid only.
-FieldMatcher CreateAttributionUidDimensions(const int atomId,
- const std::vector<Position>& positions);
-
-void writeAttribution(AStatsEvent* statsEvent, const vector<int>& attributionUids,
- const vector<string>& attributionTags);
-
-void parseStatsEventToLogEvent(AStatsEvent* statsEvent, LogEvent* logEvent);
-
-// Create log event for screen state changed.
-std::unique_ptr<LogEvent> CreateScreenStateChangedEvent(
- uint64_t timestampNs, const android::view::DisplayStateEnum state);
-
-// Create log event when scheduled job starts.
-std::unique_ptr<LogEvent> CreateStartScheduledJobEvent(uint64_t timestampNs,
- const vector<int>& attributionUids,
- const vector<string>& attributionTags,
- const string& jobName);
-
-// Create log event when scheduled job finishes.
-std::unique_ptr<LogEvent> CreateFinishScheduledJobEvent(uint64_t timestampNs,
- const vector<int>& attributionUids,
- const vector<string>& attributionTags,
- const string& jobName);
-
-// Create log event when the app sync starts.
-std::unique_ptr<LogEvent> CreateSyncStartEvent(uint64_t timestampNs,
- const vector<int>& attributionUids,
- const vector<string>& attributionTags,
- const string& name);
-
-// Create log event when the app sync ends.
-std::unique_ptr<LogEvent> CreateSyncEndEvent(uint64_t timestampNs,
- const vector<int>& attributionUids,
- const vector<string>& attributionTags,
- const string& name);
-
-// Create a statsd log event processor upon the start time in seconds, config and key.
-sp<StatsLogProcessor> CreateStatsLogProcessor(const long timeBaseSec, const StatsdConfig& config,
- const ConfigKey& key);
-
-// Util function to sort the log events by timestamp.
-void sortLogEventsByTimestamp(std::vector<std::unique_ptr<LogEvent>> *events);
-
-int64_t StringToId(const string& str);
-
-} // namespace statsd
-} // namespace os
-} // namespace android
diff --git a/statsd/benchmark/stats_write_benchmark.cpp b/statsd/benchmark/stats_write_benchmark.cpp
index d817b122..b84b0cde 100644
--- a/statsd/benchmark/stats_write_benchmark.cpp
+++ b/statsd/benchmark/stats_write_benchmark.cpp
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include <statslog.h>
+#include <statslog_statsdtest.h>
#include "benchmark/benchmark.h"
@@ -31,16 +31,11 @@ static void BM_StatsEventObtain(benchmark::State& state) {
BENCHMARK(BM_StatsEventObtain);
static void BM_StatsWrite(benchmark::State& state) {
- const char* reason = "test";
- int64_t boot_end_time = 1234567;
- int64_t total_duration = 100;
- int64_t bootloader_duration = 10;
- int64_t time_since_last_boot = 99999999;
+ int32_t parent_uid = 0;
+ int32_t isolated_uid = 100;
+ int32_t event = 1;
while (state.KeepRunning()) {
- android::util::stats_write(
- android::util::BOOT_SEQUENCE_REPORTED, reason, reason,
- boot_end_time, total_duration, bootloader_duration, time_since_last_boot);
- total_duration++;
+ util::stats_write(util::ISOLATED_UID_CHANGED, parent_uid, isolated_uid, event++);
}
}
BENCHMARK(BM_StatsWrite);
@@ -50,10 +45,9 @@ static void BM_StatsWriteViaQueue(benchmark::State& state) {
int32_t uid = 0;
int32_t label = 100;
int32_t a_state = 1;
- // TODO: choose atom with a same structure as used in BM_StatsWrite
while (state.KeepRunning()) {
- benchmark::DoNotOptimize(android::util::stats_write(android::util::APP_BREADCRUMB_REPORTED,
- uid, label, a_state++));
+ benchmark::DoNotOptimize(
+ util::stats_write(util::APP_BREADCRUMB_REPORTED, uid, label, a_state++));
}
}
BENCHMARK(BM_StatsWriteViaQueue);
diff --git a/statsd/src/HashableDimensionKey.h b/statsd/src/HashableDimensionKey.h
index b5df4561..5753d98c 100644
--- a/statsd/src/HashableDimensionKey.h
+++ b/statsd/src/HashableDimensionKey.h
@@ -142,7 +142,7 @@ private:
class AtomDimensionKey {
public:
- explicit AtomDimensionKey(const int32_t atomTag, const HashableDimensionKey& atomFieldValues)
+ explicit AtomDimensionKey(int32_t atomTag, const HashableDimensionKey& atomFieldValues)
: mAtomTag(atomTag), mAtomFieldValues(atomFieldValues){};
AtomDimensionKey(){};
@@ -269,22 +269,16 @@ bool linked(const std::vector<Metric2State>& stateLinks, const int32_t stateAtom
} // namespace os
} // namespace android
-namespace std {
-
-using android::os::statsd::AtomDimensionKey;
-using android::os::statsd::HashableDimensionKey;
-using android::os::statsd::MetricDimensionKey;
-
template <>
-struct hash<HashableDimensionKey> {
- std::size_t operator()(const HashableDimensionKey& key) const {
+struct std::hash<android::os::statsd::HashableDimensionKey> {
+ std::size_t operator()(const android::os::statsd::HashableDimensionKey& key) const {
return hashDimension(key);
}
};
template <>
-struct hash<MetricDimensionKey> {
- std::size_t operator()(const MetricDimensionKey& key) const {
+struct std::hash<android::os::statsd::MetricDimensionKey> {
+ std::size_t operator()(const android::os::statsd::MetricDimensionKey& key) const {
android::hash_t hash = hashDimension(key.getDimensionKeyInWhat());
hash = android::JenkinsHashMix(hash, hashDimension(key.getStateValuesKey()));
return android::JenkinsHashWhiten(hash);
@@ -292,11 +286,10 @@ struct hash<MetricDimensionKey> {
};
template <>
-struct hash<AtomDimensionKey> {
- std::size_t operator()(const AtomDimensionKey& key) const {
+struct std::hash<android::os::statsd::AtomDimensionKey> {
+ std::size_t operator()(const android::os::statsd::AtomDimensionKey& key) const {
android::hash_t hash = hashDimension(key.getAtomFieldValues());
hash = android::JenkinsHashMix(hash, key.getAtomTag());
return android::JenkinsHashWhiten(hash);
}
};
-} // namespace std
diff --git a/statsd/src/StatsLogProcessor.cpp b/statsd/src/StatsLogProcessor.cpp
index 841c5c1a..e2b3efa2 100644
--- a/statsd/src/StatsLogProcessor.cpp
+++ b/statsd/src/StatsLogProcessor.cpp
@@ -134,14 +134,14 @@ static void flushProtoToBuffer(ProtoOutputStream& proto, vector<uint8_t>* outDat
}
void StatsLogProcessor::processFiredAnomalyAlarmsLocked(
- const int64_t& timestampNs,
+ const int64_t timestampNs,
unordered_set<sp<const InternalAlarm>, SpHash<InternalAlarm>>& alarmSet) {
for (const auto& itr : mMetricsManagers) {
itr.second->onAnomalyAlarmFired(timestampNs, alarmSet);
}
}
void StatsLogProcessor::onPeriodicAlarmFired(
- const int64_t& timestampNs,
+ const int64_t timestampNs,
unordered_set<sp<const InternalAlarm>, SpHash<InternalAlarm>>& alarmSet) {
std::lock_guard<std::mutex> lock(mMetricsMutex);
for (const auto& itr : mMetricsManagers) {
@@ -1415,7 +1415,7 @@ int64_t StatsLogProcessor::getLastReportTimeNs(const ConfigKey& key) {
}
}
-void StatsLogProcessor::notifyAppUpgrade(const int64_t& eventTimeNs, const string& apk,
+void StatsLogProcessor::notifyAppUpgrade(const int64_t eventTimeNs, const string& apk,
const int uid, const int64_t version) {
std::lock_guard<std::mutex> lock(mMetricsMutex);
VLOG("Received app upgrade");
@@ -1425,7 +1425,7 @@ void StatsLogProcessor::notifyAppUpgrade(const int64_t& eventTimeNs, const strin
}
}
-void StatsLogProcessor::notifyAppRemoved(const int64_t& eventTimeNs, const string& apk,
+void StatsLogProcessor::notifyAppRemoved(const int64_t eventTimeNs, const string& apk,
const int uid) {
std::lock_guard<std::mutex> lock(mMetricsMutex);
VLOG("Received app removed");
@@ -1435,7 +1435,7 @@ void StatsLogProcessor::notifyAppRemoved(const int64_t& eventTimeNs, const strin
}
}
-void StatsLogProcessor::onUidMapReceived(const int64_t& eventTimeNs) {
+void StatsLogProcessor::onUidMapReceived(const int64_t eventTimeNs) {
std::lock_guard<std::mutex> lock(mMetricsMutex);
VLOG("Received uid map");
StateManager::getInstance().updateLogSources(mUidMap);
@@ -1444,7 +1444,7 @@ void StatsLogProcessor::onUidMapReceived(const int64_t& eventTimeNs) {
}
}
-void StatsLogProcessor::onStatsdInitCompleted(const int64_t& elapsedTimeNs) {
+void StatsLogProcessor::onStatsdInitCompleted(const int64_t elapsedTimeNs) {
std::lock_guard<std::mutex> lock(mMetricsMutex);
VLOG("Received boot completed signal");
for (const auto& it : mMetricsManagers) {
diff --git a/statsd/src/StatsLogProcessor.h b/statsd/src/StatsLogProcessor.h
index 1449911e..54b1b298 100644
--- a/statsd/src/StatsLogProcessor.h
+++ b/statsd/src/StatsLogProcessor.h
@@ -40,7 +40,7 @@ public:
StatsLogProcessor(
const sp<UidMap>& uidMap, const sp<StatsPullerManager>& pullerManager,
const sp<AlarmMonitor>& anomalyAlarmMonitor,
- const sp<AlarmMonitor>& subscriberTriggerAlarmMonitor, const int64_t timeBaseNs,
+ const sp<AlarmMonitor>& subscriberTriggerAlarmMonitor, int64_t timeBaseNs,
const std::function<bool(const ConfigKey&)>& sendBroadcast,
const std::function<bool(const int&, const vector<int64_t>&)>& sendActivationBroadcast,
const std::function<void(const ConfigKey&, const string&, const vector<int64_t>&)>&
@@ -51,7 +51,7 @@ public:
void OnLogEvent(LogEvent* event);
- void OnConfigUpdated(const int64_t timestampNs, const int64_t wallClockNs, const ConfigKey& key,
+ void OnConfigUpdated(const int64_t timestampNs, int64_t wallClockNs, const ConfigKey& key,
const StatsdConfig& config, bool modularUpdate = true);
// For testing only.
void OnConfigUpdated(const int64_t timestampNs, const ConfigKey& key,
@@ -62,28 +62,28 @@ public:
void GetActiveConfigs(const int uid, vector<int64_t>& outActiveConfigs);
- void onDumpReport(const ConfigKey& key, const int64_t dumpTimeNs, const int64_t wallClockNs,
+ void onDumpReport(const ConfigKey& key, int64_t dumpTimeNs, int64_t wallClockNs,
const bool include_current_partial_bucket, const bool erase_data,
const DumpReportReason dumpReportReason, const DumpLatency dumpLatency,
vector<uint8_t>* outData);
- void onDumpReport(const ConfigKey& key, const int64_t dumpTimeNs, const int64_t wallClockNs,
+ void onDumpReport(const ConfigKey& key, int64_t dumpTimeNs, int64_t wallClockNs,
const bool include_current_partial_bucket, const bool erase_data,
const DumpReportReason dumpReportReason, const DumpLatency dumpLatency,
ProtoOutputStream* proto);
// For testing only.
- void onDumpReport(const ConfigKey& key, const int64_t dumpTimeNs,
+ void onDumpReport(const ConfigKey& key, int64_t dumpTimeNs,
const bool include_current_partial_bucket, const bool erase_data,
const DumpReportReason dumpReportReason, const DumpLatency dumpLatency,
vector<uint8_t>* outData);
/* Tells MetricsManager that the alarms in alarmSet have fired. Modifies periodic alarmSet. */
void onPeriodicAlarmFired(
- const int64_t& timestampNs,
+ int64_t timestampNs,
unordered_set<sp<const InternalAlarm>, SpHash<InternalAlarm>>& alarmSet);
/* Flushes data to disk. Data on memory will be gone after written to disk. */
void WriteDataToDisk(const DumpReportReason dumpReportReason, const DumpLatency dumpLatency,
- const int64_t elapsedRealtimeNs, const int64_t wallClockNs);
+ const int64_t elapsedRealtimeNs, int64_t wallClockNs);
/* Persist configs containing metrics with active activations to disk. */
void SaveActiveConfigsToDisk(int64_t currentTimeNs);
@@ -113,25 +113,25 @@ public:
int64_t systemElapsedTimeNs);
/* Enforces ttls for restricted metrics */
- void EnforceDataTtls(const int64_t wallClockNs, const int64_t elapsedRealtimeNs);
+ void EnforceDataTtls(const int64_t wallClockNs, int64_t elapsedRealtimeNs);
/* Sets the active status/ttl for all configs and metrics to the status in ActiveConfigList. */
void SetConfigsActiveState(const ActiveConfigList& activeConfigList, int64_t currentTimeNs);
/* Notify all MetricsManagers of app upgrades */
- void notifyAppUpgrade(const int64_t& eventTimeNs, const string& apk, const int uid,
- const int64_t version) override;
+ void notifyAppUpgrade(int64_t eventTimeNs, const string& apk, int uid,
+ int64_t version) override;
/* Notify all MetricsManagers of app removals */
- void notifyAppRemoved(const int64_t& eventTimeNs, const string& apk, const int uid) override;
+ void notifyAppRemoved(int64_t eventTimeNs, const string& apk, int uid) override;
/* Notify all MetricsManagers of uid map snapshots received */
- void onUidMapReceived(const int64_t& eventTimeNs) override;
+ void onUidMapReceived(int64_t eventTimeNs) override;
/* Notify all metrics managers of boot completed
* This will force a bucket split when the boot is finished.
*/
- void onStatsdInitCompleted(const int64_t& elapsedTimeNs);
+ void onStatsdInitCompleted(int64_t elapsedTimeNs);
// Reset all configs.
void resetConfigs();
@@ -248,15 +248,15 @@ private:
metadata::StatsMetadataList* metadataList);
void WriteDataToDiskLocked(const DumpReportReason dumpReportReason,
- const DumpLatency dumpLatency, const int64_t elapsedRealtimeNs,
+ const DumpLatency dumpLatency, int64_t elapsedRealtimeNs,
const int64_t wallClockNs);
- void WriteDataToDiskLocked(const ConfigKey& key, const int64_t timestampNs,
- const int64_t wallClockNs, const DumpReportReason dumpReportReason,
+ void WriteDataToDiskLocked(const ConfigKey& key, int64_t timestampNs, const int64_t wallClockNs,
+ const DumpReportReason dumpReportReason,
const DumpLatency dumpLatency);
void onConfigMetricsReportLocked(
- const ConfigKey& key, const int64_t dumpTimeStampNs, const int64_t wallClockNs,
+ const ConfigKey& key, int64_t dumpTimeStampNs, int64_t wallClockNs,
const bool include_current_partial_bucket, const bool erase_data,
const DumpReportReason dumpReportReason, const DumpLatency dumpLatency,
/*if dataSavedToDisk is true, it indicates the caller will write the data to disk
@@ -269,7 +269,7 @@ private:
const int64_t elapsedRealtimeNs);
// Enforces ttls on all restricted metrics.
- void enforceDataTtlsLocked(const int64_t wallClockNs, const int64_t elapsedRealtimeNs);
+ void enforceDataTtlsLocked(const int64_t wallClockNs, int64_t elapsedRealtimeNs);
// Enforces that dbs are within guardrail parameters.
void enforceDbGuardrailsIfNecessaryLocked(const int64_t wallClockNs,
@@ -279,8 +279,7 @@ private:
* actually delete the data. */
void flushIfNecessaryLocked(const ConfigKey& key, MetricsManager& metricsManager);
- set<ConfigKey> getRestrictedConfigKeysToQueryLocked(const int32_t callingUid,
- const int64_t configId,
+ set<ConfigKey> getRestrictedConfigKeysToQueryLocked(int32_t callingUid, const int64_t configId,
const set<int32_t>& configPackageUids,
string& err,
InvalidQueryReason& invalidQueryReason);
@@ -304,8 +303,8 @@ private:
// Gets experiment ids on disk for associated train and updates them
// depending on rollback type. Then writes them back to disk and returns
// them.
- std::vector<int64_t> processWatchdogRollbackOccurred(const int32_t rollbackTypeIn,
- const string& packageName);
+ std::vector<int64_t> processWatchdogRollbackOccurred(int32_t rollbackTypeIn,
+ const string& packageName);
// Reset all configs.
void resetConfigsLocked(const int64_t timestampNs);
@@ -318,7 +317,7 @@ private:
/* Tells MetricsManager that the alarms in alarmSet have fired. Modifies anomaly alarmSet. */
void processFiredAnomalyAlarmsLocked(
- const int64_t& timestampNs,
+ int64_t timestampNs,
unordered_set<sp<const InternalAlarm>, SpHash<InternalAlarm>>& alarmSet);
void flushRestrictedDataLocked(const int64_t elapsedRealtimeNs);
diff --git a/statsd/src/StatsService.cpp b/statsd/src/StatsService.cpp
index 8b2c218c..f0c13cd3 100644
--- a/statsd/src/StatsService.cpp
+++ b/statsd/src/StatsService.cpp
@@ -1514,9 +1514,8 @@ void StatsService::stopReadingLogs() {
mIsStopRequested = true;
// Push this event so that readLogs will process and break out of the loop
// after the stop is requested.
- int64_t timeStamp;
std::unique_ptr<LogEvent> logEvent = std::make_unique<LogEvent>(/*uid=*/0, /*pid=*/0);
- mEventQueue->push(std::move(logEvent), &timeStamp);
+ mEventQueue->push(std::move(logEvent));
}
} // namespace statsd
diff --git a/statsd/src/StatsService.h b/statsd/src/StatsService.h
index c170e003..3c34492b 100644
--- a/statsd/src/StatsService.h
+++ b/statsd/src/StatsService.h
@@ -146,7 +146,7 @@ public:
/**
* Binder call to remove the active configs changed operation for the specified package..
*/
- virtual Status removeActiveConfigsChangedOperation(const int32_t callingUid) override;
+ virtual Status removeActiveConfigsChangedOperation(int32_t callingUid) override;
/**
* Binder call to allow clients to remove the specified configuration.
*/
diff --git a/statsd/src/anomaly/AlarmMonitor.cpp b/statsd/src/anomaly/AlarmMonitor.cpp
index 4822b541..6359c5f5 100644
--- a/statsd/src/anomaly/AlarmMonitor.cpp
+++ b/statsd/src/anomaly/AlarmMonitor.cpp
@@ -36,7 +36,7 @@ AlarmMonitor::AlarmMonitor(
AlarmMonitor::~AlarmMonitor() {}
void AlarmMonitor::setStatsCompanionService(
- shared_ptr<IStatsCompanionService> statsCompanionService) {
+ const shared_ptr<IStatsCompanionService>& statsCompanionService) {
std::lock_guard<std::mutex> lock(mLock);
shared_ptr<IStatsCompanionService> tmpForLock = mStatsCompanionService;
mStatsCompanionService = statsCompanionService;
@@ -51,7 +51,7 @@ void AlarmMonitor::setStatsCompanionService(
}
}
-void AlarmMonitor::add(sp<const InternalAlarm> alarm) {
+void AlarmMonitor::add(const sp<const InternalAlarm>& alarm) {
std::lock_guard<std::mutex> lock(mLock);
if (alarm == nullptr) {
ALOGW("Asked to add a null alarm.");
@@ -71,7 +71,7 @@ void AlarmMonitor::add(sp<const InternalAlarm> alarm) {
}
}
-void AlarmMonitor::remove(sp<const InternalAlarm> alarm) {
+void AlarmMonitor::remove(const sp<const InternalAlarm>& alarm) {
std::lock_guard<std::mutex> lock(mLock);
if (alarm == nullptr) {
ALOGW("Asked to remove a null alarm.");
diff --git a/statsd/src/anomaly/AlarmMonitor.h b/statsd/src/anomaly/AlarmMonitor.h
index 5c34e381..ee955c97 100644
--- a/statsd/src/anomaly/AlarmMonitor.h
+++ b/statsd/src/anomaly/AlarmMonitor.h
@@ -49,7 +49,7 @@ struct InternalAlarm : public RefBase {
/** InternalAlarm a is smaller (higher priority) than b if its timestamp is sooner. */
struct SmallerTimestamp {
- bool operator()(sp<const InternalAlarm> a, sp<const InternalAlarm> b) const {
+ bool operator()(const sp<const InternalAlarm>& a, const sp<const InternalAlarm>& b) const {
return (a->timestampSec < b->timestampSec);
}
};
@@ -77,19 +77,19 @@ public:
* If nullptr, AnomalyMonitor will continue to add/remove alarms, but won't
* update IStatsCompanionService (until such time as it is set non-null).
*/
- void setStatsCompanionService(shared_ptr<IStatsCompanionService> statsCompanionService);
+ void setStatsCompanionService(const shared_ptr<IStatsCompanionService>& statsCompanionService);
/**
* Adds the given alarm (reference) to the queue.
*/
- void add(sp<const InternalAlarm> alarm);
+ void add(const sp<const InternalAlarm>& alarm);
/**
* Removes the given alarm (reference) from the queue.
* Note that alarm comparison is reference-based; if another alarm exists
* with the same timestampSec, that alarm will still remain in the queue.
*/
- void remove(sp<const InternalAlarm> alarm);
+ void remove(const sp<const InternalAlarm>& alarm);
/**
* Returns and removes all alarms whose timestamp <= the given timestampSec.
diff --git a/statsd/src/anomaly/AlarmTracker.cpp b/statsd/src/anomaly/AlarmTracker.cpp
index 8e311d4b..9d1aa106 100644
--- a/statsd/src/anomaly/AlarmTracker.cpp
+++ b/statsd/src/anomaly/AlarmTracker.cpp
@@ -69,7 +69,7 @@ int64_t AlarmTracker::findNextAlarmSec(int64_t currentTimeSec) {
}
void AlarmTracker::informAlarmsFired(
- const int64_t& timestampNs,
+ const int64_t timestampNs,
unordered_set<sp<const InternalAlarm>, SpHash<InternalAlarm>>& firedAlarms) {
if (firedAlarms.empty() || mInternalAlarm == nullptr ||
firedAlarms.find(mInternalAlarm) == firedAlarms.end()) {
diff --git a/statsd/src/anomaly/AlarmTracker.h b/statsd/src/anomaly/AlarmTracker.h
index 4b8fab36..c89099f9 100644
--- a/statsd/src/anomaly/AlarmTracker.h
+++ b/statsd/src/anomaly/AlarmTracker.h
@@ -42,7 +42,8 @@ public:
void addSubscription(const Subscription& subscription);
- void informAlarmsFired(const int64_t& timestampNs,
+ void informAlarmsFired(
+ int64_t timestampNs,
unordered_set<sp<const InternalAlarm>, SpHash<InternalAlarm>>& firedAlarms);
protected:
diff --git a/statsd/src/anomaly/AnomalyTracker.cpp b/statsd/src/anomaly/AnomalyTracker.cpp
index 2e0d2382..2829bff0 100644
--- a/statsd/src/anomaly/AnomalyTracker.cpp
+++ b/statsd/src/anomaly/AnomalyTracker.cpp
@@ -63,7 +63,7 @@ size_t AnomalyTracker::index(int64_t bucketNum) const {
return bucketNum % mNumOfPastBuckets;
}
-void AnomalyTracker::advanceMostRecentBucketTo(const int64_t& bucketNum) {
+void AnomalyTracker::advanceMostRecentBucketTo(const int64_t bucketNum) {
VLOG("advanceMostRecentBucketTo() called.");
if (mNumOfPastBuckets <= 0) {
return;
@@ -89,9 +89,8 @@ void AnomalyTracker::advanceMostRecentBucketTo(const int64_t& bucketNum) {
mMostRecentBucketNum = bucketNum;
}
-void AnomalyTracker::addPastBucket(const MetricDimensionKey& key,
- const int64_t& bucketValue,
- const int64_t& bucketNum) {
+void AnomalyTracker::addPastBucket(const MetricDimensionKey& key, const int64_t bucketValue,
+ const int64_t bucketNum) {
VLOG("addPastBucket(bucketValue) called.");
if (mNumOfPastBuckets == 0 ||
bucketNum < 0 || bucketNum <= mMostRecentBucketNum - mNumOfPastBuckets) {
@@ -119,8 +118,8 @@ void AnomalyTracker::addPastBucket(const MetricDimensionKey& key,
}
}
-void AnomalyTracker::addPastBucket(std::shared_ptr<DimToValMap> bucket,
- const int64_t& bucketNum) {
+void AnomalyTracker::addPastBucket(const std::shared_ptr<DimToValMap>& bucket,
+ const int64_t bucketNum) {
VLOG("addPastBucket(bucket) called.");
if (mNumOfPastBuckets == 0 ||
bucketNum < 0 || bucketNum <= mMostRecentBucketNum - mNumOfPastBuckets) {
@@ -147,9 +146,8 @@ void AnomalyTracker::subtractBucketFromSum(const shared_ptr<DimToValMap>& bucket
}
}
-
void AnomalyTracker::subtractValueFromSum(const MetricDimensionKey& key,
- const int64_t& bucketValue) {
+ const int64_t bucketValue) {
auto itr = mSumOverPastBuckets.find(key);
if (itr == mSumOverPastBuckets.end()) {
return;
@@ -171,7 +169,7 @@ void AnomalyTracker::addBucketToSum(const shared_ptr<DimToValMap>& bucket) {
}
int64_t AnomalyTracker::getPastBucketValue(const MetricDimensionKey& key,
- const int64_t& bucketNum) const {
+ const int64_t bucketNum) const {
if (bucketNum < 0 || mMostRecentBucketNum < 0
|| bucketNum <= mMostRecentBucketNum - mNumOfPastBuckets
|| bucketNum > mMostRecentBucketNum) {
@@ -194,10 +192,8 @@ int64_t AnomalyTracker::getSumOverPastBuckets(const MetricDimensionKey& key) con
return 0;
}
-bool AnomalyTracker::detectAnomaly(const int64_t& currentBucketNum,
- const MetricDimensionKey& key,
- const int64_t& currentBucketValue) {
-
+bool AnomalyTracker::detectAnomaly(const int64_t currentBucketNum, const MetricDimensionKey& key,
+ const int64_t currentBucketValue) {
// currentBucketNum should be the next bucket after pastBuckets. If not, advance so that it is.
if (currentBucketNum > mMostRecentBucketNum + 1) {
advanceMostRecentBucketTo(currentBucketNum - 1);
@@ -206,7 +202,7 @@ bool AnomalyTracker::detectAnomaly(const int64_t& currentBucketNum,
getSumOverPastBuckets(key) + currentBucketValue > mAlert.trigger_if_sum_gt();
}
-void AnomalyTracker::declareAnomaly(const int64_t& timestampNs, int64_t metricId,
+void AnomalyTracker::declareAnomaly(const int64_t timestampNs, int64_t metricId,
const MetricDimensionKey& key, int64_t metricValue) {
// TODO(b/110563466): Why receive timestamp? RefractoryPeriod should always be based on
// real time right now.
@@ -246,16 +242,15 @@ void AnomalyTracker::declareAnomaly(const int64_t& timestampNs, int64_t metricId
StatsdStats::getInstance().noteAnomalyDeclared(mConfigKey, mAlert.id());
}
-void AnomalyTracker::detectAndDeclareAnomaly(const int64_t& timestampNs,
- const int64_t& currBucketNum, int64_t metricId,
- const MetricDimensionKey& key,
- const int64_t& currentBucketValue) {
+void AnomalyTracker::detectAndDeclareAnomaly(const int64_t timestampNs, const int64_t currBucketNum,
+ int64_t metricId, const MetricDimensionKey& key,
+ const int64_t currentBucketValue) {
if (detectAnomaly(currBucketNum, key, currentBucketValue)) {
declareAnomaly(timestampNs, metricId, key, currentBucketValue);
}
}
-bool AnomalyTracker::isInRefractoryPeriod(const int64_t& timestampNs,
+bool AnomalyTracker::isInRefractoryPeriod(const int64_t timestampNs,
const MetricDimensionKey& key) const {
const auto& it = mRefractoryPeriodEndsSec.find(key);
if (it != mRefractoryPeriodEndsSec.end()) {
diff --git a/statsd/src/anomaly/AnomalyTracker.h b/statsd/src/anomaly/AnomalyTracker.h
index 92a7173d..4a4f7ffc 100644
--- a/statsd/src/anomaly/AnomalyTracker.h
+++ b/statsd/src/anomaly/AnomalyTracker.h
@@ -55,32 +55,30 @@ public:
// If a bucket for bucketNum already exists, it will be replaced.
// Also, advances to bucketNum (if not in the past), effectively filling any intervening
// buckets with 0s.
- void addPastBucket(std::shared_ptr<DimToValMap> bucket, const int64_t& bucketNum);
+ void addPastBucket(const std::shared_ptr<DimToValMap>& bucket, const int64_t bucketNum);
// Inserts (or replaces) the bucket entry for the given bucketNum at the given key to be the
// given bucketValue. If the bucket does not exist, it will be created.
// Also, advances to bucketNum (if not in the past), effectively filling any intervening
// buckets with 0s.
- void addPastBucket(const MetricDimensionKey& key, const int64_t& bucketValue,
- const int64_t& bucketNum);
+ void addPastBucket(const MetricDimensionKey& key, int64_t bucketValue, int64_t bucketNum);
// Returns true if, based on past buckets plus the new currentBucketValue (which generally
// represents the partially-filled current bucket), an anomaly has happened.
// Also advances to currBucketNum-1.
- bool detectAnomaly(const int64_t& currBucketNum, const MetricDimensionKey& key,
- const int64_t& currentBucketValue);
+ bool detectAnomaly(int64_t currBucketNum, const MetricDimensionKey& key,
+ int64_t currentBucketValue);
// Informs incidentd about the detected alert.
- void declareAnomaly(const int64_t& timestampNs, int64_t metricId, const MetricDimensionKey& key,
+ void declareAnomaly(int64_t timestampNs, int64_t metricId, const MetricDimensionKey& key,
int64_t metricValue);
// Detects if, based on past buckets plus the new currentBucketValue (which generally
// represents the partially-filled current bucket), an anomaly has happened, and if so,
// declares an anomaly and informs relevant subscribers.
// Also advances to currBucketNum-1.
- void detectAndDeclareAnomaly(const int64_t& timestampNs, const int64_t& currBucketNum,
- int64_t metricId, const MetricDimensionKey& key,
- const int64_t& currentBucketValue);
+ void detectAndDeclareAnomaly(int64_t timestampNs, int64_t currBucketNum, int64_t metricId,
+ const MetricDimensionKey& key, int64_t currentBucketValue);
// Init the AlarmMonitor which is shared across anomaly trackers.
virtual void setAlarmMonitor(const sp<AlarmMonitor>& alarmMonitor) {
@@ -91,7 +89,7 @@ public:
int64_t getSumOverPastBuckets(const MetricDimensionKey& key) const;
// Returns the value for a past bucket, or 0 if that bucket doesn't exist.
- int64_t getPastBucketValue(const MetricDimensionKey& key, const int64_t& bucketNum) const;
+ int64_t getPastBucketValue(const MetricDimensionKey& key, int64_t bucketNum) const;
// Returns the anomaly threshold set in the configuration.
inline int64_t getAnomalyThreshold() const {
@@ -115,14 +113,14 @@ public:
// Sets an alarm for the given timestamp.
// Replaces previous alarm if one already exists.
- virtual void startAlarm(const MetricDimensionKey& dimensionKey, const int64_t& eventTime) {
+ virtual void startAlarm(const MetricDimensionKey& dimensionKey, int64_t eventTime) {
return; // The base AnomalyTracker class doesn't have alarms.
}
// Stops the alarm.
// If it should have already fired, but hasn't yet (e.g. because the AlarmManager is delayed),
// declare the anomaly now.
- virtual void stopAlarm(const MetricDimensionKey& dimensionKey, const int64_t& timestampNs) {
+ virtual void stopAlarm(const MetricDimensionKey& dimensionKey, int64_t timestampNs) {
return; // The base AnomalyTracker class doesn't have alarms.
}
@@ -133,7 +131,8 @@ public:
// Declares an anomaly for each alarm in firedAlarms that belongs to this AnomalyTracker,
// and removes it from firedAlarms. Does NOT remove the alarm from the AlarmMonitor.
- virtual void informAlarmsFired(const int64_t& timestampNs,
+ virtual void informAlarmsFired(
+ int64_t timestampNs,
unordered_set<sp<const InternalAlarm>, SpHash<InternalAlarm>>& firedAlarms) {
return; // The base AnomalyTracker class doesn't have alarms.
}
@@ -190,7 +189,7 @@ protected:
// Advances mMostRecentBucketNum to bucketNum, deleting any data that is now too old.
// Specifically, since it is now too old, removes the data for
// [mMostRecentBucketNum - mNumOfPastBuckets + 1, bucketNum - mNumOfPastBuckets].
- void advanceMostRecentBucketTo(const int64_t& bucketNum);
+ void advanceMostRecentBucketTo(int64_t bucketNum);
// Add the information in the given bucket to mSumOverPastBuckets.
void addBucketToSum(const shared_ptr<DimToValMap>& bucket);
@@ -200,10 +199,10 @@ protected:
void subtractBucketFromSum(const shared_ptr<DimToValMap>& bucket);
// From mSumOverPastBuckets[key], subtracts bucketValue, removing it if it is now 0.
- void subtractValueFromSum(const MetricDimensionKey& key, const int64_t& bucketValue);
+ void subtractValueFromSum(const MetricDimensionKey& key, int64_t bucketValue);
// Returns true if in the refractory period, else false.
- bool isInRefractoryPeriod(const int64_t& timestampNs, const MetricDimensionKey& key) const;
+ bool isInRefractoryPeriod(int64_t timestampNs, const MetricDimensionKey& key) const;
// Calculates the corresponding bucket index within the circular array.
// Requires bucketNum >= 0.
diff --git a/statsd/src/anomaly/DurationAnomalyTracker.cpp b/statsd/src/anomaly/DurationAnomalyTracker.cpp
index 66c71ad5..f3bfc056 100644
--- a/statsd/src/anomaly/DurationAnomalyTracker.cpp
+++ b/statsd/src/anomaly/DurationAnomalyTracker.cpp
@@ -36,7 +36,7 @@ DurationAnomalyTracker::~DurationAnomalyTracker() {
}
void DurationAnomalyTracker::startAlarm(const MetricDimensionKey& dimensionKey,
- const int64_t& timestampNs) {
+ const int64_t timestampNs) {
// Alarms are stored in secs. Must round up, since if it fires early, it is ignored completely.
uint32_t timestampSec = static_cast<uint32_t>((timestampNs -1) / NS_PER_SEC) + 1; // round up
if (isInRefractoryPeriod(timestampNs, dimensionKey)) {
@@ -57,7 +57,7 @@ void DurationAnomalyTracker::startAlarm(const MetricDimensionKey& dimensionKey,
}
void DurationAnomalyTracker::stopAlarm(const MetricDimensionKey& dimensionKey,
- const int64_t& timestampNs) {
+ const int64_t timestampNs) {
const auto itr = mAlarms.find(dimensionKey);
if (itr == mAlarms.end()) {
return;
@@ -84,9 +84,9 @@ void DurationAnomalyTracker::cancelAllAlarms() {
mAlarms.clear();
}
-void DurationAnomalyTracker::informAlarmsFired(const int64_t& timestampNs,
+void DurationAnomalyTracker::informAlarmsFired(
+ const int64_t timestampNs,
unordered_set<sp<const InternalAlarm>, SpHash<InternalAlarm>>& firedAlarms) {
-
if (firedAlarms.empty() || mAlarms.empty()) return;
// Find the intersection of firedAlarms and mAlarms.
// The for loop is inefficient, since it loops over all keys, but that's okay since it is very
diff --git a/statsd/src/anomaly/DurationAnomalyTracker.h b/statsd/src/anomaly/DurationAnomalyTracker.h
index a5237829..ce06df02 100644
--- a/statsd/src/anomaly/DurationAnomalyTracker.h
+++ b/statsd/src/anomaly/DurationAnomalyTracker.h
@@ -34,12 +34,12 @@ public:
// Sets an alarm for the given timestamp.
// Replaces previous alarm if one already exists.
- void startAlarm(const MetricDimensionKey& dimensionKey, const int64_t& eventTime) override;
+ void startAlarm(const MetricDimensionKey& dimensionKey, int64_t eventTime) override;
// Stops the alarm.
// If it should have already fired, but hasn't yet (e.g. because the AlarmManager is delayed),
// declare the anomaly now.
- void stopAlarm(const MetricDimensionKey& dimensionKey, const int64_t& timestampNs) override;
+ void stopAlarm(const MetricDimensionKey& dimensionKey, int64_t timestampNs) override;
// Stop all the alarms owned by this tracker. Does not declare any anomalies.
void cancelAllAlarms() override;
@@ -48,7 +48,8 @@ public:
// and removes it from firedAlarms. The AlarmMonitor is not informed.
// Note that this will generally be called from a different thread from the other functions;
// the caller is responsible for thread safety.
- void informAlarmsFired(const int64_t& timestampNs,
+ void informAlarmsFired(
+ int64_t timestampNs,
unordered_set<sp<const InternalAlarm>, SpHash<InternalAlarm>>& firedAlarms) override;
protected:
diff --git a/statsd/src/anomaly/subscriber_util.h b/statsd/src/anomaly/subscriber_util.h
index 4d4c83b8..d55581d8 100644
--- a/statsd/src/anomaly/subscriber_util.h
+++ b/statsd/src/anomaly/subscriber_util.h
@@ -24,7 +24,7 @@ namespace android {
namespace os {
namespace statsd {
-void triggerSubscribers(const int64_t ruleId, const int64_t metricId,
+void triggerSubscribers(const int64_t ruleId, int64_t metricId,
const MetricDimensionKey& dimensionKey, int64_t metricValue,
const ConfigKey& configKey, const std::vector<Subscription>& subscriptions);
diff --git a/statsd/src/condition/CombinationConditionTracker.cpp b/statsd/src/condition/CombinationConditionTracker.cpp
index b3f30c79..af4a18a0 100644
--- a/statsd/src/condition/CombinationConditionTracker.cpp
+++ b/statsd/src/condition/CombinationConditionTracker.cpp
@@ -25,7 +25,7 @@ namespace statsd {
using std::unordered_map;
using std::vector;
-CombinationConditionTracker::CombinationConditionTracker(const int64_t& id, const int index,
+CombinationConditionTracker::CombinationConditionTracker(const int64_t id, const int index,
const uint64_t protoHash)
: ConditionTracker(id, index, protoHash) {
VLOG("creating CombinationConditionTracker %lld", (long long)mConditionId);
diff --git a/statsd/src/condition/CombinationConditionTracker.h b/statsd/src/condition/CombinationConditionTracker.h
index 77eeb605..3ed4a83d 100644
--- a/statsd/src/condition/CombinationConditionTracker.h
+++ b/statsd/src/condition/CombinationConditionTracker.h
@@ -26,7 +26,7 @@ namespace statsd {
class CombinationConditionTracker : public ConditionTracker {
public:
- CombinationConditionTracker(const int64_t& id, const int index, const uint64_t protoHash);
+ CombinationConditionTracker(int64_t id, int index, const uint64_t protoHash);
~CombinationConditionTracker();
@@ -37,7 +37,7 @@ public:
std::vector<uint8_t>& stack, std::vector<ConditionState>& conditionCache) override;
optional<InvalidConfigReason> onConfigUpdated(
- const std::vector<Predicate>& allConditionProtos, const int index,
+ const std::vector<Predicate>& allConditionProtos, int index,
const std::vector<sp<ConditionTracker>>& allConditionTrackers,
const std::unordered_map<int64_t, int>& atomMatchingTrackerMap,
const std::unordered_map<int64_t, int>& conditionTrackerMap) override;
diff --git a/statsd/src/condition/ConditionTracker.h b/statsd/src/condition/ConditionTracker.h
index adf89037..b09d3503 100644
--- a/statsd/src/condition/ConditionTracker.h
+++ b/statsd/src/condition/ConditionTracker.h
@@ -31,7 +31,7 @@ namespace statsd {
class ConditionTracker : public virtual RefBase {
public:
- ConditionTracker(const int64_t& id, const int index, const uint64_t protoHash)
+ ConditionTracker(int64_t id, int index, const uint64_t protoHash)
: mConditionId(id),
mIndex(index),
mInitialized(false),
@@ -73,7 +73,7 @@ public:
// conditionTrackerMap: map of condition tracker id to index after the config update.
// returns whether or not the update is successful.
virtual optional<InvalidConfigReason> onConfigUpdated(
- const std::vector<Predicate>& allConditionProtos, const int index,
+ const std::vector<Predicate>& allConditionProtos, int index,
const std::vector<sp<ConditionTracker>>& allConditionTrackers,
const std::unordered_map<int64_t, int>& atomMatchingTrackerMap,
const std::unordered_map<int64_t, int>& conditionTrackerMap) {
diff --git a/statsd/src/condition/SimpleConditionTracker.cpp b/statsd/src/condition/SimpleConditionTracker.cpp
index e9373e5e..5b87f13d 100644
--- a/statsd/src/condition/SimpleConditionTracker.cpp
+++ b/statsd/src/condition/SimpleConditionTracker.cpp
@@ -27,7 +27,7 @@ namespace statsd {
using std::unordered_map;
SimpleConditionTracker::SimpleConditionTracker(
- const ConfigKey& key, const int64_t& id, const uint64_t protoHash, const int index,
+ const ConfigKey& key, const int64_t id, const uint64_t protoHash, const int index,
const SimplePredicate& simplePredicate,
const unordered_map<int64_t, int>& atomMatchingTrackerMap)
: ConditionTracker(id, index, protoHash),
diff --git a/statsd/src/condition/SimpleConditionTracker.h b/statsd/src/condition/SimpleConditionTracker.h
index 5e3e4e49..8af89cbe 100644
--- a/statsd/src/condition/SimpleConditionTracker.h
+++ b/statsd/src/condition/SimpleConditionTracker.h
@@ -29,7 +29,7 @@ namespace statsd {
class SimpleConditionTracker : public ConditionTracker {
public:
- SimpleConditionTracker(const ConfigKey& key, const int64_t& id, const uint64_t protoHash,
+ SimpleConditionTracker(const ConfigKey& key, int64_t id, const uint64_t protoHash,
const int index, const SimplePredicate& simplePredicate,
const std::unordered_map<int64_t, int>& atomMatchingTrackerMap);
@@ -42,7 +42,7 @@ public:
std::vector<uint8_t>& stack, std::vector<ConditionState>& conditionCache) override;
optional<InvalidConfigReason> onConfigUpdated(
- const std::vector<Predicate>& allConditionProtos, const int index,
+ const std::vector<Predicate>& allConditionProtos, int index,
const std::vector<sp<ConditionTracker>>& allConditionTrackers,
const std::unordered_map<int64_t, int>& atomMatchingTrackerMap,
const std::unordered_map<int64_t, int>& conditionTrackerMap) override;
diff --git a/statsd/src/config/ConfigKey.cpp b/statsd/src/config/ConfigKey.cpp
index 4a2bd279..3b0b8357 100644
--- a/statsd/src/config/ConfigKey.cpp
+++ b/statsd/src/config/ConfigKey.cpp
@@ -26,7 +26,7 @@ ConfigKey::ConfigKey() {
ConfigKey::ConfigKey(const ConfigKey& that) : mId(that.mId), mUid(that.mUid) {
}
-ConfigKey::ConfigKey(int uid, const int64_t& id) : mId(id), mUid(uid) {
+ConfigKey::ConfigKey(int uid, const int64_t id) : mId(id), mUid(uid) {
}
ConfigKey::~ConfigKey() {
diff --git a/statsd/src/config/ConfigKey.h b/statsd/src/config/ConfigKey.h
index 0e5a7e3a..e8df3554 100644
--- a/statsd/src/config/ConfigKey.h
+++ b/statsd/src/config/ConfigKey.h
@@ -34,13 +34,13 @@ class ConfigKey {
public:
ConfigKey();
ConfigKey(const ConfigKey& that);
- ConfigKey(int uid, const int64_t& id);
+ ConfigKey(int uid, int64_t id);
~ConfigKey();
inline int GetUid() const {
return mUid;
}
- inline const int64_t& GetId() const {
+ inline int64_t GetId() const {
return mId;
}
@@ -73,17 +73,10 @@ int64_t StrToInt64(const string& str);
/**
* A hash function for ConfigKey so it can be used for unordered_map/set.
- * Unfortunately this has to go in std namespace because C++ is fun!
*/
-namespace std {
-
-using android::os::statsd::ConfigKey;
-
template <>
-struct hash<ConfigKey> {
- std::size_t operator()(const ConfigKey& key) const {
+struct std::hash<android::os::statsd::ConfigKey> {
+ std::size_t operator()(const android::os::statsd::ConfigKey& key) const {
return (7 * key.GetUid()) ^ ((hash<long long>()(key.GetId())));
}
};
-
-} // namespace std
diff --git a/statsd/src/config/ConfigKeyWithPackage.h b/statsd/src/config/ConfigKeyWithPackage.h
index 85e95d58..9cf507b7 100644
--- a/statsd/src/config/ConfigKeyWithPackage.h
+++ b/statsd/src/config/ConfigKeyWithPackage.h
@@ -31,7 +31,7 @@ using std::string;
*/
class ConfigKeyWithPackage {
public:
- ConfigKeyWithPackage(const string& package, const int64_t id) : mPackage(package), mId(id) {
+ ConfigKeyWithPackage(const string& package, int64_t id) : mPackage(package), mId(id) {
}
inline string GetPackage() const {
diff --git a/statsd/src/config/ConfigManager.h b/statsd/src/config/ConfigManager.h
index dd7d5bbb..e8819494 100644
--- a/statsd/src/config/ConfigManager.h
+++ b/statsd/src/config/ConfigManager.h
@@ -116,14 +116,14 @@ public:
/**
* Sets the pending intent that is notified whenever the list of restricted metrics changes
*/
- void SetRestrictedMetricsChangedReceiver(const string& configPackage, const int64_t configId,
+ void SetRestrictedMetricsChangedReceiver(const string& configPackage, int64_t configId,
const int32_t callingUid,
const shared_ptr<IPendingIntentRef>& pir);
/**
* Erase any restricted metrics changed pending intents associated with this config key & uid.
*/
- void RemoveRestrictedMetricsChangedReceiver(const string& configPackage, const int64_t configId,
+ void RemoveRestrictedMetricsChangedReceiver(const string& configPackage, int64_t configId,
const int32_t callingUid);
/**
diff --git a/statsd/src/external/PullResultReceiver.h b/statsd/src/external/PullResultReceiver.h
index ceaae801..f2d0a4ef 100644
--- a/statsd/src/external/PullResultReceiver.h
+++ b/statsd/src/external/PullResultReceiver.h
@@ -29,8 +29,8 @@ namespace statsd {
class PullResultReceiver : public BnPullAtomResultReceiver {
public:
- PullResultReceiver(function<void(int32_t, bool, const vector<StatsEventParcel>&)>
- pullFinishCallback);
+ PullResultReceiver(
+ function<void(int32_t, bool, const vector<StatsEventParcel>&)> pullFinishCallback);
~PullResultReceiver();
/**
diff --git a/statsd/src/external/StatsCallbackPuller.cpp b/statsd/src/external/StatsCallbackPuller.cpp
index 7d5d04b1..a1c8df2e 100644
--- a/statsd/src/external/StatsCallbackPuller.cpp
+++ b/statsd/src/external/StatsCallbackPuller.cpp
@@ -37,7 +37,7 @@ namespace statsd {
StatsCallbackPuller::StatsCallbackPuller(int tagId, const shared_ptr<IPullAtomCallback>& callback,
const int64_t coolDownNs, int64_t timeoutNs,
- const vector<int> additiveFields)
+ const vector<int>& additiveFields)
: StatsPuller(tagId, coolDownNs, timeoutNs, additiveFields), mCallback(callback) {
VLOG("StatsCallbackPuller created for tag %d", tagId);
}
diff --git a/statsd/src/external/StatsCallbackPuller.h b/statsd/src/external/StatsCallbackPuller.h
index 43d35fc1..65acb004 100644
--- a/statsd/src/external/StatsCallbackPuller.h
+++ b/statsd/src/external/StatsCallbackPuller.h
@@ -29,8 +29,8 @@ namespace statsd {
class StatsCallbackPuller : public StatsPuller {
public:
explicit StatsCallbackPuller(int tagId, const shared_ptr<IPullAtomCallback>& callback,
- const int64_t coolDownNs, const int64_t timeoutNs,
- const std::vector<int> additiveFields);
+ const int64_t coolDownNs, int64_t timeoutNs,
+ const std::vector<int>& additiveFields);
private:
PullErrorCode PullInternal(vector<std::shared_ptr<LogEvent>>* data) override;
diff --git a/statsd/src/external/StatsPuller.cpp b/statsd/src/external/StatsPuller.cpp
index 395e660e..0051b0c3 100644
--- a/statsd/src/external/StatsPuller.cpp
+++ b/statsd/src/external/StatsPuller.cpp
@@ -33,7 +33,7 @@ sp<UidMap> StatsPuller::mUidMap = nullptr;
void StatsPuller::SetUidMap(const sp<UidMap>& uidMap) { mUidMap = uidMap; }
StatsPuller::StatsPuller(const int tagId, const int64_t coolDownNs, const int64_t pullTimeoutNs,
- const std::vector<int> additiveFields)
+ const std::vector<int>& additiveFields)
: mTagId(tagId),
mPullTimeoutNs(pullTimeoutNs),
mCoolDownNs(coolDownNs),
diff --git a/statsd/src/external/StatsPuller.h b/statsd/src/external/StatsPuller.h
index d8c7eb3b..4a383821 100644
--- a/statsd/src/external/StatsPuller.h
+++ b/statsd/src/external/StatsPuller.h
@@ -41,10 +41,9 @@ enum PullErrorCode {
class StatsPuller : public virtual RefBase {
public:
- explicit StatsPuller(const int tagId,
- const int64_t coolDownNs = NS_PER_SEC,
+ explicit StatsPuller(const int tagId, int64_t coolDownNs = NS_PER_SEC,
const int64_t pullTimeoutNs = StatsdStats::kPullMaxDelayNs,
- const std::vector<int> additiveFields = std::vector<int>());
+ const std::vector<int>& additiveFields = std::vector<int>());
virtual ~StatsPuller() {}
@@ -69,7 +68,7 @@ public:
static void SetUidMap(const sp<UidMap>& uidMap);
virtual void SetStatsCompanionService(
- shared_ptr<IStatsCompanionService> statsCompanionService) {};
+ const shared_ptr<IStatsCompanionService>& statsCompanionService){};
protected:
const int mTagId;
diff --git a/statsd/src/external/StatsPullerManager.cpp b/statsd/src/external/StatsPullerManager.cpp
index 8fabcad5..4fb63a66 100644
--- a/statsd/src/external/StatsPullerManager.cpp
+++ b/statsd/src/external/StatsPullerManager.cpp
@@ -135,7 +135,7 @@ void StatsPullerManager::updateAlarmLocked() {
}
void StatsPullerManager::SetStatsCompanionService(
- shared_ptr<IStatsCompanionService> statsCompanionService) {
+ const shared_ptr<IStatsCompanionService>& statsCompanionService) {
std::lock_guard<std::mutex> _l(mLock);
shared_ptr<IStatsCompanionService> tmpForLock = mStatsCompanionService;
mStatsCompanionService = statsCompanionService;
@@ -148,8 +148,8 @@ void StatsPullerManager::SetStatsCompanionService(
}
void StatsPullerManager::RegisterReceiver(int tagId, const ConfigKey& configKey,
- wp<PullDataReceiver> receiver, int64_t nextPullTimeNs,
- int64_t intervalNs) {
+ const wp<PullDataReceiver>& receiver,
+ int64_t nextPullTimeNs, int64_t intervalNs) {
std::lock_guard<std::mutex> _l(mLock);
auto& receivers = mReceivers[{.atomTag = tagId, .configKey = configKey}];
for (auto it = receivers.begin(); it != receivers.end(); it++) {
@@ -184,7 +184,7 @@ void StatsPullerManager::RegisterReceiver(int tagId, const ConfigKey& configKey,
}
void StatsPullerManager::UnRegisterReceiver(int tagId, const ConfigKey& configKey,
- wp<PullDataReceiver> receiver) {
+ const wp<PullDataReceiver>& receiver) {
std::lock_guard<std::mutex> _l(mLock);
auto receiversIt = mReceivers.find({.atomTag = tagId, .configKey = configKey});
if (receiversIt == mReceivers.end()) {
@@ -202,13 +202,13 @@ void StatsPullerManager::UnRegisterReceiver(int tagId, const ConfigKey& configKe
}
void StatsPullerManager::RegisterPullUidProvider(const ConfigKey& configKey,
- wp<PullUidProvider> provider) {
+ const wp<PullUidProvider>& provider) {
std::lock_guard<std::mutex> _l(mLock);
mPullUidProviders[configKey] = provider;
}
void StatsPullerManager::UnregisterPullUidProvider(const ConfigKey& configKey,
- wp<PullUidProvider> provider) {
+ const wp<PullUidProvider>& provider) {
std::lock_guard<std::mutex> _l(mLock);
const auto& it = mPullUidProviders.find(configKey);
if (it != mPullUidProviders.end() && it->second == provider) {
diff --git a/statsd/src/external/StatsPullerManager.h b/statsd/src/external/StatsPullerManager.h
index 80a13312..9f5a41c8 100644
--- a/statsd/src/external/StatsPullerManager.h
+++ b/statsd/src/external/StatsPullerManager.h
@@ -70,20 +70,21 @@ public:
// Registers a receiver for tagId. It will be pulled on the nextPullTimeNs
// and then every intervalNs thereafter.
virtual void RegisterReceiver(int tagId, const ConfigKey& configKey,
- wp<PullDataReceiver> receiver, int64_t nextPullTimeNs,
+ const wp<PullDataReceiver>& receiver, int64_t nextPullTimeNs,
int64_t intervalNs);
// Stop listening on a tagId.
virtual void UnRegisterReceiver(int tagId, const ConfigKey& configKey,
- wp<PullDataReceiver> receiver);
+ const wp<PullDataReceiver>& receiver);
// Registers a pull uid provider for the config key. When pulling atoms, it will be used to
// determine which uids to pull from.
- virtual void RegisterPullUidProvider(const ConfigKey& configKey, wp<PullUidProvider> provider);
+ virtual void RegisterPullUidProvider(const ConfigKey& configKey,
+ const wp<PullUidProvider>& provider);
// Unregister a pull uid provider.
virtual void UnregisterPullUidProvider(const ConfigKey& configKey,
- wp<PullUidProvider> provider);
+ const wp<PullUidProvider>& provider);
// Verify if we know how to pull for this matcher
bool PullerForMatcherExists(int tagId) const;
@@ -101,11 +102,11 @@ public:
// registered for any of the uids for this atom.
// If the metric wants to make any change to the data, like timestamps, they
// should make a copy as this data may be shared with multiple metrics.
- virtual bool Pull(int tagId, const ConfigKey& configKey, const int64_t eventTimeNs,
+ virtual bool Pull(int tagId, const ConfigKey& configKey, int64_t eventTimeNs,
vector<std::shared_ptr<LogEvent>>* data);
// Same as above, but directly specify the allowed uids to pull from.
- virtual bool Pull(int tagId, const vector<int32_t>& uids, const int64_t eventTimeNs,
+ virtual bool Pull(int tagId, const vector<int32_t>& uids, int64_t eventTimeNs,
vector<std::shared_ptr<LogEvent>>* data);
// Clear pull data cache immediately.
@@ -114,9 +115,9 @@ public:
// Clear pull data cache if it is beyond respective cool down time.
int ClearPullerCacheIfNecessary(int64_t timestampNs);
- void SetStatsCompanionService(shared_ptr<IStatsCompanionService> statsCompanionService);
+ void SetStatsCompanionService(const shared_ptr<IStatsCompanionService>& statsCompanionService);
- void RegisterPullAtomCallback(const int uid, const int32_t atomTag, const int64_t coolDownNs,
+ void RegisterPullAtomCallback(const int uid, const int32_t atomTag, int64_t coolDownNs,
const int64_t timeoutNs, const vector<int32_t>& additiveFields,
const shared_ptr<IPullAtomCallback>& callback);
@@ -151,10 +152,10 @@ private:
// mapping from Config Key to the PullUidProvider for that config
std::map<ConfigKey, wp<PullUidProvider>> mPullUidProviders;
- bool PullLocked(int tagId, const ConfigKey& configKey, const int64_t eventTimeNs,
+ bool PullLocked(int tagId, const ConfigKey& configKey, int64_t eventTimeNs,
vector<std::shared_ptr<LogEvent>>* data);
- bool PullLocked(int tagId, const vector<int32_t>& uids, const int64_t eventTimeNs,
+ bool PullLocked(int tagId, const vector<int32_t>& uids, int64_t eventTimeNs,
vector<std::shared_ptr<LogEvent>>* data);
// locks for data receiver and StatsCompanionService changes
diff --git a/statsd/src/guardrail/StatsdStats.cpp b/statsd/src/guardrail/StatsdStats.cpp
index 939d39fa..191ea3fa 100644
--- a/statsd/src/guardrail/StatsdStats.cpp
+++ b/statsd/src/guardrail/StatsdStats.cpp
@@ -62,6 +62,7 @@ const int FIELD_ID_SHARD_OFFSET = 21;
const int FIELD_ID_STATSD_STATS_ID = 22;
const int FIELD_ID_SUBSCRIPTION_STATS = 23;
const int FIELD_ID_SOCKET_LOSS_STATS = 24;
+const int FIELD_ID_QUEUE_STATS = 25;
const int FIELD_ID_RESTRICTED_METRIC_QUERY_STATS_CALLING_UID = 1;
const int FIELD_ID_RESTRICTED_METRIC_QUERY_STATS_CONFIG_ID = 2;
@@ -93,6 +94,9 @@ const int FIELD_ID_OVERFLOW_COUNT = 1;
const int FIELD_ID_OVERFLOW_MAX_HISTORY = 2;
const int FIELD_ID_OVERFLOW_MIN_HISTORY = 3;
+const int FIELD_ID_QUEUE_MAX_SIZE_OBSERVED = 1;
+const int FIELD_ID_QUEUE_MAX_SIZE_OBSERVED_ELAPSED_NANOS = 2;
+
const int FIELD_ID_CONFIG_STATS_UID = 1;
const int FIELD_ID_CONFIG_STATS_ID = 2;
const int FIELD_ID_CONFIG_STATS_CREATION = 3;
@@ -361,6 +365,15 @@ void StatsdStats::noteEventQueueOverflow(int64_t oldestEventTimestampNs, int32_t
noteAtomDroppedLocked(atomId);
}
+void StatsdStats::noteEventQueueSize(int32_t size, int64_t eventTimestampNs) {
+ lock_guard<std::mutex> lock(mLock);
+
+ if (mEventQueueMaxSizeObserved < size) {
+ mEventQueueMaxSizeObserved = size;
+ mEventQueueMaxSizeObservedElapsedNanos = eventTimestampNs;
+ }
+}
+
void StatsdStats::noteAtomDroppedLocked(int32_t atomId) {
constexpr int kMaxPushedAtomDroppedStatsSize = kMaxPushedAtomId + kMaxNonPlatformPushedAtoms;
if (mPushedAtomDropsStats.size() < kMaxPushedAtomDroppedStatsSize ||
@@ -532,7 +545,7 @@ void StatsdStats::setCurrentUidMapMemory(int bytes) {
mUidMapStats.bytes_used = bytes;
}
-void StatsdStats::noteConditionDimensionSize(const ConfigKey& key, const int64_t& id, int size) {
+void StatsdStats::noteConditionDimensionSize(const ConfigKey& key, const int64_t id, int size) {
lock_guard<std::mutex> lock(mLock);
// if name doesn't exist before, it will create the key with count 0.
auto statsIt = mConfigStats.find(key);
@@ -546,7 +559,7 @@ void StatsdStats::noteConditionDimensionSize(const ConfigKey& key, const int64_t
}
}
-void StatsdStats::noteMetricDimensionSize(const ConfigKey& key, const int64_t& id, int size) {
+void StatsdStats::noteMetricDimensionSize(const ConfigKey& key, const int64_t id, int size) {
lock_guard<std::mutex> lock(mLock);
// if name doesn't exist before, it will create the key with count 0.
auto statsIt = mConfigStats.find(key);
@@ -559,8 +572,8 @@ void StatsdStats::noteMetricDimensionSize(const ConfigKey& key, const int64_t& i
}
}
-void StatsdStats::noteMetricDimensionInConditionSize(
- const ConfigKey& key, const int64_t& id, int size) {
+void StatsdStats::noteMetricDimensionInConditionSize(const ConfigKey& key, const int64_t id,
+ int size) {
lock_guard<std::mutex> lock(mLock);
// if name doesn't exist before, it will create the key with count 0.
auto statsIt = mConfigStats.find(key);
@@ -573,7 +586,7 @@ void StatsdStats::noteMetricDimensionInConditionSize(
}
}
-void StatsdStats::noteMatcherMatched(const ConfigKey& key, const int64_t& id) {
+void StatsdStats::noteMatcherMatched(const ConfigKey& key, const int64_t id) {
lock_guard<std::mutex> lock(mLock);
auto statsIt = mConfigStats.find(key);
@@ -583,7 +596,7 @@ void StatsdStats::noteMatcherMatched(const ConfigKey& key, const int64_t& id) {
statsIt->second->matcher_stats[id]++;
}
-void StatsdStats::noteAnomalyDeclared(const ConfigKey& key, const int64_t& id) {
+void StatsdStats::noteAnomalyDeclared(const ConfigKey& key, const int64_t id) {
lock_guard<std::mutex> lock(mLock);
auto statsIt = mConfigStats.find(key);
if (statsIt == mConfigStats.end()) {
@@ -1029,6 +1042,8 @@ void StatsdStats::resetInternalLocked() {
mOverflowCount = 0;
mMinQueueHistoryNs = kInt64Max;
mMaxQueueHistoryNs = 0;
+ mEventQueueMaxSizeObserved = 0;
+ mEventQueueMaxSizeObservedElapsedNanos = 0;
for (auto& config : mConfigStats) {
config.second->broadcast_sent_time_sec.clear();
config.second->activation_time_sec.clear();
@@ -1124,7 +1139,7 @@ int StatsdStats::getPushedAtomDropsLocked(int atomId) const {
}
}
-bool StatsdStats::hasRestrictedConfigErrors(std::shared_ptr<ConfigStats> configStats) const {
+bool StatsdStats::hasRestrictedConfigErrors(const std::shared_ptr<ConfigStats>& configStats) const {
return configStats->device_info_table_creation_failed || configStats->db_corrupted_count ||
configStats->db_deletion_size_exceeded_limit || configStats->db_deletion_stat_failed ||
configStats->db_deletion_config_invalid || configStats->db_deletion_too_old ||
@@ -1428,6 +1443,8 @@ void StatsdStats::dumpStats(int out) const {
dprintf(out, "********EventQueueOverflow stats***********\n");
dprintf(out, "Event queue overflow: %d; MaxHistoryNs: %lld; MinHistoryNs: %lld\n",
mOverflowCount, (long long)mMaxQueueHistoryNs, (long long)mMinQueueHistoryNs);
+ dprintf(out, "Event queue max size: %d; Observed at : %lld\n", mEventQueueMaxSizeObserved,
+ (long long)mEventQueueMaxSizeObservedElapsedNanos);
if (mActivationBroadcastGuardrailStats.size() > 0) {
dprintf(out, "********mActivationBroadcastGuardrail stats***********\n");
@@ -1783,6 +1800,13 @@ void StatsdStats::dumpStats(std::vector<uint8_t>* output, bool reset) {
proto.end(token);
}
+ uint64_t queueStatsToken = proto.start(FIELD_TYPE_MESSAGE | FIELD_ID_QUEUE_STATS);
+ proto.write(FIELD_TYPE_INT32 | FIELD_ID_QUEUE_MAX_SIZE_OBSERVED,
+ (int32_t)mEventQueueMaxSizeObserved);
+ proto.write(FIELD_TYPE_INT64 | FIELD_ID_QUEUE_MAX_SIZE_OBSERVED_ELAPSED_NANOS,
+ (long long)mEventQueueMaxSizeObservedElapsedNanos);
+ proto.end(queueStatsToken);
+
for (const auto& restart : mSystemServerRestartSec) {
proto.write(FIELD_TYPE_INT32 | FIELD_ID_SYSTEM_SERVER_RESTART | FIELD_COUNT_REPEATED,
restart);
diff --git a/statsd/src/guardrail/StatsdStats.h b/statsd/src/guardrail/StatsdStats.h
index c7ca8d0c..e3ab443c 100644
--- a/statsd/src/guardrail/StatsdStats.h
+++ b/statsd/src/guardrail/StatsdStats.h
@@ -395,7 +395,7 @@ public:
* [id]: The id of the condition.
* [size]: The output tuple size.
*/
- void noteConditionDimensionSize(const ConfigKey& key, const int64_t& id, int size);
+ void noteConditionDimensionSize(const ConfigKey& key, int64_t id, int size);
/**
* Report the size of output tuple of a metric.
@@ -407,7 +407,7 @@ public:
* [id]: The id of the metric.
* [size]: The output tuple size.
*/
- void noteMetricDimensionSize(const ConfigKey& key, const int64_t& id, int size);
+ void noteMetricDimensionSize(const ConfigKey& key, int64_t id, int size);
/**
* Report the max size of output tuple of dimension in condition across dimensions in what.
@@ -419,7 +419,7 @@ public:
* [id]: The id of the metric.
* [size]: The output tuple size.
*/
- void noteMetricDimensionInConditionSize(const ConfigKey& key, const int64_t& id, int size);
+ void noteMetricDimensionInConditionSize(const ConfigKey& key, int64_t id, int size);
/**
* Report a matcher has been matched.
@@ -427,7 +427,7 @@ public:
* [key]: The config key that this matcher belongs to.
* [id]: The id of the matcher.
*/
- void noteMatcherMatched(const ConfigKey& key, const int64_t& id);
+ void noteMatcherMatched(const ConfigKey& key, int64_t id);
/**
* Report that an anomaly detection alert has been declared.
@@ -435,7 +435,7 @@ public:
* [key]: The config key that this alert belongs to.
* [id]: The id of the alert.
*/
- void noteAnomalyDeclared(const ConfigKey& key, const int64_t& id);
+ void noteAnomalyDeclared(const ConfigKey& key, int64_t id);
/**
* Report an atom event has been logged.
@@ -614,6 +614,9 @@ public:
* in the queue */
void noteEventQueueOverflow(int64_t oldestEventTimestampNs, int32_t atomId, bool isSkipped);
+ /* Notes queue max size seen so far and associated timestamp */
+ void noteEventQueueSize(int32_t size, int64_t eventTimestampNs);
+
/**
* Reports that the activation broadcast guardrail was hit for this uid. Namely, the broadcast
* should have been sent, but instead was skipped due to hitting the guardrail.
@@ -633,7 +636,7 @@ public:
/** Report query of restricted metric succeed **/
void noteQueryRestrictedMetricSucceed(const int64_t configId, const string& configPackage,
const std::optional<int32_t> configUid,
- const int32_t callingUid, const int64_t queryLatencyNs);
+ const int32_t callingUid, int64_t queryLatencyNs);
/** Report query of restricted metric failed **/
void noteQueryRestrictedMetricFailed(const int64_t configId, const string& configPackage,
@@ -650,24 +653,24 @@ public:
void noteRestrictedMetricInsertError(const ConfigKey& configKey, int64_t metricId);
// Reports that a restricted metric fails to create table in database.
- void noteRestrictedMetricTableCreationError(const ConfigKey& configKey, const int64_t metricId);
+ void noteRestrictedMetricTableCreationError(const ConfigKey& configKey, int64_t metricId);
// Reports that a restricted metric fails to delete table in database.
- void noteRestrictedMetricTableDeletionError(const ConfigKey& configKey, const int64_t metricId);
+ void noteRestrictedMetricTableDeletionError(const ConfigKey& configKey, int64_t metricId);
// Reports the time it takes for a restricted metric to flush the data to the database.
- void noteRestrictedMetricFlushLatency(const ConfigKey& configKey, const int64_t metricId,
+ void noteRestrictedMetricFlushLatency(const ConfigKey& configKey, int64_t metricId,
const int64_t flushLatencyNs);
// Reports that a restricted metric had a category change.
- void noteRestrictedMetricCategoryChanged(const ConfigKey& configKey, const int64_t metricId);
+ void noteRestrictedMetricCategoryChanged(const ConfigKey& configKey, int64_t metricId);
// Reports the time is takes to flush a restricted config to the database.
void noteRestrictedConfigFlushLatency(const ConfigKey& configKey,
const int64_t totalFlushLatencyNs);
// Reports the size of the internal sqlite db.
- void noteRestrictedConfigDbSize(const ConfigKey& configKey, const int64_t elapsedTimeNs,
+ void noteRestrictedConfigDbSize(const ConfigKey& configKey, int64_t elapsedTimeNs,
const int64_t dbSize);
/**
@@ -824,7 +827,7 @@ private:
// Stores the stats for the configs that are no longer in use.
// The size of the vector is capped by kMaxIceBoxSize.
- std::list<const std::shared_ptr<ConfigStats>> mIceBox;
+ std::list<std::shared_ptr<ConfigStats>> mIceBox;
// Stores the number of times a pushed atom is logged and skipped (if skipped).
// The size of the vector is the largest pushed atom id in atoms.proto + 1. Atoms
@@ -922,6 +925,12 @@ private:
// Total number of events that are lost due to queue overflow.
int32_t mOverflowCount = 0;
+ // Max number of events stored into the queue seen so far.
+ int32_t mEventQueueMaxSizeObserved = 0;
+
+ // Event timestamp for associated max size hit.
+ int64_t mEventQueueMaxSizeObservedElapsedNanos = 0;
+
// Timestamps when we detect log loss, and the number of logs lost.
std::list<LogLossStats> mLogLossStats;
@@ -1001,7 +1010,7 @@ private:
int getPushedAtomDropsLocked(int atomId) const;
- bool hasRestrictedConfigErrors(std::shared_ptr<ConfigStats> configStats) const;
+ bool hasRestrictedConfigErrors(const std::shared_ptr<ConfigStats>& configStats) const;
/**
* Get a reference to AtomMetricStats for a metric. If none exists, create it. The reference
@@ -1009,40 +1018,42 @@ private:
*/
StatsdStats::AtomMetricStats& getAtomMetricStats(int64_t metricId);
- FRIEND_TEST(StatsdStatsTest, TestValidConfigAdd);
+ FRIEND_TEST(LogEventQueue_test, TestQueueMaxSize);
+ FRIEND_TEST(SocketParseMessageTest, TestProcessMessage);
+ FRIEND_TEST(StatsLogProcessorTest, InvalidConfigRemoved);
+ FRIEND_TEST(StatsdStatsTest, TestActivationBroadcastGuardrailHit);
+ FRIEND_TEST(StatsdStatsTest, TestAnomalyMonitor);
+ FRIEND_TEST(StatsdStatsTest, TestAtomDroppedStats);
+ FRIEND_TEST(StatsdStatsTest, TestAtomErrorStats);
+ FRIEND_TEST(StatsdStatsTest, TestAtomLog);
+ FRIEND_TEST(StatsdStatsTest, TestAtomLoggedAndDroppedAndSkippedStats);
+ FRIEND_TEST(StatsdStatsTest, TestAtomLoggedAndDroppedStats);
+ FRIEND_TEST(StatsdStatsTest, TestAtomMetricsStats);
+ FRIEND_TEST(StatsdStatsTest, TestAtomSkippedStats);
+ FRIEND_TEST(StatsdStatsTest, TestConfigRemove);
+ FRIEND_TEST(StatsdStatsTest, TestHasHitDimensionGuardrail);
FRIEND_TEST(StatsdStatsTest, TestInvalidConfigAdd);
FRIEND_TEST(StatsdStatsTest, TestInvalidConfigMissingMetricId);
FRIEND_TEST(StatsdStatsTest, TestInvalidConfigOnlyMetricId);
- FRIEND_TEST(StatsdStatsTest, TestConfigRemove);
- FRIEND_TEST(StatsdStatsTest, TestSubStats);
- FRIEND_TEST(StatsdStatsTest, TestAtomLog);
FRIEND_TEST(StatsdStatsTest, TestNonPlatformAtomLog);
- FRIEND_TEST(StatsdStatsTest, TestTimestampThreshold);
- FRIEND_TEST(StatsdStatsTest, TestAnomalyMonitor);
- FRIEND_TEST(StatsdStatsTest, TestSystemServerCrash);
FRIEND_TEST(StatsdStatsTest, TestPullAtomStats);
- FRIEND_TEST(StatsdStatsTest, TestAtomMetricsStats);
- FRIEND_TEST(StatsdStatsTest, TestActivationBroadcastGuardrailHit);
- FRIEND_TEST(StatsdStatsTest, TestAtomErrorStats);
- FRIEND_TEST(StatsdStatsTest, TestAtomSkippedStats);
- FRIEND_TEST(StatsdStatsTest, TestRestrictedMetricsStats);
+ FRIEND_TEST(StatsdStatsTest, TestQueueStats);
FRIEND_TEST(StatsdStatsTest, TestRestrictedMetricsQueryStats);
- FRIEND_TEST(StatsdStatsTest, TestAtomDroppedStats);
- FRIEND_TEST(StatsdStatsTest, TestAtomLoggedAndDroppedStats);
- FRIEND_TEST(StatsdStatsTest, TestAtomLoggedAndDroppedAndSkippedStats);
+ FRIEND_TEST(StatsdStatsTest, TestRestrictedMetricsStats);
FRIEND_TEST(StatsdStatsTest, TestShardOffsetProvider);
- FRIEND_TEST(StatsdStatsTest, TestHasHitDimensionGuardrail);
- FRIEND_TEST(StatsdStatsTest, TestSubscriptionStarted);
- FRIEND_TEST(StatsdStatsTest, TestSubscriptionFlushed);
- FRIEND_TEST(StatsdStatsTest, TestSubscriptionEnded);
+ FRIEND_TEST(StatsdStatsTest, TestSocketLossStats);
+ FRIEND_TEST(StatsdStatsTest, TestSocketLossStatsOverflowCounter);
+ FRIEND_TEST(StatsdStatsTest, TestSubStats);
FRIEND_TEST(StatsdStatsTest, TestSubscriptionAtomPulled);
+ FRIEND_TEST(StatsdStatsTest, TestSubscriptionEnded);
+ FRIEND_TEST(StatsdStatsTest, TestSubscriptionFlushed);
FRIEND_TEST(StatsdStatsTest, TestSubscriptionPullThreadWakeup);
+ FRIEND_TEST(StatsdStatsTest, TestSubscriptionStarted);
FRIEND_TEST(StatsdStatsTest, TestSubscriptionStartedMaxActiveSubscriptions);
FRIEND_TEST(StatsdStatsTest, TestSubscriptionStartedRemoveFinishedSubscription);
- FRIEND_TEST(StatsdStatsTest, TestSocketLossStats);
- FRIEND_TEST(StatsdStatsTest, TestSocketLossStatsOverflowCounter);
-
- FRIEND_TEST(StatsLogProcessorTest, InvalidConfigRemoved);
+ FRIEND_TEST(StatsdStatsTest, TestSystemServerCrash);
+ FRIEND_TEST(StatsdStatsTest, TestTimestampThreshold);
+ FRIEND_TEST(StatsdStatsTest, TestValidConfigAdd);
};
InvalidConfigReason createInvalidConfigReasonWithMatcher(const InvalidConfigReasonEnum reason,
@@ -1077,10 +1088,10 @@ InvalidConfigReason createInvalidConfigReasonWithSubscription(const InvalidConfi
const int64_t subscriptionId);
InvalidConfigReason createInvalidConfigReasonWithSubscriptionAndAlarm(
- const InvalidConfigReasonEnum reason, const int64_t subscriptionId, const int64_t alarmId);
+ const InvalidConfigReasonEnum reason, int64_t subscriptionId, int64_t alarmId);
InvalidConfigReason createInvalidConfigReasonWithSubscriptionAndAlert(
- const InvalidConfigReasonEnum reason, const int64_t subscriptionId, const int64_t alertId);
+ const InvalidConfigReasonEnum reason, int64_t subscriptionId, int64_t alertId);
} // namespace statsd
} // namespace os
diff --git a/statsd/src/guardrail/stats_log_enums.proto b/statsd/src/guardrail/stats_log_enums.proto
index 3db1e088..5fcdfdae 100644
--- a/statsd/src/guardrail/stats_log_enums.proto
+++ b/statsd/src/guardrail/stats_log_enums.proto
@@ -142,6 +142,7 @@ enum InvalidConfigReasonEnum {
INVALID_CONFIG_REASON_RESTRICTED_METRIC_NOT_ENABLED = 84;
INVALID_CONFIG_REASON_RESTRICTED_METRIC_NOT_SUPPORTED = 85;
INVALID_CONFIG_REASON_METRIC_INCORRECT_SAMPLING_PERCENTAGE = 86;
+ INVALID_CONFIG_REASON_GAUGE_METRIC_PULLED_WITH_SAMPLING = 87;
};
enum InvalidQueryReason {
diff --git a/statsd/src/logd/LogEventQueue.cpp b/statsd/src/logd/LogEventQueue.cpp
index 96b7f015..a83fcf81 100644
--- a/statsd/src/logd/LogEventQueue.cpp
+++ b/statsd/src/logd/LogEventQueue.cpp
@@ -39,22 +39,23 @@ unique_ptr<LogEvent> LogEventQueue::waitPop() {
return item;
}
-bool LogEventQueue::push(unique_ptr<LogEvent> item, int64_t* oldestTimestampNs) {
- bool success;
+LogEventQueue::Result LogEventQueue::push(unique_ptr<LogEvent> item) {
+ Result result;
{
std::unique_lock<std::mutex> lock(mMutex);
if (mQueue.size() < mQueueLimit) {
mQueue.push(std::move(item));
- success = true;
+ result.success = true;
} else {
// safe operation as queue must not be empty.
- *oldestTimestampNs = mQueue.front()->GetElapsedTimestampNs();
- success = false;
+ result.oldestTimestampNs = mQueue.front()->GetElapsedTimestampNs();
+ result.success = false;
}
+ result.size = mQueue.size();
}
mCondition.notify_one();
- return success;
+ return result;
}
} // namespace statsd
diff --git a/statsd/src/logd/LogEventQueue.h b/statsd/src/logd/LogEventQueue.h
index 53f2adf2..d01f3a94 100644
--- a/statsd/src/logd/LogEventQueue.h
+++ b/statsd/src/logd/LogEventQueue.h
@@ -40,12 +40,18 @@ public:
*/
std::unique_ptr<LogEvent> waitPop();
+ struct Result {
+ bool success = false;
+ int64_t oldestTimestampNs = 0;
+ int32_t size = 0;
+ };
+
/**
* Puts a LogEvent ptr to the end of the queue.
* Returns false on failure when the queue is full, and output the oldest event timestamp
- * in the queue.
+ * in the queue. Returns true on success and new queue size.
*/
- bool push(std::unique_ptr<LogEvent> event, int64_t* oldestTimestampNs);
+ Result push(std::unique_ptr<LogEvent> event);
private:
const size_t mQueueLimit;
diff --git a/statsd/src/metrics/CountMetricProducer.cpp b/statsd/src/metrics/CountMetricProducer.cpp
index 9a4d9224..e7a331bb 100644
--- a/statsd/src/metrics/CountMetricProducer.cpp
+++ b/statsd/src/metrics/CountMetricProducer.cpp
@@ -400,7 +400,7 @@ void CountMetricProducer::onMatchedLogEventInternalLocked(
// When a new matched event comes in, we check if event falls into the current
// bucket. If not, flush the old counter to past buckets and initialize the new bucket.
-void CountMetricProducer::flushIfNeededLocked(const int64_t& eventTimeNs) {
+void CountMetricProducer::flushIfNeededLocked(const int64_t eventTimeNs) {
int64_t currentBucketEndTimeNs = getCurrentBucketEndTimeNs();
if (eventTimeNs < currentBucketEndTimeNs) {
return;
@@ -416,7 +416,7 @@ void CountMetricProducer::flushIfNeededLocked(const int64_t& eventTimeNs) {
(long long)mCurrentBucketStartTimeNs);
}
-bool CountMetricProducer::countPassesThreshold(const int64_t& count) {
+bool CountMetricProducer::countPassesThreshold(const int64_t count) {
if (mUploadThreshold == nullopt) {
return true;
}
@@ -436,8 +436,8 @@ bool CountMetricProducer::countPassesThreshold(const int64_t& count) {
}
}
-void CountMetricProducer::flushCurrentBucketLocked(const int64_t& eventTimeNs,
- const int64_t& nextBucketStartTimeNs) {
+void CountMetricProducer::flushCurrentBucketLocked(const int64_t eventTimeNs,
+ const int64_t nextBucketStartTimeNs) {
int64_t fullBucketEndTimeNs = getCurrentBucketEndTimeNs();
CountBucket info;
info.mBucketStartNs = mCurrentBucketStartTimeNs;
diff --git a/statsd/src/metrics/CountMetricProducer.h b/statsd/src/metrics/CountMetricProducer.h
index 3f67a18a..7fa463f3 100644
--- a/statsd/src/metrics/CountMetricProducer.h
+++ b/statsd/src/metrics/CountMetricProducer.h
@@ -44,9 +44,9 @@ struct CountBucket {
class CountMetricProducer : public MetricProducer {
public:
CountMetricProducer(
- const ConfigKey& key, const CountMetric& countMetric, const int conditionIndex,
+ const ConfigKey& key, const CountMetric& countMetric, int conditionIndex,
const vector<ConditionState>& initialConditionCache, const sp<ConditionWizard>& wizard,
- const uint64_t protoHash, const int64_t timeBaseNs, const int64_t startTimeNs,
+ const uint64_t protoHash, int64_t timeBaseNs, int64_t startTimeNs,
const std::unordered_map<int, std::shared_ptr<Activation>>& eventActivationMap = {},
const std::unordered_map<int, std::vector<std::shared_ptr<Activation>>>&
eventDeactivationMap = {},
@@ -81,10 +81,10 @@ private:
void clearPastBucketsLocked(const int64_t dumpTimeNs) override;
// Internal interface to handle condition change.
- void onConditionChangedLocked(const bool conditionMet, const int64_t eventTime) override;
+ void onConditionChangedLocked(const bool conditionMet, int64_t eventTime) override;
// Internal interface to handle sliced condition change.
- void onSlicedConditionMayChangeLocked(bool overallCondition, const int64_t eventTime) override;
+ void onSlicedConditionMayChangeLocked(bool overallCondition, int64_t eventTime) override;
// Internal function to calculate the current used bytes.
size_t byteSizeLocked() const override;
@@ -94,15 +94,14 @@ private:
void dropDataLocked(const int64_t dropTimeNs) override;
// Util function to flush the old packet.
- void flushIfNeededLocked(const int64_t& newEventTime) override;
+ void flushIfNeededLocked(int64_t newEventTime) override;
- void flushCurrentBucketLocked(const int64_t& eventTimeNs,
- const int64_t& nextBucketStartTimeNs) override;
+ void flushCurrentBucketLocked(int64_t eventTimeNs, int64_t nextBucketStartTimeNs) override;
void onActiveStateChangedLocked(const int64_t eventTimeNs, const bool isActive) override;
optional<InvalidConfigReason> onConfigUpdatedLocked(
- const StatsdConfig& config, const int configIndex, const int metricIndex,
+ const StatsdConfig& config, int configIndex, int metricIndex,
const std::vector<sp<AtomMatchingTracker>>& allAtomMatchingTrackers,
const std::unordered_map<int64_t, int>& oldAtomMatchingTrackerMap,
const std::unordered_map<int64_t, int>& newAtomMatchingTrackerMap,
@@ -130,7 +129,7 @@ private:
bool hitGuardRailLocked(const MetricDimensionKey& newKey);
- bool countPassesThreshold(const int64_t& count);
+ bool countPassesThreshold(int64_t count);
// Tracks if the dimension guardrail has been hit in the current report.
bool mDimensionGuardrailHit;
diff --git a/statsd/src/metrics/DurationMetricProducer.cpp b/statsd/src/metrics/DurationMetricProducer.cpp
index a7b886dd..9973a9e2 100644
--- a/statsd/src/metrics/DurationMetricProducer.cpp
+++ b/statsd/src/metrics/DurationMetricProducer.cpp
@@ -603,7 +603,7 @@ void DurationMetricProducer::onDumpReportLocked(
}
}
-void DurationMetricProducer::flushIfNeededLocked(const int64_t& eventTimeNs) {
+void DurationMetricProducer::flushIfNeededLocked(const int64_t eventTimeNs) {
int64_t currentBucketEndTimeNs = getCurrentBucketEndTimeNs();
if (currentBucketEndTimeNs > eventTimeNs) {
@@ -617,8 +617,8 @@ void DurationMetricProducer::flushIfNeededLocked(const int64_t& eventTimeNs) {
mCurrentBucketNum += numBucketsForward;
}
-void DurationMetricProducer::flushCurrentBucketLocked(const int64_t& eventTimeNs,
- const int64_t& nextBucketStartTimeNs) {
+void DurationMetricProducer::flushCurrentBucketLocked(const int64_t eventTimeNs,
+ const int64_t nextBucketStartTimeNs) {
const auto [globalConditionTrueNs, globalConditionCorrectionNs] =
mConditionTimer.newBucketStart(eventTimeNs, nextBucketStartTimeNs);
diff --git a/statsd/src/metrics/DurationMetricProducer.h b/statsd/src/metrics/DurationMetricProducer.h
index a3662921..2f3d8597 100644
--- a/statsd/src/metrics/DurationMetricProducer.h
+++ b/statsd/src/metrics/DurationMetricProducer.h
@@ -39,12 +39,11 @@ namespace statsd {
class DurationMetricProducer : public MetricProducer {
public:
DurationMetricProducer(
- const ConfigKey& key, const DurationMetric& durationMetric, const int conditionIndex,
- const vector<ConditionState>& initialConditionCache, const int whatIndex,
- const int startIndex, const int stopIndex, const int stopAllIndex, const bool nesting,
+ const ConfigKey& key, const DurationMetric& durationMetric, int conditionIndex,
+ const vector<ConditionState>& initialConditionCache, int whatIndex,
+ const int startIndex, int stopIndex, int stopAllIndex, const bool nesting,
const sp<ConditionWizard>& wizard, const uint64_t protoHash,
- const FieldMatcher& internalDimensions, const int64_t timeBaseNs,
- const int64_t startTimeNs,
+ const FieldMatcher& internalDimensions, int64_t timeBaseNs, const int64_t startTimeNs,
const unordered_map<int, shared_ptr<Activation>>& eventActivationMap = {},
const unordered_map<int, vector<shared_ptr<Activation>>>& eventDeactivationMap = {},
const vector<int>& slicedStateAtoms = {},
@@ -57,7 +56,7 @@ public:
const UpdateStatus& updateStatus,
const int64_t updateTimeNs) override;
- void addAnomalyTracker(sp<AnomalyTracker>& anomalyTracker, const int64_t updateTimeNs) override;
+ void addAnomalyTracker(sp<AnomalyTracker>& anomalyTracker, int64_t updateTimeNs) override;
void onStateChanged(const int64_t eventTimeNs, const int32_t atomId,
const HashableDimensionKey& primaryKey, const FieldValue& oldState,
@@ -77,13 +76,13 @@ protected:
private:
// Initializes true dimensions of the 'what' predicate. Only to be called during initialization.
- void initTrueDimensions(const int whatIndex, const int64_t startTimeNs);
+ void initTrueDimensions(const int whatIndex, int64_t startTimeNs);
void handleMatchedLogEventValuesLocked(const size_t matcherIndex,
const std::vector<FieldValue>& values,
const int64_t eventTimeNs);
void handleStartEvent(const MetricDimensionKey& eventKey, const ConditionKey& conditionKeys,
- bool condition, const int64_t eventTimeNs,
+ bool condition, int64_t eventTimeNs,
const vector<FieldValue>& eventValues);
void onDumpReportLocked(const int64_t dumpTimeNs,
@@ -96,13 +95,13 @@ private:
void clearPastBucketsLocked(const int64_t dumpTimeNs) override;
// Internal interface to handle condition change.
- void onConditionChangedLocked(const bool conditionMet, const int64_t eventTime) override;
+ void onConditionChangedLocked(const bool conditionMet, int64_t eventTime) override;
// Internal interface to handle active state change.
void onActiveStateChangedLocked(const int64_t eventTimeNs, const bool isActive) override;
// Internal interface to handle sliced condition change.
- void onSlicedConditionMayChangeLocked(bool overallCondition, const int64_t eventTime) override;
+ void onSlicedConditionMayChangeLocked(bool overallCondition, int64_t eventTime) override;
void onSlicedConditionMayChangeInternalLocked(const int64_t eventTimeNs);
@@ -116,13 +115,12 @@ private:
void dropDataLocked(const int64_t dropTimeNs) override;
// Util function to flush the old packet.
- void flushIfNeededLocked(const int64_t& eventTime);
+ void flushIfNeededLocked(int64_t eventTime);
- void flushCurrentBucketLocked(const int64_t& eventTimeNs,
- const int64_t& nextBucketStartTimeNs) override;
+ void flushCurrentBucketLocked(int64_t eventTimeNs, int64_t nextBucketStartTimeNs) override;
optional<InvalidConfigReason> onConfigUpdatedLocked(
- const StatsdConfig& config, const int configIndex, const int metricIndex,
+ const StatsdConfig& config, int configIndex, int metricIndex,
const std::vector<sp<AtomMatchingTracker>>& allAtomMatchingTrackers,
const std::unordered_map<int64_t, int>& oldAtomMatchingTrackerMap,
const std::unordered_map<int64_t, int>& newAtomMatchingTrackerMap,
@@ -138,7 +136,7 @@ private:
std::vector<int>& metricsWithActivation) override;
void addAnomalyTrackerLocked(sp<AnomalyTracker>& anomalyTracker,
- const UpdateStatus& updateStatus, const int64_t updateTimeNs);
+ const UpdateStatus& updateStatus, int64_t updateTimeNs);
const DurationMetric_AggregationType mAggregationType;
diff --git a/statsd/src/metrics/EventMetricProducer.h b/statsd/src/metrics/EventMetricProducer.h
index f27f24bf..6e026597 100644
--- a/statsd/src/metrics/EventMetricProducer.h
+++ b/statsd/src/metrics/EventMetricProducer.h
@@ -35,9 +35,9 @@ namespace statsd {
class EventMetricProducer : public MetricProducer {
public:
EventMetricProducer(
- const ConfigKey& key, const EventMetric& eventMetric, const int conditionIndex,
+ const ConfigKey& key, const EventMetric& eventMetric, int conditionIndex,
const vector<ConditionState>& initialConditionCache, const sp<ConditionWizard>& wizard,
- const uint64_t protoHash, const int64_t startTimeNs,
+ const uint64_t protoHash, int64_t startTimeNs,
const std::unordered_map<int, std::shared_ptr<Activation>>& eventActivationMap = {},
const std::unordered_map<int, std::vector<std::shared_ptr<Activation>>>&
eventDeactivationMap = {},
@@ -68,13 +68,13 @@ private:
void clearPastBucketsLocked(const int64_t dumpTimeNs) override;
// Internal interface to handle condition change.
- void onConditionChangedLocked(const bool conditionMet, const int64_t eventTime) override;
+ void onConditionChangedLocked(const bool conditionMet, int64_t eventTime) override;
// Internal interface to handle sliced condition change.
- void onSlicedConditionMayChangeLocked(bool overallCondition, const int64_t eventTime) override;
+ void onSlicedConditionMayChangeLocked(bool overallCondition, int64_t eventTime) override;
optional<InvalidConfigReason> onConfigUpdatedLocked(
- const StatsdConfig& config, const int configIndex, const int metricIndex,
+ const StatsdConfig& config, int configIndex, int metricIndex,
const std::vector<sp<AtomMatchingTracker>>& allAtomMatchingTrackers,
const std::unordered_map<int64_t, int>& oldAtomMatchingTrackerMap,
const std::unordered_map<int64_t, int>& newAtomMatchingTrackerMap,
diff --git a/statsd/src/metrics/GaugeMetricProducer.cpp b/statsd/src/metrics/GaugeMetricProducer.cpp
index 66d8f45e..7566f3bd 100644
--- a/statsd/src/metrics/GaugeMetricProducer.cpp
+++ b/statsd/src/metrics/GaugeMetricProducer.cpp
@@ -100,7 +100,8 @@ GaugeMetricProducer::GaugeMetricProducer(
mDimensionSoftLimit(dimensionSoftLimit),
mDimensionHardLimit(dimensionHardLimit),
mGaugeAtomsPerDimensionLimit(metric.max_num_gauge_atoms_per_bucket()),
- mDimensionGuardrailHit(false) {
+ mDimensionGuardrailHit(false),
+ mSamplingPercentage(metric.sampling_percentage()) {
mCurrentSlicedBucket = std::make_shared<DimToGaugeAtomsMap>();
mCurrentSlicedBucketForAnomaly = std::make_shared<DimToValMap>();
int64_t bucketSizeMills = 0;
@@ -539,6 +540,12 @@ void GaugeMetricProducer::onMatchedLogEventInternalLocked(
if (condition == false) {
return;
}
+
+ if (mPullTagId == -1 && mSamplingPercentage < 100 &&
+ !shouldKeepRandomSample(mSamplingPercentage)) {
+ return;
+ }
+
int64_t eventTimeNs = event.GetElapsedTimestampNs();
if (eventTimeNs < mCurrentBucketStartTimeNs) {
VLOG("Gauge Skip event due to late arrival: %lld vs %lld", (long long)eventTimeNs,
@@ -617,7 +624,7 @@ void GaugeMetricProducer::dropDataLocked(const int64_t dropTimeNs) {
// bucket.
// if data is pushed, onMatchedLogEvent will only be called through onConditionChanged() inside
// the GaugeMetricProducer while holding the lock.
-void GaugeMetricProducer::flushIfNeededLocked(const int64_t& eventTimeNs) {
+void GaugeMetricProducer::flushIfNeededLocked(const int64_t eventTimeNs) {
int64_t currentBucketEndTimeNs = getCurrentBucketEndTimeNs();
if (eventTimeNs < currentBucketEndTimeNs) {
@@ -636,8 +643,8 @@ void GaugeMetricProducer::flushIfNeededLocked(const int64_t& eventTimeNs) {
(long long)mCurrentBucketStartTimeNs);
}
-void GaugeMetricProducer::flushCurrentBucketLocked(const int64_t& eventTimeNs,
- const int64_t& nextBucketStartTimeNs) {
+void GaugeMetricProducer::flushCurrentBucketLocked(const int64_t eventTimeNs,
+ const int64_t nextBucketStartTimeNs) {
int64_t fullBucketEndTimeNs = getCurrentBucketEndTimeNs();
int64_t bucketEndTime = eventTimeNs < fullBucketEndTimeNs ? eventTimeNs : fullBucketEndTimeNs;
diff --git a/statsd/src/metrics/GaugeMetricProducer.h b/statsd/src/metrics/GaugeMetricProducer.h
index 51df9e65..7c737a41 100644
--- a/statsd/src/metrics/GaugeMetricProducer.h
+++ b/statsd/src/metrics/GaugeMetricProducer.h
@@ -34,7 +34,7 @@ namespace os {
namespace statsd {
struct GaugeAtom {
- GaugeAtom(std::shared_ptr<vector<FieldValue>> fields, int64_t elapsedTimeNs)
+ GaugeAtom(const std::shared_ptr<vector<FieldValue>>& fields, int64_t elapsedTimeNs)
: mFields(fields), mElapsedTimestampNs(elapsedTimeNs) {
}
std::shared_ptr<vector<FieldValue>> mFields;
@@ -60,13 +60,12 @@ typedef std::unordered_map<MetricDimensionKey, std::vector<GaugeAtom>>
class GaugeMetricProducer : public MetricProducer, public virtual PullDataReceiver {
public:
GaugeMetricProducer(
- const ConfigKey& key, const GaugeMetric& gaugeMetric, const int conditionIndex,
+ const ConfigKey& key, const GaugeMetric& gaugeMetric, int conditionIndex,
const vector<ConditionState>& initialConditionCache,
const sp<ConditionWizard>& conditionWizard, const uint64_t protoHash,
const int whatMatcherIndex, const sp<EventMatcherWizard>& matcherWizard,
- const int pullTagId, const int triggerAtomId, const int atomId,
- const int64_t timeBaseNs, const int64_t startTimeNs,
- const sp<StatsPullerManager>& pullerManager,
+ const int pullTagId, int triggerAtomId, int atomId, const int64_t timeBaseNs,
+ int64_t startTimeNs, const sp<StatsPullerManager>& pullerManager,
const std::unordered_map<int, std::shared_ptr<Activation>>& eventActivationMap = {},
const std::unordered_map<int, std::vector<std::shared_ptr<Activation>>>&
eventDeactivationMap = {},
@@ -86,7 +85,7 @@ public:
};
// GaugeMetric needs to immediately trigger another pull when we create the partial bucket.
- void notifyAppUpgradeInternalLocked(const int64_t eventTimeNs) override {
+ void notifyAppUpgradeInternalLocked(int64_t eventTimeNs) override {
flushLocked(eventTimeNs);
if (mIsPulled && mSamplingType == GaugeMetric::RANDOM_ONE_SAMPLE && mIsActive) {
pullAndMatchEventsLocked(eventTimeNs);
@@ -94,7 +93,7 @@ public:
};
// GaugeMetric needs to immediately trigger another pull when we create the partial bucket.
- void onStatsdInitCompleted(const int64_t& eventTimeNs) override {
+ void onStatsdInitCompleted(int64_t eventTimeNs) override {
std::lock_guard<std::mutex> lock(mMutex);
flushLocked(eventTimeNs);
@@ -123,13 +122,13 @@ private:
void clearPastBucketsLocked(const int64_t dumpTimeNs) override;
// Internal interface to handle condition change.
- void onConditionChangedLocked(const bool conditionMet, const int64_t eventTime) override;
+ void onConditionChangedLocked(const bool conditionMet, int64_t eventTime) override;
// Internal interface to handle active state change.
void onActiveStateChangedLocked(const int64_t eventTimeNs, const bool isActive) override;
// Internal interface to handle sliced condition change.
- void onSlicedConditionMayChangeLocked(bool overallCondition, const int64_t eventTime) override;
+ void onSlicedConditionMayChangeLocked(bool overallCondition, int64_t eventTime) override;
// Internal function to calculate the current used bytes.
size_t byteSizeLocked() const override;
@@ -139,10 +138,9 @@ private:
void dropDataLocked(const int64_t dropTimeNs) override;
// Util function to flush the old packet.
- void flushIfNeededLocked(const int64_t& eventTime) override;
+ void flushIfNeededLocked(int64_t eventTime) override;
- void flushCurrentBucketLocked(const int64_t& eventTimeNs,
- const int64_t& nextBucketStartTimeNs) override;
+ void flushCurrentBucketLocked(int64_t eventTimeNs, int64_t nextBucketStartTimeNs) override;
void prepareFirstBucketLocked() override;
@@ -150,7 +148,7 @@ private:
void pullAndMatchEventsLocked(const int64_t timestampNs);
optional<InvalidConfigReason> onConfigUpdatedLocked(
- const StatsdConfig& config, const int configIndex, const int metricIndex,
+ const StatsdConfig& config, int configIndex, int metricIndex,
const std::vector<sp<AtomMatchingTracker>>& allAtomMatchingTrackers,
const std::unordered_map<int64_t, int>& oldAtomMatchingTrackerMap,
const std::unordered_map<int64_t, int>& newAtomMatchingTrackerMap,
@@ -227,6 +225,8 @@ private:
// Tracks if the dimension guardrail has been hit in the current report.
bool mDimensionGuardrailHit;
+ const int mSamplingPercentage;
+
FRIEND_TEST(GaugeMetricProducerTest, TestPulledEventsWithCondition);
FRIEND_TEST(GaugeMetricProducerTest, TestPulledEventsWithSlicedCondition);
FRIEND_TEST(GaugeMetricProducerTest, TestPulledEventsNoCondition);
diff --git a/statsd/src/metrics/MetricProducer.cpp b/statsd/src/metrics/MetricProducer.cpp
index bd697982..55c9adfc 100644
--- a/statsd/src/metrics/MetricProducer.cpp
+++ b/statsd/src/metrics/MetricProducer.cpp
@@ -45,9 +45,9 @@ const int FIELD_ID_ACTIVE_EVENT_ACTIVATION_REMAINING_TTL_NANOS = 2;
const int FIELD_ID_ACTIVE_EVENT_ACTIVATION_STATE = 3;
MetricProducer::MetricProducer(
- const int64_t& metricId, const ConfigKey& key, const int64_t timeBaseNs,
- const int conditionIndex, const vector<ConditionState>& initialConditionCache,
- const sp<ConditionWizard>& wizard, const uint64_t protoHash,
+ int64_t metricId, const ConfigKey& key, const int64_t timeBaseNs, const int conditionIndex,
+ const vector<ConditionState>& initialConditionCache, const sp<ConditionWizard>& wizard,
+ const uint64_t protoHash,
const std::unordered_map<int, std::shared_ptr<Activation>>& eventActivationMap,
const std::unordered_map<int, std::vector<std::shared_ptr<Activation>>>&
eventDeactivationMap,
@@ -243,7 +243,7 @@ void MetricProducer::cancelEventActivationLocked(int deactivationTrackerIndex) {
if (it == mEventDeactivationMap.end()) {
return;
}
- for (auto activationToCancelIt : it->second) {
+ for (auto& activationToCancelIt : it->second) {
activationToCancelIt->state = ActivationState::kNotActive;
}
}
@@ -319,7 +319,7 @@ void MetricProducer::writeActiveMetricToProtoOutputStream(
}
}
-void MetricProducer::queryStateValue(const int32_t atomId, const HashableDimensionKey& queryKey,
+void MetricProducer::queryStateValue(int32_t atomId, const HashableDimensionKey& queryKey,
FieldValue* value) {
if (!StateManager::getInstance().getStateValue(atomId, queryKey, value)) {
value->mValue = Value(StateTracker::kStateUnknown);
@@ -329,7 +329,7 @@ void MetricProducer::queryStateValue(const int32_t atomId, const HashableDimensi
}
}
-void MetricProducer::mapStateValue(const int32_t atomId, FieldValue* value) {
+void MetricProducer::mapStateValue(int32_t atomId, FieldValue* value) {
// check if there is a state map for this atom
auto atomIt = mStateGroupMap.find(atomId);
if (atomIt == mStateGroupMap.end()) {
diff --git a/statsd/src/metrics/MetricProducer.h b/statsd/src/metrics/MetricProducer.h
index 24e761af..133aa323 100644
--- a/statsd/src/metrics/MetricProducer.h
+++ b/statsd/src/metrics/MetricProducer.h
@@ -73,11 +73,12 @@ enum MetricType {
};
struct Activation {
- Activation(const ActivationType& activationType, const int64_t ttlNs)
+ Activation(const ActivationType& activationType, int64_t ttlNs)
: ttl_ns(ttlNs),
start_ns(0),
state(ActivationState::kNotActive),
- activationType(activationType) {}
+ activationType(activationType) {
+ }
const int64_t ttl_ns;
int64_t start_ns;
@@ -127,7 +128,7 @@ optional<bool> getAppUpgradeBucketSplit(const T& metric) {
// be a no-op.
class MetricProducer : public virtual RefBase, public virtual StateListener {
public:
- MetricProducer(const int64_t& metricId, const ConfigKey& key, const int64_t timeBaseNs,
+ MetricProducer(int64_t metricId, const ConfigKey& key, int64_t timeBaseNs,
const int conditionIndex, const vector<ConditionState>& initialConditionCache,
const sp<ConditionWizard>& wizard, const uint64_t protoHash,
const std::unordered_map<int, std::shared_ptr<Activation>>& eventActivationMap,
@@ -149,7 +150,7 @@ public:
// This function also updates several maps used by metricsManager.
// This function clears all anomaly trackers. All anomaly trackers need to be added again.
optional<InvalidConfigReason> onConfigUpdated(
- const StatsdConfig& config, const int configIndex, const int metricIndex,
+ const StatsdConfig& config, int configIndex, int metricIndex,
const std::vector<sp<AtomMatchingTracker>>& allAtomMatchingTrackers,
const std::unordered_map<int64_t, int>& oldAtomMatchingTrackerMap,
const std::unordered_map<int64_t, int>& newAtomMatchingTrackerMap,
@@ -175,7 +176,7 @@ public:
/**
* Force a partial bucket split on app upgrade
*/
- void notifyAppUpgrade(const int64_t& eventTimeNs) {
+ void notifyAppUpgrade(int64_t eventTimeNs) {
std::lock_guard<std::mutex> lock(mMutex);
const bool splitBucket =
mSplitBucketForAppUpgrade ? mSplitBucketForAppUpgrade.value() : false;
@@ -185,7 +186,7 @@ public:
notifyAppUpgradeInternalLocked(eventTimeNs);
};
- void notifyAppRemoved(const int64_t& eventTimeNs) {
+ void notifyAppRemoved(int64_t eventTimeNs) {
// Force buckets to split on removal also.
notifyAppUpgrade(eventTimeNs);
};
@@ -193,7 +194,7 @@ public:
/**
* Force a partial bucket split on boot complete.
*/
- virtual void onStatsdInitCompleted(const int64_t& eventTimeNs) {
+ virtual void onStatsdInitCompleted(int64_t eventTimeNs) {
std::lock_guard<std::mutex> lock(mMutex);
flushLocked(eventTimeNs);
}
@@ -203,12 +204,12 @@ public:
onMatchedLogEventLocked(matcherIndex, event);
}
- void onConditionChanged(const bool condition, const int64_t eventTime) {
+ void onConditionChanged(const bool condition, int64_t eventTime) {
std::lock_guard<std::mutex> lock(mMutex);
onConditionChangedLocked(condition, eventTime);
}
- void onSlicedConditionMayChange(bool overallCondition, const int64_t eventTime) {
+ void onSlicedConditionMayChange(bool overallCondition, int64_t eventTime) {
std::lock_guard<std::mutex> lock(mMutex);
onSlicedConditionMayChangeLocked(overallCondition, eventTime);
}
@@ -236,7 +237,7 @@ public:
}
virtual optional<InvalidConfigReason> onConfigUpdatedLocked(
- const StatsdConfig& config, const int configIndex, const int metricIndex,
+ const StatsdConfig& config, int configIndex, int metricIndex,
const std::vector<sp<AtomMatchingTracker>>& allAtomMatchingTrackers,
const std::unordered_map<int64_t, int>& oldAtomMatchingTrackerMap,
const std::unordered_map<int64_t, int>& newAtomMatchingTrackerMap,
@@ -307,7 +308,7 @@ public:
void writeActiveMetricToProtoOutputStream(
int64_t currentTimeNs, const DumpReportReason reason, ProtoOutputStream* proto);
- virtual void enforceRestrictedDataTtl(sqlite3* db, const int64_t wallClockNs){};
+ virtual void enforceRestrictedDataTtl(sqlite3* db, int64_t wallClockNs){};
virtual bool writeMetricMetadataToProto(metadata::MetricMetadata* metricMetadata) {
return false;
@@ -364,7 +365,7 @@ public:
}
/* Adds an AnomalyTracker that has already been created */
- virtual void addAnomalyTracker(sp<AnomalyTracker>& anomalyTracker, const int64_t updateTimeNs) {
+ virtual void addAnomalyTracker(sp<AnomalyTracker>& anomalyTracker, int64_t updateTimeNs) {
std::lock_guard<std::mutex> lock(mMutex);
mAnomalyTrackers.push_back(anomalyTracker);
}
@@ -379,7 +380,7 @@ protected:
/**
* Flushes the current bucket if the eventTime is after the current bucket's end time.
*/
- virtual void flushIfNeededLocked(const int64_t& eventTime){};
+ virtual void flushIfNeededLocked(int64_t eventTime){};
/**
* For metrics that aggregate (ie, every metric producer except for EventMetricProducer),
@@ -391,13 +392,12 @@ protected:
* flushIfNeededLocked or flushLocked or the app upgrade handler; the caller MUST update the
* bucket timestamp and bucket number as needed.
*/
- virtual void flushCurrentBucketLocked(const int64_t& eventTimeNs,
- const int64_t& nextBucketStartTimeNs) {};
+ virtual void flushCurrentBucketLocked(int64_t eventTimeNs, int64_t nextBucketStartTimeNs){};
/**
* Flushes all the data including the current partial bucket.
*/
- void flushLocked(const int64_t& eventTimeNs) {
+ void flushLocked(int64_t eventTimeNs) {
flushIfNeededLocked(eventTimeNs);
flushCurrentBucketLocked(eventTimeNs, eventTimeNs);
};
@@ -428,7 +428,7 @@ protected:
// Consume the parsed stats log entry that already matched the "what" of the metric.
virtual void onMatchedLogEventLocked(const size_t matcherIndex, const LogEvent& event);
- virtual void onConditionChangedLocked(const bool condition, const int64_t eventTime) = 0;
+ virtual void onConditionChangedLocked(const bool condition, int64_t eventTime) = 0;
virtual void onSlicedConditionMayChangeLocked(bool overallCondition,
const int64_t eventTime) = 0;
virtual void onDumpReportLocked(const int64_t dumpTimeNs,
@@ -470,13 +470,12 @@ protected:
// Query StateManager for original state value using the queryKey.
// The field and value are output.
- void queryStateValue(const int32_t atomId, const HashableDimensionKey& queryKey,
- FieldValue* value);
+ void queryStateValue(int32_t atomId, const HashableDimensionKey& queryKey, FieldValue* value);
// If a state map exists for the given atom, replace the original state
// value with the group id mapped to the value.
// If no state map exists, keep the original state value.
- void mapStateValue(const int32_t atomId, FieldValue* value);
+ void mapStateValue(int32_t atomId, FieldValue* value);
// Returns a HashableDimensionKey with unknown state value for each state
// atom.
diff --git a/statsd/src/metrics/MetricsManager.cpp b/statsd/src/metrics/MetricsManager.cpp
index e7e35611..1813def8 100644
--- a/statsd/src/metrics/MetricsManager.cpp
+++ b/statsd/src/metrics/MetricsManager.cpp
@@ -364,7 +364,7 @@ bool MetricsManager::isConfigValid() const {
return !mInvalidConfigReason.has_value();
}
-void MetricsManager::notifyAppUpgrade(const int64_t& eventTimeNs, const string& apk, const int uid,
+void MetricsManager::notifyAppUpgrade(const int64_t eventTimeNs, const string& apk, const int uid,
const int64_t version) {
// Inform all metric producers.
for (const auto& it : mAllMetricProducers) {
@@ -385,8 +385,7 @@ void MetricsManager::notifyAppUpgrade(const int64_t& eventTimeNs, const string&
}
}
-void MetricsManager::notifyAppRemoved(const int64_t& eventTimeNs, const string& apk,
- const int uid) {
+void MetricsManager::notifyAppRemoved(const int64_t eventTimeNs, const string& apk, const int uid) {
// Inform all metric producers.
for (const auto& it : mAllMetricProducers) {
it->notifyAppRemoved(eventTimeNs);
@@ -406,7 +405,7 @@ void MetricsManager::notifyAppRemoved(const int64_t& eventTimeNs, const string&
}
}
-void MetricsManager::onUidMapReceived(const int64_t& eventTimeNs) {
+void MetricsManager::onUidMapReceived(const int64_t eventTimeNs) {
// Purposefully don't inform metric producers on a new snapshot
// because we don't need to flush partial buckets.
// This occurs if a new user is added/removed or statsd crashes.
@@ -418,7 +417,7 @@ void MetricsManager::onUidMapReceived(const int64_t& eventTimeNs) {
initAllowedLogSources();
}
-void MetricsManager::onStatsdInitCompleted(const int64_t& eventTimeNs) {
+void MetricsManager::onStatsdInitCompleted(const int64_t eventTimeNs) {
// Inform all metric producers.
for (const auto& it : mAllMetricProducers) {
it->onStatsdInitCompleted(eventTimeNs);
@@ -725,7 +724,7 @@ void MetricsManager::onLogEvent(const LogEvent& event) {
}
void MetricsManager::onAnomalyAlarmFired(
- const int64_t& timestampNs,
+ const int64_t timestampNs,
unordered_set<sp<const InternalAlarm>, SpHash<InternalAlarm>>& alarmSet) {
for (const auto& itr : mAllAnomalyTrackers) {
itr->informAlarmsFired(timestampNs, alarmSet);
@@ -733,7 +732,7 @@ void MetricsManager::onAnomalyAlarmFired(
}
void MetricsManager::onPeriodicAlarmFired(
- const int64_t& timestampNs,
+ const int64_t timestampNs,
unordered_set<sp<const InternalAlarm>, SpHash<InternalAlarm>>& alarmSet) {
for (const auto& itr : mAllPeriodicAlarmTrackers) {
itr->informAlarmsFired(timestampNs, alarmSet);
diff --git a/statsd/src/metrics/MetricsManager.h b/statsd/src/metrics/MetricsManager.h
index 4674a85e..4721075b 100644
--- a/statsd/src/metrics/MetricsManager.h
+++ b/statsd/src/metrics/MetricsManager.h
@@ -39,7 +39,7 @@ namespace statsd {
// A MetricsManager is responsible for managing metrics from one single config source.
class MetricsManager : public virtual RefBase, public virtual PullUidProvider {
public:
- MetricsManager(const ConfigKey& configKey, const StatsdConfig& config, const int64_t timeBaseNs,
+ MetricsManager(const ConfigKey& configKey, const StatsdConfig& config, int64_t timeBaseNs,
const int64_t currentTimeNs, const sp<UidMap>& uidMap,
const sp<StatsPullerManager>& pullerManager,
const sp<AlarmMonitor>& anomalyAlarmMonitor,
@@ -47,8 +47,8 @@ public:
virtual ~MetricsManager();
- bool updateConfig(const StatsdConfig& config, const int64_t timeBaseNs,
- const int64_t currentTimeNs, const sp<AlarmMonitor>& anomalyAlarmMonitor,
+ bool updateConfig(const StatsdConfig& config, int64_t timeBaseNs, const int64_t currentTimeNs,
+ const sp<AlarmMonitor>& anomalyAlarmMonitor,
const sp<AlarmMonitor>& periodicAlarmMonitor);
// Return whether the configuration is valid.
@@ -61,21 +61,20 @@ public:
virtual void onLogEvent(const LogEvent& event);
void onAnomalyAlarmFired(
- const int64_t& timestampNs,
- unordered_set<sp<const InternalAlarm>, SpHash<InternalAlarm>>& alarmSet);
+ int64_t timestampNs,
+ unordered_set<sp<const InternalAlarm>, SpHash<InternalAlarm>>& alarmSet);
void onPeriodicAlarmFired(
- const int64_t& timestampNs,
- unordered_set<sp<const InternalAlarm>, SpHash<InternalAlarm>>& alarmSet);
+ int64_t timestampNs,
+ unordered_set<sp<const InternalAlarm>, SpHash<InternalAlarm>>& alarmSet);
- void notifyAppUpgrade(const int64_t& eventTimeNs, const string& apk, const int uid,
- const int64_t version);
+ void notifyAppUpgrade(int64_t eventTimeNs, const string& apk, int uid, int64_t version);
- void notifyAppRemoved(const int64_t& eventTimeNs, const string& apk, const int uid);
+ void notifyAppRemoved(int64_t eventTimeNs, const string& apk, int uid);
- void onUidMapReceived(const int64_t& eventTimeNs);
+ void onUidMapReceived(int64_t eventTimeNs);
- void onStatsdInitCompleted(const int64_t& elapsedTimeNs);
+ void onStatsdInitCompleted(int64_t elapsedTimeNs);
void init();
@@ -133,7 +132,7 @@ public:
virtual void dropData(const int64_t dropTimeNs);
- virtual void onDumpReport(const int64_t dumpTimeNs, const int64_t wallClockNs,
+ virtual void onDumpReport(const int64_t dumpTimeNs, int64_t wallClockNs,
const bool include_current_partial_bucket, const bool erase_data,
const DumpLatency dumpLatency, std::set<string>* str_set,
android::util::ProtoOutputStream* protoOutput);
@@ -176,7 +175,7 @@ public:
void enforceRestrictedDataTtls(const int64_t wallClockNs);
- bool validateRestrictedMetricsDelegate(const int32_t callingUid);
+ bool validateRestrictedMetricsDelegate(int32_t callingUid);
virtual void flushRestrictedData();
diff --git a/statsd/src/metrics/NumericValueMetricProducer.h b/statsd/src/metrics/NumericValueMetricProducer.h
index 52eab1a5..775fc1af 100644
--- a/statsd/src/metrics/NumericValueMetricProducer.h
+++ b/statsd/src/metrics/NumericValueMetricProducer.h
@@ -118,7 +118,7 @@ private:
bool hitFullBucketGuardRailLocked(const MetricDimensionKey& newKey);
inline bool canSkipLogEventLocked(
- const MetricDimensionKey& eventKey, const bool condition, const int64_t eventTimeNs,
+ const MetricDimensionKey& eventKey, const bool condition, int64_t eventTimeNs,
const map<int, HashableDimensionKey>& statePrimaryKeys) const override {
// For pushed metrics, can only skip if condition is false.
// For pulled metrics, can only skip if metric is not diffed and condition is false or
diff --git a/statsd/src/metrics/RestrictedEventMetricProducer.h b/statsd/src/metrics/RestrictedEventMetricProducer.h
index 74b0b803..1f68387e 100644
--- a/statsd/src/metrics/RestrictedEventMetricProducer.h
+++ b/statsd/src/metrics/RestrictedEventMetricProducer.h
@@ -15,7 +15,7 @@ public:
RestrictedEventMetricProducer(
const ConfigKey& key, const EventMetric& eventMetric, const int conditionIndex,
const vector<ConditionState>& initialConditionCache, const sp<ConditionWizard>& wizard,
- const uint64_t protoHash, const int64_t startTimeNs,
+ const uint64_t protoHash, int64_t startTimeNs,
const std::unordered_map<int, std::shared_ptr<Activation>>& eventActivationMap = {},
const std::unordered_map<int, std::vector<std::shared_ptr<Activation>>>&
eventDeactivationMap = {},
@@ -24,7 +24,7 @@ public:
void onMetricRemove() override;
- void enforceRestrictedDataTtl(sqlite3* db, const int64_t wallClockNs);
+ void enforceRestrictedDataTtl(sqlite3* db, int64_t wallClockNs);
void flushRestrictedData() override;
diff --git a/statsd/src/metrics/ValueMetricProducer.cpp b/statsd/src/metrics/ValueMetricProducer.cpp
index c61e1233..732cccc5 100644
--- a/statsd/src/metrics/ValueMetricProducer.cpp
+++ b/statsd/src/metrics/ValueMetricProducer.cpp
@@ -72,7 +72,7 @@ const int FIELD_ID_SLICE_BY_STATE = 6;
template <typename AggregatedValue, typename DimExtras>
ValueMetricProducer<AggregatedValue, DimExtras>::ValueMetricProducer(
- const int64_t& metricId, const ConfigKey& key, const uint64_t protoHash,
+ const int64_t metricId, const ConfigKey& key, const uint64_t protoHash,
const PullOptions& pullOptions, const BucketOptions& bucketOptions,
const WhatOptions& whatOptions, const ConditionOptions& conditionOptions,
const StateOptions& stateOptions, const ActivationOptions& activationOptions,
@@ -154,7 +154,7 @@ ValueMetricProducer<AggregatedValue, DimExtras>::~ValueMetricProducer() {
template <typename AggregatedValue, typename DimExtras>
void ValueMetricProducer<AggregatedValue, DimExtras>::onStatsdInitCompleted(
- const int64_t& eventTimeNs) {
+ const int64_t eventTimeNs) {
lock_guard<mutex> lock(mMutex);
if (isPulled() && mCondition == ConditionState::kTrue && mIsActive) {
@@ -717,7 +717,7 @@ void ValueMetricProducer<AggregatedValue, DimExtras>::onMatchedLogEventInternalL
// if mCondition and mIsActive are true!
template <typename AggregatedValue, typename DimExtras>
void ValueMetricProducer<AggregatedValue, DimExtras>::flushIfNeededLocked(
- const int64_t& eventTimeNs) {
+ const int64_t eventTimeNs) {
const int64_t currentBucketEndTimeNs = getCurrentBucketEndTimeNs();
if (eventTimeNs < currentBucketEndTimeNs) {
VLOG("eventTime is %lld, less than current bucket end time %lld", (long long)eventTimeNs,
@@ -742,7 +742,7 @@ int64_t ValueMetricProducer<AggregatedValue, DimExtras>::calcBucketsForwardCount
template <typename AggregatedValue, typename DimExtras>
void ValueMetricProducer<AggregatedValue, DimExtras>::flushCurrentBucketLocked(
- const int64_t& eventTimeNs, const int64_t& nextBucketStartTimeNs) {
+ const int64_t eventTimeNs, const int64_t nextBucketStartTimeNs) {
if (mCondition == ConditionState::kUnknown) {
StatsdStats::getInstance().noteBucketUnknownCondition(mMetricId);
invalidateCurrentBucket(eventTimeNs, BucketDropReason::CONDITION_UNKNOWN);
diff --git a/statsd/src/metrics/ValueMetricProducer.h b/statsd/src/metrics/ValueMetricProducer.h
index 6bfc95dc..92541029 100644
--- a/statsd/src/metrics/ValueMetricProducer.h
+++ b/statsd/src/metrics/ValueMetricProducer.h
@@ -127,13 +127,13 @@ public:
}
// ValueMetric needs special logic if it's a pulled atom.
- void onStatsdInitCompleted(const int64_t& eventTimeNs) override;
+ void onStatsdInitCompleted(int64_t eventTimeNs) override;
void onStateChanged(int64_t eventTimeNs, int32_t atomId, const HashableDimensionKey& primaryKey,
const FieldValue& oldState, const FieldValue& newState) override;
protected:
- ValueMetricProducer(const int64_t& metricId, const ConfigKey& key, const uint64_t protoHash,
+ ValueMetricProducer(int64_t metricId, const ConfigKey& key, uint64_t protoHash,
const PullOptions& pullOptions, const BucketOptions& bucketOptions,
const WhatOptions& whatOptions, const ConditionOptions& conditionOptions,
const StateOptions& stateOptions,
@@ -178,7 +178,7 @@ protected:
}
// ValueMetricProducer internal interface to handle condition change.
- void onConditionChangedLocked(const bool condition, const int64_t eventTimeNs) override;
+ void onConditionChangedLocked(const bool condition, int64_t eventTimeNs) override;
// Only called when mIsActive, the event is NOT too late, and after pulling.
virtual void onConditionChangedInternalLocked(const ConditionState oldCondition,
@@ -187,7 +187,7 @@ protected:
}
// Internal interface to handle sliced condition change.
- void onSlicedConditionMayChangeLocked(bool overallCondition, const int64_t eventTime) override;
+ void onSlicedConditionMayChangeLocked(bool overallCondition, int64_t eventTime) override;
void dumpStatesLocked(int out, bool verbose) const override;
@@ -195,12 +195,11 @@ protected:
// For pulled metrics, this method should only be called if a pull has been done. Else we will
// not have complete data for the bucket.
- void flushIfNeededLocked(const int64_t& eventTime) override;
+ void flushIfNeededLocked(int64_t eventTime) override;
// For pulled metrics, this method should only be called if a pulled has been done. Else we will
// not have complete data for the bucket.
- void flushCurrentBucketLocked(const int64_t& eventTimeNs,
- const int64_t& nextBucketStartTimeNs) override;
+ void flushCurrentBucketLocked(int64_t eventTimeNs, int64_t nextBucketStartTimeNs) override;
void dropDataLocked(const int64_t dropTimeNs) override;
@@ -216,7 +215,7 @@ protected:
void skipCurrentBucket(const int64_t dropTimeNs, const BucketDropReason reason);
optional<InvalidConfigReason> onConfigUpdatedLocked(
- const StatsdConfig& config, const int configIndex, const int metricIndex,
+ const StatsdConfig& config, int configIndex, int metricIndex,
const std::vector<sp<AtomMatchingTracker>>& allAtomMatchingTrackers,
const std::unordered_map<int64_t, int>& oldAtomMatchingTrackerMap,
const std::unordered_map<int64_t, int>& newAtomMatchingTrackerMap,
@@ -332,7 +331,7 @@ protected:
virtual PastBucket<AggregatedValue> buildPartialBucket(int64_t bucketEndTime,
std::vector<Interval>& intervals) = 0;
- virtual void closeCurrentBucket(const int64_t eventTimeNs, const int64_t nextBucketStartTimeNs);
+ virtual void closeCurrentBucket(const int64_t eventTimeNs, int64_t nextBucketStartTimeNs);
virtual void initNextSlicedBucket(int64_t nextBucketStartTimeNs);
diff --git a/statsd/src/metrics/duration_helper/DurationTracker.h b/statsd/src/metrics/duration_helper/DurationTracker.h
index 5f2e6433..f86197a9 100644
--- a/statsd/src/metrics/duration_helper/DurationTracker.h
+++ b/statsd/src/metrics/duration_helper/DurationTracker.h
@@ -73,8 +73,8 @@ struct DurationValues {
class DurationTracker {
public:
- DurationTracker(const ConfigKey& key, const int64_t& id, const MetricDimensionKey& eventKey,
- sp<ConditionWizard> wizard, int conditionIndex, bool nesting,
+ DurationTracker(const ConfigKey& key, const int64_t id, const MetricDimensionKey& eventKey,
+ const sp<ConditionWizard>& wizard, int conditionIndex, bool nesting,
int64_t currentBucketStartNs, int64_t currentBucketNum, int64_t startTimeNs,
int64_t bucketSizeNs, bool conditionSliced, bool fullLink,
const std::vector<sp<AnomalyTracker>>& anomalyTrackers)
@@ -95,21 +95,21 @@ public:
virtual ~DurationTracker(){};
- void onConfigUpdated(const sp<ConditionWizard>& wizard, const int conditionTrackerIndex) {
+ void onConfigUpdated(const sp<ConditionWizard>& wizard, int conditionTrackerIndex) {
sp<ConditionWizard> tmpWizard = mWizard;
mWizard = wizard;
mConditionTrackerIndex = conditionTrackerIndex;
mAnomalyTrackers.clear();
};
- virtual void noteStart(const HashableDimensionKey& key, bool condition, const int64_t eventTime,
+ virtual void noteStart(const HashableDimensionKey& key, bool condition, int64_t eventTime,
const ConditionKey& conditionKey, size_t dimensionHardLimit) = 0;
- virtual void noteStop(const HashableDimensionKey& key, const int64_t eventTime,
+ virtual void noteStop(const HashableDimensionKey& key, int64_t eventTime,
const bool stopAll) = 0;
virtual void noteStopAll(const int64_t eventTime) = 0;
virtual void onSlicedConditionMayChange(const int64_t timestamp) = 0;
- virtual void onConditionChanged(bool condition, const int64_t timestamp) = 0;
+ virtual void onConditionChanged(bool condition, int64_t timestamp) = 0;
virtual void onStateChanged(const int64_t timestamp, const int32_t atomId,
const FieldValue& newState) = 0;
@@ -123,7 +123,7 @@ public:
// Should only be called during an app upgrade or from this tracker's flushIfNeeded. If from
// an app upgrade, we assume that we're trying to form a partial bucket.
virtual bool flushCurrentBucket(
- const int64_t& eventTimeNs, const optional<UploadThreshold>& uploadThreshold,
+ int64_t eventTimeNs, const optional<UploadThreshold>& uploadThreshold,
const int64_t globalConditionTrueNs,
std::unordered_map<MetricDimensionKey, std::vector<DurationBucket>>* output) = 0;
@@ -138,7 +138,7 @@ public:
virtual int64_t getCurrentStateKeyFullBucketDuration() const = 0;
// Replace old value with new value for the given state atom.
- virtual void updateCurrentStateKey(const int32_t atomId, const FieldValue& newState) = 0;
+ virtual void updateCurrentStateKey(int32_t atomId, const FieldValue& newState) = 0;
virtual bool hasAccumulatedDuration() const = 0;
@@ -188,8 +188,8 @@ protected:
}
}
- void addPastBucketToAnomalyTrackers(const MetricDimensionKey eventKey,
- const int64_t& bucketValue, const int64_t& bucketNum) {
+ void addPastBucketToAnomalyTrackers(const MetricDimensionKey& eventKey, int64_t bucketValue,
+ int64_t bucketNum) {
for (auto& anomalyTracker : mAnomalyTrackers) {
if (anomalyTracker != nullptr) {
anomalyTracker->addPastBucket(eventKey, bucketValue, bucketNum);
@@ -197,8 +197,8 @@ protected:
}
}
- void detectAndDeclareAnomaly(const int64_t& timestamp, const int64_t& currBucketNum,
- const int64_t& currentBucketValue) {
+ void detectAndDeclareAnomaly(int64_t timestamp, int64_t currBucketNum,
+ int64_t currentBucketValue) {
for (auto& anomalyTracker : mAnomalyTrackers) {
if (anomalyTracker != nullptr) {
anomalyTracker->detectAndDeclareAnomaly(timestamp, currBucketNum, mTrackerId,
diff --git a/statsd/src/metrics/duration_helper/MaxDurationTracker.cpp b/statsd/src/metrics/duration_helper/MaxDurationTracker.cpp
index a263bc56..8a253e26 100644
--- a/statsd/src/metrics/duration_helper/MaxDurationTracker.cpp
+++ b/statsd/src/metrics/duration_helper/MaxDurationTracker.cpp
@@ -24,12 +24,12 @@ namespace android {
namespace os {
namespace statsd {
-MaxDurationTracker::MaxDurationTracker(const ConfigKey& key, const int64_t& id,
+MaxDurationTracker::MaxDurationTracker(const ConfigKey& key, const int64_t id,
const MetricDimensionKey& eventKey,
- sp<ConditionWizard> wizard, int conditionIndex, bool nesting,
- int64_t currentBucketStartNs, int64_t currentBucketNum,
- int64_t startTimeNs, int64_t bucketSizeNs,
- bool conditionSliced, bool fullLink,
+ const sp<ConditionWizard>& wizard, int conditionIndex,
+ bool nesting, int64_t currentBucketStartNs,
+ int64_t currentBucketNum, int64_t startTimeNs,
+ int64_t bucketSizeNs, bool conditionSliced, bool fullLink,
const vector<sp<AnomalyTracker>>& anomalyTrackers)
: DurationTracker(key, id, eventKey, wizard, conditionIndex, nesting, currentBucketStartNs,
currentBucketNum, startTimeNs, bucketSizeNs, conditionSliced, fullLink,
@@ -175,7 +175,7 @@ void MaxDurationTracker::noteStopAll(const int64_t eventTime) {
}
bool MaxDurationTracker::flushCurrentBucket(
- const int64_t& eventTimeNs, const optional<UploadThreshold>& uploadThreshold,
+ const int64_t eventTimeNs, const optional<UploadThreshold>& uploadThreshold,
const int64_t globalConditionTrueNs,
std::unordered_map<MetricDimensionKey, std::vector<DurationBucket>>* output) {
VLOG("MaxDurationTracker flushing.....");
diff --git a/statsd/src/metrics/duration_helper/MaxDurationTracker.h b/statsd/src/metrics/duration_helper/MaxDurationTracker.h
index cff3fb6a..27692326 100644
--- a/statsd/src/metrics/duration_helper/MaxDurationTracker.h
+++ b/statsd/src/metrics/duration_helper/MaxDurationTracker.h
@@ -28,30 +28,29 @@ namespace statsd {
// they stop or bucket expires.
class MaxDurationTracker : public DurationTracker {
public:
- MaxDurationTracker(const ConfigKey& key, const int64_t& id, const MetricDimensionKey& eventKey,
- sp<ConditionWizard> wizard, int conditionIndex, bool nesting,
+ MaxDurationTracker(const ConfigKey& key, const int64_t id, const MetricDimensionKey& eventKey,
+ const sp<ConditionWizard>& wizard, int conditionIndex, bool nesting,
int64_t currentBucketStartNs, int64_t currentBucketNum, int64_t startTimeNs,
int64_t bucketSizeNs, bool conditionSliced, bool fullLink,
const std::vector<sp<AnomalyTracker>>& anomalyTrackers);
MaxDurationTracker(const MaxDurationTracker& tracker) = default;
- void noteStart(const HashableDimensionKey& key, bool condition, const int64_t eventTime,
+ void noteStart(const HashableDimensionKey& key, bool condition, int64_t eventTime,
const ConditionKey& conditionKey, size_t dimensionHardLimit) override;
- void noteStop(const HashableDimensionKey& key, const int64_t eventTime,
- const bool stopAll) override;
+ void noteStop(const HashableDimensionKey& key, int64_t eventTime, const bool stopAll) override;
void noteStopAll(const int64_t eventTime) override;
bool flushIfNeeded(
int64_t timestampNs, const optional<UploadThreshold>& uploadThreshold,
std::unordered_map<MetricDimensionKey, std::vector<DurationBucket>>* output) override;
bool flushCurrentBucket(
- const int64_t& eventTimeNs, const optional<UploadThreshold>& uploadThreshold,
+ int64_t eventTimeNs, const optional<UploadThreshold>& uploadThreshold,
const int64_t globalConditionTrueNs,
std::unordered_map<MetricDimensionKey, std::vector<DurationBucket>>*) override;
void onSlicedConditionMayChange(const int64_t timestamp) override;
- void onConditionChanged(bool condition, const int64_t timestamp) override;
+ void onConditionChanged(bool condition, int64_t timestamp) override;
void onStateChanged(const int64_t timestamp, const int32_t atomId,
const FieldValue& newState) override;
@@ -64,7 +63,7 @@ public:
int64_t getCurrentStateKeyFullBucketDuration() const override;
- void updateCurrentStateKey(const int32_t atomId, const FieldValue& newState);
+ void updateCurrentStateKey(int32_t atomId, const FieldValue& newState);
bool hasAccumulatedDuration() const override;
diff --git a/statsd/src/metrics/duration_helper/OringDurationTracker.cpp b/statsd/src/metrics/duration_helper/OringDurationTracker.cpp
index c1c66f85..3fab0e8d 100644
--- a/statsd/src/metrics/duration_helper/OringDurationTracker.cpp
+++ b/statsd/src/metrics/duration_helper/OringDurationTracker.cpp
@@ -24,11 +24,14 @@ namespace statsd {
using std::pair;
-OringDurationTracker::OringDurationTracker(
- const ConfigKey& key, const int64_t& id, const MetricDimensionKey& eventKey,
- sp<ConditionWizard> wizard, int conditionIndex, bool nesting, int64_t currentBucketStartNs,
- int64_t currentBucketNum, int64_t startTimeNs, int64_t bucketSizeNs, bool conditionSliced,
- bool fullLink, const vector<sp<AnomalyTracker>>& anomalyTrackers)
+OringDurationTracker::OringDurationTracker(const ConfigKey& key, const int64_t id,
+ const MetricDimensionKey& eventKey,
+ const sp<ConditionWizard>& wizard, int conditionIndex,
+ bool nesting, int64_t currentBucketStartNs,
+ int64_t currentBucketNum, int64_t startTimeNs,
+ int64_t bucketSizeNs, bool conditionSliced,
+ bool fullLink,
+ const vector<sp<AnomalyTracker>>& anomalyTrackers)
: DurationTracker(key, id, eventKey, wizard, conditionIndex, nesting, currentBucketStartNs,
currentBucketNum, startTimeNs, bucketSizeNs, conditionSliced, fullLink,
anomalyTrackers),
@@ -138,7 +141,7 @@ void OringDurationTracker::noteStopAll(const int64_t timestamp) {
}
bool OringDurationTracker::flushCurrentBucket(
- const int64_t& eventTimeNs, const optional<UploadThreshold>& uploadThreshold,
+ const int64_t eventTimeNs, const optional<UploadThreshold>& uploadThreshold,
const int64_t globalConditionTrueNs,
std::unordered_map<MetricDimensionKey, std::vector<DurationBucket>>* output) {
VLOG("OringDurationTracker Flushing.............");
diff --git a/statsd/src/metrics/duration_helper/OringDurationTracker.h b/statsd/src/metrics/duration_helper/OringDurationTracker.h
index da9b7e3a..a50862b5 100644
--- a/statsd/src/metrics/duration_helper/OringDurationTracker.h
+++ b/statsd/src/metrics/duration_helper/OringDurationTracker.h
@@ -26,29 +26,27 @@ namespace statsd {
// Tracks the "Or'd" duration -- if 2 durations are overlapping, they won't be double counted.
class OringDurationTracker : public DurationTracker {
public:
- OringDurationTracker(const ConfigKey& key, const int64_t& id,
- const MetricDimensionKey& eventKey, sp<ConditionWizard> wizard,
- int conditionIndex, bool nesting, int64_t currentBucketStartNs,
- int64_t currentBucketNum, int64_t startTimeNs, int64_t bucketSizeNs,
- bool conditionSliced, bool fullLink,
- const std::vector<sp<AnomalyTracker>>& anomalyTrackers);
+ OringDurationTracker(const ConfigKey& key, const int64_t id, const MetricDimensionKey& eventKey,
+ const sp<ConditionWizard>& wizard, int conditionIndex, bool nesting,
+ int64_t currentBucketStartNs, int64_t currentBucketNum,
+ int64_t startTimeNs, int64_t bucketSizeNs, bool conditionSliced,
+ bool fullLink, const std::vector<sp<AnomalyTracker>>& anomalyTrackers);
OringDurationTracker(const OringDurationTracker& tracker) = default;
- void noteStart(const HashableDimensionKey& key, bool condition, const int64_t eventTime,
+ void noteStart(const HashableDimensionKey& key, bool condition, int64_t eventTime,
const ConditionKey& conditionKey, size_t dimensionHardLimit) override;
- void noteStop(const HashableDimensionKey& key, const int64_t eventTime,
- const bool stopAll) override;
+ void noteStop(const HashableDimensionKey& key, int64_t eventTime, const bool stopAll) override;
void noteStopAll(const int64_t eventTime) override;
void onSlicedConditionMayChange(const int64_t timestamp) override;
- void onConditionChanged(bool condition, const int64_t timestamp) override;
+ void onConditionChanged(bool condition, int64_t timestamp) override;
void onStateChanged(const int64_t timestamp, const int32_t atomId,
const FieldValue& newState) override;
bool flushCurrentBucket(
- const int64_t& eventTimeNs, const optional<UploadThreshold>& uploadThreshold,
+ int64_t eventTimeNs, const optional<UploadThreshold>& uploadThreshold,
const int64_t globalConditionTrueNs,
std::unordered_map<MetricDimensionKey, std::vector<DurationBucket>>* output) override;
bool flushIfNeeded(
@@ -63,7 +61,7 @@ public:
int64_t getCurrentStateKeyFullBucketDuration() const override;
- void updateCurrentStateKey(const int32_t atomId, const FieldValue& newState);
+ void updateCurrentStateKey(int32_t atomId, const FieldValue& newState);
bool hasAccumulatedDuration() const override;
diff --git a/statsd/src/metrics/parsing_utils/config_update_utils.cpp b/statsd/src/metrics/parsing_utils/config_update_utils.cpp
index 85495e4d..908fee10 100644
--- a/statsd/src/metrics/parsing_utils/config_update_utils.cpp
+++ b/statsd/src/metrics/parsing_utils/config_update_utils.cpp
@@ -519,7 +519,7 @@ optional<InvalidConfigReason> determineMetricUpdateStatus(
if (invalidConfigReason.has_value()) {
return invalidConfigReason;
}
- const sp<MetricProducer> oldMetricProducer = oldMetricProducers[oldMetricProducerIt->second];
+ const sp<MetricProducer>& oldMetricProducer = oldMetricProducers[oldMetricProducerIt->second];
if (oldMetricProducer->getMetricType() != metricType ||
oldMetricProducer->getProtoHash() != metricHash) {
updateStatus = UPDATE_REPLACE;
diff --git a/statsd/src/metrics/parsing_utils/config_update_utils.h b/statsd/src/metrics/parsing_utils/config_update_utils.h
index 4ef8805e..8b6c7841 100644
--- a/statsd/src/metrics/parsing_utils/config_update_utils.h
+++ b/statsd/src/metrics/parsing_utils/config_update_utils.h
@@ -46,7 +46,7 @@ namespace statsd {
// [cycleTracker]: intermediate param used during recursion.
// Returns nullopt if successful and InvalidConfigReason if not.
optional<InvalidConfigReason> determineMatcherUpdateStatus(
- const StatsdConfig& config, const int matcherIdx,
+ const StatsdConfig& config, int matcherIdx,
const std::unordered_map<int64_t, int>& oldAtomMatchingTrackerMap,
const std::vector<sp<AtomMatchingTracker>>& oldAtomMatchingTrackers,
const std::unordered_map<int64_t, int>& newAtomMatchingTrackerMap,
@@ -86,7 +86,7 @@ optional<InvalidConfigReason> updateAtomMatchingTrackers(
// [cycleTracker]: intermediate param used during recursion.
// Returns nullopt if successful and InvalidConfigReason if not.
optional<InvalidConfigReason> determineConditionUpdateStatus(
- const StatsdConfig& config, const int conditionIdx,
+ const StatsdConfig& config, int conditionIdx,
const std::unordered_map<int64_t, int>& oldConditionTrackerMap,
const std::vector<sp<ConditionTracker>>& oldConditionTrackers,
const std::unordered_map<int64_t, int>& newConditionTrackerMap,
@@ -164,7 +164,7 @@ optional<InvalidConfigReason> determineAllMetricUpdateStatuses(
// [trackerToMetricMap]: contains the mapping from log tracker to MetricProducer index.
// Returns nullopt if successful and InvalidConfigReason if not.
optional<InvalidConfigReason> updateMetrics(
- const ConfigKey& key, const StatsdConfig& config, const int64_t timeBaseNs,
+ const ConfigKey& key, const StatsdConfig& config, int64_t timeBaseNs,
const int64_t currentTimeNs, const sp<StatsPullerManager>& pullerManager,
const std::unordered_map<int64_t, int>& oldAtomMatchingTrackerMap,
const std::unordered_map<int64_t, int>& newAtomMatchingTrackerMap,
@@ -219,7 +219,7 @@ optional<InvalidConfigReason> determineAlertUpdateStatus(
// [newAnomalyTrackers]: contains the list of sp to the AnomalyTrackers created.
// Returns nullopt if successful and InvalidConfigReason if not.
optional<InvalidConfigReason> updateAlerts(
- const StatsdConfig& config, const int64_t currentTimeNs,
+ const StatsdConfig& config, int64_t currentTimeNs,
const std::unordered_map<int64_t, int>& metricProducerMap,
const std::set<int64_t>& replacedMetrics,
const std::unordered_map<int64_t, int>& oldAlertTrackerMap,
@@ -234,7 +234,7 @@ optional<InvalidConfigReason> updateAlerts(
optional<InvalidConfigReason> updateStatsdConfig(
const ConfigKey& key, const StatsdConfig& config, const sp<UidMap>& uidMap,
const sp<StatsPullerManager>& pullerManager, const sp<AlarmMonitor>& anomalyAlarmMonitor,
- const sp<AlarmMonitor>& periodicAlarmMonitor, const int64_t timeBaseNs,
+ const sp<AlarmMonitor>& periodicAlarmMonitor, int64_t timeBaseNs,
const int64_t currentTimeNs,
const std::vector<sp<AtomMatchingTracker>>& oldAtomMatchingTrackers,
const std::unordered_map<int64_t, int>& oldAtomMatchingTrackerMap,
diff --git a/statsd/src/metrics/parsing_utils/metrics_manager_util.cpp b/statsd/src/metrics/parsing_utils/metrics_manager_util.cpp
index bae9918d..0feb7932 100644
--- a/statsd/src/metrics/parsing_utils/metrics_manager_util.cpp
+++ b/statsd/src/metrics/parsing_utils/metrics_manager_util.cpp
@@ -620,7 +620,7 @@ optional<sp<MetricProducer>> createDurationMetricProducerAndUpdateMetadata(
}
}
- FieldMatcher internalDimensions = simplePredicate.dimensions();
+ const FieldMatcher& internalDimensions = simplePredicate.dimensions();
int conditionIndex = -1;
if (metric.has_condition()) {
@@ -860,7 +860,7 @@ optional<sp<MetricProducer>> createNumericValueMetricProducerAndUpdateMetadata(
return nullopt;
}
- sp<AtomMatchingTracker> atomMatcher = allAtomMatchingTrackers.at(trackerIndex);
+ const sp<AtomMatchingTracker>& atomMatcher = allAtomMatchingTrackers.at(trackerIndex);
int atomTagId = *(atomMatcher->getAtomIds().begin());
int pullTagId = pullerManager->PullerForMatcherExists(atomTagId) ? atomTagId : -1;
@@ -1089,7 +1089,7 @@ optional<sp<MetricProducer>> createKllMetricProducerAndUpdateMetadata(
const bool containsAnyPositionInDimensionsInWhat = HasPositionANY(metric.dimensions_in_what());
const bool shouldUseNestedDimensions = ShouldUseNestedDimensions(metric.dimensions_in_what());
- sp<AtomMatchingTracker> atomMatcher = allAtomMatchingTrackers.at(trackerIndex);
+ const sp<AtomMatchingTracker>& atomMatcher = allAtomMatchingTrackers.at(trackerIndex);
const int atomTagId = *(atomMatcher->getAtomIds().begin());
const auto [dimensionSoftLimit, dimensionHardLimit] =
StatsdStats::getAtomDimensionKeySizeLimits(
@@ -1167,7 +1167,7 @@ optional<sp<MetricProducer>> createGaugeMetricProducerAndUpdateMetadata(
return nullopt;
}
- sp<AtomMatchingTracker> atomMatcher = allAtomMatchingTrackers.at(trackerIndex);
+ const sp<AtomMatchingTracker>& atomMatcher = allAtomMatchingTrackers.at(trackerIndex);
int atomTagId = *(atomMatcher->getAtomIds().begin());
int pullTagId = pullerManager->PullerForMatcherExists(atomTagId) ? atomTagId : -1;
@@ -1194,7 +1194,7 @@ optional<sp<MetricProducer>> createGaugeMetricProducerAndUpdateMetadata(
if (invalidConfigReason.has_value()) {
return nullopt;
}
- sp<AtomMatchingTracker> triggerAtomMatcher =
+ const sp<AtomMatchingTracker>& triggerAtomMatcher =
allAtomMatchingTrackers.at(triggerTrackerIndex);
triggerAtomId = *(triggerAtomMatcher->getAtomIds().begin());
}
@@ -1216,6 +1216,18 @@ optional<sp<MetricProducer>> createGaugeMetricProducerAndUpdateMetadata(
}
}
+ if (pullTagId != -1 && metric.sampling_percentage() != 100) {
+ invalidConfigReason = InvalidConfigReason(
+ INVALID_CONFIG_REASON_GAUGE_METRIC_PULLED_WITH_SAMPLING, metric.id());
+ return nullopt;
+ }
+
+ if (metric.sampling_percentage() < 1 || metric.sampling_percentage() > 100) {
+ invalidConfigReason = InvalidConfigReason(
+ INVALID_CONFIG_REASON_METRIC_INCORRECT_SAMPLING_PERCENTAGE, metric.id());
+ return nullopt;
+ }
+
unordered_map<int, shared_ptr<Activation>> eventActivationMap;
unordered_map<int, vector<shared_ptr<Activation>>> eventDeactivationMap;
invalidConfigReason = handleMetricActivation(
@@ -1423,8 +1435,8 @@ optional<InvalidConfigReason> initStates(
stateProtoHashes[stateId] = Hash64(serializedState);
const StateMap& stateMap = state.map();
- for (auto group : stateMap.group()) {
- for (auto value : group.value()) {
+ for (const auto& group : stateMap.group()) {
+ for (const auto& value : group.value()) {
allStateGroupMaps[stateId][value] = group.group_id();
}
}
diff --git a/statsd/src/metrics/parsing_utils/metrics_manager_util.h b/statsd/src/metrics/parsing_utils/metrics_manager_util.h
index 67c09f0b..41e8dc7e 100644
--- a/statsd/src/metrics/parsing_utils/metrics_manager_util.h
+++ b/statsd/src/metrics/parsing_utils/metrics_manager_util.h
@@ -52,21 +52,20 @@ sp<AtomMatchingTracker> createAtomMatchingTracker(
// output:
// new ConditionTracker, or null if the tracker is unable to be created
sp<ConditionTracker> createConditionTracker(
- const ConfigKey& key, const Predicate& predicate, const int index,
+ const ConfigKey& key, const Predicate& predicate, int index,
const unordered_map<int64_t, int>& atomMatchingTrackerMap,
optional<InvalidConfigReason>& invalidConfigReason);
// Get the hash of a metric, combining the activation if the metric has one.
optional<InvalidConfigReason> getMetricProtoHash(
- const StatsdConfig& config, const google::protobuf::MessageLite& metric, const int64_t id,
+ const StatsdConfig& config, const google::protobuf::MessageLite& metric, int64_t id,
const std::unordered_map<int64_t, int>& metricToActivationMap, uint64_t& metricHash);
// 1. Validates matcher existence
// 2. Enforces matchers with dimensions and those used for trigger_event are about one atom
// 3. Gets matcher index and updates tracker to metric map
optional<InvalidConfigReason> handleMetricWithAtomMatchingTrackers(
- const int64_t matcherId, const int64_t metricId, const int metricIndex,
- const bool enforceOneAtom,
+ const int64_t matcherId, int64_t metricId, int metricIndex, const bool enforceOneAtom,
const std::vector<sp<AtomMatchingTracker>>& allAtomMatchingTrackers,
const std::unordered_map<int64_t, int>& atomMatchingTrackerMap,
std::unordered_map<int, std::vector<int>>& trackerToMetricMap, int& logTrackerIndex);
@@ -74,7 +73,7 @@ optional<InvalidConfigReason> handleMetricWithAtomMatchingTrackers(
// 1. Validates condition existence, including those in links
// 2. Gets condition index and updates condition to metric map
optional<InvalidConfigReason> handleMetricWithConditions(
- const int64_t condition, const int64_t metricId, const int metricIndex,
+ const int64_t condition, int64_t metricId, int metricIndex,
const std::unordered_map<int64_t, int>& conditionTrackerMap,
const ::google::protobuf::RepeatedPtrField<MetricConditionLink>& links,
const std::vector<sp<ConditionTracker>>& allConditionTrackers, int& conditionIndex,
@@ -84,7 +83,7 @@ optional<InvalidConfigReason> handleMetricWithConditions(
// Fills the new event activation/deactivation maps, preserving the existing activations.
// Returns nullopt if successful and InvalidConfigReason if not.
optional<InvalidConfigReason> handleMetricActivationOnConfigUpdate(
- const StatsdConfig& config, const int64_t metricId, const int metricIndex,
+ const StatsdConfig& config, int64_t metricId, int metricIndex,
const std::unordered_map<int64_t, int>& metricToActivationMap,
const std::unordered_map<int64_t, int>& oldAtomMatchingTrackerMap,
const std::unordered_map<int64_t, int>& newAtomMatchingTrackerMap,
@@ -98,8 +97,8 @@ optional<InvalidConfigReason> handleMetricActivationOnConfigUpdate(
// Creates a CountMetricProducer and updates the vectors/maps used by MetricsManager with
// the appropriate indices. Returns an sp to the producer, or nullopt if there was an error.
optional<sp<MetricProducer>> createCountMetricProducerAndUpdateMetadata(
- const ConfigKey& key, const StatsdConfig& config, const int64_t timeBaseNs,
- const int64_t currentTimeNs, const CountMetric& metric, const int metricIndex,
+ const ConfigKey& key, const StatsdConfig& config, int64_t timeBaseNs,
+ const int64_t currentTimeNs, const CountMetric& metric, int metricIndex,
const std::vector<sp<AtomMatchingTracker>>& allAtomMatchingTrackers,
const std::unordered_map<int64_t, int>& atomMatchingTrackerMap,
std::vector<sp<ConditionTracker>>& allConditionTrackers,
@@ -118,8 +117,8 @@ optional<sp<MetricProducer>> createCountMetricProducerAndUpdateMetadata(
// Creates a DurationMetricProducer and updates the vectors/maps used by MetricsManager with
// the appropriate indices. Returns an sp to the producer, or nullopt if there was an error.
optional<sp<MetricProducer>> createDurationMetricProducerAndUpdateMetadata(
- const ConfigKey& key, const StatsdConfig& config, const int64_t timeBaseNs,
- const int64_t currentTimeNs, const DurationMetric& metric, const int metricIndex,
+ const ConfigKey& key, const StatsdConfig& config, int64_t timeBaseNs,
+ const int64_t currentTimeNs, const DurationMetric& metric, int metricIndex,
const std::vector<sp<AtomMatchingTracker>>& allAtomMatchingTrackers,
const std::unordered_map<int64_t, int>& atomMatchingTrackerMap,
std::vector<sp<ConditionTracker>>& allConditionTrackers,
@@ -138,8 +137,8 @@ optional<sp<MetricProducer>> createDurationMetricProducerAndUpdateMetadata(
// Creates an EventMetricProducer and updates the vectors/maps used by MetricsManager with
// the appropriate indices. Returns an sp to the producer, or nullopt if there was an error.
optional<sp<MetricProducer>> createEventMetricProducerAndUpdateMetadata(
- const ConfigKey& key, const StatsdConfig& config, const int64_t timeBaseNs,
- const EventMetric& metric, const int metricIndex,
+ const ConfigKey& key, const StatsdConfig& config, int64_t timeBaseNs,
+ const EventMetric& metric, int metricIndex,
const std::vector<sp<AtomMatchingTracker>>& allAtomMatchingTrackers,
const std::unordered_map<int64_t, int>& atomMatchingTrackerMap,
std::vector<sp<ConditionTracker>>& allConditionTrackers,
@@ -156,9 +155,9 @@ optional<sp<MetricProducer>> createEventMetricProducerAndUpdateMetadata(
// Creates a NumericValueMetricProducer and updates the vectors/maps used by MetricsManager with
// the appropriate indices. Returns an sp to the producer, or nullopt if there was an error.
optional<sp<MetricProducer>> createNumericValueMetricProducerAndUpdateMetadata(
- const ConfigKey& key, const StatsdConfig& config, const int64_t timeBaseNs,
+ const ConfigKey& key, const StatsdConfig& config, int64_t timeBaseNs,
const int64_t currentTimeNs, const sp<StatsPullerManager>& pullerManager,
- const ValueMetric& metric, const int metricIndex,
+ const ValueMetric& metric, int metricIndex,
const std::vector<sp<AtomMatchingTracker>>& allAtomMatchingTrackers,
const std::unordered_map<int64_t, int>& atomMatchingTrackerMap,
std::vector<sp<ConditionTracker>>& allConditionTrackers,
@@ -178,9 +177,9 @@ optional<sp<MetricProducer>> createNumericValueMetricProducerAndUpdateMetadata(
// Creates a GaugeMetricProducer and updates the vectors/maps used by MetricsManager with
// the appropriate indices. Returns an sp to the producer, or nullopt if there was an error.
optional<sp<MetricProducer>> createGaugeMetricProducerAndUpdateMetadata(
- const ConfigKey& key, const StatsdConfig& config, const int64_t timeBaseNs,
+ const ConfigKey& key, const StatsdConfig& config, int64_t timeBaseNs,
const int64_t currentTimeNs, const sp<StatsPullerManager>& pullerManager,
- const GaugeMetric& metric, const int metricIndex,
+ const GaugeMetric& metric, int metricIndex,
const std::vector<sp<AtomMatchingTracker>>& allAtomMatchingTrackers,
const std::unordered_map<int64_t, int>& atomMatchingTrackerMap,
std::vector<sp<ConditionTracker>>& allConditionTrackers,
@@ -198,9 +197,9 @@ optional<sp<MetricProducer>> createGaugeMetricProducerAndUpdateMetadata(
// Creates a KllMetricProducer and updates the vectors/maps used by MetricsManager with
// the appropriate indices. Returns an sp to the producer, or nullopt if there was an error.
optional<sp<MetricProducer>> createKllMetricProducerAndUpdateMetadata(
- const ConfigKey& key, const StatsdConfig& config, const int64_t timeBaseNs,
+ const ConfigKey& key, const StatsdConfig& config, int64_t timeBaseNs,
const int64_t currentTimeNs, const sp<StatsPullerManager>& pullerManager,
- const KllMetric& metric, const int metricIndex,
+ const KllMetric& metric, int metricIndex,
const vector<sp<AtomMatchingTracker>>& allAtomMatchingTrackers,
const unordered_map<int64_t, int>& atomMatchingTrackerMap,
vector<sp<ConditionTracker>>& allConditionTrackers,
@@ -220,7 +219,7 @@ optional<sp<MetricProducer>> createKllMetricProducerAndUpdateMetadata(
// Returns an sp to the AnomalyTracker, or nullopt if there was an error.
optional<sp<AnomalyTracker>> createAnomalyTracker(
const Alert& alert, const sp<AlarmMonitor>& anomalyAlarmMonitor,
- const UpdateStatus& updateStatus, const int64_t currentTimeNs,
+ const UpdateStatus& updateStatus, int64_t currentTimeNs,
const std::unordered_map<int64_t, int>& metricProducerMap,
std::vector<sp<MetricProducer>>& allMetricProducers,
optional<InvalidConfigReason>& invalidConfigReason);
@@ -339,7 +338,7 @@ optional<InvalidConfigReason> initStates(
// [trackerToMetricMap]: contains the mapping from log tracker to MetricProducer index.
// Returns nullopt if successful and InvalidConfigReason if not.
optional<InvalidConfigReason> initMetrics(
- const ConfigKey& key, const StatsdConfig& config, const int64_t timeBaseTimeNs,
+ const ConfigKey& key, const StatsdConfig& config, int64_t timeBaseTimeNs,
const int64_t currentTimeNs, const sp<StatsPullerManager>& pullerManager,
const std::unordered_map<int64_t, int>& atomMatchingTrackerMap,
const std::unordered_map<int64_t, int>& conditionTrackerMap,
@@ -360,7 +359,7 @@ optional<InvalidConfigReason> initMetrics(
// Is called both on initialize new configs and config updates since alarms do not have any state.
optional<InvalidConfigReason> initAlarms(const StatsdConfig& config, const ConfigKey& key,
const sp<AlarmMonitor>& periodicAlarmMonitor,
- const int64_t timeBaseNs, const int64_t currentTimeNs,
+ const int64_t timeBaseNs, int64_t currentTimeNs,
std::vector<sp<AlarmTracker>>& allAlarmTrackers);
// Initialize MetricsManager from StatsdConfig.
@@ -368,7 +367,7 @@ optional<InvalidConfigReason> initAlarms(const StatsdConfig& config, const Confi
optional<InvalidConfigReason> initStatsdConfig(
const ConfigKey& key, const StatsdConfig& config, const sp<UidMap>& uidMap,
const sp<StatsPullerManager>& pullerManager, const sp<AlarmMonitor>& anomalyAlarmMonitor,
- const sp<AlarmMonitor>& periodicAlarmMonitor, const int64_t timeBaseNs,
+ const sp<AlarmMonitor>& periodicAlarmMonitor, int64_t timeBaseNs,
const int64_t currentTimeNs,
std::unordered_map<int, std::vector<int>>& allTagIdsToMatchersMap,
std::vector<sp<AtomMatchingTracker>>& allAtomMatchingTrackers,
diff --git a/statsd/src/packages/PackageInfoListener.h b/statsd/src/packages/PackageInfoListener.h
index 485f9fd4..d796774c 100644
--- a/statsd/src/packages/PackageInfoListener.h
+++ b/statsd/src/packages/PackageInfoListener.h
@@ -29,15 +29,14 @@ class PackageInfoListener : public virtual RefBase {
public:
// Uid map will notify this listener that the app with apk name and uid has been upgraded to
// the specified version.
- virtual void notifyAppUpgrade(const int64_t& eventTimeNs, const std::string& apk,
- const int uid, const int64_t version) = 0;
+ virtual void notifyAppUpgrade(int64_t eventTimeNs, const std::string& apk, const int uid,
+ int64_t version) = 0;
// Notify interested listeners that the given apk and uid combination no longer exits.
- virtual void notifyAppRemoved(const int64_t& eventTimeNs, const std::string& apk,
- const int uid) = 0;
+ virtual void notifyAppRemoved(int64_t eventTimeNs, const std::string& apk, const int uid) = 0;
// Notify the listener that the UidMap snapshot is available.
- virtual void onUidMapReceived(const int64_t& eventTimeNs) = 0;
+ virtual void onUidMapReceived(int64_t eventTimeNs) = 0;
};
} // namespace statsd
diff --git a/statsd/src/packages/UidMap.cpp b/statsd/src/packages/UidMap.cpp
index aa43e8d2..bde1fffd 100644
--- a/statsd/src/packages/UidMap.cpp
+++ b/statsd/src/packages/UidMap.cpp
@@ -94,12 +94,12 @@ string UidMap::normalizeAppName(const string& appName) const {
return normalizedName;
}
-std::set<string> UidMap::getAppNamesFromUid(const int32_t& uid, bool returnNormalized) const {
+std::set<string> UidMap::getAppNamesFromUid(const int32_t uid, bool returnNormalized) const {
lock_guard<mutex> lock(mMutex);
return getAppNamesFromUidLocked(uid,returnNormalized);
}
-std::set<string> UidMap::getAppNamesFromUidLocked(const int32_t& uid, bool returnNormalized) const {
+std::set<string> UidMap::getAppNamesFromUidLocked(const int32_t uid, bool returnNormalized) const {
std::set<string> names;
for (const auto& kv : mMap) {
if (kv.first.first == uid && !kv.second.deleted) {
@@ -119,7 +119,7 @@ int64_t UidMap::getAppVersion(int uid, const string& packageName) const {
return it->second.versionCode;
}
-void UidMap::updateMap(const int64_t& timestamp, const UidData& uidData) {
+void UidMap::updateMap(const int64_t timestamp, const UidData& uidData) {
wp<PackageInfoListener> broadcast = NULL;
{
lock_guard<mutex> lock(mMutex); // Exclusively lock for updates.
@@ -162,8 +162,8 @@ void UidMap::updateMap(const int64_t& timestamp, const UidData& uidData) {
}
}
-void UidMap::updateApp(const int64_t& timestamp, const string& appName, const int32_t& uid,
- const int64_t& versionCode, const string& versionString,
+void UidMap::updateApp(const int64_t timestamp, const string& appName, const int32_t uid,
+ const int64_t versionCode, const string& versionString,
const string& installer, const vector<uint8_t>& certificateHash) {
wp<PackageInfoListener> broadcast = NULL;
@@ -224,7 +224,7 @@ void UidMap::ensureBytesUsedBelowLimit() {
}
}
-void UidMap::removeApp(const int64_t& timestamp, const string& app, const int32_t& uid) {
+void UidMap::removeApp(const int64_t timestamp, const string& app, const int32_t uid) {
wp<PackageInfoListener> broadcast = NULL;
{
lock_guard<mutex> lock(mMutex);
@@ -260,7 +260,7 @@ void UidMap::removeApp(const int64_t& timestamp, const string& app, const int32_
}
}
-void UidMap::setListener(wp<PackageInfoListener> listener) {
+void UidMap::setListener(const wp<PackageInfoListener>& listener) {
lock_guard<mutex> lock(mMutex); // Lock for updates
mSubscriber = listener;
}
@@ -409,7 +409,7 @@ void UidMap::writeUidMapSnapshotLocked(const int64_t timestamp, const bool inclu
}
}
-void UidMap::appendUidMap(const int64_t& timestamp, const ConfigKey& key,
+void UidMap::appendUidMap(const int64_t timestamp, const ConfigKey& key,
const bool includeVersionStrings, const bool includeInstaller,
const uint8_t truncatedCertificateHashSize, std::set<string>* str_set,
ProtoOutputStream* proto) {
diff --git a/statsd/src/packages/UidMap.h b/statsd/src/packages/UidMap.h
index d081803c..45429cb8 100644
--- a/statsd/src/packages/UidMap.h
+++ b/statsd/src/packages/UidMap.h
@@ -73,9 +73,9 @@ struct ChangeRecord {
const string versionString;
const string prevVersionString;
- ChangeRecord(const bool isDeletion, const int64_t timestampNs, const string& package,
- const int32_t uid, const int64_t version, const string versionString,
- const int64_t prevVersion, const string prevVersionString)
+ ChangeRecord(const bool isDeletion, int64_t timestampNs, const string& package,
+ const int32_t uid, int64_t version, const string& versionString,
+ const int64_t prevVersion, const string& prevVersionString)
: deletion(isDeletion),
timestampNs(timestampNs),
package(package),
@@ -99,18 +99,18 @@ public:
static sp<UidMap> getInstance();
- void updateMap(const int64_t& timestamp, const UidData& uidData);
+ void updateMap(const int64_t timestamp, const UidData& uidData);
- void updateApp(const int64_t& timestamp, const string& appName, const int32_t& uid,
- const int64_t& versionCode, const string& versionString, const string& installer,
+ void updateApp(const int64_t timestamp, const string& appName, const int32_t uid,
+ const int64_t versionCode, const string& versionString, const string& installer,
const vector<uint8_t>& certificateHash);
- void removeApp(const int64_t& timestamp, const string& app, const int32_t& uid);
+ void removeApp(const int64_t timestamp, const string& app, const int32_t uid);
// Returns true if the given uid contains the specified app (eg. com.google.android.gms).
bool hasApp(int uid, const string& packageName) const;
// Returns the app names from uid.
- std::set<string> getAppNamesFromUid(const int32_t& uid, bool returnNormalized) const;
+ std::set<string> getAppNamesFromUid(int32_t uid, bool returnNormalized) const;
int64_t getAppVersion(int uid, const string& packageName) const;
@@ -121,7 +121,7 @@ public:
// Command for indicating to the map that StatsLogProcessor should be notified if an app is
// updated. This allows metric producers and managers to distinguish when the same uid or app
// represents a different version of an app.
- void setListener(wp<PackageInfoListener> listener);
+ void setListener(const wp<PackageInfoListener>& listener);
// Informs uid map that a config is added/updated. Used for keeping mConfigKeys up to date.
void OnConfigUpdated(const ConfigKey& key);
@@ -138,10 +138,9 @@ public:
// Gets all snapshots and changes that have occurred since the last output.
// If every config key has received a change or snapshot record, then this
// record is deleted.
- void appendUidMap(const int64_t& timestamp, const ConfigKey& key,
- const bool includeVersionStrings, const bool includeInstaller,
- const uint8_t truncatedCertificateHashSize, std::set<string>* str_set,
- ProtoOutputStream* proto);
+ void appendUidMap(int64_t timestamp, const ConfigKey& key, const bool includeVersionStrings,
+ const bool includeInstaller, const uint8_t truncatedCertificateHashSize,
+ std::set<string>* str_set, ProtoOutputStream* proto);
// Forces the output to be cleared. We still generate a snapshot based on the current state.
// This results in extra data uploaded but helps us reconstruct the uid mapping on the server
@@ -165,7 +164,7 @@ public:
ProtoOutputStream* proto) const;
private:
- std::set<string> getAppNamesFromUidLocked(const int32_t& uid, bool returnNormalized) const;
+ std::set<string> getAppNamesFromUidLocked(int32_t uid, bool returnNormalized) const;
string normalizeAppName(const string& appName) const;
void writeUidMapSnapshotLocked(const int64_t timestamp, const bool includeVersionStrings,
@@ -179,7 +178,7 @@ private:
mutable mutex mIsolatedMutex;
struct PairHash {
- size_t operator()(std::pair<int, string> p) const noexcept {
+ size_t operator()(const std::pair<int, string>& p) const noexcept {
std::hash<std::string> hash_fn;
return hash_fn(std::to_string(p.first) + p.second);
}
diff --git a/statsd/src/shell/ShellSubscriber.h b/statsd/src/shell/ShellSubscriber.h
index 4ff88616..5e54fbf2 100644
--- a/statsd/src/shell/ShellSubscriber.h
+++ b/statsd/src/shell/ShellSubscriber.h
@@ -56,7 +56,7 @@ namespace statsd {
*/
class ShellSubscriber : public virtual RefBase {
public:
- ShellSubscriber(sp<UidMap> uidMap, sp<StatsPullerManager> pullerMgr,
+ ShellSubscriber(const sp<UidMap>& uidMap, const sp<StatsPullerManager>& pullerMgr,
const std::shared_ptr<LogEventFilter>& logEventFilter)
: mUidMap(uidMap), mPullerMgr(pullerMgr), mLogEventFilter(logEventFilter){};
diff --git a/statsd/src/socket/StatsSocketListener.cpp b/statsd/src/socket/StatsSocketListener.cpp
index 3f360333..dd1013d4 100644
--- a/statsd/src/socket/StatsSocketListener.cpp
+++ b/statsd/src/socket/StatsSocketListener.cpp
@@ -38,10 +38,10 @@ namespace android {
namespace os {
namespace statsd {
-StatsSocketListener::StatsSocketListener(std::shared_ptr<LogEventQueue> queue,
+StatsSocketListener::StatsSocketListener(const std::shared_ptr<LogEventQueue>& queue,
const std::shared_ptr<LogEventFilter>& logEventFilter)
: SocketListener(getLogSocket(), false /*start listen*/),
- mQueue(std::move(queue)),
+ mQueue(queue),
mLogEventFilter(logEventFilter) {
}
@@ -148,6 +148,7 @@ void StatsSocketListener::processMessage(const uint8_t* msg, uint32_t len, uint3
const int32_t atomId = logEvent->GetTagId();
const bool isAtomSkipped = logEvent->isParsedHeaderOnly();
+ const int64_t atomTimestamp = logEvent->GetElapsedTimestampNs();
if (atomId == util::STATS_SOCKET_LOSS_REPORTED) {
if (isAtomSkipped) {
@@ -164,8 +165,10 @@ void StatsSocketListener::processMessage(const uint8_t* msg, uint32_t len, uint3
}
}
- int64_t oldestTimestamp;
- if (!queue->push(std::move(logEvent), &oldestTimestamp)) {
+ const auto [success, oldestTimestamp, queueSize] = queue->push(std::move(logEvent));
+ if (success) {
+ StatsdStats::getInstance().noteEventQueueSize(queueSize, atomTimestamp);
+ } else {
StatsdStats::getInstance().noteEventQueueOverflow(oldestTimestamp, atomId, isAtomSkipped);
}
}
diff --git a/statsd/src/socket/StatsSocketListener.h b/statsd/src/socket/StatsSocketListener.h
index 903eff39..fcff2c2b 100644
--- a/statsd/src/socket/StatsSocketListener.h
+++ b/statsd/src/socket/StatsSocketListener.h
@@ -38,7 +38,7 @@ namespace statsd {
class StatsSocketListener : public SocketListener, public virtual RefBase {
public:
- explicit StatsSocketListener(std::shared_ptr<LogEventQueue> queue,
+ explicit StatsSocketListener(const std::shared_ptr<LogEventQueue>& queue,
const std::shared_ptr<LogEventFilter>& logEventFilter);
virtual ~StatsSocketListener() = default;
@@ -81,6 +81,7 @@ private:
FRIEND_TEST(SocketParseMessageTest, TestProcessMessageFilterCompleteSet);
FRIEND_TEST(SocketParseMessageTest, TestProcessMessageFilterPartialSet);
FRIEND_TEST(SocketParseMessageTest, TestProcessMessageFilterToggle);
+ FRIEND_TEST(LogEventQueue_test, TestQueueMaxSize);
};
} // namespace statsd
diff --git a/statsd/src/state/StateManager.cpp b/statsd/src/state/StateManager.cpp
index 7841748f..1a324952 100644
--- a/statsd/src/state/StateManager.cpp
+++ b/statsd/src/state/StateManager.cpp
@@ -53,7 +53,7 @@ void StateManager::onLogEvent(const LogEvent& event) {
}
}
-void StateManager::registerListener(const int32_t atomId, wp<StateListener> listener) {
+void StateManager::registerListener(const int32_t atomId, const wp<StateListener>& listener) {
// Check if state tracker already exists.
if (mStateTrackers.find(atomId) == mStateTrackers.end()) {
mStateTrackers[atomId] = new StateTracker(atomId);
@@ -61,7 +61,7 @@ void StateManager::registerListener(const int32_t atomId, wp<StateListener> list
mStateTrackers[atomId]->registerListener(listener);
}
-void StateManager::unregisterListener(const int32_t atomId, wp<StateListener> listener) {
+void StateManager::unregisterListener(const int32_t atomId, const wp<StateListener>& listener) {
std::unique_lock<std::mutex> lock(mMutex);
// Hold the sp<> until the lock is released so that ~StateTracker() is
diff --git a/statsd/src/state/StateManager.h b/statsd/src/state/StateManager.h
index 68b5c906..2db206ec 100644
--- a/statsd/src/state/StateManager.h
+++ b/statsd/src/state/StateManager.h
@@ -55,17 +55,17 @@ public:
// If the correct StateTracker does not exist, a new StateTracker is created.
// Note: StateTrackers can be created for non-state atoms. They are essentially empty and
// do not perform any actions.
- void registerListener(const int32_t atomId, wp<StateListener> listener);
+ void registerListener(const int32_t atomId, const wp<StateListener>& listener);
// Notifies the correct StateTracker to unregister a listener
// and removes the tracker if it no longer has any listeners.
- void unregisterListener(const int32_t atomId, wp<StateListener> listener);
+ void unregisterListener(const int32_t atomId, const wp<StateListener>& listener);
// Returns true if the StateTracker exists and queries for the
// original state value mapped to the given query key. The state value is
// stored and output in a FieldValue class.
// Returns false if the StateTracker doesn't exist.
- bool getStateValue(const int32_t atomId, const HashableDimensionKey& queryKey,
+ bool getStateValue(int32_t atomId, const HashableDimensionKey& queryKey,
FieldValue* output) const;
// Updates mAllowedLogSources with the latest uids for the packages that are allowed to log.
@@ -77,7 +77,7 @@ public:
return mStateTrackers.size();
}
- inline int getListenersCount(const int32_t atomId) const {
+ inline int getListenersCount(int32_t atomId) const {
auto it = mStateTrackers.find(atomId);
if (it != mStateTrackers.end()) {
return it->second->getListenersCount();
diff --git a/statsd/src/state/StateTracker.cpp b/statsd/src/state/StateTracker.cpp
index 250a65c0..d037e734 100644
--- a/statsd/src/state/StateTracker.cpp
+++ b/statsd/src/state/StateTracker.cpp
@@ -25,7 +25,7 @@ namespace android {
namespace os {
namespace statsd {
-StateTracker::StateTracker(const int32_t atomId) : mField(atomId, 0) {
+StateTracker::StateTracker(int32_t atomId) : mField(atomId, 0) {
}
void StateTracker::onLogEvent(const LogEvent& event) {
@@ -62,11 +62,11 @@ void StateTracker::onLogEvent(const LogEvent& event) {
updateStateForPrimaryKey(eventTimeNs, primaryKey, newState, nested, mStateMap[primaryKey]);
}
-void StateTracker::registerListener(wp<StateListener> listener) {
+void StateTracker::registerListener(const wp<StateListener>& listener) {
mListeners.insert(listener);
}
-void StateTracker::unregisterListener(wp<StateListener> listener) {
+void StateTracker::unregisterListener(const wp<StateListener>& listener) {
mListeners.erase(listener);
}
@@ -165,7 +165,7 @@ void StateTracker::updateStateForPrimaryKey(const int64_t eventTimeNs,
void StateTracker::notifyListeners(const int64_t eventTimeNs,
const HashableDimensionKey& primaryKey,
const FieldValue& oldState, const FieldValue& newState) {
- for (auto l : mListeners) {
+ for (const auto& l : mListeners) {
auto sl = l.promote();
if (sl != nullptr) {
sl->onStateChanged(eventTimeNs, mField.getTag(), primaryKey, oldState, newState);
diff --git a/statsd/src/state/StateTracker.h b/statsd/src/state/StateTracker.h
index 2bef70ea..0fd504d3 100644
--- a/statsd/src/state/StateTracker.h
+++ b/statsd/src/state/StateTracker.h
@@ -29,7 +29,7 @@ namespace statsd {
class StateTracker : public virtual RefBase {
public:
- StateTracker(const int32_t atomId);
+ StateTracker(int32_t atomId);
virtual ~StateTracker(){};
@@ -40,9 +40,9 @@ public:
// Adds new listeners to set of StateListeners. If a listener is already
// registered, it is ignored.
- void registerListener(wp<StateListener> listener);
+ void registerListener(const wp<StateListener>& listener);
- void unregisterListener(wp<StateListener> listener);
+ void unregisterListener(const wp<StateListener>& listener);
// The output is a FieldValue object that has mStateField as the field and
// the original state value (found using the given query key) as the value.
diff --git a/statsd/src/stats_log.proto b/statsd/src/stats_log.proto
index b0955467..fdb031a9 100644
--- a/statsd/src/stats_log.proto
+++ b/statsd/src/stats_log.proto
@@ -682,6 +682,13 @@ message StatsdStatsReport {
}
optional SocketLossStats socket_loss_stats = 24;
+
+ message EventQueueStats {
+ optional int32 max_size_observed = 1;
+ optional int64 max_size_observed_elapsed_nanos = 2;
+ }
+
+ optional EventQueueStats event_queue_stats = 25;
}
message AlertTriggerDetails {
diff --git a/statsd/src/stats_log_util.cpp b/statsd/src/stats_log_util.cpp
index 1d9a43bd..77a3d4f6 100644
--- a/statsd/src/stats_log_util.cpp
+++ b/statsd/src/stats_log_util.cpp
@@ -617,7 +617,7 @@ bool checkPermissionForIds(const char* permission, pid_t pid, uid_t uid) {
return success;
}
-void mapIsolatedUidsToHostUidInLogEvent(const sp<UidMap> uidMap, LogEvent& event) {
+void mapIsolatedUidsToHostUidInLogEvent(const sp<UidMap>& uidMap, LogEvent& event) {
uint8_t remainingUidCount = event.getNumUidFields();
vector<FieldValue>* fieldValues = event.getMutableValues();
auto it = fieldValues->begin();
diff --git a/statsd/src/stats_log_util.h b/statsd/src/stats_log_util.h
index 68155e46..3ca94be6 100644
--- a/statsd/src/stats_log_util.h
+++ b/statsd/src/stats_log_util.h
@@ -79,7 +79,7 @@ int64_t NanoToMillis(const int64_t nano);
int64_t MillisToNano(const int64_t millis);
// Helper function to write a stats field to ProtoOutputStream if it's a non-zero value.
-void writeNonZeroStatToStream(const uint64_t fieldId, const int64_t value,
+void writeNonZeroStatToStream(const uint64_t fieldId, int64_t value,
ProtoOutputStream* protoOutput);
// Helper function to write PulledAtomStats to ProtoOutputStream
@@ -117,7 +117,7 @@ inline bool isPulledAtom(int atomId) {
return atomId >= StatsdStats::kPullAtomStartTag && atomId < StatsdStats::kVendorAtomStartTag;
}
-void mapIsolatedUidsToHostUidInLogEvent(const sp<UidMap> uidMap, LogEvent& event);
+void mapIsolatedUidsToHostUidInLogEvent(const sp<UidMap>& uidMap, LogEvent& event);
std::string toHexString(const string& bytes);
diff --git a/statsd/src/statsd_config.proto b/statsd/src/statsd_config.proto
index e8c1d99f..9c937a57 100644
--- a/statsd/src/statsd_config.proto
+++ b/statsd/src/statsd_config.proto
@@ -343,6 +343,8 @@ message GaugeMetric {
optional int32 max_dimensions_per_bucket = 16;
+ optional int32 sampling_percentage = 17 [default = 100];
+
reserved 100;
reserved 101;
}
diff --git a/statsd/src/storage/StorageManager.h b/statsd/src/storage/StorageManager.h
index 9a25bf07..0a459a86 100644
--- a/statsd/src/storage/StorageManager.h
+++ b/statsd/src/storage/StorageManager.h
@@ -42,7 +42,7 @@ const uint32_t TRAIN_INFO_FILE_MAGIC = 0xfb7447bf;
class StorageManager : public virtual RefBase {
public:
struct FileInfo {
- FileInfo(std::string name, bool isHistory, int fileSize, long fileAge)
+ FileInfo(const std::string& name, bool isHistory, int fileSize, long fileAge)
: mFileName(name),
mIsHistory(isHistory),
mFileSizeBytes(fileSize),
@@ -162,8 +162,7 @@ public:
static void sortFiles(vector<FileInfo>* fileNames);
- static void enforceDbGuardrails(const char* path, const int64_t wallClockSec,
- const int64_t maxBytes);
+ static void enforceDbGuardrails(const char* path, int64_t wallClockSec, int64_t maxBytes);
static bool hasFile(const char* file);
diff --git a/statsd/src/utils/DbUtils.h b/statsd/src/utils/DbUtils.h
index 8a561e64..06d12929 100644
--- a/statsd/src/utils/DbUtils.h
+++ b/statsd/src/utils/DbUtils.h
@@ -39,15 +39,15 @@ string getDbName(const ConfigKey& key);
string reformatMetricId(const int64_t metricId);
/* Creates a new data table for a specified metric if one does not yet exist. */
-bool createTableIfNeeded(const ConfigKey& key, const int64_t metricId, const LogEvent& event);
+bool createTableIfNeeded(const ConfigKey& key, int64_t metricId, const LogEvent& event);
/* Checks whether the table schema for the given metric matches the event.
* Returns true if the table has not yet been created.
*/
-bool isEventCompatible(const ConfigKey& key, const int64_t metricId, const LogEvent& event);
+bool isEventCompatible(const ConfigKey& key, int64_t metricId, const LogEvent& event);
/* Deletes a data table for the specified metric. */
-bool deleteTable(const ConfigKey& key, const int64_t metricId);
+bool deleteTable(const ConfigKey& key, int64_t metricId);
/* Deletes the SQLite db data file. */
void deleteDb(const ConfigKey& key);
@@ -63,11 +63,10 @@ void closeDb(sqlite3* db);
/* Inserts new data into the specified metric data table.
* A temp sqlite handle is created using the ConfigKey.
*/
-bool insert(const ConfigKey& key, const int64_t metricId, const vector<LogEvent>& events,
- string& error);
+bool insert(const ConfigKey& key, int64_t metricId, const vector<LogEvent>& events, string& error);
/* Inserts new data into the specified sqlite db handle. */
-bool insert(sqlite3* db, const int64_t metricId, const vector<LogEvent>& events, string& error);
+bool insert(sqlite3* db, int64_t metricId, const vector<LogEvent>& events, string& error);
/* Executes a sql query on the specified SQLite db.
* A temp sqlite handle is created using the ConfigKey.
@@ -75,7 +74,7 @@ bool insert(sqlite3* db, const int64_t metricId, const vector<LogEvent>& events,
bool query(const ConfigKey& key, const string& zSql, vector<vector<string>>& rows,
vector<int32_t>& columnTypes, vector<string>& columnNames, string& err);
-bool flushTtl(sqlite3* db, const int64_t metricId, const int64_t ttlWallClockNs);
+bool flushTtl(sqlite3* db, int64_t metricId, int64_t ttlWallClockNs);
/* Checks for database corruption and deletes the db if it is corrupted. */
void verifyIntegrityAndDeleteIfNecessary(const ConfigKey& key);
@@ -86,4 +85,4 @@ bool updateDeviceInfoTable(const ConfigKey& key, string& error);
} // namespace dbutils
} // namespace statsd
} // namespace os
-} // namespace android \ No newline at end of file
+} // namespace android
diff --git a/statsd/src/utils/MultiConditionTrigger.cpp b/statsd/src/utils/MultiConditionTrigger.cpp
index 5ef50ee0..8ef064a8 100644
--- a/statsd/src/utils/MultiConditionTrigger.cpp
+++ b/statsd/src/utils/MultiConditionTrigger.cpp
@@ -28,7 +28,7 @@ namespace statsd {
MultiConditionTrigger::MultiConditionTrigger(const set<string>& conditionNames,
function<void()> trigger)
: mRemainingConditionNames(conditionNames),
- mTrigger(trigger),
+ mTrigger(std::move(trigger)),
mCompleted(mRemainingConditionNames.empty()) {
if (mCompleted) {
thread executorThread([this] { mTrigger(); });
diff --git a/statsd/src/utils/ShardOffsetProvider.h b/statsd/src/utils/ShardOffsetProvider.h
index 7facd98b..506e2306 100644
--- a/statsd/src/utils/ShardOffsetProvider.h
+++ b/statsd/src/utils/ShardOffsetProvider.h
@@ -51,6 +51,7 @@ private:
FRIEND_TEST(CountMetricE2eTest, TestDimensionalSampling);
FRIEND_TEST(DurationMetricE2eTest, TestDimensionalSampling);
FRIEND_TEST(GaugeMetricE2ePushedTest, TestDimensionalSampling);
+ FRIEND_TEST(GaugeMetricE2ePushedTest, TestPushedGaugeMetricSamplingWithDimensionalSampling);
FRIEND_TEST(GaugeMetricProducerTest, TestPullDimensionalSampling);
FRIEND_TEST(KllMetricE2eTest, TestDimensionalSampling);
FRIEND_TEST(NumericValueMetricProducerTest, TestDimensionalSampling);
diff --git a/statsd/tests/SocketListener_test.cpp b/statsd/tests/SocketListener_test.cpp
index 90e5d3e1..3636508f 100644
--- a/statsd/tests/SocketListener_test.cpp
+++ b/statsd/tests/SocketListener_test.cpp
@@ -87,8 +87,11 @@ INSTANTIATE_TEST_SUITE_P(SocketParseMessageTest, SocketParseMessageTest, testing
SocketParseMessageTest::ToString);
TEST_P(SocketParseMessageTest, TestProcessMessage) {
+ StatsdStats::getInstance().reset();
+
generateAtomLogging(mEventQueue, mLogEventFilter, kEventCount, kAtomId);
+ int64_t lastEventTs = 0;
// check content of the queue
EXPECT_EQ(kEventCount, mEventQueue->mQueue.size());
for (int i = 0; i < kEventCount; i++) {
@@ -96,7 +99,11 @@ TEST_P(SocketParseMessageTest, TestProcessMessage) {
EXPECT_TRUE(logEvent->isValid());
EXPECT_EQ(kAtomId + i, logEvent->GetTagId());
EXPECT_EQ(logEvent->isParsedHeaderOnly(), GetParam());
+ lastEventTs = logEvent->GetElapsedTimestampNs();
}
+
+ EXPECT_EQ(StatsdStats::getInstance().mEventQueueMaxSizeObserved, kEventCount);
+ EXPECT_EQ(StatsdStats::getInstance().mEventQueueMaxSizeObservedElapsedNanos, lastEventTs);
}
TEST_P(SocketParseMessageTest, TestProcessMessageEmptySetExplicitSet) {
diff --git a/statsd/tests/anomaly/AnomalyTracker_test.cpp b/statsd/tests/anomaly/AnomalyTracker_test.cpp
index 9d7ccea2..827f8f52 100644
--- a/statsd/tests/anomaly/AnomalyTracker_test.cpp
+++ b/statsd/tests/anomaly/AnomalyTracker_test.cpp
@@ -74,8 +74,7 @@ int64_t getBucketValue(const std::shared_ptr<DimToValMap>& bucket,
}
// Returns true if keys in trueList are detected as anomalies and keys in falseList are not.
-bool detectAnomaliesPass(AnomalyTracker& tracker,
- const int64_t& bucketNum,
+bool detectAnomaliesPass(AnomalyTracker& tracker, int64_t bucketNum,
const std::shared_ptr<DimToValMap>& currentBucket,
const std::set<const MetricDimensionKey>& trueList,
const std::set<const MetricDimensionKey>& falseList) {
@@ -93,10 +92,8 @@ bool detectAnomaliesPass(AnomalyTracker& tracker,
}
// Calls tracker.detectAndDeclareAnomaly on each key in the bucket.
-void detectAndDeclareAnomalies(AnomalyTracker& tracker,
- const int64_t& bucketNum,
- const std::shared_ptr<DimToValMap>& bucket,
- const int64_t& eventTimestamp) {
+void detectAndDeclareAnomalies(AnomalyTracker& tracker, int64_t bucketNum,
+ const std::shared_ptr<DimToValMap>& bucket, int64_t eventTimestamp) {
for (const auto& kv : *bucket) {
tracker.detectAndDeclareAnomaly(eventTimestamp, bucketNum, 0 /*metric_id*/, kv.first,
kv.second);
@@ -107,9 +104,8 @@ void detectAndDeclareAnomalies(AnomalyTracker& tracker,
// timestamp (in ns) + refractoryPeriodSec.
// If a timestamp value is negative, instead asserts that the refractory period is inapplicable
// (either non-existant or already past).
-void checkRefractoryTimes(AnomalyTracker& tracker,
- const int64_t& currTimestampNs,
- const int32_t& refractoryPeriodSec,
+void checkRefractoryTimes(AnomalyTracker& tracker, int64_t currTimestampNs,
+ int32_t refractoryPeriodSec,
const std::unordered_map<MetricDimensionKey, int64_t>& timestamps) {
for (const auto& kv : timestamps) {
if (kv.second < 0) {
diff --git a/statsd/tests/e2e/GaugeMetric_e2e_push_test.cpp b/statsd/tests/e2e/GaugeMetric_e2e_push_test.cpp
index 4f7589f1..b852d7f8 100644
--- a/statsd/tests/e2e/GaugeMetric_e2e_push_test.cpp
+++ b/statsd/tests/e2e/GaugeMetric_e2e_push_test.cpp
@@ -498,6 +498,178 @@ TEST_F(GaugeMetricE2ePushedTest, TestDimensionalSampling) {
{gaugeEventTimeNs3, gaugeEventTimeNs6});
}
+TEST_F(GaugeMetricE2ePushedTest, TestPushedGaugeMetricSampling) {
+ // Initiating StatsdStats at the start of this test, so it doesn't call rand() during the test.
+ StatsdStats::getInstance();
+ // Set srand seed to make rand deterministic for testing.
+ srand(0);
+
+ StatsdConfig config;
+ config.add_allowed_log_source("AID_ROOT"); // LogEvent defaults to UID of root.
+
+ AtomMatcher appCrashMatcher =
+ CreateSimpleAtomMatcher("APP_CRASH_OCCURRED", util::APP_CRASH_OCCURRED);
+ *config.add_atom_matcher() = appCrashMatcher;
+
+ GaugeMetric sampledGaugeMetric =
+ createGaugeMetric("GaugeSampledAppCrashesPerUid", appCrashMatcher.id(),
+ GaugeMetric::FIRST_N_SAMPLES, nullopt, nullopt);
+ *sampledGaugeMetric.mutable_dimensions_in_what() =
+ CreateDimensions(util::APP_CRASH_OCCURRED, {1 /* uid */});
+ sampledGaugeMetric.set_sampling_percentage(50);
+ *config.add_gauge_metric() = sampledGaugeMetric;
+
+ const int64_t configAddedTimeNs = 10 * NS_PER_SEC; // 0:10
+ const int64_t bucketSizeNs =
+ TimeUnitToBucketSizeInMillis(config.gauge_metric(0).bucket()) * 1000LL * 1000LL;
+
+ int uid = 12345;
+ int64_t cfgId = 98765;
+ ConfigKey cfgKey(uid, cfgId);
+
+ sp<StatsLogProcessor> processor = CreateStatsLogProcessor(
+ configAddedTimeNs, configAddedTimeNs, config, cfgKey, nullptr, 0, new UidMap());
+
+ std::vector<std::unique_ptr<LogEvent>> events;
+ for (int i = 0; i < 10; i++) {
+ events.push_back(
+ CreateAppCrashOccurredEvent(configAddedTimeNs + (10 * i * NS_PER_SEC), 1000 + i));
+ }
+
+ // Send log events to StatsLogProcessor.
+ for (auto& event : events) {
+ processor->OnLogEvent(event.get());
+ }
+
+ ConfigMetricsReportList reports;
+ vector<uint8_t> buffer;
+ processor->onDumpReport(cfgKey, configAddedTimeNs + bucketSizeNs + 1, false, true, ADB_DUMP,
+ FAST, &buffer);
+ EXPECT_TRUE(buffer.size() > 0);
+ EXPECT_TRUE(reports.ParseFromArray(&buffer[0], buffer.size()));
+ backfillDimensionPath(&reports);
+ backfillStringInReport(&reports);
+ backfillStartEndTimestamp(&reports);
+ backfillAggregatedAtoms(&reports);
+
+ ASSERT_EQ(1, reports.reports_size());
+ ASSERT_EQ(1, reports.reports(0).metrics_size());
+ EXPECT_TRUE(reports.reports(0).metrics(0).has_gauge_metrics());
+ StatsLogReport::GaugeMetricDataWrapper gaugeMetrics;
+ sortMetricDataByDimensionsValue(reports.reports(0).metrics(0).gauge_metrics(), &gaugeMetrics);
+ ASSERT_EQ(5, gaugeMetrics.data_size());
+
+ GaugeMetricData data = gaugeMetrics.data(0);
+ ValidateUidDimension(data.dimensions_in_what(), util::APP_CRASH_OCCURRED, 1000);
+ ValidateGaugeBucketTimes(data.bucket_info(0), configAddedTimeNs,
+ configAddedTimeNs + bucketSizeNs, {configAddedTimeNs});
+
+ data = gaugeMetrics.data(1);
+ ValidateUidDimension(data.dimensions_in_what(), util::APP_CRASH_OCCURRED, 1002);
+ ValidateGaugeBucketTimes(data.bucket_info(0), configAddedTimeNs,
+ configAddedTimeNs + bucketSizeNs,
+ {configAddedTimeNs + (10 * 2 * NS_PER_SEC)});
+
+ data = gaugeMetrics.data(2);
+ ValidateUidDimension(data.dimensions_in_what(), util::APP_CRASH_OCCURRED, 1003);
+ ValidateGaugeBucketTimes(data.bucket_info(0), configAddedTimeNs,
+ configAddedTimeNs + bucketSizeNs,
+ {configAddedTimeNs + (10 * 3 * NS_PER_SEC)});
+
+ data = gaugeMetrics.data(3);
+ ValidateUidDimension(data.dimensions_in_what(), util::APP_CRASH_OCCURRED, 1007);
+ ValidateGaugeBucketTimes(data.bucket_info(0), configAddedTimeNs,
+ configAddedTimeNs + bucketSizeNs,
+ {configAddedTimeNs + (10 * 7 * NS_PER_SEC)});
+
+ data = gaugeMetrics.data(4);
+ ValidateUidDimension(data.dimensions_in_what(), util::APP_CRASH_OCCURRED, 1009);
+ ValidateGaugeBucketTimes(data.bucket_info(0), configAddedTimeNs,
+ configAddedTimeNs + bucketSizeNs,
+ {configAddedTimeNs + (10 * 9 * NS_PER_SEC)});
+}
+
+TEST_F(GaugeMetricE2ePushedTest, TestPushedGaugeMetricSamplingWithDimensionalSampling) {
+ ShardOffsetProvider::getInstance().setShardOffset(5);
+ // Initiating StatsdStats at the start of this test, so it doesn't call rand() during the test.
+ StatsdStats::getInstance();
+ // Set srand seed to make rand deterministic for testing.
+ srand(0);
+
+ StatsdConfig config;
+ config.add_allowed_log_source("AID_ROOT"); // LogEvent defaults to UID of root.
+
+ AtomMatcher appCrashMatcher =
+ CreateSimpleAtomMatcher("APP_CRASH_OCCURRED", util::APP_CRASH_OCCURRED);
+ *config.add_atom_matcher() = appCrashMatcher;
+
+ GaugeMetric sampledGaugeMetric =
+ createGaugeMetric("GaugeSampledAppCrashesPerUid", appCrashMatcher.id(),
+ GaugeMetric::FIRST_N_SAMPLES, nullopt, nullopt);
+ *sampledGaugeMetric.mutable_dimensions_in_what() =
+ CreateDimensions(util::APP_CRASH_OCCURRED, {1 /* uid */});
+ *sampledGaugeMetric.mutable_dimensional_sampling_info()->mutable_sampled_what_field() =
+ CreateDimensions(util::APP_CRASH_OCCURRED, {1 /*uid*/});
+ sampledGaugeMetric.mutable_dimensional_sampling_info()->set_shard_count(2);
+ sampledGaugeMetric.set_sampling_percentage(50);
+ *config.add_gauge_metric() = sampledGaugeMetric;
+
+ const int64_t configAddedTimeNs = 10 * NS_PER_SEC; // 0:10
+ const int64_t bucketSizeNs =
+ TimeUnitToBucketSizeInMillis(config.gauge_metric(0).bucket()) * 1000LL * 1000LL;
+
+ int uid = 12345;
+ int64_t cfgId = 98765;
+ ConfigKey cfgKey(uid, cfgId);
+
+ sp<StatsLogProcessor> processor = CreateStatsLogProcessor(
+ configAddedTimeNs, configAddedTimeNs, config, cfgKey, nullptr, 0, new UidMap());
+
+ std::vector<std::unique_ptr<LogEvent>> events;
+ for (int i = 0; i < 30; i++) {
+ // Generate events with three different app uids: 1001, 1002, 1003.
+ events.push_back(CreateAppCrashOccurredEvent(configAddedTimeNs + (10 * i * NS_PER_SEC),
+ 1001 + (i % 3)));
+ }
+
+ // Send log events to StatsLogProcessor.
+ for (auto& event : events) {
+ processor->OnLogEvent(event.get());
+ }
+
+ ConfigMetricsReportList reports;
+ vector<uint8_t> buffer;
+ processor->onDumpReport(cfgKey, configAddedTimeNs + bucketSizeNs + 1, false, true, ADB_DUMP,
+ FAST, &buffer);
+ EXPECT_TRUE(buffer.size() > 0);
+ EXPECT_TRUE(reports.ParseFromArray(&buffer[0], buffer.size()));
+ backfillDimensionPath(&reports);
+ backfillStringInReport(&reports);
+ backfillStartEndTimestamp(&reports);
+ backfillAggregatedAtoms(&reports);
+
+ ASSERT_EQ(1, reports.reports_size());
+ ASSERT_EQ(1, reports.reports(0).metrics_size());
+ EXPECT_TRUE(reports.reports(0).metrics(0).has_gauge_metrics());
+ StatsLogReport::GaugeMetricDataWrapper gaugeMetrics;
+ sortMetricDataByDimensionsValue(reports.reports(0).metrics(0).gauge_metrics(), &gaugeMetrics);
+ ASSERT_EQ(2, gaugeMetrics.data_size());
+
+ // Only Uid 1 and 3 are logged. (odd hash value) + (offset of 5) % (shard count of 2) = 0
+ GaugeMetricData data = gaugeMetrics.data(0);
+ ValidateUidDimension(data.dimensions_in_what(), util::APP_CRASH_OCCURRED, 1001);
+ ValidateGaugeBucketTimes(
+ data.bucket_info(0), configAddedTimeNs, configAddedTimeNs + bucketSizeNs,
+ {10 * NS_PER_SEC, 40 * NS_PER_SEC, 220 * NS_PER_SEC, 280 * NS_PER_SEC});
+
+ data = gaugeMetrics.data(1);
+ ValidateUidDimension(data.dimensions_in_what(), util::APP_CRASH_OCCURRED, 1003);
+ ValidateGaugeBucketTimes(data.bucket_info(0), configAddedTimeNs,
+ configAddedTimeNs + bucketSizeNs,
+ {60 * NS_PER_SEC, 120 * NS_PER_SEC, 150 * NS_PER_SEC, 180 * NS_PER_SEC,
+ 210 * NS_PER_SEC, 300 * NS_PER_SEC});
+}
+
#else
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif
diff --git a/statsd/tests/guardrail/StatsdStats_test.cpp b/statsd/tests/guardrail/StatsdStats_test.cpp
index 6e61b620..1d56caaf 100644
--- a/statsd/tests/guardrail/StatsdStats_test.cpp
+++ b/statsd/tests/guardrail/StatsdStats_test.cpp
@@ -750,6 +750,16 @@ TEST(StatsdStatsTest, TestAtomDroppedStats) {
EXPECT_FALSE(nonPlatformPushedAtomStats.has_skip_count());
}
+TEST(StatsdStatsTest, TestQueueStats) {
+ StatsdStats stats;
+
+ stats.noteEventQueueSize(100, 1000);
+ StatsdStatsReport report = getStatsdStatsReport(stats, /* reset stats */ true);
+
+ ASSERT_EQ(100, report.event_queue_stats().max_size_observed());
+ ASSERT_EQ(1000, report.event_queue_stats().max_size_observed_elapsed_nanos());
+}
+
TEST(StatsdStatsTest, TestAtomLoggedAndDroppedStats) {
StatsdStats stats;
diff --git a/statsd/tests/indexed_priority_queue_test.cpp b/statsd/tests/indexed_priority_queue_test.cpp
index 3a654565..1d365e8b 100644
--- a/statsd/tests/indexed_priority_queue_test.cpp
+++ b/statsd/tests/indexed_priority_queue_test.cpp
@@ -30,7 +30,7 @@ struct AATest : public RefBase {
const std::string b;
struct Smaller {
- bool operator()(const sp<const AATest> a, const sp<const AATest> b) const {
+ bool operator()(const sp<const AATest>& a, const sp<const AATest>& b) const {
return (a->val < b->val);
}
};
diff --git a/statsd/tests/log_event/LogEventQueue_test.cpp b/statsd/tests/log_event/LogEventQueue_test.cpp
index a15f95be..acc9c5d5 100644
--- a/statsd/tests/log_event/LogEventQueue_test.cpp
+++ b/statsd/tests/log_event/LogEventQueue_test.cpp
@@ -20,6 +20,7 @@
#include <thread>
+#include "socket/StatsSocketListener.h"
#include "stats_event.h"
#include "tests/statsd_test_util.h"
@@ -34,37 +35,43 @@ using std::unique_ptr;
namespace {
-std::unique_ptr<LogEvent> makeLogEvent(uint64_t timestampNs) {
+AStatsEvent* makeStatsEvent(uint64_t timestampNs) {
AStatsEvent* statsEvent = AStatsEvent_obtain();
AStatsEvent_setAtomId(statsEvent, 10);
AStatsEvent_overwriteTimestamp(statsEvent, timestampNs);
+ AStatsEvent_build(statsEvent);
+ return statsEvent;
+}
+std::unique_ptr<LogEvent> makeLogEvent(uint64_t timestampNs) {
+ AStatsEvent* statsEvent = makeStatsEvent(timestampNs);
std::unique_ptr<LogEvent> logEvent = std::make_unique<LogEvent>(/*uid=*/0, /*pid=*/0);
parseStatsEventToLogEvent(statsEvent, logEvent.get());
+ EXPECT_EQ(logEvent->GetElapsedTimestampNs(), timestampNs);
return logEvent;
}
-} // anonymous namespace
+} // anonymous namespace
#ifdef __ANDROID__
TEST(LogEventQueue_test, TestGoodConsumer) {
LogEventQueue queue(50);
- int64_t timeBaseNs = 100;
- std::thread writer([&queue, timeBaseNs] {
+ int64_t eventTimeNs = 100;
+ std::thread writer([&queue, eventTimeNs] {
+ LogEventQueue::Result result;
for (int i = 0; i < 100; i++) {
- int64_t oldestEventNs;
- bool success = queue.push(makeLogEvent(timeBaseNs + i * 1000), &oldestEventNs);
- EXPECT_TRUE(success);
+ result = queue.push(makeLogEvent(eventTimeNs + i * 1000));
+ EXPECT_TRUE(result.success);
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}
});
- std::thread reader([&queue, timeBaseNs] {
+ std::thread reader([&queue, eventTimeNs] {
for (int i = 0; i < 100; i++) {
auto event = queue.waitPop();
EXPECT_TRUE(event != nullptr);
// All events are in right order.
- EXPECT_EQ(timeBaseNs + i * 1000, event->GetElapsedTimestampNs());
+ EXPECT_EQ(eventTimeNs + i * 1000, event->GetElapsedTimestampNs());
}
});
@@ -74,13 +81,15 @@ TEST(LogEventQueue_test, TestGoodConsumer) {
TEST(LogEventQueue_test, TestSlowConsumer) {
LogEventQueue queue(50);
- int64_t timeBaseNs = 100;
- std::thread writer([&queue, timeBaseNs] {
+ int64_t eventTimeNs = 100;
+ std::thread writer([&queue, eventTimeNs] {
int failure_count = 0;
- int64_t oldestEventNs;
+ LogEventQueue::Result result;
for (int i = 0; i < 100; i++) {
- bool success = queue.push(makeLogEvent(timeBaseNs + i * 1000), &oldestEventNs);
- if (!success) failure_count++;
+ result = queue.push(makeLogEvent(eventTimeNs + i * 1000));
+ if (!result.success) {
+ failure_count++;
+ }
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}
@@ -89,16 +98,16 @@ TEST(LogEventQueue_test, TestSlowConsumer) {
// There will be at least 45 events lost due to overflow.
EXPECT_TRUE(failure_count >= 45);
// The oldest event must be at least the 6th event.
- EXPECT_TRUE(oldestEventNs <= (100 + 5 * 1000));
+ EXPECT_TRUE(result.oldestTimestampNs <= (100 + 5 * 1000));
});
- std::thread reader([&queue, timeBaseNs] {
+ std::thread reader([&queue, eventTimeNs] {
// The consumer quickly processed 5 events, then it got stuck (not reading anymore).
for (int i = 0; i < 5; i++) {
auto event = queue.waitPop();
EXPECT_TRUE(event != nullptr);
// All events are in right order.
- EXPECT_EQ(timeBaseNs + i * 1000, event->GetElapsedTimestampNs());
+ EXPECT_EQ(eventTimeNs + i * 1000, event->GetElapsedTimestampNs());
}
});
@@ -106,6 +115,87 @@ TEST(LogEventQueue_test, TestSlowConsumer) {
writer.join();
}
+TEST(LogEventQueue_test, TestQueueMaxSize) {
+ StatsdStats::getInstance().reset();
+
+ std::shared_ptr<LogEventQueue> queue(std::make_shared<LogEventQueue>(50));
+ std::shared_ptr<LogEventFilter> filter(std::make_shared<LogEventFilter>());
+ filter->setFilteringEnabled(false);
+
+ int64_t eventTimeNs = 100;
+ int64_t oldestEventNs = 0;
+ int32_t newSize = 0;
+ for (int i = 0; i < 30; i++, eventTimeNs++) {
+ auto statsEvent = makeStatsEvent(eventTimeNs);
+ size_t bufferSize;
+ const uint8_t* buffer = AStatsEvent_getBuffer(statsEvent, &bufferSize);
+ StatsSocketListener::processMessage(buffer, bufferSize, 0, 0, queue, filter);
+ AStatsEvent_release(statsEvent);
+ EXPECT_EQ(StatsdStats::getInstance().mEventQueueMaxSizeObserved, i + 1);
+ EXPECT_EQ(StatsdStats::getInstance().mEventQueueMaxSizeObservedElapsedNanos, eventTimeNs);
+ }
+
+ const int32_t lastMaxSizeObserved = StatsdStats::getInstance().mEventQueueMaxSizeObserved;
+ const int64_t lastMaxSizeElapsedNanos =
+ StatsdStats::getInstance().mEventQueueMaxSizeObservedElapsedNanos;
+
+ // consumer reads the entire queue
+ int64_t nextEventTs = 100;
+ for (int i = 0; i < 30; i++, nextEventTs++) {
+ auto event = queue->waitPop();
+ EXPECT_TRUE(event != nullptr);
+ // All events are in right order.
+ EXPECT_EQ(nextEventTs, event->GetElapsedTimestampNs());
+ }
+
+ // the expectation after queue drained entirely the max count & ts do not update for
+ // smaller values
+ {
+ auto statsEvent = makeStatsEvent(eventTimeNs);
+ size_t bufferSize;
+ const uint8_t* buffer = AStatsEvent_getBuffer(statsEvent, &bufferSize);
+ StatsSocketListener::processMessage(buffer, bufferSize, 0, 0, queue, filter);
+ AStatsEvent_release(statsEvent);
+ EXPECT_EQ(StatsdStats::getInstance().mEventQueueMaxSizeObserved, lastMaxSizeObserved);
+ EXPECT_EQ(StatsdStats::getInstance().mEventQueueMaxSizeObservedElapsedNanos,
+ lastMaxSizeElapsedNanos);
+ eventTimeNs++;
+ }
+
+ for (int i = 0; i < 1; i++, nextEventTs++) {
+ auto event = queue->waitPop();
+ EXPECT_TRUE(event != nullptr);
+ // All events are in right order.
+ EXPECT_EQ(nextEventTs, event->GetElapsedTimestampNs());
+ }
+
+ // the expectation after queue drained entirely the max count & ts do update for
+ // bigger values
+ // fill up to the the previous max values observed - stats are not changed
+ for (int i = 0; i < lastMaxSizeObserved; i++, eventTimeNs++) {
+ auto statsEvent = makeStatsEvent(eventTimeNs);
+ size_t bufferSize;
+ const uint8_t* buffer = AStatsEvent_getBuffer(statsEvent, &bufferSize);
+ StatsSocketListener::processMessage(buffer, bufferSize, 0, 0, queue, filter);
+ AStatsEvent_release(statsEvent);
+ EXPECT_EQ(StatsdStats::getInstance().mEventQueueMaxSizeObserved, lastMaxSizeObserved);
+ EXPECT_EQ(StatsdStats::getInstance().mEventQueueMaxSizeObservedElapsedNanos,
+ lastMaxSizeElapsedNanos);
+ }
+
+ // add extra elements to update the stats
+ for (int i = 0; i < 10; i++, eventTimeNs++) {
+ auto statsEvent = makeStatsEvent(eventTimeNs);
+ size_t bufferSize;
+ const uint8_t* buffer = AStatsEvent_getBuffer(statsEvent, &bufferSize);
+ StatsSocketListener::processMessage(buffer, bufferSize, 0, 0, queue, filter);
+ AStatsEvent_release(statsEvent);
+ EXPECT_EQ(StatsdStats::getInstance().mEventQueueMaxSizeObserved,
+ lastMaxSizeObserved + i + 1);
+ EXPECT_EQ(StatsdStats::getInstance().mEventQueueMaxSizeObservedElapsedNanos, eventTimeNs);
+ }
+}
+
#else
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif
diff --git a/statsd/tests/metrics/metrics_test_helper.h b/statsd/tests/metrics/metrics_test_helper.h
index 39232c19..d7501496 100644
--- a/statsd/tests/metrics/metrics_test_helper.h
+++ b/statsd/tests/metrics/metrics_test_helper.h
@@ -34,18 +34,18 @@ public:
class MockStatsPullerManager : public StatsPullerManager {
public:
MOCK_METHOD5(RegisterReceiver,
- void(int tagId, const ConfigKey& key, wp<PullDataReceiver> receiver,
+ void(int tagId, const ConfigKey& key, const wp<PullDataReceiver>& receiver,
int64_t nextPulltimeNs, int64_t intervalNs));
MOCK_METHOD3(UnRegisterReceiver,
- void(int tagId, const ConfigKey& key, wp<PullDataReceiver> receiver));
- MOCK_METHOD4(Pull, bool(const int pullCode, const ConfigKey& key, const int64_t eventTimeNs,
+ void(int tagId, const ConfigKey& key, const wp<PullDataReceiver>& receiver));
+ MOCK_METHOD4(Pull, bool(const int pullCode, const ConfigKey& key, int64_t eventTimeNs,
vector<std::shared_ptr<LogEvent>>* data));
MOCK_METHOD4(Pull, bool(const int pullCode, const vector<int32_t>& uids,
const int64_t eventTimeNs, vector<std::shared_ptr<LogEvent>>* data));
MOCK_METHOD2(RegisterPullUidProvider,
- void(const ConfigKey& configKey, wp<PullUidProvider> provider));
+ void(const ConfigKey& configKey, const wp<PullUidProvider>& provider));
MOCK_METHOD2(UnregisterPullUidProvider,
- void(const ConfigKey& configKey, wp<PullUidProvider> provider));
+ void(const ConfigKey& configKey, const wp<PullUidProvider>& provider));
};
HashableDimensionKey getMockedDimensionKey(int tagId, int key, std::string value);
@@ -55,7 +55,7 @@ HashableDimensionKey getMockedDimensionKeyLongValue(int tagId, int key, int64_t
MetricDimensionKey getMockedStateDimensionKey(int tagId, int key, int64_t value);
// Utils to build FieldMatcher proto for simple one-depth atoms.
-void buildSimpleAtomFieldMatcher(const int tagId, const int atomFieldNum, FieldMatcher* matcher);
+void buildSimpleAtomFieldMatcher(const int tagId, int atomFieldNum, FieldMatcher* matcher);
void buildSimpleAtomFieldMatcher(const int tagId, FieldMatcher* matcher);
} // namespace statsd
diff --git a/statsd/tests/metrics/parsing_utils/metrics_manager_util_test.cpp b/statsd/tests/metrics/parsing_utils/metrics_manager_util_test.cpp
index 1da910b9..7b12a368 100644
--- a/statsd/tests/metrics/parsing_utils/metrics_manager_util_test.cpp
+++ b/statsd/tests/metrics/parsing_utils/metrics_manager_util_test.cpp
@@ -628,7 +628,7 @@ TEST_F(MetricsManagerUtilTest, TestEventMetricInvalidSamplingPercentage) {
StringToId("Event")));
}
-TEST_F(MetricsManagerUtilTest, TestEventMetricInvalidSamplingPercentage2) {
+TEST_F(MetricsManagerUtilTest, TestEventMetricInvalidSamplingPercentageZero) {
StatsdConfig config;
EventMetric* metric = config.add_event_metric();
*metric = createEventMetric(/*name=*/"Event", /*what=*/StringToId("ScreenTurnedOn"),
@@ -641,7 +641,7 @@ TEST_F(MetricsManagerUtilTest, TestEventMetricInvalidSamplingPercentage2) {
StringToId("Event")));
}
-TEST_F(MetricsManagerUtilTest, TestEventMetricValidSamplingPercentage2) {
+TEST_F(MetricsManagerUtilTest, TestEventMetricValidSamplingPercentage) {
StatsdConfig config;
EventMetric* metric = config.add_event_metric();
*metric = createEventMetric(/*name=*/"Event", /*what=*/StringToId("ScreenTurnedOn"),
@@ -652,6 +652,61 @@ TEST_F(MetricsManagerUtilTest, TestEventMetricValidSamplingPercentage2) {
EXPECT_EQ(initConfig(config), nullopt);
}
+TEST_F(MetricsManagerUtilTest, TestGaugeMetricInvalidSamplingPercentage) {
+ StatsdConfig config;
+ GaugeMetric* metric = config.add_gauge_metric();
+ *metric = createGaugeMetric(/*name=*/"Gauge", /*what=*/StringToId("ScreenTurnedOn"),
+ GaugeMetric::FIRST_N_SAMPLES,
+ /*condition=*/nullopt, /*triggerEvent=*/nullopt);
+ metric->set_sampling_percentage(101);
+ *config.add_atom_matcher() = CreateScreenTurnedOnAtomMatcher();
+
+ EXPECT_EQ(initConfig(config),
+ InvalidConfigReason(INVALID_CONFIG_REASON_METRIC_INCORRECT_SAMPLING_PERCENTAGE,
+ StringToId("Gauge")));
+}
+
+TEST_F(MetricsManagerUtilTest, TestGaugeMetricInvalidSamplingPercentageZero) {
+ StatsdConfig config;
+ GaugeMetric* metric = config.add_gauge_metric();
+ *metric = createGaugeMetric(/*name=*/"Gauge", /*what=*/StringToId("ScreenTurnedOn"),
+ GaugeMetric::FIRST_N_SAMPLES,
+ /*condition=*/nullopt, /*triggerEvent=*/nullopt);
+ metric->set_sampling_percentage(0);
+ *config.add_atom_matcher() = CreateScreenTurnedOnAtomMatcher();
+
+ EXPECT_EQ(initConfig(config),
+ InvalidConfigReason(INVALID_CONFIG_REASON_METRIC_INCORRECT_SAMPLING_PERCENTAGE,
+ StringToId("Gauge")));
+}
+
+TEST_F(MetricsManagerUtilTest, TestGaugeMetricValidSamplingPercentage) {
+ StatsdConfig config;
+ GaugeMetric* metric = config.add_gauge_metric();
+ *metric = createGaugeMetric(/*name=*/"Gauge", /*what=*/StringToId("ScreenTurnedOn"),
+ GaugeMetric::FIRST_N_SAMPLES,
+ /*condition=*/nullopt, /*triggerEvent=*/nullopt);
+ metric->set_sampling_percentage(50);
+ *config.add_atom_matcher() = CreateScreenTurnedOnAtomMatcher();
+
+ EXPECT_EQ(initConfig(config), nullopt);
+}
+
+TEST_F(MetricsManagerUtilTest, TestPulledGaugeMetricWithSamplingPercentage) {
+ StatsdConfig config;
+ GaugeMetric* metric = config.add_gauge_metric();
+ *metric = createGaugeMetric(/*name=*/"Gauge", /*what=*/StringToId("SubsystemSleep"),
+ GaugeMetric::FIRST_N_SAMPLES,
+ /*condition=*/nullopt, /*triggerEvent=*/nullopt);
+ metric->set_sampling_percentage(50);
+ *config.add_atom_matcher() =
+ CreateSimpleAtomMatcher("SubsystemSleep", util::SUBSYSTEM_SLEEP_STATE);
+
+ EXPECT_EQ(initConfig(config),
+ InvalidConfigReason(INVALID_CONFIG_REASON_GAUGE_METRIC_PULLED_WITH_SAMPLING,
+ StringToId("Gauge")));
+}
+
TEST_F(MetricsManagerUtilTest, TestNumericValueMetricMissingIdOrWhat) {
StatsdConfig config;
int64_t metricId = 1;
diff --git a/statsd/tests/statsd_test_util.h b/statsd/tests/statsd_test_util.h
index ca389446..52c8b981 100644
--- a/statsd/tests/statsd_test_util.h
+++ b/statsd/tests/statsd_test_util.h
@@ -334,31 +334,29 @@ FieldMatcher CreateAttributionUidAndOtherDimensions(const int atomId,
const std::vector<Position>& positions,
const std::vector<int>& fields);
-EventMetric createEventMetric(const string& name, const int64_t what,
- const optional<int64_t>& condition);
+EventMetric createEventMetric(const string& name, int64_t what, const optional<int64_t>& condition);
-CountMetric createCountMetric(const string& name, const int64_t what,
- const optional<int64_t>& condition, const vector<int64_t>& states);
+CountMetric createCountMetric(const string& name, int64_t what, const optional<int64_t>& condition,
+ const vector<int64_t>& states);
-DurationMetric createDurationMetric(const string& name, const int64_t what,
+DurationMetric createDurationMetric(const string& name, int64_t what,
const optional<int64_t>& condition,
const vector<int64_t>& states);
-GaugeMetric createGaugeMetric(const string& name, const int64_t what,
+GaugeMetric createGaugeMetric(const string& name, int64_t what,
const GaugeMetric::SamplingType samplingType,
const optional<int64_t>& condition,
const optional<int64_t>& triggerEvent);
-ValueMetric createValueMetric(const string& name, const AtomMatcher& what, const int valueField,
+ValueMetric createValueMetric(const string& name, const AtomMatcher& what, int valueField,
const optional<int64_t>& condition, const vector<int64_t>& states);
-KllMetric createKllMetric(const string& name, const AtomMatcher& what, const int kllField,
+KllMetric createKllMetric(const string& name, const AtomMatcher& what, int kllField,
const optional<int64_t>& condition);
-Alert createAlert(const string& name, const int64_t metricId, const int buckets,
- const int64_t triggerSum);
+Alert createAlert(const string& name, int64_t metricId, int buckets, const int64_t triggerSum);
-Alarm createAlarm(const string& name, const int64_t offsetMillis, const int64_t periodMillis);
+Alarm createAlarm(const string& name, int64_t offsetMillis, int64_t periodMillis);
Subscription createSubscription(const string& name, const Subscription_RuleType type,
const int64_t ruleId);
@@ -478,10 +476,10 @@ std::unique_ptr<LogEvent> CreateBatteryStateChangedEvent(const uint64_t timestam
std::unique_ptr<LogEvent> CreateMalformedBatteryStateChangedEvent(const uint64_t timestampNs);
// Create log event for app moving to background.
-std::unique_ptr<LogEvent> CreateMoveToBackgroundEvent(uint64_t timestampNs, const int uid);
+std::unique_ptr<LogEvent> CreateMoveToBackgroundEvent(uint64_t timestampNs, int uid);
// Create log event for app moving to foreground.
-std::unique_ptr<LogEvent> CreateMoveToForegroundEvent(uint64_t timestampNs, const int uid);
+std::unique_ptr<LogEvent> CreateMoveToForegroundEvent(uint64_t timestampNs, int uid);
// Create log event when the app sync starts.
std::unique_ptr<LogEvent> CreateSyncStartEvent(uint64_t timestampNs, const vector<int>& uids,
@@ -492,10 +490,10 @@ std::unique_ptr<LogEvent> CreateSyncEndEvent(uint64_t timestampNs, const vector<
const vector<string>& tags, const string& name);
// Create log event when the app sync ends.
-std::unique_ptr<LogEvent> CreateAppCrashEvent(uint64_t timestampNs, const int uid);
+std::unique_ptr<LogEvent> CreateAppCrashEvent(uint64_t timestampNs, int uid);
// Create log event for an app crash.
-std::unique_ptr<LogEvent> CreateAppCrashOccurredEvent(uint64_t timestampNs, const int uid);
+std::unique_ptr<LogEvent> CreateAppCrashOccurredEvent(uint64_t timestampNs, int uid);
// Create log event for acquiring wakelock.
std::unique_ptr<LogEvent> CreateAcquireWakelockEvent(uint64_t timestampNs, const vector<int>& uids,
@@ -528,7 +526,7 @@ std::unique_ptr<LogEvent> CreateOverlayStateChangedEvent(int64_t timestampNs, co
const OverlayStateChanged::State state);
std::unique_ptr<LogEvent> CreateAppStartOccurredEvent(
- uint64_t timestampNs, const int uid, const string& pkg_name,
+ uint64_t timestampNs, int uid, const string& pkg_name,
AppStartOccurred::TransitionType type, const string& activity_name,
const string& calling_pkg_name, const bool is_instant_app, int64_t activity_start_msec);
@@ -551,7 +549,7 @@ std::unique_ptr<LogEvent> CreatePhoneSignalStrengthChangedEvent(
std::unique_ptr<LogEvent> CreateTestAtomReportedEvent(
uint64_t timestampNs, const vector<int>& attributionUids,
- const vector<string>& attributionTags, const int intField, const long longField,
+ const vector<string>& attributionTags, int intField, const long longField,
const float floatField, const string& stringField, const bool boolField,
const TestAtomReported::State enumField, const vector<uint8_t>& bytesField,
const vector<int>& repeatedIntField, const vector<int64_t>& repeatedLongField,
@@ -565,7 +563,7 @@ void fillStatsEventWithSampleValue(AStatsEvent* statsEvent, uint8_t typeId);
// Create a statsd log event processor upon the start time in seconds, config and key.
sp<StatsLogProcessor> CreateStatsLogProcessor(
- const int64_t timeBaseNs, const int64_t currentTimeNs, const StatsdConfig& config,
+ const int64_t timeBaseNs, int64_t currentTimeNs, const StatsdConfig& config,
const ConfigKey& key, const shared_ptr<IPullAtomCallback>& puller = nullptr,
const int32_t atomTag = 0 /*for puller only*/, const sp<UidMap> = new UidMap(),
const shared_ptr<LogEventFilter>& logEventFilter = std::make_shared<LogEventFilter>());
@@ -585,7 +583,7 @@ StatsDimensionsValueParcel CreateAttributionUidDimensionsValueParcel(const int a
const int uid);
void ValidateUidDimension(const DimensionsValue& value, int atomId, int uid);
-void ValidateWakelockAttributionUidAndTagDimension(const DimensionsValue& value, const int atomId,
+void ValidateWakelockAttributionUidAndTagDimension(const DimensionsValue& value, int atomId,
const int uid, const string& tag);
void ValidateUidDimension(const DimensionsValue& value, int node_idx, int atomId, int uid);
void ValidateAttributionUidDimension(const DimensionsValue& value, int atomId, int uid);
@@ -712,8 +710,8 @@ void sortMetricDataByFirstDimensionLeafValue(const T& metricData, T* sortedMetri
}
template <typename T>
-void backfillStartEndTimestampForFullBucket(
- const int64_t timeBaseNs, const int64_t bucketSizeNs, T* bucket) {
+void backfillStartEndTimestampForFullBucket(const int64_t timeBaseNs, int64_t bucketSizeNs,
+ T* bucket) {
bucket->set_start_bucket_elapsed_nanos(timeBaseNs + bucketSizeNs * bucket->bucket_num());
bucket->set_end_bucket_elapsed_nanos(
timeBaseNs + bucketSizeNs * bucket->bucket_num() + bucketSizeNs);
@@ -735,7 +733,7 @@ void backfillStartEndTimestampForPartialBucket(const int64_t timeBaseNs, T* buck
}
template <typename T>
-void backfillStartEndTimestampForMetrics(const int64_t timeBaseNs, const int64_t bucketSizeNs,
+void backfillStartEndTimestampForMetrics(const int64_t timeBaseNs, int64_t bucketSizeNs,
T* metrics) {
for (int i = 0; i < metrics->data_size(); ++i) {
auto data = metrics->mutable_data(i);
@@ -790,10 +788,10 @@ void writeBootFlag(const std::string& flagName, const std::string& flagValue);
PackageInfoSnapshot getPackageInfoSnapshot(const sp<UidMap> uidMap);
-ApplicationInfo createApplicationInfo(const int32_t uid, const int64_t version,
- const string& versionString, const string& package);
+ApplicationInfo createApplicationInfo(int32_t uid, int64_t version, const string& versionString,
+ const string& package);
-PackageInfo buildPackageInfo(const std::string& name, const int32_t uid, const int64_t version,
+PackageInfo buildPackageInfo(const std::string& name, const int32_t uid, int64_t version,
const std::string& versionString,
const std::optional<std::string> installer,
const std::vector<uint8_t>& certHash, const bool deleted,