xref: /aosp_15_r20/system/extras/simpleperf/Android.bp (revision 288bf5226967eb3dac5cce6c939ccc2a7f2b4fe5)
1//
2// Copyright (C) 2018 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_team: "trendy_team_llvm_and_toolchains",
19    default_applicable_licenses: ["system_extras_simpleperf_license"],
20}
21
22// Added automatically by a large-scale-change
23// See: http://go/android-license-faq
24license {
25    name: "system_extras_simpleperf_license",
26    visibility: [":__subpackages__"],
27    license_kinds: [
28        "SPDX-license-identifier-Apache-2.0",
29    ],
30    license_text: [
31        "NOTICE",
32    ],
33}
34
35cc_defaults {
36    name: "libsimpleperf_readelf_defaults",
37    static_libs: [
38        "libsimpleperf_readelf",
39    ],
40    target: {
41        linux: {
42            ldflags: ["-Wl,--exclude-libs=libsimpleperf_readelf.a"],
43        },
44        windows: {
45            host_ldlibs: [
46                "-lole32",
47                "-luuid",
48            ],
49        },
50    },
51    sanitize: {
52        hwaddress: false,
53    },
54}
55
56cc_defaults {
57    name: "simpleperf_cflags",
58    target: {
59        host: {
60            cflags: [
61                "-DUSE_BIONIC_UAPI_HEADERS",
62                "-fvisibility=hidden",
63            ],
64            compile_multilib: "64",
65            include_dirs: ["bionic/libc/kernel"],
66        },
67        darwin: {
68            cflags: ["-DNO_LIBDEXFILE_SUPPORT"],
69            local_include_dirs: ["nonlinux_support/include"],
70        },
71        windows: {
72            cflags: ["-DNO_LIBDEXFILE_SUPPORT"],
73            local_include_dirs: ["nonlinux_support/include"],
74        },
75        android: {
76            compile_multilib: "both",
77        },
78    },
79}
80
81// linked as a separate library because using OpenCSD headers needs to enable exception
82cc_library_static {
83    name: "libsimpleperf_etm_decoder",
84    defaults: [
85        "simpleperf_cflags",
86        "libsimpleperf_readelf_defaults",
87    ],
88    host_supported: true,
89    srcs: ["ETMDecoder.cpp"],
90    cppflags: [
91        // flags needed to include libopencsd_decoder headers
92        "-Wno-ignored-qualifiers",
93        "-Wno-unused-parameter",
94        "-Wno-switch",
95        "-Wno-unused-private-field",
96        "-Wno-implicit-fallthrough",
97        "-fexceptions",
98    ],
99    rtti: true,
100    static_libs: [
101        "libopencsd_decoder",
102        "libbase",
103        "liblog",
104    ],
105    target: {
106        windows: {
107            enabled: true,
108        },
109    },
110}
111
112// Build regex support in a separate library to catch std::regex_error exception.
113cc_library_static {
114    name: "libsimpleperf_regex",
115    host_supported: true,
116    srcs: ["RegEx.cpp"],
117    cppflags: ["-fexceptions"],
118    static_libs: ["libbase"],
119    target: {
120        windows: {
121            enabled: true,
122        },
123    },
124}
125
126cc_defaults {
127    name: "simpleperf_static_libs",
128    defaults: [
129        "libsimpleperf_readelf_defaults",
130        "simpleperf_cflags",
131    ],
132    host_supported: true,
133    static_libs: [
134        "libsimpleperf_etm_decoder",
135        "libsimpleperf_regex",
136        "libbase",
137        "liblog",
138        "liblzma",
139        "libutils",
140        "libprotobuf-cpp-lite",
141        "libopencsd_decoder",
142        "libz",
143        "libziparchive",
144        "libzstd",
145    ],
146    target: {
147        host: {
148            stl: "libc++_static",
149        },
150        linux: {
151            static_libs: [
152                "libunwindstack",
153                "libcutils",
154                "libprocinfo",
155                "libevent",
156                "librustc_demangle_static",
157            ],
158        },
159        windows: {
160            enabled: true,
161        },
162    },
163    use_version_lib: true,
164}
165
166cc_defaults {
167    name: "simpleperf_shared_libs",
168    defaults: [
169        "simpleperf_cflags",
170        "libsimpleperf_readelf_defaults",
171    ],
172    host_supported: true,
173    shared_libs: [
174        "libbase",
175        "liblog",
176        "liblzma",
177        "libprotobuf-cpp-lite",
178        "libz",
179        "libziparchive",
180    ],
181    static_libs: [
182        "libsimpleperf_etm_decoder",
183        "libsimpleperf_regex",
184        "libopencsd_decoder",
185        "libzstd",
186    ],
187    target: {
188        linux: {
189            shared_libs: [
190                "libcutils",
191                "libevent",
192                "libprocinfo",
193                "libunwindstack",
194            ],
195            static_libs: [
196                "libdexfile_support",
197                "librustc_demangle_static",
198            ],
199            runtime_libs: [
200                "libdexfile", // libdexfile_support dependency
201            ],
202        },
203        windows: {
204            enabled: true,
205        },
206    },
207    use_version_lib: true,
208}
209
210python_binary_host {
211    name: "event_table_generator",
212    srcs: ["event_table_generator.py"],
213}
214
215genrule {
216    name: "simpleperf_event_table",
217    out: ["event_table.cpp"],
218    srcs: ["event_table.json"],
219    tools: ["event_table_generator"],
220    cmd: "$(location event_table_generator) $(in) $(out)",
221}
222
223cc_defaults {
224    name: "libsimpleperf_srcs",
225    srcs: [
226        "cmd_dumprecord.cpp",
227        "cmd_help.cpp",
228        "cmd_inject.cpp",
229        "cmd_kmem.cpp",
230        "cmd_merge.cpp",
231        "cmd_report.cpp",
232        "cmd_report_sample.cpp",
233        "cmd_report_sample.proto",
234        "command.cpp",
235        "dso.cpp",
236        "branch_list.proto",
237        "BranchListFile.cpp",
238        "event_attr.cpp",
239        "event_type.cpp",
240        "kallsyms.cpp",
241        "perf_regs.cpp",
242        "read_apk.cpp",
243        "read_elf.cpp",
244        "read_symbol_map.cpp",
245        "record.cpp",
246        "RecordFilter.cpp",
247        "record_file.proto",
248        "record_file_reader.cpp",
249        "record_file_writer.cpp",
250        "report_utils.cpp",
251        "thread_tree.cpp",
252        "tracing.cpp",
253        "utils.cpp",
254        "ZstdUtil.cpp",
255        ":simpleperf_event_table",
256    ],
257    target: {
258        android: {
259            srcs: [
260                "cmd_boot_record.cpp",
261            ],
262        },
263        linux: {
264            srcs: [
265                "CallChainJoiner.cpp",
266                "cmd_api.cpp",
267                "cmd_debug_unwind.cpp",
268                "cmd_list.cpp",
269                "cmd_monitor.cpp",
270                "cmd_record.cpp",
271                "cmd_stat.cpp",
272                "cmd_trace_sched.cpp",
273                "environment.cpp",
274                "ETMRecorder.cpp",
275                "event_fd.cpp",
276                "event_selection_set.cpp",
277                "IOEventLoop.cpp",
278                "JITDebugReader.cpp",
279                "MapRecordReader.cpp",
280                "OfflineUnwinder.cpp",
281                "ProbeEvents.cpp",
282                "read_dex_file.cpp",
283                "RecordReadThread.cpp",
284                "workload.cpp",
285            ],
286        },
287        darwin: {
288            srcs: ["nonlinux_support/nonlinux_support.cpp"],
289        },
290        windows: {
291            srcs: ["nonlinux_support/nonlinux_support.cpp"],
292        },
293    },
294}
295
296cc_library_static {
297    name: "libsimpleperf",
298    defaults: [
299        "libsimpleperf_srcs",
300        "simpleperf_static_libs",
301    ],
302    proto: {
303        type: "lite",
304    },
305    static_libs: [
306        "libbuildversion",
307    ],
308    use_version_lib: false,
309
310    target: {
311        linux: {
312            // See note for libdexfile_static in simpleperf_ndk.
313            static_libs: ["libdexfile_support"],
314            runtime_libs: ["libdexfile"], // libdexfile_support dependency
315        },
316    },
317}
318
319// simpleperf shipped in system image
320cc_binary {
321    name: "simpleperf",
322    defaults: [
323        "simpleperf_shared_libs",
324    ],
325    host_supported: false,
326    srcs: [
327        "main.cpp",
328    ],
329    static_libs: ["libsimpleperf"],
330    target: {
331        android: {
332            compile_multilib: "first",
333        },
334    },
335    init_rc: ["simpleperf.rc"],
336}
337
338cc_library {
339    name: "libsimpleperf_profcollect",
340    defaults: ["simpleperf_shared_libs"],
341    srcs: ["profcollect.cpp"],
342    host_supported: false,
343    ldflags: ["-Wl,--exclude-libs=ALL"],
344    static_libs: ["libsimpleperf"],
345    shared_libs: [
346        "libpower",
347    ],
348}
349
350rust_bindgen {
351    name: "libsimpleperf_profcollect_bindgen",
352    wrapper_src: "include/simpleperf_profcollect.hpp",
353    crate_name: "simpleperf_profcollect_bindgen",
354    source_stem: "bindings",
355}
356
357rust_library {
358    name: "libsimpleperf_profcollect_rust",
359    crate_name: "simpleperf_profcollect",
360    srcs: ["rust/lib.rs"],
361    rlibs: ["libsimpleperf_profcollect_bindgen"],
362    shared_libs: ["libsimpleperf_profcollect"],
363    visibility: ["//system/extras/profcollectd:__subpackages__"],
364}
365
366rust_test {
367    name: "libsimpleperf_profcollect_bindgen_test",
368    srcs: [":libsimpleperf_profcollect_bindgen"],
369    crate_name: "simpleperf_profcollect_bindgen_test",
370    test_suites: ["general-tests"],
371    auto_gen_config: true,
372    clippy_lints: "none",
373    lints: "none",
374}
375
376// simpleperf released in ndk
377cc_binary {
378    name: "simpleperf_ndk",
379    defaults: [
380        "simpleperf_static_libs",
381    ],
382    dist: {
383        targets: ["simpleperf"],
384    },
385    multilib: {
386        lib32: {
387            suffix: "32",
388        },
389    },
390    srcs: [
391        "main.cpp",
392    ],
393    static_libs: [
394        "libsimpleperf",
395    ],
396
397    target: {
398        android: {
399            static_executable: true,
400            static_libs: [
401                "libc",
402            ],
403        },
404        android_arm: {
405            dist: {
406                dir: "simpleperf/android/arm",
407            },
408        },
409        android_arm64: {
410            dist: {
411                dir: "simpleperf/android/arm64",
412            },
413        },
414        android_x86: {
415            dist: {
416                dir: "simpleperf/android/x86",
417            },
418        },
419        android_x86_64: {
420            dist: {
421                dir: "simpleperf/android/x86_64",
422            },
423        },
424        host: {
425            stem: "simpleperf",
426        },
427        darwin: {
428            dist: {
429                dir: "simpleperf/darwin/x86",
430            },
431        },
432        darwin_x86_64: {
433            dist: {
434                dir: "simpleperf/darwin/x86_64",
435            },
436        },
437        linux: {
438            // In the NDK we need libdexfile_static which links libdexfile and
439            // its ART dependencies statically. However in other libraries we
440            // must use libdexfile_support, which dlopen's libdexfile.so from
441            // the ART APEX, to avoid getting ART internals in the system image.
442            static_libs: ["libdexfile_static"],
443        },
444        linux_glibc_x86: {
445            dist: {
446                dir: "simpleperf/linux/x86",
447            },
448        },
449        linux_glibc_x86_64: {
450            dist: {
451                dir: "simpleperf/linux/x86_64",
452            },
453        },
454        linux_musl_x86: {
455            dist: {
456                dir: "simpleperf/linux_musl/x86",
457            },
458        },
459        linux_musl_x86_64: {
460            dist: {
461                dir: "simpleperf/linux_musl/x86_64",
462            },
463        },
464        windows_x86: {
465            dist: {
466                dir: "simpleperf/windows/x86",
467            },
468        },
469        windows_x86_64: {
470            dist: {
471                dir: "simpleperf/windows/x86_64",
472            },
473        },
474    },
475}
476
477// It's linked to user's program, to get profile counters and samples for specific code ranges.
478cc_library {
479    name: "libsimpleperf_record",
480    defaults: [
481        "simpleperf_static_libs",
482    ],
483    export_include_dirs: ["include"],
484    ldflags: ["-Wl,--exclude-libs,ALL"],
485    srcs: [
486        "record_lib_interface.cpp",
487    ],
488    static_libs: [
489        "libsimpleperf",
490    ],
491    target: {
492        darwin: {
493            enabled: false,
494        },
495        windows: {
496            enabled: false,
497        },
498        linux: {
499            // See note for libdexfile_static in simpleperf_ndk.
500            static_libs: ["libdexfile_static"],
501        },
502    },
503}
504
505// It's the shared library used on host by python scripts to report samples in different ways.
506cc_library_shared {
507    name: "libsimpleperf_report",
508    defaults: [
509        "simpleperf_static_libs",
510    ],
511    dist: {
512        targets: ["simpleperf"],
513    },
514    srcs: [
515        "report_lib_interface.cpp",
516    ],
517    static_libs: ["libsimpleperf"],
518
519    target: {
520        android: {
521            enabled: false,
522        },
523        linux: {
524            ldflags: ["-Wl,--exclude-libs,ALL"],
525            // See note for libdexfile_static in simpleperf_ndk.
526            static_libs: ["libdexfile_static"],
527        },
528        darwin: {
529            dist: {
530                dir: "simpleperf/darwin/x86",
531            },
532        },
533        darwin_x86_64: {
534            dist: {
535                dir: "simpleperf/darwin/x86_64",
536            },
537        },
538        linux_glibc_x86: {
539            dist: {
540                dir: "simpleperf/linux/x86",
541            },
542        },
543        linux_glibc_x86_64: {
544            dist: {
545                dir: "simpleperf/linux/x86_64",
546            },
547        },
548        linux_musl_x86: {
549            dist: {
550                dir: "simpleperf/linux_musl/x86",
551            },
552        },
553        linux_musl_x86_64: {
554            dist: {
555                dir: "simpleperf/linux_musl/x86_64",
556            },
557        },
558        windows_x86: {
559            dist: {
560                dir: "simpleperf/windows/x86",
561            },
562        },
563        windows_x86_64: {
564            dist: {
565                dir: "simpleperf/windows/x86_64",
566            },
567        },
568    },
569}
570
571cc_defaults {
572    name: "simpleperf_test_srcs",
573    tidy_timeout_srcs: [
574        "record_test.cpp",
575        "cmd_report_sample_test.cpp",
576        "cmd_report_test.cpp",
577    ],
578    srcs: [
579        "BranchListFile_test.cpp",
580        "cmd_inject_test.cpp",
581        "cmd_kmem_test.cpp",
582        "cmd_merge_test.cpp",
583        "cmd_report_test.cpp",
584        "cmd_report_sample_test.cpp",
585        "command_test.cpp",
586        "dso_test.cpp",
587        "gtest_main.cpp",
588        "kallsyms_test.cpp",
589        "perf_regs_test.cpp",
590        "read_apk_test.cpp",
591        "read_elf_test.cpp",
592        "read_symbol_map_test.cpp",
593        "RecordFilter_test.cpp",
594        "RegEx_test.cpp",
595        "record_file_test.cpp",
596        "record_test.cpp",
597        "report_utils_test.cpp",
598        "sample_tree_test.cpp",
599        "thread_tree_test.cpp",
600        "test_util.cpp",
601        "tracing_test.cpp",
602        "utils_test.cpp",
603        "ZstdUtil_test.cpp",
604    ],
605    target: {
606        android: {
607            srcs: [
608                "cmd_boot_record_test.cpp",
609            ],
610        },
611        linux: {
612            tidy_timeout_srcs: [
613                "cmd_stat_test.cpp",
614                "cmd_record_test.cpp",
615            ],
616            srcs: [
617                "CallChainJoiner_test.cpp",
618                "cmd_api_test.cpp",
619                "cmd_debug_unwind_test.cpp",
620                "cmd_dumprecord_test.cpp",
621                "cmd_list_test.cpp",
622                "cmd_record_test.cpp",
623                "cmd_monitor_test.cpp",
624                "cmd_stat_test.cpp",
625                "cmd_trace_sched_test.cpp",
626                "environment_test.cpp",
627                "event_selection_set_test.cpp",
628                "IOEventLoop_test.cpp",
629                "JITDebugReader_test.cpp",
630                "MapRecordReader_test.cpp",
631                "OfflineUnwinder_test.cpp",
632                "ProbeEvents_test.cpp",
633                "read_dex_file_test.cpp",
634                "RecordReadThread_test.cpp",
635                "workload_test.cpp",
636            ],
637        },
638    },
639}
640
641cc_test {
642    name: "simpleperf_unit_test",
643    defaults: [
644        "simpleperf_test_srcs",
645        "simpleperf_shared_libs",
646    ],
647    static_libs: [
648        "libgmock",
649        "libsimpleperf",
650    ],
651    target: {
652        android: {
653            test_suites: ["device-tests"],
654        },
655    },
656    data: [
657        "testdata/**/*",
658    ],
659    sanitize: {
660        memtag_heap: false,
661    },
662}
663
664cc_test {
665    name: "simpleperf_cpu_hotplug_test",
666    defaults: [
667        "simpleperf_shared_libs",
668    ],
669    test_options: {
670        unit_test: true,
671    },
672    srcs: [
673        "cpu_hotplug_test.cpp",
674    ],
675    static_libs: ["libsimpleperf"],
676    target: {
677        android: {
678            test_suites: ["device-tests"],
679        },
680        darwin: {
681            enabled: false,
682        },
683        windows: {
684            enabled: false,
685        },
686    },
687}
688
689cc_library_static {
690    name: "libsimpleperf_cts_test",
691    defaults: [
692        "simpleperf_test_srcs",
693        "simpleperf_shared_libs",
694    ],
695    host_supported: false,
696    cflags: [
697        "-DIN_CTS_TEST",
698    ],
699    static_libs: [
700        "libgtest",
701    ],
702    whole_static_libs: [
703        "libgmock",
704        "libsimpleperf",
705        "libsimpleperf_regex",
706    ],
707}
708
709cc_test {
710    name: "simpleperf_record_test",
711    defaults: [
712        "simpleperf_shared_libs",
713    ],
714    srcs: [
715        "record_lib_test.cpp",
716    ],
717    shared_libs: ["libsimpleperf_record"],
718    target: {
719        android: {
720            test_suites: ["device-tests"],
721        },
722        darwin: {
723            enabled: false,
724        },
725        windows: {
726            enabled: false,
727        },
728    },
729}
730
731filegroup {
732    name: "system-extras-simpleperf-testdata",
733    srcs: ["CtsSimpleperfTestCases_testdata/**/*"],
734}
735
736cc_fuzz {
737    name: "libsimpleperf_report_fuzzer",
738    defaults: [
739        "simpleperf_static_libs",
740    ],
741    fuzzing_frameworks: {
742        afl: false,
743    },
744    host_supported: true,
745    srcs: [
746        "libsimpleperf_report_fuzzer.cpp",
747    ],
748    static_libs: [
749        "libsimpleperf",
750    ],
751    target: {
752        linux: {
753            // Fuzzer may not be able to load libdexfile. So statically link it.
754            static_libs: ["libdexfile_static"],
755        },
756        windows: {
757            enabled: false,
758        },
759    },
760    dictionary: "simpleperf_dict.dict",
761    corpus: ["testdata/**/*.data"],
762}
763
764cc_fuzz {
765    name: "simpleperf_writer_fuzzer",
766    defaults: [
767        "simpleperf_static_libs",
768    ],
769    fuzzing_frameworks: {
770        afl: false,
771    },
772    host_supported: true,
773    srcs: [
774        "simpleperf_writer_fuzzer.cpp",
775    ],
776    static_libs: [
777        "libsimpleperf",
778    ],
779    target: {
780        linux: {
781            // Fuzzer may not be able to load libdexfile. So statically link it.
782            static_libs: ["libdexfile_static"],
783        },
784        windows: {
785            enabled: false,
786        },
787    },
788}
789
790genrule {
791    name: "simpleperf_script.zip",
792    tools: [
793        "soong_zip",
794    ],
795    srcs: [
796        "**/*.proto",
797        "app_api/**/*",
798        "doc/**/*",
799        "demo/**/*",
800        "runtest/**/*",
801        "scripts/**/*",
802        "testdata/**/*",
803    ],
804    exclude_srcs: [
805        "scripts/binary_cache/**/*",
806    ],
807    cmd: "$(location soong_zip) -o $(out) -C system/extras/simpleperf " +
808        "-D system/extras/simpleperf ",
809    out: [
810        "simpleperf/simpleperf_script.zip",
811    ],
812    dist: {
813        targets: ["simpleperf"],
814        dir: "simpleperf",
815    },
816}
817