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: "libsimpleperf_dex_read_static_reqs_defaults", 100 defaults: ["libdexfile_static_defaults"], 101 static_libs: [ 102 "libdexfile_support_static", 103 ], 104 header_libs: ["libdexfile_external_headers"], 105 export_header_lib_headers: ["libdexfile_external_headers"], 106} 107 108cc_library_static { 109 name: "libsimpleperf_dex_read", 110 defaults: [ 111 "simpleperf_defaults", 112 "libsimpleperf_dex_read_static_reqs_defaults", 113 ], 114 host_supported: true, 115 116 export_include_dirs: [ 117 ".", 118 ], 119 120 static_libs: ["libbase"], 121 122 srcs: [ 123 "read_dex_file.cpp", 124 ], 125 126 group_static_libs: true, 127} 128 129cc_defaults { 130 name: "simpleperf_cflags", 131 target: { 132 host: { 133 cflags: [ 134 "-DUSE_BIONIC_UAPI_HEADERS", 135 "-fvisibility=hidden" 136 ], 137 include_dirs: ["bionic/libc/kernel"], 138 }, 139 darwin: { 140 cflags: ["-DNO_LIBDEXFILE_SUPPORT"], 141 local_include_dirs: ["nonlinux_support/include"], 142 }, 143 windows: { 144 cflags: ["-DNO_LIBDEXFILE_SUPPORT"], 145 local_include_dirs: ["nonlinux_support/include"], 146 } 147 }, 148} 149 150// linked as a separate library because using OpenCSD headers needs to enable exception 151cc_library_static { 152 name: "libsimpleperf_etm_decoder", 153 defaults: [ 154 "simpleperf_cflags", 155 "libsimpleperf_elf_read_static_reqs_defaults", 156 ], 157 host_supported: true, 158 srcs: ["ETMDecoder.cpp"], 159 cppflags: [ 160 // flags needed to include libopencsd_decoder headers 161 "-Wno-ignored-qualifiers", 162 "-Wno-unused-parameter", 163 "-Wno-switch", 164 "-Wno-unused-private-field", 165 "-Wno-implicit-fallthrough", 166 "-fexceptions", 167 ], 168 rtti: true, 169 static_libs: [ 170 "libopencsd_decoder", 171 "libbase", 172 "liblog", 173 ], 174 target: { 175 windows: { 176 enabled: true, 177 } 178 } 179} 180 181cc_defaults { 182 name: "simpleperf_static_libs", 183 defaults: [ 184 "libsimpleperf_elf_read_static_reqs_defaults", 185 "simpleperf_cflags", 186 ], 187 host_supported: true, 188 static_libs: [ 189 "libsimpleperf_etm_decoder", 190 "libbase", 191 "liblog", 192 "libutils", 193 "libprotobuf-cpp-lite", 194 "libopencsd_decoder", 195 ], 196 target: { 197 linux: { 198 static_libs: [ 199 "libunwindstack", 200 "libdexfile_support_static", 201 "libcutils", 202 "libprocinfo", 203 "libevent", 204 ], 205 }, 206 android: { 207 static_libs: [ 208 "libc", 209 ], 210 }, 211 host: { 212 stl: "libc++_static", 213 }, 214 windows: { 215 enabled: true, 216 }, 217 }, 218 use_version_lib: true, 219} 220 221cc_defaults { 222 name: "simpleperf_shared_libs", 223 defaults: [ 224 "simpleperf_cflags", 225 ], 226 host_supported: true, 227 shared_libs: [ 228 "libbase", 229 "liblzma", 230 "libprotobuf-cpp-lite", 231 "libziparchive", 232 ], 233 static_libs: [ 234 "libsimpleperf_etm_decoder", 235 "libopencsd_decoder", 236 ], 237 target: { 238 linux: { 239 shared_libs: [ 240 "libcutils", 241 "libdexfile_support", 242 "libevent", 243 "libprocinfo", 244 "libunwindstack", 245 ], 246 }, 247 darwin: { 248 host_ldlibs: [ 249 "-lncurses", 250 ], 251 }, 252 linux_glibc: { 253 host_ldlibs: [ 254 "-lncurses", 255 ], 256 }, 257 host: { 258 static_libs: [ 259 "libLLVMObject", 260 "libLLVMBitReader", 261 "libLLVMMC", 262 "libLLVMMCParser", 263 "libLLVMCore", 264 "libLLVMSupport", 265 ], 266 }, 267 windows: { 268 enabled: true, 269 }, 270 }, 271 use_version_lib: true, 272} 273 274cc_defaults { 275 name: "simpleperf_libs_for_tests", 276 defaults: ["simpleperf_shared_libs"], 277 target: { 278 android: { 279 // 32-bit libLLVM_android isn't shipped on device. So use static llvm libs in tests. 280 static_libs: [ 281 "libLLVMObject", 282 "libLLVMBitReader", 283 "libLLVMMC", 284 "libLLVMMCParser", 285 "libLLVMCore", 286 "libLLVMSupport", 287 ], 288 }, 289 }, 290} 291 292cc_defaults { 293 name: "libsimpleperf_srcs", 294 srcs: [ 295 "cmd_dumprecord.cpp", 296 "cmd_help.cpp", 297 "cmd_inject.cpp", 298 "cmd_kmem.cpp", 299 "cmd_report.cpp", 300 "cmd_report_sample.cpp", 301 "command.cpp", 302 "dso.cpp", 303 "event_attr.cpp", 304 "event_type.cpp", 305 "perf_regs.cpp", 306 "read_apk.cpp", 307 "read_elf.cpp", 308 "record.cpp", 309 "record_file_reader.cpp", 310 "report_sample.proto", 311 "thread_tree.cpp", 312 "tracing.cpp", 313 "utils.cpp", 314 ], 315 target: { 316 linux: { 317 srcs: [ 318 "CallChainJoiner.cpp", 319 "cmd_api.cpp", 320 "cmd_debug_unwind.cpp", 321 "cmd_list.cpp", 322 "cmd_record.cpp", 323 "cmd_stat.cpp", 324 "cmd_trace_sched.cpp", 325 "environment.cpp", 326 "ETMRecorder.cpp", 327 "event_fd.cpp", 328 "event_selection_set.cpp", 329 "InplaceSamplerClient.cpp", 330 "IOEventLoop.cpp", 331 "JITDebugReader.cpp", 332 "OfflineUnwinder.cpp", 333 "read_dex_file.cpp", 334 "record_file_writer.cpp", 335 "RecordReadThread.cpp", 336 "UnixSocket.cpp", 337 "workload.cpp", 338 ], 339 }, 340 darwin: { 341 srcs: ["nonlinux_support/nonlinux_support.cpp"], 342 }, 343 windows: { 344 srcs: ["nonlinux_support/nonlinux_support.cpp"], 345 }, 346 }, 347} 348 349cc_library_static { 350 name: "libsimpleperf", 351 defaults: [ 352 "libsimpleperf_srcs", 353 "simpleperf_static_libs", 354 ], 355 compile_multilib: "both", 356 proto: { 357 type: "lite", 358 }, 359 static_libs: [ 360 "libbuildversion", 361 ], 362 use_version_lib: false, 363} 364 365// simpleperf shipped in system image 366cc_binary { 367 name: "simpleperf", 368 defaults: [ 369 "simpleperf_shared_libs", 370 ], 371 host_supported: false, 372 srcs: [ 373 "main.cpp", 374 ], 375 static_libs: ["libsimpleperf"], 376 target: { 377 android: { 378 shared_libs: [ 379 "libLLVM_android", 380 ], 381 }, 382 }, 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 }, 412 android_arm: { 413 dist: { 414 dir: "simpleperf/android/arm", 415 }, 416 }, 417 android_arm64: { 418 dist: { 419 dir: "simpleperf/android/arm64", 420 }, 421 }, 422 android_x86: { 423 dist: { 424 dir: "simpleperf/android/x86", 425 }, 426 }, 427 android_x86_64: { 428 dist: { 429 dir: "simpleperf/android/x86_64", 430 }, 431 }, 432 darwin: { 433 dist: { 434 dir: "simpleperf/darwin/x86", 435 }, 436 }, 437 darwin_x86_64: { 438 dist: { 439 dir: "simpleperf/darwin/x86_64", 440 }, 441 }, 442 linux_glibc_x86: { 443 dist: { 444 dir: "simpleperf/linux/x86", 445 }, 446 }, 447 linux_glibc_x86_64: { 448 dist: { 449 dir: "simpleperf/linux/x86_64", 450 }, 451 }, 452 windows_x86: { 453 dist: { 454 dir: "simpleperf/windows/x86", 455 }, 456 }, 457 windows_x86_64: { 458 dist: { 459 dir: "simpleperf/windows/x86_64", 460 }, 461 }, 462 }, 463} 464 465// It's linked to user's program, to get profile counters and samples for specific code ranges. 466cc_library { 467 name: "libsimpleperf_record", 468 defaults: [ 469 "simpleperf_static_libs", 470 ], 471 export_include_dirs: ["include"], 472 ldflags: ["-Wl,--exclude-libs,ALL"], 473 srcs: [ 474 "record_lib_interface.cpp", 475 ], 476 static_libs: [ 477 "libsimpleperf" 478 ], 479 target: { 480 darwin: { 481 enabled: false, 482 }, 483 windows: { 484 enabled: false, 485 }, 486 }, 487} 488 489// It's the shared library used on host by python scripts to report samples in different ways. 490cc_library_shared { 491 name: "libsimpleperf_report", 492 defaults: [ 493 "simpleperf_static_libs", 494 ], 495 dist: { 496 targets: ["simpleperf"], 497 }, 498 srcs: [ 499 "report_lib_interface.cpp", 500 ], 501 static_libs: ["libsimpleperf"], 502 503 target: { 504 android: { 505 enabled: false, 506 }, 507 linux: { 508 ldflags: ["-Wl,--exclude-libs,ALL"], 509 }, 510 darwin: { 511 dist: { 512 dir: "simpleperf/darwin/x86", 513 }, 514 }, 515 darwin_x86_64: { 516 dist: { 517 dir: "simpleperf/darwin/x86_64", 518 }, 519 }, 520 linux_glibc_x86: { 521 dist: { 522 dir: "simpleperf/linux/x86", 523 }, 524 }, 525 linux_glibc_x86_64: { 526 dist: { 527 dir: "simpleperf/linux/x86_64", 528 }, 529 }, 530 windows_x86: { 531 dist: { 532 dir: "simpleperf/windows/x86", 533 }, 534 }, 535 windows_x86_64: { 536 dist: { 537 dir: "simpleperf/windows/x86_64", 538 }, 539 }, 540 }, 541} 542 543// It's the shared library linked with user's app and get samples from signal handlers in each 544// thread. Doesn't work yet. 545cc_library_shared { 546 name: "libsimpleperf_inplace_sampler", 547 defaults: [ 548 "simpleperf_static_libs", 549 ], 550 export_include_dirs: ["include"], 551 ldflags: ["-Wl,--exclude-libs,ALL"], 552 srcs: [ 553 "inplace_sampler_lib.cpp", 554 ], 555 static_libs: ["libsimpleperf"], 556 target: { 557 darwin: { 558 enabled: false, 559 }, 560 windows: { 561 enabled: false, 562 }, 563 }, 564} 565 566cc_defaults { 567 name: "simpleperf_test_srcs", 568 srcs: [ 569 "cmd_inject_test.cpp", 570 "cmd_kmem_test.cpp", 571 "cmd_report_test.cpp", 572 "cmd_report_sample_test.cpp", 573 "command_test.cpp", 574 "dso_test.cpp", 575 "gtest_main.cpp", 576 "read_apk_test.cpp", 577 "read_elf_test.cpp", 578 "record_test.cpp", 579 "sample_tree_test.cpp", 580 "thread_tree_test.cpp", 581 "utils_test.cpp", 582 ], 583 target: { 584 linux: { 585 srcs: [ 586 "CallChainJoiner_test.cpp", 587 "cmd_debug_unwind_test.cpp", 588 "cmd_dumprecord_test.cpp", 589 "cmd_list_test.cpp", 590 "cmd_record_test.cpp", 591 "cmd_stat_test.cpp", 592 "cmd_trace_sched_test.cpp", 593 "environment_test.cpp", 594 "IOEventLoop_test.cpp", 595 "read_dex_file_test.cpp", 596 "record_file_test.cpp", 597 "RecordReadThread_test.cpp", 598 "UnixSocket_test.cpp", 599 "workload_test.cpp", 600 ], 601 }, 602 }, 603} 604 605cc_test { 606 name: "simpleperf_unit_test", 607 defaults: [ 608 "simpleperf_test_srcs", 609 "simpleperf_libs_for_tests", 610 ], 611 static_libs: [ 612 "libgmock", 613 "libsimpleperf" 614 ], 615 target: { 616 android: { 617 test_suites: ["device-tests"], 618 }, 619 }, 620 data: [ 621 "testdata/**/*", 622 ], 623} 624 625cc_test { 626 name: "simpleperf_cpu_hotplug_test", 627 defaults: [ 628 "simpleperf_libs_for_tests", 629 ], 630 srcs: [ 631 "cpu_hotplug_test.cpp", 632 ], 633 static_libs: ["libsimpleperf"], 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 647cc_library_static { 648 name: "libsimpleperf_cts_test", 649 defaults: [ 650 "simpleperf_test_srcs", 651 "simpleperf_libs_for_tests", 652 ], 653 host_supported: false, 654 cflags: [ 655 "-DIN_CTS_TEST", 656 ], 657 static_libs: [ 658 "libgtest", 659 ], 660 whole_static_libs: [ 661 "libgmock", 662 "libsimpleperf", 663 ], 664} 665 666cc_test { 667 name: "simpleperf_record_test", 668 defaults: [ 669 "simpleperf_libs_for_tests", 670 ], 671 srcs: [ 672 "record_lib_test.cpp", 673 ], 674 shared_libs: ["libsimpleperf_record"], 675 target: { 676 android: { 677 test_suites: ["device-tests"], 678 }, 679 darwin: { 680 enabled: false, 681 }, 682 windows: { 683 enabled: false, 684 }, 685 }, 686} 687