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