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_applicable_licenses: ["system_extras_simpleperf_license"],
19}
20
21// Added automatically by a large-scale-change
22// See: http://go/android-license-faq
23license {
24    name: "system_extras_simpleperf_license",
25    visibility: [":__subpackages__"],
26    license_kinds: [
27        "SPDX-license-identifier-Apache-2.0",
28    ],
29    license_text: [
30        "NOTICE",
31    ],
32}
33
34cc_defaults {
35    name: "libsimpleperf_elf_read_static_reqs_defaults",
36    static_libs: [
37        "libLLVMObject",
38        "libLLVMBitReader",
39        "libLLVMMC",
40        "libLLVMMCParser",
41        "libLLVMCore",
42        "libLLVMSupport",
43        "liblzma",
44        "libz",
45        "libziparchive",
46    ],
47}
48
49cc_defaults {
50    name: "simpleperf_cflags",
51    target: {
52        host: {
53            cflags: [
54                "-DUSE_BIONIC_UAPI_HEADERS",
55                "-fvisibility=hidden",
56            ],
57            include_dirs: ["bionic/libc/kernel"],
58        },
59        darwin: {
60            cflags: ["-DNO_LIBDEXFILE_SUPPORT"],
61            local_include_dirs: ["nonlinux_support/include"],
62        },
63        windows: {
64            cflags: ["-DNO_LIBDEXFILE_SUPPORT"],
65            local_include_dirs: ["nonlinux_support/include"],
66        },
67    },
68}
69
70// linked as a separate library because using OpenCSD headers needs to enable exception
71cc_library_static {
72    name: "libsimpleperf_etm_decoder",
73    defaults: [
74        "simpleperf_cflags",
75        "libsimpleperf_elf_read_static_reqs_defaults",
76    ],
77    host_supported: true,
78    srcs: ["ETMDecoder.cpp"],
79    cppflags: [
80        // flags needed to include libopencsd_decoder headers
81        "-Wno-ignored-qualifiers",
82        "-Wno-unused-parameter",
83        "-Wno-switch",
84        "-Wno-unused-private-field",
85        "-Wno-implicit-fallthrough",
86        "-fexceptions",
87    ],
88    rtti: true,
89    static_libs: [
90        "libopencsd_decoder",
91        "libbase",
92        "liblog",
93    ],
94    target: {
95        windows: {
96            enabled: true,
97        },
98    },
99}
100
101cc_defaults {
102    name: "simpleperf_static_libs",
103    defaults: [
104        "libsimpleperf_elf_read_static_reqs_defaults",
105        "simpleperf_cflags",
106    ],
107    host_supported: true,
108    static_libs: [
109        "libsimpleperf_etm_decoder",
110        "libbase",
111        "liblog",
112        "libutils",
113        "libprotobuf-cpp-lite",
114        "libopencsd_decoder",
115    ],
116    target: {
117        linux: {
118            static_libs: [
119                "libunwindstack",
120                "libcutils",
121                "libprocinfo",
122                "libevent",
123                "libc++fs",
124            ],
125        },
126        android: {
127            static_libs: [
128                "libc",
129            ],
130        },
131        host: {
132            stl: "libc++_static",
133        },
134        windows: {
135            enabled: true,
136        },
137    },
138    use_version_lib: true,
139}
140
141cc_defaults {
142    name: "simpleperf_shared_libs",
143    defaults: [
144        "simpleperf_cflags",
145    ],
146    host_supported: true,
147    shared_libs: [
148        "libbase",
149        "liblzma",
150        "libprotobuf-cpp-lite",
151        "libziparchive",
152    ],
153    static_libs: [
154        "libsimpleperf_etm_decoder",
155        "libopencsd_decoder",
156    ],
157    target: {
158        linux: {
159            shared_libs: [
160                "libcutils",
161                "libevent",
162                "liblog",
163                "libprocinfo",
164                "libunwindstack",
165            ],
166            static_libs: [
167                "libc++fs",
168                "libdexfile_support",
169            ],
170        },
171        host: {
172            static_libs: [
173                "libLLVMObject",
174                "libLLVMBitReader",
175                "libLLVMMC",
176                "libLLVMMCParser",
177                "libLLVMCore",
178                "libLLVMSupport",
179            ],
180        },
181        windows: {
182            enabled: true,
183        },
184    },
185    use_version_lib: true,
186}
187
188cc_defaults {
189    name: "simpleperf_libs_for_tests",
190    defaults: ["simpleperf_shared_libs"],
191    target: {
192        android: {
193            // 32-bit libLLVM_android isn't shipped on device. So use static llvm libs in tests.
194            static_libs: [
195                "libLLVMObject",
196                "libLLVMBitReader",
197                "libLLVMMC",
198                "libLLVMMCParser",
199                "libLLVMCore",
200                "libLLVMSupport",
201            ],
202        },
203    },
204}
205
206cc_defaults {
207    name: "libsimpleperf_srcs",
208    srcs: [
209        "cmd_dumprecord.cpp",
210        "cmd_help.cpp",
211        "cmd_inject.cpp",
212        "cmd_kmem.cpp",
213        "cmd_merge.cpp",
214        "cmd_report.cpp",
215        "cmd_report_sample.cpp",
216        "cmd_report_sample.proto",
217        "command.cpp",
218        "dso.cpp",
219        "etm_branch_list.proto",
220        "event_attr.cpp",
221        "event_type.cpp",
222        "kallsyms.cpp",
223        "perf_regs.cpp",
224        "read_apk.cpp",
225        "read_elf.cpp",
226        "read_symbol_map.cpp",
227        "record.cpp",
228        "record_file.proto",
229        "record_file_reader.cpp",
230        "record_file_writer.cpp",
231        "report_utils.cpp",
232        "thread_tree.cpp",
233        "tracing.cpp",
234        "utils.cpp",
235    ],
236    target: {
237        linux: {
238            srcs: [
239                "CallChainJoiner.cpp",
240                "cmd_api.cpp",
241                "cmd_debug_unwind.cpp",
242                "cmd_list.cpp",
243                "cmd_monitor.cpp",
244                "cmd_record.cpp",
245                "cmd_stat.cpp",
246                "cmd_trace_sched.cpp",
247                "environment.cpp",
248                "ETMRecorder.cpp",
249                "event_fd.cpp",
250                "event_selection_set.cpp",
251                "IOEventLoop.cpp",
252                "JITDebugReader.cpp",
253                "MapRecordReader.cpp",
254                "OfflineUnwinder.cpp",
255                "ProbeEvents.cpp",
256                "read_dex_file.cpp",
257                "RecordFilter.cpp",
258                "RecordReadThread.cpp",
259                "workload.cpp",
260            ],
261        },
262        darwin: {
263            srcs: ["nonlinux_support/nonlinux_support.cpp"],
264        },
265        windows: {
266            srcs: ["nonlinux_support/nonlinux_support.cpp"],
267        },
268    },
269}
270
271cc_library_static {
272    name: "libsimpleperf",
273    defaults: [
274        "libsimpleperf_srcs",
275        "simpleperf_static_libs",
276    ],
277    compile_multilib: "both",
278    proto: {
279        type: "lite",
280    },
281    static_libs: [
282        "libbuildversion",
283    ],
284    use_version_lib: false,
285
286    target: {
287        linux: {
288            // See note for libdexfile_static in simpleperf_ndk.
289            static_libs: ["libdexfile_support"],
290        },
291    },
292}
293
294// simpleperf shipped in system image
295cc_binary {
296    name: "simpleperf",
297    defaults: [
298        "simpleperf_shared_libs",
299    ],
300    host_supported: false,
301    srcs: [
302        "main.cpp",
303    ],
304    static_libs: ["libsimpleperf"],
305    target: {
306        android: {
307            shared_libs: [
308                "libLLVM_android",
309            ],
310        },
311    },
312}
313
314cc_library {
315    name: "libsimpleperf_profcollect",
316    defaults: ["simpleperf_shared_libs"],
317    srcs: ["profcollect.cpp"],
318    host_supported: false,
319    static_libs: ["libsimpleperf"],
320    shared_libs: ["libLLVM_android"],
321}
322
323rust_bindgen {
324    name: "libsimpleperf_profcollect_bindgen",
325    wrapper_src: "include/simpleperf_profcollect.hpp",
326    crate_name: "simpleperf_profcollect_bindgen",
327    source_stem: "bindings",
328}
329
330rust_library {
331    name: "libsimpleperf_profcollect_rust",
332    crate_name: "simpleperf_profcollect",
333    srcs: ["rust/lib.rs"],
334    rlibs: ["libsimpleperf_profcollect_bindgen"],
335    shared_libs: ["libsimpleperf_profcollect"],
336    visibility: ["//system/extras/profcollectd:__subpackages__"],
337}
338
339// simpleperf released in ndk
340cc_binary {
341    name: "simpleperf_ndk",
342    defaults: [
343        "simpleperf_static_libs",
344    ],
345    dist: {
346        targets: ["simpleperf"],
347    },
348    srcs: [
349        "main.cpp",
350    ],
351    static_libs: [
352        "libsimpleperf",
353    ],
354
355    compile_multilib: "both",
356    multilib: {
357        lib64: {
358            suffix: "64",
359        },
360    },
361
362    target: {
363        android: {
364            static_executable: true,
365        },
366        android_arm: {
367            dist: {
368                dir: "simpleperf/android/arm",
369            },
370        },
371        android_arm64: {
372            dist: {
373                dir: "simpleperf/android/arm64",
374            },
375        },
376        android_x86: {
377            dist: {
378                dir: "simpleperf/android/x86",
379            },
380        },
381        android_x86_64: {
382            dist: {
383                dir: "simpleperf/android/x86_64",
384            },
385        },
386        darwin: {
387            dist: {
388                dir: "simpleperf/darwin/x86",
389            },
390        },
391        darwin_x86_64: {
392            dist: {
393                dir: "simpleperf/darwin/x86_64",
394            },
395        },
396        linux: {
397            // In the NDK we need libdexfile_static which links libdexfile and
398            // its ART dependencies statically. However in other libraries we
399            // must use libdexfile_support, which dlopen's libdexfile.so from
400            // the ART APEX, to avoid getting ART internals in the system image.
401            static_libs: ["libdexfile_static"],
402        },
403        linux_glibc_x86: {
404            dist: {
405                dir: "simpleperf/linux/x86",
406            },
407        },
408        linux_glibc_x86_64: {
409            dist: {
410                dir: "simpleperf/linux/x86_64",
411            },
412        },
413        windows_x86: {
414            dist: {
415                dir: "simpleperf/windows/x86",
416            },
417        },
418        windows_x86_64: {
419            dist: {
420                dir: "simpleperf/windows/x86_64",
421            },
422        },
423    },
424}
425
426// It's linked to user's program, to get profile counters and samples for specific code ranges.
427cc_library {
428    name: "libsimpleperf_record",
429    defaults: [
430        "simpleperf_static_libs",
431    ],
432    export_include_dirs: ["include"],
433    ldflags: ["-Wl,--exclude-libs,ALL"],
434    srcs: [
435        "record_lib_interface.cpp",
436    ],
437    static_libs: [
438        "libsimpleperf",
439    ],
440    target: {
441        darwin: {
442            enabled: false,
443        },
444        windows: {
445            enabled: false,
446        },
447        linux: {
448            // See note for libdexfile_static in simpleperf_ndk.
449            static_libs: ["libdexfile_static"],
450        },
451    },
452}
453
454// It's the shared library used on host by python scripts to report samples in different ways.
455cc_library_shared {
456    name: "libsimpleperf_report",
457    defaults: [
458        "simpleperf_static_libs",
459    ],
460    dist: {
461        targets: ["simpleperf"],
462    },
463    srcs: [
464        "report_lib_interface.cpp",
465    ],
466    static_libs: ["libsimpleperf"],
467
468    target: {
469        android: {
470            enabled: false,
471        },
472        linux: {
473            ldflags: ["-Wl,--exclude-libs,ALL"],
474            // See note for libdexfile_static in simpleperf_ndk.
475            static_libs: ["libdexfile_static"],
476        },
477        darwin: {
478            dist: {
479                dir: "simpleperf/darwin/x86",
480            },
481        },
482        darwin_x86_64: {
483            dist: {
484                dir: "simpleperf/darwin/x86_64",
485            },
486        },
487        linux_glibc_x86: {
488            dist: {
489                dir: "simpleperf/linux/x86",
490            },
491        },
492        linux_glibc_x86_64: {
493            dist: {
494                dir: "simpleperf/linux/x86_64",
495            },
496        },
497        windows_x86: {
498            dist: {
499                dir: "simpleperf/windows/x86",
500            },
501        },
502        windows_x86_64: {
503            dist: {
504                dir: "simpleperf/windows/x86_64",
505            },
506        },
507    },
508}
509
510cc_defaults {
511    name: "simpleperf_test_srcs",
512    srcs: [
513        "cmd_inject_test.cpp",
514        "cmd_kmem_test.cpp",
515        "cmd_merge_test.cpp",
516        "cmd_report_test.cpp",
517        "cmd_report_sample_test.cpp",
518        "command_test.cpp",
519        "dso_test.cpp",
520        "gtest_main.cpp",
521        "kallsyms_test.cpp",
522        "perf_regs_test.cpp",
523        "read_apk_test.cpp",
524        "read_elf_test.cpp",
525        "read_symbol_map_test.cpp",
526        "record_file_test.cpp",
527        "record_test.cpp",
528        "report_utils_test.cpp",
529        "sample_tree_test.cpp",
530        "thread_tree_test.cpp",
531        "test_util.cpp",
532        "tracing_test.cpp",
533        "utils_test.cpp",
534    ],
535    target: {
536        linux: {
537            srcs: [
538                "CallChainJoiner_test.cpp",
539                "cmd_api_test.cpp",
540                "cmd_debug_unwind_test.cpp",
541                "cmd_dumprecord_test.cpp",
542                "cmd_list_test.cpp",
543                "cmd_record_test.cpp",
544                "cmd_monitor_test.cpp",
545                "cmd_stat_test.cpp",
546                "cmd_trace_sched_test.cpp",
547                "environment_test.cpp",
548                "IOEventLoop_test.cpp",
549                "MapRecordReader_test.cpp",
550                "OfflineUnwinder_test.cpp",
551                "ProbeEvents_test.cpp",
552                "read_dex_file_test.cpp",
553                "RecordFilter_test.cpp",
554                "RecordReadThread_test.cpp",
555                "workload_test.cpp",
556            ],
557        },
558    },
559}
560
561cc_test {
562    name: "simpleperf_unit_test",
563    defaults: [
564        "simpleperf_test_srcs",
565        "simpleperf_libs_for_tests",
566    ],
567    static_libs: [
568        "libgmock",
569        "libsimpleperf",
570    ],
571    target: {
572        android: {
573            test_suites: ["device-tests"],
574        },
575    },
576    data: [
577        "testdata/**/*",
578    ],
579}
580
581cc_test {
582    name: "simpleperf_cpu_hotplug_test",
583    defaults: [
584        "simpleperf_libs_for_tests",
585    ],
586    test_options: {
587        unit_test: true,
588    },
589    srcs: [
590        "cpu_hotplug_test.cpp",
591    ],
592    static_libs: ["libsimpleperf"],
593    target: {
594        android: {
595            test_suites: ["device-tests"],
596        },
597        darwin: {
598            enabled: false,
599        },
600        windows: {
601            enabled: false,
602        },
603    },
604}
605
606cc_library_static {
607    name: "libsimpleperf_cts_test",
608    defaults: [
609        "simpleperf_test_srcs",
610        "simpleperf_libs_for_tests",
611    ],
612    host_supported: false,
613    cflags: [
614        "-DIN_CTS_TEST",
615    ],
616    static_libs: [
617        "libgtest",
618    ],
619    whole_static_libs: [
620        "libgmock",
621        "libsimpleperf",
622    ],
623}
624
625cc_test {
626    name: "simpleperf_record_test",
627    defaults: [
628        "simpleperf_libs_for_tests",
629    ],
630    srcs: [
631        "record_lib_test.cpp",
632    ],
633    shared_libs: ["libsimpleperf_record"],
634    target: {
635        android: {
636            test_suites: ["device-tests"],
637        },
638        darwin: {
639            enabled: false,
640        },
641        windows: {
642            enabled: false,
643        },
644    },
645}
646
647python_library_host {
648    name: "simpleperf_report_lib",
649    srcs: [
650        "scripts/simpleperf_report_lib.py",
651        "scripts/simpleperf_utils.py",
652    ],
653    data: [
654        "scripts/bin/darwin/x86_64/libsimpleperf_report.dylib",
655        "scripts/bin/linux/x86_64/libsimpleperf_report.so",
656        "scripts/bin/windows/**/*.dll",
657    ],
658}
659