Overall flow of implementation: 1. parsing the config in MetricsManager to store the uids per atom. It follows the mAllowedLogSources logic very closely 2. MetricsManager register itself as a PullUidProvider with the PullerManager. 3. Metrics pass the config key when pulling (for both registering receivers and normal pulls) , and the puller manager gets the allowed uids from the PullUidProvider for that config. 4. PullerManager keys receivers by <atomId, configKey> so that it can look up the uids for that atom using the PullUidProvider as well. 5. Added shell subscriber support. Hardcode a default of AID_SYSTEM for them and also allow packages per atom. This involved adding a second interface to Pull that simply accepts the uids, since I didnt want to make the ShellSubscriber a PullUidProvider as well. 6. Change adb shell cmd stats pull-source to allow users to specify a package. Default to AID_SYSTEM as well. Notes: The feature is flagged off right now, since configs do not pass in the desired package. Another approach could be to hardcode in the current mapping, but that doesn't work for OEM pulled atoms. Test: m statsd Test: bit statsd_test:* with useUids = false Test: bit statsd_test:* with useUids = true Bug: 144099783 Bug: 151978258 Change-Id: I4a7481d7402a52b9beb4ea28b102803f9e50e79f
464 lines
13 KiB
Plaintext
464 lines
13 KiB
Plaintext
//
|
|
// 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.
|
|
//
|
|
|
|
// ==========================================================
|
|
// Build the library for use on the host
|
|
// ==========================================================
|
|
cc_library_host_shared {
|
|
name: "libstats_proto_host",
|
|
srcs: [
|
|
"src/atoms.proto",
|
|
"src/atom_field_options.proto",
|
|
],
|
|
|
|
shared_libs: [
|
|
"libplatformprotos",
|
|
],
|
|
|
|
proto: {
|
|
type: "full",
|
|
export_proto_headers: true,
|
|
include_dirs: [
|
|
"external/protobuf/src",
|
|
],
|
|
},
|
|
|
|
export_shared_lib_headers: [
|
|
"libplatformprotos",
|
|
]
|
|
|
|
}
|
|
|
|
cc_defaults {
|
|
name: "statsd_defaults",
|
|
|
|
srcs: [
|
|
"src/active_config_list.proto",
|
|
"src/anomaly/AlarmMonitor.cpp",
|
|
"src/anomaly/AlarmTracker.cpp",
|
|
"src/anomaly/AnomalyTracker.cpp",
|
|
"src/anomaly/DurationAnomalyTracker.cpp",
|
|
"src/anomaly/subscriber_util.cpp",
|
|
"src/condition/CombinationConditionTracker.cpp",
|
|
"src/condition/condition_util.cpp",
|
|
"src/condition/ConditionWizard.cpp",
|
|
"src/condition/SimpleConditionTracker.cpp",
|
|
"src/condition/StateConditionTracker.cpp",
|
|
"src/config/ConfigKey.cpp",
|
|
"src/config/ConfigListener.cpp",
|
|
"src/config/ConfigManager.cpp",
|
|
"src/experiment_ids.proto",
|
|
"src/external/Perfetto.cpp",
|
|
"src/external/PullResultReceiver.cpp",
|
|
"src/external/puller_util.cpp",
|
|
"src/external/StatsCallbackPuller.cpp",
|
|
"src/external/StatsPuller.cpp",
|
|
"src/external/StatsPullerManager.cpp",
|
|
"src/external/TrainInfoPuller.cpp",
|
|
"src/FieldValue.cpp",
|
|
"src/guardrail/StatsdStats.cpp",
|
|
"src/hash.cpp",
|
|
"src/HashableDimensionKey.cpp",
|
|
"src/logd/LogEvent.cpp",
|
|
"src/logd/LogEventQueue.cpp",
|
|
"src/matchers/CombinationLogMatchingTracker.cpp",
|
|
"src/matchers/EventMatcherWizard.cpp",
|
|
"src/matchers/matcher_util.cpp",
|
|
"src/matchers/SimpleLogMatchingTracker.cpp",
|
|
"src/metrics/CountMetricProducer.cpp",
|
|
"src/metrics/duration_helper/MaxDurationTracker.cpp",
|
|
"src/metrics/duration_helper/OringDurationTracker.cpp",
|
|
"src/metrics/DurationMetricProducer.cpp",
|
|
"src/metrics/EventMetricProducer.cpp",
|
|
"src/metrics/GaugeMetricProducer.cpp",
|
|
"src/metrics/MetricProducer.cpp",
|
|
"src/metrics/metrics_manager_util.cpp",
|
|
"src/metrics/MetricsManager.cpp",
|
|
"src/metrics/ValueMetricProducer.cpp",
|
|
"src/packages/UidMap.cpp",
|
|
"src/shell/shell_config.proto",
|
|
"src/shell/ShellSubscriber.cpp",
|
|
"src/socket/StatsSocketListener.cpp",
|
|
"src/state/StateManager.cpp",
|
|
"src/state/StateTracker.cpp",
|
|
"src/stats_log_util.cpp",
|
|
"src/statscompanion_util.cpp",
|
|
"src/statsd_config.proto",
|
|
"src/statsd_metadata.proto",
|
|
"src/StatsLogProcessor.cpp",
|
|
"src/StatsService.cpp",
|
|
"src/storage/StorageManager.cpp",
|
|
"src/subscriber/IncidentdReporter.cpp",
|
|
"src/subscriber/SubscriberReporter.cpp",
|
|
"src/uid_data.proto",
|
|
],
|
|
|
|
local_include_dirs: [
|
|
"src",
|
|
],
|
|
|
|
static_libs: [
|
|
"libbase",
|
|
"libcutils",
|
|
"libprotoutil",
|
|
"libstatsmetadata",
|
|
"libstatslog_statsd",
|
|
"libsysutils",
|
|
"libutils",
|
|
],
|
|
shared_libs: [
|
|
"libbinder_ndk",
|
|
"libincident",
|
|
"liblog",
|
|
"statsd-aidl-ndk_platform",
|
|
],
|
|
}
|
|
|
|
// ================
|
|
// libstatsmetadata
|
|
// ================
|
|
|
|
genrule {
|
|
name: "atoms_info.h",
|
|
tools: ["stats-log-api-gen"],
|
|
cmd: "$(location stats-log-api-gen) --atomsInfoHeader $(genDir)/atoms_info.h",
|
|
out: [
|
|
"atoms_info.h",
|
|
],
|
|
}
|
|
|
|
genrule {
|
|
name: "atoms_info.cpp",
|
|
tools: ["stats-log-api-gen"],
|
|
cmd: "$(location stats-log-api-gen) --atomsInfoCpp $(genDir)/atoms_info.cpp",
|
|
out: [
|
|
"atoms_info.cpp",
|
|
],
|
|
}
|
|
|
|
cc_library_static {
|
|
name: "libstatsmetadata",
|
|
host_supported: true,
|
|
generated_sources: [
|
|
"atoms_info.cpp",
|
|
],
|
|
generated_headers: [
|
|
"atoms_info.h",
|
|
],
|
|
cflags: [
|
|
"-Wall",
|
|
"-Werror",
|
|
],
|
|
export_generated_headers: [
|
|
"atoms_info.h",
|
|
],
|
|
apex_available: [
|
|
//TODO(b/149782403): Remove this once statsd no longer links against libstatsmetadata
|
|
"com.android.os.statsd",
|
|
"test_com.android.os.statsd",
|
|
],
|
|
}
|
|
|
|
genrule {
|
|
name: "statslog_statsd.h",
|
|
tools: ["stats-log-api-gen"],
|
|
cmd: "$(location stats-log-api-gen) --header $(genDir)/statslog_statsd.h --module statsd --namespace android,os,statsd,util",
|
|
out: [
|
|
"statslog_statsd.h",
|
|
],
|
|
}
|
|
|
|
genrule {
|
|
name: "statslog_statsd.cpp",
|
|
tools: ["stats-log-api-gen"],
|
|
cmd: "$(location stats-log-api-gen) --cpp $(genDir)/statslog_statsd.cpp --module statsd --namespace android,os,statsd,util --importHeader statslog_statsd.h",
|
|
out: [
|
|
"statslog_statsd.cpp",
|
|
],
|
|
}
|
|
|
|
genrule {
|
|
name: "statslog_statsdtest.h",
|
|
tools: ["stats-log-api-gen"],
|
|
cmd: "$(location stats-log-api-gen) --header $(genDir)/statslog_statsdtest.h --module statsdtest --namespace android,os,statsd,util",
|
|
out: [
|
|
"statslog_statsdtest.h",
|
|
],
|
|
}
|
|
|
|
genrule {
|
|
name: "statslog_statsdtest.cpp",
|
|
tools: ["stats-log-api-gen"],
|
|
cmd: "$(location stats-log-api-gen) --cpp $(genDir)/statslog_statsdtest.cpp --module statsdtest --namespace android,os,statsd,util --importHeader statslog_statsdtest.h",
|
|
out: [
|
|
"statslog_statsdtest.cpp",
|
|
],
|
|
}
|
|
|
|
cc_library_static {
|
|
name: "libstatslog_statsdtest",
|
|
generated_sources: ["statslog_statsdtest.cpp"],
|
|
generated_headers: ["statslog_statsdtest.h"],
|
|
export_generated_headers: ["statslog_statsdtest.h"],
|
|
shared_libs: [
|
|
"libstatssocket",
|
|
]
|
|
}
|
|
|
|
cc_library_static {
|
|
name: "libstatslog_statsd",
|
|
generated_sources: ["statslog_statsd.cpp"],
|
|
generated_headers: ["statslog_statsd.h"],
|
|
export_generated_headers: ["statslog_statsd.h"],
|
|
apex_available: [
|
|
"com.android.os.statsd",
|
|
"test_com.android.os.statsd",
|
|
],
|
|
shared_libs: [
|
|
"libstatssocket",
|
|
]
|
|
}
|
|
|
|
// =========
|
|
// statsd
|
|
// =========
|
|
|
|
cc_binary {
|
|
name: "statsd",
|
|
defaults: ["statsd_defaults"],
|
|
|
|
srcs: ["src/main.cpp"],
|
|
|
|
cflags: [
|
|
"-Wall",
|
|
"-Wextra",
|
|
"-Werror",
|
|
"-Wno-unused-parameter",
|
|
// optimize for size (protobuf glop can get big)
|
|
"-Os",
|
|
// "-g",
|
|
// "-O0",
|
|
],
|
|
|
|
product_variables: {
|
|
eng: {
|
|
// Enable sanitizer ONLY on eng builds
|
|
//sanitize: {
|
|
// address: true,
|
|
//},
|
|
},
|
|
debuggable: {
|
|
// Add a flag to enable stats log printing from statsd on debug builds.
|
|
cflags: ["-DVERY_VERBOSE_PRINTING"],
|
|
},
|
|
},
|
|
|
|
proto: {
|
|
type: "lite",
|
|
},
|
|
|
|
shared_libs: [
|
|
"libgtest_prod",
|
|
"libstatssocket",
|
|
],
|
|
|
|
apex_available: [
|
|
"com.android.os.statsd",
|
|
"test_com.android.os.statsd",
|
|
],
|
|
}
|
|
|
|
// ==============
|
|
// statsd_test
|
|
// ==============
|
|
|
|
cc_test {
|
|
name: "statsd_test",
|
|
defaults: ["statsd_defaults"],
|
|
test_suites: ["device-tests"],
|
|
|
|
cflags: [
|
|
"-Wall",
|
|
"-Werror",
|
|
"-Wno-missing-field-initializers",
|
|
"-Wno-unused-variable",
|
|
"-Wno-unused-function",
|
|
"-Wno-unused-parameter",
|
|
],
|
|
|
|
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",
|
|
|
|
"src/atom_field_options.proto",
|
|
"src/atoms.proto",
|
|
"src/shell/shell_data.proto",
|
|
"src/stats_log.proto",
|
|
"tests/AlarmMonitor_test.cpp",
|
|
"tests/anomaly/AlarmTracker_test.cpp",
|
|
"tests/anomaly/AnomalyTracker_test.cpp",
|
|
"tests/condition/CombinationConditionTracker_test.cpp",
|
|
"tests/condition/ConditionTimer_test.cpp",
|
|
"tests/condition/SimpleConditionTracker_test.cpp",
|
|
"tests/condition/StateConditionTracker_test.cpp",
|
|
"tests/ConfigManager_test.cpp",
|
|
"tests/e2e/Alarm_e2e_test.cpp",
|
|
"tests/e2e/Anomaly_count_e2e_test.cpp",
|
|
"tests/e2e/Anomaly_duration_sum_e2e_test.cpp",
|
|
"tests/e2e/Attribution_e2e_test.cpp",
|
|
"tests/e2e/ConfigTtl_e2e_test.cpp",
|
|
"tests/e2e/CountMetric_e2e_test.cpp",
|
|
"tests/e2e/DurationMetric_e2e_test.cpp",
|
|
"tests/e2e/GaugeMetric_e2e_pull_test.cpp",
|
|
"tests/e2e/GaugeMetric_e2e_push_test.cpp",
|
|
"tests/e2e/MetricActivation_e2e_test.cpp",
|
|
"tests/e2e/MetricConditionLink_e2e_test.cpp",
|
|
"tests/e2e/PartialBucket_e2e_test.cpp",
|
|
"tests/e2e/ValueMetric_pull_e2e_test.cpp",
|
|
"tests/e2e/WakelockDuration_e2e_test.cpp",
|
|
"tests/external/puller_util_test.cpp",
|
|
"tests/external/StatsCallbackPuller_test.cpp",
|
|
"tests/external/StatsPuller_test.cpp",
|
|
"tests/external/StatsPullerManager_test.cpp",
|
|
"tests/FieldValue_test.cpp",
|
|
"tests/guardrail/StatsdStats_test.cpp",
|
|
"tests/indexed_priority_queue_test.cpp",
|
|
"tests/log_event/LogEventQueue_test.cpp",
|
|
"tests/LogEntryMatcher_test.cpp",
|
|
"tests/LogEvent_test.cpp",
|
|
"tests/metrics/CountMetricProducer_test.cpp",
|
|
"tests/metrics/DurationMetricProducer_test.cpp",
|
|
"tests/metrics/EventMetricProducer_test.cpp",
|
|
"tests/metrics/GaugeMetricProducer_test.cpp",
|
|
"tests/metrics/MaxDurationTracker_test.cpp",
|
|
"tests/metrics/metrics_test_helper.cpp",
|
|
"tests/metrics/OringDurationTracker_test.cpp",
|
|
"tests/metrics/ValueMetricProducer_test.cpp",
|
|
"tests/MetricsManager_test.cpp",
|
|
"tests/shell/ShellSubscriber_test.cpp",
|
|
"tests/state/StateTracker_test.cpp",
|
|
"tests/statsd_test_util.cpp",
|
|
"tests/StatsLogProcessor_test.cpp",
|
|
"tests/StatsService_test.cpp",
|
|
"tests/storage/StorageManager_test.cpp",
|
|
"tests/UidMap_test.cpp",
|
|
],
|
|
|
|
static_libs: [
|
|
"libgmock",
|
|
"libplatformprotos",
|
|
"libstatslog_statsdtest",
|
|
"libstatssocket_private",
|
|
],
|
|
|
|
proto: {
|
|
type: "lite",
|
|
include_dirs: ["external/protobuf/src"],
|
|
},
|
|
|
|
shared_libs: [
|
|
"libprotobuf-cpp-lite",
|
|
],
|
|
|
|
}
|
|
|
|
//#############################
|
|
// statsd micro benchmark
|
|
//#############################
|
|
|
|
cc_benchmark {
|
|
name: "statsd_benchmark",
|
|
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",
|
|
|
|
"benchmark/duration_metric_benchmark.cpp",
|
|
"benchmark/filter_value_benchmark.cpp",
|
|
"benchmark/get_dimensions_for_condition_benchmark.cpp",
|
|
"benchmark/hello_world_benchmark.cpp",
|
|
"benchmark/log_event_benchmark.cpp",
|
|
"benchmark/main.cpp",
|
|
"benchmark/metric_util.cpp",
|
|
"benchmark/stats_write_benchmark.cpp",
|
|
"src/atom_field_options.proto",
|
|
"src/atoms.proto",
|
|
"src/stats_log.proto",
|
|
],
|
|
|
|
proto: {
|
|
type: "lite",
|
|
include_dirs: ["external/protobuf/src"],
|
|
},
|
|
|
|
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: [
|
|
"libgtest_prod",
|
|
"libprotobuf-cpp-lite",
|
|
"libstatslog",
|
|
],
|
|
}
|
|
|
|
// ==== java proto device library (for test only) ==============================
|
|
java_library {
|
|
name: "statsdprotolite",
|
|
sdk_version: "core_current",
|
|
proto: {
|
|
type: "lite",
|
|
include_dirs: ["external/protobuf/src"],
|
|
},
|
|
|
|
srcs: [
|
|
"src/atoms.proto",
|
|
"src/shell/shell_config.proto",
|
|
"src/shell/shell_data.proto",
|
|
"src/stats_log.proto",
|
|
"src/statsd_config.proto",
|
|
],
|
|
|
|
static_libs: [
|
|
"platformprotoslite",
|
|
],
|
|
// Protos have lots of MissingOverride and similar.
|
|
errorprone: {
|
|
javacflags: ["-XepDisableAllChecks"],
|
|
},
|
|
}
|
|
|
|
// Filegroup for statsd config proto definition.
|
|
filegroup {
|
|
name: "statsd-config-proto-def",
|
|
srcs: ["src/statsd_config.proto"],
|
|
}
|