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