• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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    default_team: "trendy_team_android_telemetry_client_infra",
20}
21
22cc_defaults {
23    name: "statsd_defaults",
24
25    cflags: [
26        "-Wno-deprecated-declarations",
27        "-Wthread-safety",
28    ],
29    tidy: true,
30    tidy_flags: [
31        // Only check our headers
32        "-header-filter=^packages/modules/StatsD/statsd",
33    ],
34
35    tidy_checks: [
36        "android-*",
37        "bugprone-*",
38        "cert-*",
39        "clang-analyzer-security*",
40        "google-*",
41        "misc-*",
42        "performance-*",
43        "-bugprone-narrowing-conversions", // lots of unsigned -> int conversions
44        "-cert-err34-c",
45        "-cert-msc30-c", // warning: rand() has limited randomness; use C++11 random library
46        "-cert-msc50-cpp", // warning: rand() has limited randomness; use C++11 random library
47    ],
48    tidy_checks_as_errors: [
49        "android-*",
50        "bugprone-*",
51        "cert-*",
52        "clang-analyzer-security*",
53        "google-*",
54        "misc-*",
55        "performance-*",
56    ],
57    srcs: [
58        "src/active_config_list.proto",
59        "src/anomaly/AlarmMonitor.cpp",
60        "src/anomaly/AlarmTracker.cpp",
61        "src/anomaly/AnomalyTracker.cpp",
62        "src/anomaly/DurationAnomalyTracker.cpp",
63        "src/anomaly/subscriber_util.cpp",
64        "src/condition/CombinationConditionTracker.cpp",
65        "src/condition/condition_util.cpp",
66        "src/condition/ConditionWizard.cpp",
67        "src/condition/SimpleConditionTracker.cpp",
68        "src/config/ConfigKey.cpp",
69        "src/config/ConfigListener.cpp",
70        "src/config/ConfigManager.cpp",
71        "src/experiment_ids.proto",
72        "src/external/Perfetto.cpp",
73        "src/external/PullResultReceiver.cpp",
74        "src/external/puller_util.cpp",
75        "src/external/StatsCallbackPuller.cpp",
76        "src/external/StatsPuller.cpp",
77        "src/external/StatsPullerManager.cpp",
78        "src/external/TrainInfoPuller.cpp",
79        "src/external/Uprobestats.cpp",
80        "src/FieldValue.cpp",
81        "src/flags/FlagProvider.cpp",
82        "src/guardrail/StatsdStats.cpp",
83        "src/hash.cpp",
84        "src/HashableDimensionKey.cpp",
85        "src/logd/LogEvent.cpp",
86        "src/logd/LogEventQueue.cpp",
87        "src/logd/logevent_util.cpp",
88        "src/matchers/CombinationAtomMatchingTracker.cpp",
89        "src/matchers/EventMatcherWizard.cpp",
90        "src/matchers/matcher_util.cpp",
91        "src/matchers/SimpleAtomMatchingTracker.cpp",
92        "src/metadata_util.cpp",
93        "src/metrics/CountMetricProducer.cpp",
94        "src/metrics/duration_helper/MaxDurationTracker.cpp",
95        "src/metrics/duration_helper/OringDurationTracker.cpp",
96        "src/metrics/DurationMetricProducer.cpp",
97        "src/metrics/EventMetricProducer.cpp",
98        "src/metrics/RestrictedEventMetricProducer.cpp",
99        "src/metrics/GaugeMetricProducer.cpp",
100        "src/metrics/HistogramValue.cpp",
101        "src/metrics/KllMetricProducer.cpp",
102        "src/metrics/MetricProducer.cpp",
103        "src/metrics/MetricsManager.cpp",
104        "src/metrics/NumericValue.cpp",
105        "src/metrics/ValueMetricProducer.cpp",
106        "src/metrics/parsing_utils/config_update_utils.cpp",
107        "src/metrics/parsing_utils/metrics_manager_util.cpp",
108        "src/metrics/parsing_utils/histogram_parsing_utils.cpp",
109        "src/metrics/NumericValueMetricProducer.cpp",
110        "src/packages/UidMap.cpp",
111        "src/shell/shell_config.proto",
112        "src/shell/ShellSubscriber.cpp",
113        "src/shell/ShellSubscriberClient.cpp",
114        "src/socket/BaseStatsSocketListener.cpp",
115        "src/socket/StatsSocketListener.cpp",
116        "src/state/StateManager.cpp",
117        "src/state/StateTracker.cpp",
118        "src/stats_log_util.cpp",
119        "src/stats_policy_config.proto",
120        "src/statscompanion_util.cpp",
121        "src/statsd_config.proto",
122        "src/statsd_metadata.proto",
123        "src/guardrail/LoggingRate.cpp",
124        "src/guardrail/stats_log_enums.proto",
125        "src/StatsLogProcessor.cpp",
126        "src/StatsService.cpp",
127        "src/storage/StorageManager.cpp",
128        "src/subscriber/IncidentdReporter.cpp",
129        "src/subscriber/SubscriberReporter.cpp",
130        "src/uid_data.proto",
131        "src/utils/MultiConditionTrigger.cpp",
132        "src/utils/DbUtils.cpp",
133        "src/utils/Regex.cpp",
134        "src/utils/RestrictedPolicyManager.cpp",
135        "src/utils/ShardOffsetProvider.cpp",
136    ],
137
138    local_include_dirs: [
139        "src",
140    ],
141
142    static_libs: [
143        "libbase",
144        "libcutils",
145        "libkll",
146        "libmodules-utils-build",
147        "libprotoutil",
148        "libstatslog_statsd",
149        "libsysutils",
150        "libutils",
151        "server_configurable_flags",
152        "statsd-aidl-ndk",
153        "statsd_flags_c_lib",
154        "libsqlite_static_noicu",
155        "libaconfig_storage_read_api_cc",
156    ],
157    shared_libs: [
158        "libbinder_ndk",
159        "libincident",
160        "liblog",
161        "libstatssocket#impl",
162    ],
163    header_libs: [
164        "libgtest_prod_headers",
165    ],
166    min_sdk_version: "30",
167}
168
169genrule {
170    name: "statslog_statsd.h",
171    tools: ["stats-log-api-gen"],
172    cmd: "$(location stats-log-api-gen) " +
173        "--header $(genDir)/statslog_statsd.h " +
174        "--module statsd " +
175        "--namespace android,os,statsd,util",
176    out: [
177        "statslog_statsd.h",
178    ],
179}
180
181genrule {
182    name: "statslog_statsd.cpp",
183    tools: ["stats-log-api-gen"],
184    cmd: "$(location stats-log-api-gen) " +
185        "--cpp $(genDir)/statslog_statsd.cpp " +
186        "--module statsd " +
187        "--namespace android,os,statsd,util " +
188        "--importHeader statslog_statsd.h",
189    out: [
190        "statslog_statsd.cpp",
191    ],
192}
193
194genrule {
195    name: "statslog_statsdtest.h",
196    tools: ["stats-log-api-gen"],
197    cmd: "$(location stats-log-api-gen) " +
198        "--header $(genDir)/statslog_statsdtest.h " +
199        "--module statsdtest " +
200        "--namespace android,os,statsd,util",
201    out: [
202        "statslog_statsdtest.h",
203    ],
204}
205
206genrule {
207    name: "statslog_statsdtest.cpp",
208    tools: ["stats-log-api-gen"],
209    cmd: "$(location stats-log-api-gen) " +
210        "--cpp $(genDir)/statslog_statsdtest.cpp " +
211        "--module statsdtest " +
212        "--namespace android,os,statsd,util " +
213        "--importHeader statslog_statsdtest.h",
214    out: [
215        "statslog_statsdtest.cpp",
216    ],
217}
218
219cc_library_static {
220    name: "libstatslog_statsdtest",
221    generated_sources: ["statslog_statsdtest.cpp"],
222    generated_headers: ["statslog_statsdtest.h"],
223    export_generated_headers: ["statslog_statsdtest.h"],
224    shared_libs: [
225        "libstatssocket",
226        "libstatspull",
227    ],
228}
229
230cc_library_static {
231    name: "libstatslog_statsd",
232    generated_sources: ["statslog_statsd.cpp"],
233    generated_headers: ["statslog_statsd.h"],
234    export_generated_headers: ["statslog_statsd.h"],
235    apex_available: ["com.android.os.statsd"],
236    min_sdk_version: "30",
237    shared_libs: [
238        "libstatssocket",
239        "libstatspull",
240    ],
241    export_shared_lib_headers: [
242        "libstatspull",
243    ],
244}
245
246// =========
247// statsd
248// =========
249
250cc_binary {
251    name: "statsd",
252    defaults: ["statsd_defaults"],
253
254    srcs: ["src/main.cpp"],
255
256    cflags: [
257        "-Wall",
258        "-Wextra",
259        "-Werror",
260        "-Wno-unused-parameter",
261        // "-g",
262        // "-O0",
263    ],
264
265    // optimize for size (protobuf glop can get big)
266    optimize_for_size: true,
267
268    proto: {
269        type: "lite",
270        static: true,
271    },
272    stl: "libc++_static",
273
274    apex_available: [
275        "com.android.os.statsd",
276        "test_com.android.os.statsd",
277    ],
278    runtime_libs: ["libuprobestats_client"],
279    min_sdk_version: "30",
280}
281
282cc_defaults {
283    name: "statsd_test_defaults",
284    defaults: ["statsd_defaults"],
285    srcs: [
286        // atom_field_options.proto needs field_options.proto, but that is
287        // not included in libprotobuf-cpp-lite, so compile it here.
288        ":libprotobuf-internal-protos",
289        ":libstats_internal_protos",
290
291        "src/shell/shell_data.proto",
292        "src/stats_log.proto",
293    ],
294    cflags: [
295        "-Wall",
296        "-Werror",
297        "-Wno-enum-compare",
298        "-Wno-missing-field-initializers",
299        "-Wno-unused-function",
300        "-Wno-unused-parameter",
301        "-Wno-unused-variable",
302    ],
303    static_libs: [
304        "libflagtest",
305        "libgmock",
306        "libstatslog_statsdtest",
307    ],
308    header_libs: [
309        "libstatssocket_test_headers",
310    ],
311    proto: {
312        type: "lite",
313        include_dirs: [
314            "external/protobuf/src",
315            "frameworks/proto_logging/stats",
316        ],
317        static: true,
318    },
319}
320
321cc_library_static {
322    name: "libstats_test_utils",
323    defaults: ["statsd_test_defaults"],
324    srcs: [
325        "tests/metrics/metrics_test_helper.cpp",
326        "tests/metrics/parsing_utils/parsing_test_utils.cpp",
327        "tests/statsd_test_util.cpp",
328    ],
329    tidy_timeout_srcs: [
330        "tests/statsd_test_util.cpp",
331    ],
332}
333
334// ==============
335// statsd_test
336// ==============
337
338filegroup {
339    name: "statsd_test_default_map",
340    srcs: ["statsd_test_default.map"],
341}
342
343cc_test {
344    name: "statsd_test",
345    defaults: ["statsd_test_defaults"],
346    test_suites: [
347        "device-tests",
348        "mts-statsd",
349    ],
350    test_config: "statsd_test.xml",
351
352    //TODO(b/153588990): Remove when the build system properly separates
353    //32bit and 64bit architectures.
354    compile_multilib: "both",
355    multilib: {
356        lib64: {
357            suffix: "64",
358        },
359        lib32: {
360            suffix: "32",
361        },
362    },
363
364    // These tests run on older platform versions, so many libraries (such as libbase and libc++)
365    // need to be linked statically. The tests also need to be linked with a version script to
366    // ensure that the statically-linked library isn't exported from the executable, where it
367    // would override the shared libraries that the platform itself uses.
368    // See http://b/333438055 for an example of what goes wrong when libc++ is partially exported
369    // from an executable.
370    version_script: ":statsd_test_default_map",
371    stl: "c++_static",
372
373    require_root: true,
374
375    tidy_timeout_srcs: [
376        "tests/condition/SimpleConditionTracker_test.cpp",
377        "tests/ConfigManager_test.cpp",
378        "tests/e2e/Anomaly_count_e2e_test.cpp",
379        "tests/e2e/Anomaly_duration_sum_e2e_test.cpp",
380        "tests/e2e/ConfigUpdate_e2e_ab_test.cpp",
381        "tests/e2e/ConfigUpdate_e2e_test.cpp",
382        "tests/e2e/CountMetric_e2e_test.cpp",
383        "tests/e2e/DurationMetric_e2e_test.cpp",
384        "tests/e2e/GaugeMetric_e2e_pull_test.cpp",
385        "tests/e2e/MetricActivation_e2e_test.cpp",
386        "tests/e2e/PartialBucket_e2e_test.cpp",
387        "tests/e2e/ValueMetric_pull_e2e_test.cpp",
388        "tests/e2e/WakelockDuration_e2e_test.cpp",
389        "tests/external/puller_util_test.cpp",
390        "tests/external/StatsPuller_test.cpp",
391        "tests/FieldValue_test.cpp",
392        "tests/guardrail/StatsdStats_test.cpp",
393        "tests/LogEvent_test.cpp",
394        "tests/metrics/CountMetricProducer_test.cpp",
395        "tests/metrics/DurationMetricProducer_test.cpp",
396        "tests/metrics/EventMetricProducer_test.cpp",
397        "tests/metrics/GaugeMetricProducer_test.cpp",
398        "tests/metrics/KllMetricProducer_test.cpp",
399        "tests/metrics/MaxDurationTracker_test.cpp",
400        "tests/metrics/NumericValueMetricProducer_test.cpp",
401        "tests/metrics/OringDurationTracker_test.cpp",
402        "tests/metrics/RestrictedEventMetricProducer_test.cpp",
403        "tests/MetricsManager_test.cpp",
404        "tests/metrics/parsing_utils/config_update_utils_test.cpp",
405        "tests/metrics/parsing_utils/metrics_manager_util_test.cpp",
406        "tests/state/StateTracker_test.cpp",
407        "tests/StatsLogProcessor_test.cpp",
408        "tests/UidMap_test.cpp",
409    ],
410
411    srcs: [
412        "tests/AlarmMonitor_test.cpp",
413        "tests/anomaly/AlarmTracker_test.cpp",
414        "tests/anomaly/AnomalyTracker_test.cpp",
415        "tests/condition/CombinationConditionTracker_test.cpp",
416        "tests/condition/ConditionTimer_test.cpp",
417        "tests/condition/SimpleConditionTracker_test.cpp",
418        "tests/ConfigManager_test.cpp",
419        "tests/e2e/Alarm_e2e_test.cpp",
420        "tests/e2e/Anomaly_count_e2e_test.cpp",
421        "tests/e2e/Anomaly_duration_sum_e2e_test.cpp",
422        "tests/e2e/Attribution_e2e_test.cpp",
423        "tests/e2e/ConfigTtl_e2e_test.cpp",
424        "tests/e2e/ConfigUpdate_e2e_ab_test.cpp",
425        "tests/e2e/ConfigUpdate_e2e_test.cpp",
426        "tests/e2e/CountMetric_e2e_test.cpp",
427        "tests/e2e/DurationMetric_e2e_test.cpp",
428        "tests/e2e/EventMetric_e2e_test.cpp",
429        "tests/e2e/GaugeMetric_e2e_pull_test.cpp",
430        "tests/e2e/GaugeMetric_e2e_push_test.cpp",
431        "tests/e2e/KllMetric_e2e_test.cpp",
432        "tests/e2e/MetricActivation_e2e_test.cpp",
433        "tests/e2e/MetricConditionLink_e2e_test.cpp",
434        "tests/e2e/PartialBucket_e2e_test.cpp",
435        "tests/e2e/RestrictedConfig_e2e_test.cpp",
436        "tests/e2e/RestrictedEventMetric_e2e_test.cpp",
437        "tests/e2e/StringReplace_e2e_test.cpp",
438        "tests/e2e/ValueMetric_histogram_e2e_test.cpp",
439        "tests/e2e/ValueMetric_pull_e2e_test.cpp",
440        "tests/e2e/WakelockDuration_e2e_test.cpp",
441        "tests/external/puller_util_test.cpp",
442        "tests/external/StatsCallbackPuller_test.cpp",
443        "tests/external/StatsPuller_test.cpp",
444        "tests/external/StatsPullerManager_test.cpp",
445        "tests/FieldValue_test.cpp",
446        "tests/flags/FlagProvider_test.cpp",
447        "tests/guardrail/StatsdStats_test.cpp",
448        "tests/HashableDimensionKey_test.cpp",
449        "tests/indexed_priority_queue_test.cpp",
450        "tests/log_event/LogEventQueue_test.cpp",
451        "tests/LogEntryMatcher_test.cpp",
452        "tests/LogEvent_test.cpp",
453        "tests/metadata_util_test.cpp",
454        "tests/metrics/CountMetricProducer_test.cpp",
455        "tests/metrics/DurationMetricProducer_test.cpp",
456        "tests/metrics/EventMetricProducer_test.cpp",
457        "tests/metrics/GaugeMetricProducer_test.cpp",
458        "tests/metrics/HistogramValue_test.cpp",
459        "tests/metrics/KllMetricProducer_test.cpp",
460        "tests/metrics/MaxDurationTracker_test.cpp",
461        "tests/metrics/OringDurationTracker_test.cpp",
462        "tests/metrics/NumericValueMetricProducer_test.cpp",
463        "tests/metrics/RestrictedEventMetricProducer_test.cpp",
464        "tests/metrics/parsing_utils/config_update_utils_test.cpp",
465        "tests/metrics/parsing_utils/histogram_parsing_utils_test.cpp",
466        "tests/metrics/parsing_utils/metrics_manager_util_test.cpp",
467        "tests/subscriber/SubscriberReporter_test.cpp",
468        "tests/DataCorruptionReason_test.cpp",
469        "tests/LogEventFilter_test.cpp",
470        "tests/MetricsManager_test.cpp",
471        "tests/shell/ShellSubscriber_test.cpp",
472        "tests/state/StateTracker_test.cpp",
473        "tests/statsd_test_util_test.cpp",
474        "tests/SocketListener_test.cpp",
475        "tests/StatsLogProcessor_test.cpp",
476        "tests/StatsService_test.cpp",
477        "tests/storage/StorageManager_test.cpp",
478        "tests/UidMap_test.cpp",
479        "tests/utils/DbUtils_test.cpp",
480        "tests/utils/MultiConditionTrigger_test.cpp",
481    ],
482
483    static_libs: [
484        "libstatsgtestmatchers",
485        "libstats_test_utils",
486    ],
487
488    min_sdk_version: "30",
489}
490
491//#############################
492// statsd micro benchmark
493//#############################
494
495cc_benchmark {
496    name: "statsd_benchmark",
497    defaults: ["statsd_test_defaults"],
498
499    srcs: [
500        "benchmark/data_structures_benchmark.cpp",
501        "benchmark/db_benchmark.cpp",
502        "benchmark/duration_metric_benchmark.cpp",
503        "benchmark/filter_value_benchmark.cpp",
504        "benchmark/get_dimensions_for_condition_benchmark.cpp",
505        "benchmark/hello_world_benchmark.cpp",
506        "benchmark/log_event_benchmark.cpp",
507        "benchmark/log_event_filter_benchmark.cpp",
508        "benchmark/loss_info_container_benchmark.cpp",
509        "benchmark/main.cpp",
510        "benchmark/on_log_event_benchmark.cpp",
511        "benchmark/stats_write_benchmark.cpp",
512        "benchmark/string_transform_benchmark.cpp",
513        "benchmark/tex_metric_benchmark.cpp",
514        "benchmark/utils.cpp",
515        "benchmark/value_metric_benchmark.cpp",
516    ],
517
518    cflags: [
519        // Bug: http://b/29823425 Disable -Wvarargs for Clang update to r271374
520        "-Wno-varargs",
521    ],
522
523    test_config: "benchmark/AndroidTest.xml",
524
525    static_libs: [
526        "libgtest",
527        "libstats_test_utils",
528    ],
529
530}
531
532// ====  java proto device library (for test only)  ==============================
533java_library {
534    name: "statsdprotolite",
535    sdk_version: "core_current",
536    proto: {
537        type: "lite",
538        include_dirs: [
539            "external/protobuf/src",
540            "frameworks/proto_logging/stats",
541        ],
542    },
543
544    srcs: [
545        ":libstats_atoms_proto",
546        "src/shell/shell_config.proto",
547        "src/shell/shell_data.proto",
548        "src/stats_log.proto",
549        "src/statsd_config.proto",
550        "src/guardrail/stats_log_enums.proto",
551    ],
552
553    static_libs: [
554        "platformprotoslite",
555    ],
556    // Protos have lots of MissingOverride and similar.
557    errorprone: {
558        javacflags: ["-XepDisableAllChecks"],
559    },
560}
561
562java_library {
563    name: "statsdprotonano",
564    sdk_version: "9",
565    proto: {
566        type: "nano",
567        output_params: ["store_unknown_fields=true"],
568        include_dirs: [
569            "external/protobuf/src",
570            "frameworks/proto_logging/stats",
571        ],
572    },
573    srcs: [
574        ":libstats_atoms_proto",
575        "src/shell/shell_config.proto",
576        "src/shell/shell_data.proto",
577        "src/stats_log.proto",
578        "src/statsd_config.proto",
579        "src/guardrail/stats_log_enums.proto",
580    ],
581    static_libs: [
582        "platformprotosnano",
583    ],
584    // Protos have lots of MissingOverride and similar.
585    errorprone: {
586        javacflags: ["-XepDisableAllChecks"],
587    },
588}
589
590// Filegroup for statsd config proto definition.
591filegroup {
592    name: "libstats_config_protos",
593    srcs: ["src/statsd_config.proto"],
594}
595
596// Filegroup for statsd report protos.
597filegroup {
598    name: "libstats_log_protos",
599    srcs: [
600        "src/stats_log.proto",
601        "src/guardrail/stats_log_enums.proto",
602    ],
603}
604
605// Filegroup for all statsd protos
606filegroup {
607    name: "statsd_internal_protos",
608    srcs: [
609        "src/active_config_list.proto",
610        "src/experiment_ids.proto",
611        "src/shell/shell_config.proto",
612        "src/shell/shell_data.proto",
613        "src/statsd_config.proto",
614        "src/statsd_metadata.proto",
615        "src/stats_log.proto",
616        "src/uid_data.proto",
617        "src/guardrail/stats_log_enums.proto",
618    ],
619}
620
621cc_fuzz {
622    name: "statsd_service_fuzzer",
623    defaults: [
624        "statsd_defaults",
625        "service_fuzzer_defaults",
626        "fuzzer_disable_leaks",
627    ],
628    srcs: [
629        "fuzzers/statsd_service_fuzzer.cpp",
630    ],
631    shared_libs: [
632        "libvndksupport",
633    ],
634    cflags: [
635        "-Wall",
636        "-Wextra",
637        "-Werror",
638        "-Wno-unused-parameter",
639    ],
640    fuzz_config: {
641        triage_assignee: "waghpawan@google.com",
642        cc: [
643            "singhtejinder@google.com",
644            "sharaienko@google.com",
645        ],
646    },
647    proto: {
648        type: "lite",
649        static: true,
650    },
651}
652
653cc_fuzz {
654    name: "statsd_fuzzer",
655    defaults: [
656        "statsd_defaults",
657    ],
658    srcs: [
659        "fuzzers/statsd_socket_data_fuzzer.cpp",
660    ],
661    cflags: [
662        "-Wall",
663        "-Wextra",
664        "-Werror",
665        "-Wno-unused-parameter",
666    ],
667    fuzz_config: {
668        cc: [
669            "singhtejinder@google.com",
670            "sharaienko@google.com",
671        ],
672    },
673    proto: {
674        type: "lite",
675        static: true,
676    },
677}
678
679// Filegroup for subscription protos.
680filegroup {
681    name: "libstats_subscription_protos",
682    srcs: [
683        ":libstats_internal_protos",
684        ":libstats_config_protos",
685        "src/shell/shell_config.proto",
686        "src/shell/shell_data.proto",
687    ],
688}
689