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