1//
2// Copyright (C) 2017 The Android Open Source Project
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8//      http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
16
17package {
18    default_applicable_licenses: ["Android-Apache-2.0"],
19}
20
21cc_defaults {
22    name: "statsd_defaults",
23
24    srcs: [
25        "src/active_config_list.proto",
26        "src/anomaly/AlarmMonitor.cpp",
27        "src/anomaly/AlarmTracker.cpp",
28        "src/anomaly/AnomalyTracker.cpp",
29        "src/anomaly/DurationAnomalyTracker.cpp",
30        "src/anomaly/subscriber_util.cpp",
31        "src/condition/CombinationConditionTracker.cpp",
32        "src/condition/condition_util.cpp",
33        "src/condition/ConditionWizard.cpp",
34        "src/condition/SimpleConditionTracker.cpp",
35        "src/config/ConfigKey.cpp",
36        "src/config/ConfigListener.cpp",
37        "src/config/ConfigManager.cpp",
38        "src/experiment_ids.proto",
39        "src/external/Perfetto.cpp",
40        "src/external/PullResultReceiver.cpp",
41        "src/external/puller_util.cpp",
42        "src/external/StatsCallbackPuller.cpp",
43        "src/external/StatsPuller.cpp",
44        "src/external/StatsPullerManager.cpp",
45        "src/external/TrainInfoPuller.cpp",
46        "src/FieldValue.cpp",
47        "src/flags/flags.cpp",
48        "src/guardrail/StatsdStats.cpp",
49        "src/hash.cpp",
50        "src/HashableDimensionKey.cpp",
51        "src/logd/LogEvent.cpp",
52        "src/logd/LogEventQueue.cpp",
53        "src/matchers/CombinationAtomMatchingTracker.cpp",
54        "src/matchers/EventMatcherWizard.cpp",
55        "src/matchers/matcher_util.cpp",
56        "src/matchers/SimpleAtomMatchingTracker.cpp",
57        "src/metadata_util.cpp",
58        "src/metrics/CountMetricProducer.cpp",
59        "src/metrics/duration_helper/MaxDurationTracker.cpp",
60        "src/metrics/duration_helper/OringDurationTracker.cpp",
61        "src/metrics/DurationMetricProducer.cpp",
62        "src/metrics/EventMetricProducer.cpp",
63        "src/metrics/GaugeMetricProducer.cpp",
64        "src/metrics/MetricProducer.cpp",
65        "src/metrics/MetricsManager.cpp",
66        "src/metrics/parsing_utils/config_update_utils.cpp",
67        "src/metrics/parsing_utils/metrics_manager_util.cpp",
68        "src/metrics/ValueMetricProducer.cpp",
69        "src/packages/UidMap.cpp",
70        "src/shell/shell_config.proto",
71        "src/shell/ShellSubscriber.cpp",
72        "src/socket/StatsSocketListener.cpp",
73        "src/state/StateManager.cpp",
74        "src/state/StateTracker.cpp",
75        "src/stats_log_util.cpp",
76        "src/statscompanion_util.cpp",
77        "src/statsd_config.proto",
78        "src/statsd_metadata.proto",
79        "src/StatsLogProcessor.cpp",
80        "src/StatsService.cpp",
81        "src/storage/StorageManager.cpp",
82        "src/subscriber/IncidentdReporter.cpp",
83        "src/subscriber/SubscriberReporter.cpp",
84        "src/uid_data.proto",
85        "src/utils/MultiConditionTrigger.cpp",
86    ],
87
88    local_include_dirs: [
89        "src",
90    ],
91
92    static_libs: [
93        "libbase",
94        "libcutils",
95        "libmodules-utils-build",
96        "libprotoutil",
97        "libstatslog_statsd",
98        "libsysutils",
99        "libutils",
100        "server_configurable_flags",
101        "statsd-aidl-ndk_platform",
102    ],
103    shared_libs: [
104        "libbinder_ndk",
105        "libincident",
106        "liblog",
107    ],
108    header_libs: [
109        "libgtest_prod_headers",
110    ],
111}
112
113genrule {
114    name: "statslog_statsd.h",
115    tools: ["stats-log-api-gen"],
116    cmd: "$(location stats-log-api-gen) --header $(genDir)/statslog_statsd.h --module statsd --namespace android,os,statsd,util",
117    out: [
118        "statslog_statsd.h",
119    ],
120}
121
122genrule {
123    name: "statslog_statsd.cpp",
124    tools: ["stats-log-api-gen"],
125    cmd: "$(location stats-log-api-gen) --cpp $(genDir)/statslog_statsd.cpp --module statsd --namespace android,os,statsd,util --importHeader statslog_statsd.h",
126    out: [
127        "statslog_statsd.cpp",
128    ],
129}
130
131genrule {
132    name: "statslog_statsdtest.h",
133    tools: ["stats-log-api-gen"],
134    cmd: "$(location stats-log-api-gen) --header $(genDir)/statslog_statsdtest.h --module statsdtest --namespace android,os,statsd,util",
135    out: [
136        "statslog_statsdtest.h",
137    ],
138}
139
140genrule {
141    name: "statslog_statsdtest.cpp",
142    tools: ["stats-log-api-gen"],
143    cmd: "$(location stats-log-api-gen) --cpp $(genDir)/statslog_statsdtest.cpp --module statsdtest --namespace android,os,statsd,util --importHeader statslog_statsdtest.h",
144    out: [
145        "statslog_statsdtest.cpp",
146    ],
147}
148
149cc_library_static {
150    name: "libstatslog_statsdtest",
151    generated_sources: ["statslog_statsdtest.cpp"],
152    generated_headers: ["statslog_statsdtest.h"],
153    export_generated_headers: ["statslog_statsdtest.h"],
154    shared_libs: [
155        "libstatssocket",
156        "libstatspull",
157    ],
158}
159
160cc_library_static {
161    name: "libstatslog_statsd",
162    generated_sources: ["statslog_statsd.cpp"],
163    generated_headers: ["statslog_statsd.h"],
164    export_generated_headers: ["statslog_statsd.h"],
165    apex_available: [
166        "com.android.os.statsd",
167        "test_com.android.os.statsd",
168    ],
169    min_sdk_version: "30",
170    shared_libs: [
171        "libstatssocket",
172        "libstatspull",
173    ],
174    export_shared_lib_headers: [
175        "libstatspull",
176    ],
177}
178
179// =========
180// statsd
181// =========
182
183cc_binary {
184    name: "statsd",
185    defaults: ["statsd_defaults"],
186
187    srcs: ["src/main.cpp"],
188
189    cflags: [
190        "-Wall",
191        "-Wextra",
192        "-Werror",
193        "-Wno-unused-parameter",
194        // optimize for size (protobuf glop can get big)
195        "-Os",
196        // "-g",
197        // "-O0",
198    ],
199
200    product_variables: {
201        eng: {
202            // Enable sanitizer ONLY on eng builds
203            //sanitize: {
204            //    address: true,
205            //},
206        },
207    },
208
209    proto: {
210        type: "lite",
211        static: true,
212    },
213    stl: "libc++_static",
214
215    shared_libs: [
216        "libstatssocket",
217    ],
218
219    apex_available: [
220        "com.android.os.statsd",
221        "test_com.android.os.statsd",
222    ],
223    min_sdk_version: "30",
224
225    sanitize: {
226        memtag_heap: true,
227    },
228}
229
230// ==============
231// statsd_test
232// ==============
233
234cc_test {
235    name: "statsd_test",
236    defaults: ["statsd_defaults"],
237    test_suites: ["device-tests", "mts-statsd"],
238    test_config: "statsd_test.xml",
239
240    //TODO(b/153588990): Remove when the build system properly separates
241    //32bit and 64bit architectures.
242    compile_multilib: "both",
243    multilib: {
244        lib64: {
245            suffix: "64",
246        },
247        lib32: {
248            suffix: "32",
249        },
250    },
251
252    cflags: [
253        "-Wall",
254        "-Werror",
255        "-Wno-missing-field-initializers",
256        "-Wno-unused-variable",
257        "-Wno-unused-function",
258        "-Wno-unused-parameter",
259    ],
260
261    require_root: true,
262
263    srcs: [
264        // atom_field_options.proto needs field_options.proto, but that is
265        // not included in libprotobuf-cpp-lite, so compile it here.
266        ":libprotobuf-internal-protos",
267        ":libstats_internal_protos",
268
269        "src/shell/shell_data.proto",
270        "src/stats_log.proto",
271        "tests/AlarmMonitor_test.cpp",
272        "tests/anomaly/AlarmTracker_test.cpp",
273        "tests/anomaly/AnomalyTracker_test.cpp",
274        "tests/condition/CombinationConditionTracker_test.cpp",
275        "tests/condition/ConditionTimer_test.cpp",
276        "tests/condition/SimpleConditionTracker_test.cpp",
277        "tests/ConfigManager_test.cpp",
278        "tests/e2e/Alarm_e2e_test.cpp",
279        "tests/e2e/Anomaly_count_e2e_test.cpp",
280        "tests/e2e/Anomaly_duration_sum_e2e_test.cpp",
281        "tests/e2e/Attribution_e2e_test.cpp",
282        "tests/e2e/ConfigTtl_e2e_test.cpp",
283        "tests/e2e/ConfigUpdate_e2e_ab_test.cpp",
284        "tests/e2e/ConfigUpdate_e2e_test.cpp",
285        "tests/e2e/CountMetric_e2e_test.cpp",
286        "tests/e2e/DurationMetric_e2e_test.cpp",
287        "tests/e2e/GaugeMetric_e2e_pull_test.cpp",
288        "tests/e2e/GaugeMetric_e2e_push_test.cpp",
289        "tests/e2e/MetricActivation_e2e_test.cpp",
290        "tests/e2e/MetricConditionLink_e2e_test.cpp",
291        "tests/e2e/PartialBucket_e2e_test.cpp",
292        "tests/e2e/ValueMetric_pull_e2e_test.cpp",
293        "tests/e2e/WakelockDuration_e2e_test.cpp",
294        "tests/external/puller_util_test.cpp",
295        "tests/external/StatsCallbackPuller_test.cpp",
296        "tests/external/StatsPuller_test.cpp",
297        "tests/external/StatsPullerManager_test.cpp",
298        "tests/FieldValue_test.cpp",
299        "tests/guardrail/StatsdStats_test.cpp",
300        "tests/HashableDimensionKey_test.cpp",
301        "tests/indexed_priority_queue_test.cpp",
302        "tests/log_event/LogEventQueue_test.cpp",
303        "tests/LogEntryMatcher_test.cpp",
304        "tests/LogEvent_test.cpp",
305        "tests/metadata_util_test.cpp",
306        "tests/metrics/CountMetricProducer_test.cpp",
307        "tests/metrics/DurationMetricProducer_test.cpp",
308        "tests/metrics/EventMetricProducer_test.cpp",
309        "tests/metrics/GaugeMetricProducer_test.cpp",
310        "tests/metrics/MaxDurationTracker_test.cpp",
311        "tests/metrics/metrics_test_helper.cpp",
312        "tests/metrics/OringDurationTracker_test.cpp",
313        "tests/metrics/ValueMetricProducer_test.cpp",
314        "tests/metrics/parsing_utils/config_update_utils_test.cpp",
315        "tests/metrics/parsing_utils/metrics_manager_util_test.cpp",
316        "tests/subscriber/SubscriberReporter_test.cpp",
317        "tests/MetricsManager_test.cpp",
318        "tests/shell/ShellSubscriber_test.cpp",
319        "tests/state/StateTracker_test.cpp",
320        "tests/statsd_test_util.cpp",
321        "tests/StatsLogProcessor_test.cpp",
322        "tests/StatsService_test.cpp",
323        "tests/storage/StorageManager_test.cpp",
324        "tests/UidMap_test.cpp",
325        "tests/utils/MultiConditionTrigger_test.cpp",
326    ],
327
328    static_libs: [
329        "libgmock",
330        "libplatformprotos",
331        "libstatslog_statsdtest",
332        "libstatssocket_private",
333    ],
334
335    proto: {
336        type: "lite",
337        include_dirs: [
338            "external/protobuf/src",
339            "frameworks/proto_logging/stats",
340        ],
341    },
342
343}
344
345//#############################
346// statsd micro benchmark
347//#############################
348
349cc_benchmark {
350    name: "statsd_benchmark",
351    defaults: ["statsd_defaults"],
352
353    srcs: [
354        // atom_field_options.proto needs field_options.proto, but that is
355        // not included in libprotobuf-cpp-lite, so compile it here.
356        ":libprotobuf-internal-protos",
357        ":libstats_internal_protos",
358
359        "benchmark/duration_metric_benchmark.cpp",
360        "benchmark/filter_value_benchmark.cpp",
361        "benchmark/get_dimensions_for_condition_benchmark.cpp",
362        "benchmark/hello_world_benchmark.cpp",
363        "benchmark/log_event_benchmark.cpp",
364        "benchmark/main.cpp",
365        "benchmark/metric_util.cpp",
366        "benchmark/stats_write_benchmark.cpp",
367        "src/stats_log.proto",
368    ],
369
370    proto: {
371        type: "lite",
372        include_dirs: [
373            "external/protobuf/src",
374            "frameworks/proto_logging/stats",
375        ],
376    },
377
378    cflags: [
379        "-Wall",
380        "-Werror",
381        "-Wno-unused-parameter",
382        "-Wno-unused-variable",
383        "-Wno-unused-function",
384
385        // Bug: http://b/29823425 Disable -Wvarargs for Clang update to r271374
386        "-Wno-varargs",
387    ],
388
389    static_libs: [
390        "libplatformprotos",
391        "libstatssocket_private",
392    ],
393
394    shared_libs: [
395        "libprotobuf-cpp-lite",
396        "libstatslog",
397    ],
398
399    header_libs: [
400        "libgtest_prod_headers",
401    ],
402}
403
404// ====  java proto device library (for test only)  ==============================
405java_library {
406    name: "statsdprotolite",
407    sdk_version: "core_current",
408    proto: {
409        type: "lite",
410        include_dirs: [
411            "external/protobuf/src",
412            "frameworks/proto_logging/stats",
413        ],
414    },
415
416    srcs: [
417        ":libstats_atoms_proto",
418        "src/shell/shell_config.proto",
419        "src/shell/shell_data.proto",
420        "src/stats_log.proto",
421        "src/statsd_config.proto",
422    ],
423
424    static_libs: [
425        "platformprotoslite",
426    ],
427    // Protos have lots of MissingOverride and similar.
428    errorprone: {
429        javacflags: ["-XepDisableAllChecks"],
430    },
431}
432
433java_library {
434    name: "statsdprotonano",
435    sdk_version: "9",
436    proto: {
437        type: "nano",
438        output_params: ["store_unknown_fields=true"],
439        include_dirs: [
440            "external/protobuf/src",
441            "frameworks/proto_logging/stats",
442        ],
443    },
444    srcs: [
445        ":libstats_atoms_proto",
446        "src/shell/shell_config.proto",
447        "src/shell/shell_data.proto",
448        "src/stats_log.proto",
449        "src/statsd_config.proto",
450    ],
451    static_libs: [
452        "platformprotosnano",
453    ],
454    // Protos have lots of MissingOverride and similar.
455    errorprone: {
456        javacflags: ["-XepDisableAllChecks"],
457    },
458}
459
460// Filegroup for statsd config proto definition.
461filegroup {
462    name: "statsd-config-proto-def",
463    srcs: ["src/statsd_config.proto"],
464}
465
466// Filegroup for all statsd protos
467filegroup {
468    name: "statsd_internal_protos",
469    srcs: [
470        "src/active_config_list.proto",
471        "src/experiment_ids.proto",
472        "src/shell/shell_config.proto",
473        "src/shell/shell_data.proto",
474        "src/statsd_config.proto",
475        "src/statsd_metadata.proto",
476        "src/stats_log.proto",
477        "src/uid_data.proto",
478    ],
479}
480