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