From eefcd9d0758fa3deeb906e426d43d21810f713c3 Mon Sep 17 00:00:00 2001 From: chuxuezhe11 Date: Fri, 24 Dec 2021 00:46:38 -0800 Subject: [PATCH] add hiperf Signed-off-by: chuxuezhe11 --- .gitignore | 10 + BUILD.gn | 476 ++ LICENSE | 201 + OAT.xml | 109 + README.en.md | 36 - README.md | 39 - README_zh.md | 407 ++ demo/cpp/BUILD.gn | 29 + demo/cpp/hiperf_demo.cpp | 93 + demo/cpp/hiperf_example_cmd.cpp | 483 ++ demo/cpp/hiperf_malloc_demo.cpp | 41 + demo/js/.gitignore | 16 + demo/js/build.gradle | 59 + demo/js/entry/.gitignore | 2 + demo/js/entry/build.gradle | 21 + demo/js/entry/package.json | 1 + demo/js/entry/proguard-rules.pro | 1 + demo/js/entry/src/main/config.json | 63 + demo/js/entry/src/main/js/MainAbility/app.js | 8 + .../src/main/js/MainAbility/i18n/en-US.json | 15 + .../src/main/js/MainAbility/i18n/zh-CN.json | 15 + .../main/js/MainAbility/pages/index/index.css | 39 + .../main/js/MainAbility/pages/index/index.hml | 21 + .../main/js/MainAbility/pages/index/index.js | 170 + .../js/MainAbility/pages/second/second.css | 24 + .../js/MainAbility/pages/second/second.hml | 6 + .../js/MainAbility/pages/second/second.js | 12 + .../main/resources/base/element/string.json | 12 + .../src/main/resources/base/media/icon.png | Bin 0 -> 6790 bytes demo/js/package.json | 1 + demo/js/settings.gradle | 15 + demo/js/signature/demo.cer | 29 + demo/js/signature/demo.csr | 9 + demo/js/signature/demo.p12 | Bin 0 -> 944 bytes demo/js/signature/demo.p7b | Bin 0 -> 3383 bytes .../ac/4d3596db6ca84cbfa2ab39826c2d9498 | 1 + .../ce/c2058a747a5c4cadbe2dd70a487e46b5 | Bin 0 -> 48 bytes .../fd/0/e9454dd326b740b7aad2080f25df002f | 1 + .../fd/1/2e776ea784ef406180e01c7c59780637 | 1 + .../fd/2/f34ff6345fbf41d6baff573dc0f86212 | 1 + hiperf.gni | 72 + include/arm_raw_event_type_table.h | 67 + include/callstack.h | 139 + include/command.h | 32 + include/debug_logger.h | 371 ++ include/dwarf_encoding.h | 193 + include/elf_parser.h | 310 + include/hashlist.h | 225 + include/hashlist.hpp | 1000 +++ include/hiperf_hilog.h | 95 + include/hiperf_libreport.h | 98 + include/mem_map_item.h | 90 + include/noncopyable.h | 26 + include/nonlinux/MingW64Fix.h | 25 + include/nonlinux/asm/byteorder.h | 17 + include/nonlinux/linux/ioctl.h | 17 + include/nonlinux/linux/types.h | 33 + include/option.h | 140 + include/option_debug.h | 30 + include/perf_event_record.h | 435 ++ include/perf_events.h | 463 ++ include/perf_file_format.h | 259 + include/perf_file_reader.h | 102 + include/perf_file_writer.h | 86 + include/perf_record_format.h | 360 ++ include/register.h | 193 + include/report.h | 573 ++ include/report_json_file.h | 379 ++ include/report_protobuf_file.h | 100 + include/ring_buffer.h | 54 + include/subcommand.h | 102 + include/subcommand_dump.h | 118 + include/subcommand_help.h | 45 + include/subcommand_list.h | 69 + include/subcommand_record.h | 306 + include/subcommand_report.h | 191 + include/subcommand_stat.h | 124 + include/symbols_file.h | 345 ++ include/tracked_command.h | 80 + include/utilities.h | 321 + include/virtual_runtime.h | 179 + include/virtual_thread.h | 113 + interfaces/innerkits/native/BUILD.gn | 41 + .../innerkits/native/include/hiperf_client.h | 326 + .../innerkits/native/src/hiperf_client.cpp | 565 ++ interfaces/kits/js/@ohos.hiperf.d.ts | 249 + interfaces/kits/js/napi/BUILD.gn | 44 + .../kits/js/napi/hiperf_client_napi.cpp | 688 +++ interfaces/kits/js/napi/hiperf_client_napi.h | 18 + ohos.build | 27 + proto/build_proto.sh | 36 + proto/report_sample.proto | 91 + script/command_script.py | 114 + script/hiperf_utils.py | 553 ++ script/loadlib_test.py | 77 + script/make_diff.py | 95 + script/make_report.py | 65 + script/make_report_sample.py | 60 + script/package.sh | 54 + script/record_control.py | 153 + script/recv_binary_cache.py | 218 + script/report-diff.html | 5071 ++++++++++++++++ script/report.html | 5409 +++++++++++++++++ script/test/__init__.py | 17 + script/test/test_command_script.py | 74 + script/test/test_utils.py | 74 + src/callstack.cpp | 633 ++ src/command.cpp | 93 + src/debug_logger.cpp | 269 + src/dwarf_encoding.cpp | 163 + src/elf_file.cpp | 349 ++ src/elf_header.cpp | 194 + src/elf_symbol.cpp | 129 + src/hiperf_libreport.cpp | 287 + src/hiperf_libreport_demo.cpp | 22 + src/main.cpp | 93 + src/option.cpp | 180 + src/option_debug.cpp | 94 + src/perf_event_record.cpp | 855 +++ src/perf_events.cpp | 1602 +++++ src/perf_file_format.cpp | 485 ++ src/perf_file_reader.cpp | 442 ++ src/perf_file_writer.cpp | 459 ++ src/program_header.cpp | 83 + src/register.cpp | 273 + src/report.cpp | 640 ++ src/report_json_file.cpp | 314 + src/report_protobuf_file.cpp | 419 ++ src/ring_buffer.cpp | 109 + src/section_header.cpp | 106 + src/subcommand.cpp | 116 + src/subcommand_dump.cpp | 519 ++ src/subcommand_help.cpp | 73 + src/subcommand_list.cpp | 70 + src/subcommand_record.cpp | 1583 +++++ src/subcommand_report.cpp | 614 ++ src/subcommand_stat.cpp | 497 ++ src/symbols_file.cpp | 1329 ++++ src/tracked_command.cpp | 236 + src/utilities.cpp | 553 ++ src/virtual_runtime.cpp | 701 +++ src/virtual_thread.cpp | 363 ++ test/BUILD.gn | 197 + .../ClientApi_fuzzer/ClientApi_fuzzer.cpp | 115 + .../ClientApi_fuzzer/ClientApi_fuzzer.h | 34 + test/fuzztest/ClientApi_fuzzer/corpus/init | 1 + test/fuzztest/ClientApi_fuzzer/project.xml | 25 + .../CommandLine_fuzzer/CommandLine_fuzzer.cpp | 76 + .../CommandLine_fuzzer/CommandLine_fuzzer.h | 33 + test/fuzztest/CommandLine_fuzzer/corpus/init | 1 + test/fuzztest/CommandLine_fuzzer/project.xml | 25 + .../ElfParser_fuzzer/ElfParser_fuzzer.cpp | 92 + .../ElfParser_fuzzer/ElfParser_fuzzer.h | 36 + test/fuzztest/ElfParser_fuzzer/corpus/init | 1 + test/fuzztest/ElfParser_fuzzer/project.xml | 25 + .../LibReport_fuzzer/LibReport_fuzzer.cpp | 48 + .../LibReport_fuzzer/LibReport_fuzzer.h | 34 + test/fuzztest/LibReport_fuzzer/corpus/init | 1 + test/fuzztest/LibReport_fuzzer/project.xml | 25 + .../PerfFile_fuzzer/PerfFile_fuzzer.cpp | 126 + .../PerfFile_fuzzer/PerfFile_fuzzer.h | 35 + test/fuzztest/PerfFile_fuzzer/corpus/init | 1 + test/fuzztest/PerfFile_fuzzer/project.xml | 25 + test/fuzztest/resource/ohos_test.xml | 27 + test/fuzztest/resource/send_to_device.bat | 21 + test/fuzztest/resource/testdata/elf_test | Bin 0 -> 24344 bytes .../resource/testdata/report_test.data | Bin 0 -> 10538 bytes .../unittest/common/native/callstack_test.cpp | 598 ++ test/unittest/common/native/command_test.cpp | 110 + .../common/native/debug_logger_test.cpp | 284 + test/unittest/common/native/dwarf_test.cpp | 248 + .../common/native/elf_parser_test.cpp | 1498 +++++ test/unittest/common/native/hashlist_test.cpp | 309 + .../common/native/hiperf_client_test.cpp | 366 ++ .../common/native/hiperf_libreport_test.cpp | 541 ++ .../common/native/include/callstack_test.h | 132 + .../common/native/include/command_test.h | 29 + .../common/native/include/debug_logger_test.h | 26 + .../common/native/include/dwarf_test.h | 19 + .../common/native/include/elf_parser_test.h | 180 + .../common/native/include/hashlist_test.h | 24 + .../native/include/hiperf_client_test.h | 24 + .../native/include/hiperf_libreport_test.h | 25 + .../common/native/include/option_debug_test.h | 35 + .../common/native/include/option_test.h | 108 + .../native/include/perf_event_record_test.h | 24 + .../common/native/include/perf_events_test.h | 24 + .../native/include/perf_file_format_test.h | 24 + .../native/include/perf_file_reader_test.h | 25 + .../native/include/perf_file_writer_test.h | 24 + .../common/native/include/register_test.h | 26 + .../native/include/report_json_file_test.h | 34 + .../include/report_protobuf_file_test.h | 25 + .../common/native/include/report_test.h | 55 + .../common/native/include/ring_buffer_test.h | 24 + .../native/include/subcommand_dump_test.h | 24 + .../native/include/subcommand_help_test.h | 35 + .../native/include/subcommand_list_test.h | 23 + .../native/include/subcommand_record_test.h | 24 + .../native/include/subcommand_report_test.h | 29 + .../native/include/subcommand_stat_test.h | 24 + .../common/native/include/subcommand_test.h | 62 + .../common/native/include/symbols_file_test.h | 64 + .../native/include/tracked_command_test.h | 23 + .../common/native/include/utilities_test.h | 23 + .../native/include/virtual_runtime_test.h | 83 + .../native/include/virtual_thread_test.h | 28 + .../common/native/option_debug_test.cpp | 203 + test/unittest/common/native/option_test.cpp | 531 ++ .../common/native/perf_event_record_test.cpp | 683 +++ .../common/native/perf_events_test.cpp | 329 + .../common/native/perf_file_format_test.cpp | 254 + .../common/native/perf_file_reader_test.cpp | 117 + .../common/native/perf_file_writer_test.cpp | 164 + test/unittest/common/native/register_test.cpp | 212 + .../common/native/report_json_file_test.cpp | 723 +++ .../native/report_protobuf_file_test.cpp | 358 ++ test/unittest/common/native/report_test.cpp | 822 +++ .../common/native/ring_buffer_test.cpp | 151 + .../common/native/subcommand_dump_test.cpp | 183 + .../common/native/subcommand_help_test.cpp | 120 + .../common/native/subcommand_list_test.cpp | 168 + .../common/native/subcommand_record_test.cpp | 699 +++ .../common/native/subcommand_report_test.cpp | 1112 ++++ .../common/native/subcommand_stat_test.cpp | 1767 ++++++ .../common/native/subcommand_test.cpp | 195 + .../common/native/symbols_file_test.cpp | 1011 +++ .../common/native/tracked_command_test.cpp | 96 + .../unittest/common/native/utilities_test.cpp | 633 ++ .../common/native/virtual_runtime_test.cpp | 363 ++ .../common/native/virtual_thread_test.cpp | 469 ++ test/unittest/resource/ohos_test.xml | 92 + .../resource/send_dwarf_to_device.bat | 20 + .../resource/send_report_to_device.bat | 20 + test/unittest/resource/send_to_device.bat | 26 + test/unittest/resource/testdata/dummpfile | 1 + ...3_644_sample_record_213_6754913387560.dump | Bin 0 -> 8424 bytes .../testdata/dwarf/hiperf_example_cmd | Bin 0 -> 206752 bytes .../resource/testdata/dwarf/perf.data | Bin 0 -> 4509236 bytes .../resource/testdata/dwarf/user_data.dump | Bin 0 -> 8192 bytes .../resource/testdata/dwarf/user_regs.dump | Bin 0 -> 128 bytes .../resource/testdata/ehdr_from_readelf_32 | 20 + .../resource/testdata/ehdr_from_readelf_64 | 20 + test/unittest/resource/testdata/elf32_test | Bin 0 -> 18860 bytes .../resource/testdata/elf32_test_broken | Bin 0 -> 384 bytes .../resource/testdata/elf32_test_stripped | Bin 0 -> 13820 bytes .../testdata/elf32_test_stripped_nobuildid | Bin 0 -> 13648 bytes .../testdata/elf32_test_stripped_noehframehdr | Bin 0 -> 13768 bytes test/unittest/resource/testdata/elf_test | Bin 0 -> 24344 bytes .../resource/testdata/elf_test_stripped | Bin 0 -> 18648 bytes .../testdata/elf_test_stripped_broken | Bin 0 -> 561 bytes .../testdata/elf_test_stripped_nobuildid | Bin 0 -> 18408 bytes .../testdata/elf_test_stripped_noehframehdr | Bin 0 -> 18568 bytes test/unittest/resource/testdata/empytfile | 0 test/unittest/resource/testdata/perf.data | Bin 0 -> 1973039 bytes test/unittest/resource/testdata/perf2.data | Bin 0 -> 1973039 bytes test/unittest/resource/testdata/perfnew.data | Bin 0 -> 908024 bytes .../resource/testdata/phdrs_from_readelf_32 | 35 + .../resource/testdata/phdrs_from_readelf_64 | 51 + test/unittest/resource/testdata/proto_test | Bin 0 -> 1785621 bytes .../testdata/report/buildid_test_elf_32 | Bin 0 -> 18860 bytes .../testdata/report/buildid_test_elf_64 | Bin 0 -> 24344 bytes .../testdata/report/elf32_test_broken | Bin 0 -> 384 bytes .../testdata/report/hiperf_example_cmd | Bin 0 -> 238860 bytes .../report/perf.data.error.format.libreport | Bin 0 -> 387946 bytes .../testdata/report/perf.data.libreport | Bin 0 -> 388090 bytes ...erf.disable.unwind.hiperf_example_cmd.data | Bin 0 -> 12337028 bytes .../resource/testdata/report/perf.dwarf.data | Bin 0 -> 11831900 bytes .../testdata/report/perf.dwarf.data.txt | 83 + .../resource/testdata/report_test.data | Bin 0 -> 10538 bytes .../testdata/report_test_callstack.txt | 29 + .../resource/testdata/report_test_diff.txt | 21 + .../resource/testdata/report_test_dsos.txt | 19 + .../resource/testdata/report_test_funcs.txt | 17 + .../resource/testdata/report_test_i.txt | 22 + .../resource/testdata/report_test_limit.txt | 20 + .../resource/testdata/report_test_limit1.txt | 21 + .../resource/testdata/report_test_sort1.txt | 17 + .../resource/testdata/report_test_sort2.txt | 21 + .../resource/testdata/report_test_symbol.txt | 22 + .../resource/testdata/report_test_tids.txt | 19 + .../resource/testdata/report_test_tids1.txt | 15 + .../resource/testdata/shdrs_from_readelf_32 | 41 + .../resource/testdata/shdrs_from_readelf_64 | 74 + .../testdata/source/build_elf_test.sh | 24 + .../testdata/source/elf_test_source_code.cpp | 40 + .../resource/testdata/symbols_file_test_elf32 | Bin 0 -> 15560 bytes .../resource/testdata/symbols_file_test_elf64 | Bin 0 -> 16472 bytes .../resource/testdata/syms_from_readelf_32 | 153 + .../resource/testdata/syms_from_readelf_64 | 145 + test/unittest/resource/testdata/vmlinux | Bin 0 -> 13232928 bytes .../resource/testdata/vmlinux_stripped | Bin 0 -> 10619268 bytes .../resource/testdata/vmlinux_stripped_broken | Bin 0 -> 398 bytes .../testdata/vmlinux_stripped_nobuildid | Bin 0 -> 10619220 bytes test/unittest/script/coverage/gcov.sh | 21 + test/unittest/script/coverage/lcov.sh | 39 + 296 files changed, 58233 insertions(+), 75 deletions(-) create mode 100755 .gitignore create mode 100644 BUILD.gn create mode 100644 LICENSE create mode 100755 OAT.xml delete mode 100644 README.en.md delete mode 100644 README.md create mode 100755 README_zh.md create mode 100644 demo/cpp/BUILD.gn create mode 100644 demo/cpp/hiperf_demo.cpp create mode 100755 demo/cpp/hiperf_example_cmd.cpp create mode 100755 demo/cpp/hiperf_malloc_demo.cpp create mode 100755 demo/js/.gitignore create mode 100644 demo/js/build.gradle create mode 100755 demo/js/entry/.gitignore create mode 100644 demo/js/entry/build.gradle create mode 100755 demo/js/entry/package.json create mode 100755 demo/js/entry/proguard-rules.pro create mode 100644 demo/js/entry/src/main/config.json create mode 100755 demo/js/entry/src/main/js/MainAbility/app.js create mode 100755 demo/js/entry/src/main/js/MainAbility/i18n/en-US.json create mode 100755 demo/js/entry/src/main/js/MainAbility/i18n/zh-CN.json create mode 100755 demo/js/entry/src/main/js/MainAbility/pages/index/index.css create mode 100755 demo/js/entry/src/main/js/MainAbility/pages/index/index.hml create mode 100755 demo/js/entry/src/main/js/MainAbility/pages/index/index.js create mode 100755 demo/js/entry/src/main/js/MainAbility/pages/second/second.css create mode 100755 demo/js/entry/src/main/js/MainAbility/pages/second/second.hml create mode 100755 demo/js/entry/src/main/js/MainAbility/pages/second/second.js create mode 100644 demo/js/entry/src/main/resources/base/element/string.json create mode 100644 demo/js/entry/src/main/resources/base/media/icon.png create mode 100755 demo/js/package.json create mode 100644 demo/js/settings.gradle create mode 100644 demo/js/signature/demo.cer create mode 100644 demo/js/signature/demo.csr create mode 100644 demo/js/signature/demo.p12 create mode 100644 demo/js/signature/demo.p7b create mode 100644 demo/js/signature/material/ac/4d3596db6ca84cbfa2ab39826c2d9498 create mode 100644 demo/js/signature/material/ce/c2058a747a5c4cadbe2dd70a487e46b5 create mode 100644 demo/js/signature/material/fd/0/e9454dd326b740b7aad2080f25df002f create mode 100644 demo/js/signature/material/fd/1/2e776ea784ef406180e01c7c59780637 create mode 100644 demo/js/signature/material/fd/2/f34ff6345fbf41d6baff573dc0f86212 create mode 100644 hiperf.gni create mode 100644 include/arm_raw_event_type_table.h create mode 100755 include/callstack.h create mode 100755 include/command.h create mode 100755 include/debug_logger.h create mode 100755 include/dwarf_encoding.h create mode 100755 include/elf_parser.h create mode 100755 include/hashlist.h create mode 100755 include/hashlist.hpp create mode 100644 include/hiperf_hilog.h create mode 100644 include/hiperf_libreport.h create mode 100755 include/mem_map_item.h create mode 100644 include/noncopyable.h create mode 100644 include/nonlinux/MingW64Fix.h create mode 100644 include/nonlinux/asm/byteorder.h create mode 100644 include/nonlinux/linux/ioctl.h create mode 100644 include/nonlinux/linux/types.h create mode 100755 include/option.h create mode 100755 include/option_debug.h create mode 100755 include/perf_event_record.h create mode 100755 include/perf_events.h create mode 100755 include/perf_file_format.h create mode 100755 include/perf_file_reader.h create mode 100755 include/perf_file_writer.h create mode 100755 include/perf_record_format.h create mode 100755 include/register.h create mode 100755 include/report.h create mode 100755 include/report_json_file.h create mode 100755 include/report_protobuf_file.h create mode 100755 include/ring_buffer.h create mode 100755 include/subcommand.h create mode 100644 include/subcommand_dump.h create mode 100644 include/subcommand_help.h create mode 100644 include/subcommand_list.h create mode 100644 include/subcommand_record.h create mode 100644 include/subcommand_report.h create mode 100644 include/subcommand_stat.h create mode 100755 include/symbols_file.h create mode 100755 include/tracked_command.h create mode 100755 include/utilities.h create mode 100755 include/virtual_runtime.h create mode 100755 include/virtual_thread.h create mode 100644 interfaces/innerkits/native/BUILD.gn create mode 100644 interfaces/innerkits/native/include/hiperf_client.h create mode 100644 interfaces/innerkits/native/src/hiperf_client.cpp create mode 100644 interfaces/kits/js/@ohos.hiperf.d.ts create mode 100644 interfaces/kits/js/napi/BUILD.gn create mode 100644 interfaces/kits/js/napi/hiperf_client_napi.cpp create mode 100755 interfaces/kits/js/napi/hiperf_client_napi.h create mode 100644 ohos.build create mode 100755 proto/build_proto.sh create mode 100644 proto/report_sample.proto create mode 100644 script/command_script.py create mode 100644 script/hiperf_utils.py create mode 100755 script/loadlib_test.py create mode 100755 script/make_diff.py create mode 100644 script/make_report.py create mode 100755 script/make_report_sample.py create mode 100755 script/package.sh create mode 100755 script/record_control.py create mode 100755 script/recv_binary_cache.py create mode 100755 script/report-diff.html create mode 100755 script/report.html create mode 100755 script/test/__init__.py create mode 100755 script/test/test_command_script.py create mode 100755 script/test/test_utils.py create mode 100755 src/callstack.cpp create mode 100755 src/command.cpp create mode 100755 src/debug_logger.cpp create mode 100755 src/dwarf_encoding.cpp create mode 100755 src/elf_file.cpp create mode 100755 src/elf_header.cpp create mode 100755 src/elf_symbol.cpp create mode 100644 src/hiperf_libreport.cpp create mode 100644 src/hiperf_libreport_demo.cpp create mode 100755 src/main.cpp create mode 100755 src/option.cpp create mode 100755 src/option_debug.cpp create mode 100755 src/perf_event_record.cpp create mode 100755 src/perf_events.cpp create mode 100755 src/perf_file_format.cpp create mode 100755 src/perf_file_reader.cpp create mode 100755 src/perf_file_writer.cpp create mode 100755 src/program_header.cpp create mode 100755 src/register.cpp create mode 100755 src/report.cpp create mode 100755 src/report_json_file.cpp create mode 100755 src/report_protobuf_file.cpp create mode 100755 src/ring_buffer.cpp create mode 100755 src/section_header.cpp create mode 100755 src/subcommand.cpp create mode 100644 src/subcommand_dump.cpp create mode 100644 src/subcommand_help.cpp create mode 100644 src/subcommand_list.cpp create mode 100644 src/subcommand_record.cpp create mode 100644 src/subcommand_report.cpp create mode 100644 src/subcommand_stat.cpp create mode 100755 src/symbols_file.cpp create mode 100755 src/tracked_command.cpp create mode 100755 src/utilities.cpp create mode 100755 src/virtual_runtime.cpp create mode 100755 src/virtual_thread.cpp create mode 100644 test/BUILD.gn create mode 100755 test/fuzztest/ClientApi_fuzzer/ClientApi_fuzzer.cpp create mode 100755 test/fuzztest/ClientApi_fuzzer/ClientApi_fuzzer.h create mode 100755 test/fuzztest/ClientApi_fuzzer/corpus/init create mode 100755 test/fuzztest/ClientApi_fuzzer/project.xml create mode 100755 test/fuzztest/CommandLine_fuzzer/CommandLine_fuzzer.cpp create mode 100755 test/fuzztest/CommandLine_fuzzer/CommandLine_fuzzer.h create mode 100755 test/fuzztest/CommandLine_fuzzer/corpus/init create mode 100755 test/fuzztest/CommandLine_fuzzer/project.xml create mode 100755 test/fuzztest/ElfParser_fuzzer/ElfParser_fuzzer.cpp create mode 100755 test/fuzztest/ElfParser_fuzzer/ElfParser_fuzzer.h create mode 100755 test/fuzztest/ElfParser_fuzzer/corpus/init create mode 100755 test/fuzztest/ElfParser_fuzzer/project.xml create mode 100755 test/fuzztest/LibReport_fuzzer/LibReport_fuzzer.cpp create mode 100755 test/fuzztest/LibReport_fuzzer/LibReport_fuzzer.h create mode 100755 test/fuzztest/LibReport_fuzzer/corpus/init create mode 100755 test/fuzztest/LibReport_fuzzer/project.xml create mode 100755 test/fuzztest/PerfFile_fuzzer/PerfFile_fuzzer.cpp create mode 100755 test/fuzztest/PerfFile_fuzzer/PerfFile_fuzzer.h create mode 100755 test/fuzztest/PerfFile_fuzzer/corpus/init create mode 100755 test/fuzztest/PerfFile_fuzzer/project.xml create mode 100755 test/fuzztest/resource/ohos_test.xml create mode 100755 test/fuzztest/resource/send_to_device.bat create mode 100755 test/fuzztest/resource/testdata/elf_test create mode 100755 test/fuzztest/resource/testdata/report_test.data create mode 100755 test/unittest/common/native/callstack_test.cpp create mode 100755 test/unittest/common/native/command_test.cpp create mode 100755 test/unittest/common/native/debug_logger_test.cpp create mode 100755 test/unittest/common/native/dwarf_test.cpp create mode 100755 test/unittest/common/native/elf_parser_test.cpp create mode 100755 test/unittest/common/native/hashlist_test.cpp create mode 100644 test/unittest/common/native/hiperf_client_test.cpp create mode 100755 test/unittest/common/native/hiperf_libreport_test.cpp create mode 100755 test/unittest/common/native/include/callstack_test.h create mode 100755 test/unittest/common/native/include/command_test.h create mode 100755 test/unittest/common/native/include/debug_logger_test.h create mode 100755 test/unittest/common/native/include/dwarf_test.h create mode 100755 test/unittest/common/native/include/elf_parser_test.h create mode 100755 test/unittest/common/native/include/hashlist_test.h create mode 100644 test/unittest/common/native/include/hiperf_client_test.h create mode 100755 test/unittest/common/native/include/hiperf_libreport_test.h create mode 100755 test/unittest/common/native/include/option_debug_test.h create mode 100755 test/unittest/common/native/include/option_test.h create mode 100755 test/unittest/common/native/include/perf_event_record_test.h create mode 100755 test/unittest/common/native/include/perf_events_test.h create mode 100755 test/unittest/common/native/include/perf_file_format_test.h create mode 100755 test/unittest/common/native/include/perf_file_reader_test.h create mode 100755 test/unittest/common/native/include/perf_file_writer_test.h create mode 100755 test/unittest/common/native/include/register_test.h create mode 100755 test/unittest/common/native/include/report_json_file_test.h create mode 100755 test/unittest/common/native/include/report_protobuf_file_test.h create mode 100755 test/unittest/common/native/include/report_test.h create mode 100755 test/unittest/common/native/include/ring_buffer_test.h create mode 100755 test/unittest/common/native/include/subcommand_dump_test.h create mode 100644 test/unittest/common/native/include/subcommand_help_test.h create mode 100644 test/unittest/common/native/include/subcommand_list_test.h create mode 100644 test/unittest/common/native/include/subcommand_record_test.h create mode 100755 test/unittest/common/native/include/subcommand_report_test.h create mode 100644 test/unittest/common/native/include/subcommand_stat_test.h create mode 100755 test/unittest/common/native/include/subcommand_test.h create mode 100755 test/unittest/common/native/include/symbols_file_test.h create mode 100755 test/unittest/common/native/include/tracked_command_test.h create mode 100755 test/unittest/common/native/include/utilities_test.h create mode 100755 test/unittest/common/native/include/virtual_runtime_test.h create mode 100755 test/unittest/common/native/include/virtual_thread_test.h create mode 100755 test/unittest/common/native/option_debug_test.cpp create mode 100755 test/unittest/common/native/option_test.cpp create mode 100755 test/unittest/common/native/perf_event_record_test.cpp create mode 100755 test/unittest/common/native/perf_events_test.cpp create mode 100755 test/unittest/common/native/perf_file_format_test.cpp create mode 100755 test/unittest/common/native/perf_file_reader_test.cpp create mode 100755 test/unittest/common/native/perf_file_writer_test.cpp create mode 100755 test/unittest/common/native/register_test.cpp create mode 100755 test/unittest/common/native/report_json_file_test.cpp create mode 100755 test/unittest/common/native/report_protobuf_file_test.cpp create mode 100755 test/unittest/common/native/report_test.cpp create mode 100755 test/unittest/common/native/ring_buffer_test.cpp create mode 100755 test/unittest/common/native/subcommand_dump_test.cpp create mode 100644 test/unittest/common/native/subcommand_help_test.cpp create mode 100644 test/unittest/common/native/subcommand_list_test.cpp create mode 100644 test/unittest/common/native/subcommand_record_test.cpp create mode 100755 test/unittest/common/native/subcommand_report_test.cpp create mode 100644 test/unittest/common/native/subcommand_stat_test.cpp create mode 100755 test/unittest/common/native/subcommand_test.cpp create mode 100755 test/unittest/common/native/symbols_file_test.cpp create mode 100755 test/unittest/common/native/tracked_command_test.cpp create mode 100755 test/unittest/common/native/utilities_test.cpp create mode 100755 test/unittest/common/native/virtual_runtime_test.cpp create mode 100755 test/unittest/common/native/virtual_thread_test.cpp create mode 100644 test/unittest/resource/ohos_test.xml create mode 100755 test/unittest/resource/send_dwarf_to_device.bat create mode 100755 test/unittest/resource/send_report_to_device.bat create mode 100755 test/unittest/resource/send_to_device.bat create mode 100755 test/unittest/resource/testdata/dummpfile create mode 100755 test/unittest/resource/testdata/dwarf/hiperf_643_644_sample_record_213_6754913387560.dump create mode 100755 test/unittest/resource/testdata/dwarf/hiperf_example_cmd create mode 100755 test/unittest/resource/testdata/dwarf/perf.data create mode 100755 test/unittest/resource/testdata/dwarf/user_data.dump create mode 100755 test/unittest/resource/testdata/dwarf/user_regs.dump create mode 100755 test/unittest/resource/testdata/ehdr_from_readelf_32 create mode 100755 test/unittest/resource/testdata/ehdr_from_readelf_64 create mode 100755 test/unittest/resource/testdata/elf32_test create mode 100755 test/unittest/resource/testdata/elf32_test_broken create mode 100755 test/unittest/resource/testdata/elf32_test_stripped create mode 100755 test/unittest/resource/testdata/elf32_test_stripped_nobuildid create mode 100755 test/unittest/resource/testdata/elf32_test_stripped_noehframehdr create mode 100644 test/unittest/resource/testdata/elf_test create mode 100644 test/unittest/resource/testdata/elf_test_stripped create mode 100755 test/unittest/resource/testdata/elf_test_stripped_broken create mode 100755 test/unittest/resource/testdata/elf_test_stripped_nobuildid create mode 100755 test/unittest/resource/testdata/elf_test_stripped_noehframehdr create mode 100755 test/unittest/resource/testdata/empytfile create mode 100755 test/unittest/resource/testdata/perf.data create mode 100755 test/unittest/resource/testdata/perf2.data create mode 100755 test/unittest/resource/testdata/perfnew.data create mode 100755 test/unittest/resource/testdata/phdrs_from_readelf_32 create mode 100755 test/unittest/resource/testdata/phdrs_from_readelf_64 create mode 100755 test/unittest/resource/testdata/proto_test create mode 100755 test/unittest/resource/testdata/report/buildid_test_elf_32 create mode 100755 test/unittest/resource/testdata/report/buildid_test_elf_64 create mode 100755 test/unittest/resource/testdata/report/elf32_test_broken create mode 100755 test/unittest/resource/testdata/report/hiperf_example_cmd create mode 100755 test/unittest/resource/testdata/report/perf.data.error.format.libreport create mode 100755 test/unittest/resource/testdata/report/perf.data.libreport create mode 100755 test/unittest/resource/testdata/report/perf.disable.unwind.hiperf_example_cmd.data create mode 100755 test/unittest/resource/testdata/report/perf.dwarf.data create mode 100755 test/unittest/resource/testdata/report/perf.dwarf.data.txt create mode 100755 test/unittest/resource/testdata/report_test.data create mode 100755 test/unittest/resource/testdata/report_test_callstack.txt create mode 100755 test/unittest/resource/testdata/report_test_diff.txt create mode 100755 test/unittest/resource/testdata/report_test_dsos.txt create mode 100755 test/unittest/resource/testdata/report_test_funcs.txt create mode 100755 test/unittest/resource/testdata/report_test_i.txt create mode 100755 test/unittest/resource/testdata/report_test_limit.txt create mode 100755 test/unittest/resource/testdata/report_test_limit1.txt create mode 100755 test/unittest/resource/testdata/report_test_sort1.txt create mode 100755 test/unittest/resource/testdata/report_test_sort2.txt create mode 100755 test/unittest/resource/testdata/report_test_symbol.txt create mode 100755 test/unittest/resource/testdata/report_test_tids.txt create mode 100755 test/unittest/resource/testdata/report_test_tids1.txt create mode 100755 test/unittest/resource/testdata/shdrs_from_readelf_32 create mode 100755 test/unittest/resource/testdata/shdrs_from_readelf_64 create mode 100755 test/unittest/resource/testdata/source/build_elf_test.sh create mode 100755 test/unittest/resource/testdata/source/elf_test_source_code.cpp create mode 100755 test/unittest/resource/testdata/symbols_file_test_elf32 create mode 100755 test/unittest/resource/testdata/symbols_file_test_elf64 create mode 100755 test/unittest/resource/testdata/syms_from_readelf_32 create mode 100755 test/unittest/resource/testdata/syms_from_readelf_64 create mode 100644 test/unittest/resource/testdata/vmlinux create mode 100755 test/unittest/resource/testdata/vmlinux_stripped create mode 100755 test/unittest/resource/testdata/vmlinux_stripped_broken create mode 100755 test/unittest/resource/testdata/vmlinux_stripped_nobuildid create mode 100755 test/unittest/script/coverage/gcov.sh create mode 100755 test/unittest/script/coverage/lcov.sh diff --git a/.gitignore b/.gitignore new file mode 100755 index 0000000..fa346bf --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +# some test file +workspace.code-workspace +.vscode +.tags +**/local.properties +**/.idea +**/.gradle +*.log +*.patch +*.pyc diff --git a/BUILD.gn b/BUILD.gn new file mode 100644 index 0000000..8a82535 --- /dev/null +++ b/BUILD.gn @@ -0,0 +1,476 @@ +# Copyright (C) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") +import("//developtools/hiperf/hiperf.gni") + +function_disable_define = [ +] + +config("hiperf_inner_config") { + visibility = [ ":*" ] + ldflags = [] + cflags = code_check_flag + defines = function_disable_define + + if(hiperf_code_analyze && is_ohos) { + cflags += code_analyze_flag + cflags -= [ "-Werror" ] + } + + if(is_mingw) { + # lld: error: unable to find library -latomic + # lld: error: unable to find library -ldl + # lld: error: unable to find library -lrt + ldflags += [ "-Wl,--whole-archive", "-lpthread", "-Wl,--no-whole-archive"] + } else if(is_linux) { + ldflags += [ "-Wl,--whole-archive", "-lpthread", "-latomic", "-ldl", "-lrt", "-Wl,--no-whole-archive"] + } + + include_dirs = [ + "${hiperf_path}/include", + ] + + + # debug link + # ldflags += [ "-v"] + + if(hiperf_debug) { + defines += [ + "HIPERF_DEBUG", + "HIPERF_DEBUG_PRINTF", # if u want to see printf in the log ? + ] + } else { + # some value just for debug, but also can be opt by clang ,don't as error + # but maybe we need do some opt + cflags += [ "-Wno-unused-variable" ] + } + + if(hiperf_check_time) { + defines += [ "HIPERF_DEBUG_TIME", ] + } + + cflags += [ "-std=c++17" ] + if(is_linux) { + cflags += [ "-g" ] # we need debug info when it crash. + } + defines += [ "is_mingw=${is_mingw}" ] + defines += [ "is_linux=${is_linux}" ] + defines += [ "is_ohos=${is_ohos}" ] + defines += [ "is_double_framework=${is_double_framework}" ] + if(hiperf_target_host) { + defines += [ "target_cpu_${host_cpu}" ] + } else { + defines += [ "target_cpu_${target_cpu}" ] + } + + if(is_mingw) { + cflags += [ "-includeMingW64Fix.h" ] + cflags += [ "-Wno-inconsistent-dllimport" ] # in mingw some sec api will overwrite by utilsecurec + defines +=[ "WIN32_LEAN_AND_MEAN" ] + + include_dirs += [ + "${hiperf_path}/include/nonlinux/", + "//third_party/Linux_Kernel/include/uapi" + ] + } + + if(hiperf_test_coverage && is_ohos) { + cflags += [ "-fprofile-arcs", "-ftest-coverage" ] + ldflags += [ "--coverage" ] + } +} + +sources_platform_common = [ + "./src/perf_file_format.cpp", + "./src/command.cpp", + "./src/subcommand.cpp", + "./src/option.cpp", + "./src/utilities.cpp", + "./src/symbols_file.cpp", + "./src/virtual_runtime.cpp", + "./src/virtual_thread.cpp", + "./src/perf_file_reader.cpp", + "./src/perf_event_record.cpp", + "./src/dwarf_encoding.cpp", + "./src/elf_file.cpp", + "./src/elf_header.cpp", + "./src/section_header.cpp", + "./src/program_header.cpp", + "./src/elf_symbol.cpp", + "./src/subcommand_help.cpp", + "./src/subcommand_dump.cpp", + "./src/subcommand_report.cpp", + "./src/report.cpp", + "./src/report_json_file.cpp", + "./src/register.cpp", + "./src/callstack.cpp", +] + +if(hiperf_debug) { + sources_platform_common += [ + "./src/debug_logger.cpp", + "./src/option_debug.cpp", + ] +} + +sources_platform_linux = [ + "./src/perf_events.cpp", + "./src/tracked_command.cpp", + "./src/ring_buffer.cpp", + "./src/perf_file_writer.cpp", + "./src/subcommand_stat.cpp", + "./src/subcommand_record.cpp", + "./src/subcommand_list.cpp", +] + +common_deps = [ + "//utils/native/base:utilsecurec", + "//third_party/zlib:libz", + ":support_elf", + ":support_protobuf", + ":support_libunwind" +] + +if(!hiperf_use_libunwind) { + common_deps -= [ ":support_libunwind" ] +} + +if (is_ohos) { + common_deps += [ "//utils/native/base:utilsecurec_shared" ] + common_deps -= [ "//utils/native/base:utilsecurec" ] +} + +if(hiperf_target_static) { + common_deps -= [ ":support_protobuf" ] +} + +common_configs = [ + ":hiperf_inner_config", + "//utils/native/base:utils_config", + "//third_party/googletest:gtest_config", +] + +config("hiperf_syspara_config") { + defines = [ "CONFIG_HAS_SYSPARA" ] +} + +if(is_ohos && hiperf_use_syspara) { + common_configs += [ ":hiperf_syspara_config" ] + common_deps += [ "//base/startup/syspara_lite/interfaces/innerkits/native/syspara:syspara" ] +} + +ohos_source_set("hiperf_platform_common") { + use_exceptions = true + public_deps = common_deps + public_configs = common_configs + defines = [] + + if(is_ohos) { + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + ] + } else { + defines += [ "CONFIG_NO_HILOG" ] + } + sources = sources_platform_common +} + +config("platform_linux_config") { + defines = ["SUPPORT_PERF_EVENT"] +} + +ohos_source_set("hiperf_platform_linux") { + use_exceptions = true + public_deps = common_deps + public_configs = common_configs + + public_configs += [ ":platform_linux_config" ] + configs = [ "interfaces/innerkits/native:hiperf_client_config" ] + + sources = sources_platform_linux +} + +config("unwind_config") { + defines = [ "HAVE_LIBUNWIND=1" ] +} + +ohos_source_set("support_libunwind") { + public_configs = common_configs + public_configs += [ + ":unwind_config", + ] + if(hiperf_target_host) { + public_deps = [ "//third_party/libunwind:unwind_source_${host_cpu}" ] + } else { + public_deps = [ "//third_party/libunwind:unwind_source_${target_cpu}" ] + } +} + +config("elf_config") { +} +ohos_source_set("support_elf") { + public_configs = common_configs + public_configs += [ + ":elf_config", + ] +} + +config("protobuf_config") { + defines = [ "HAVE_PROTOBUF=1" ] + cflags = [ "-Wno-unused-parameter" ] # proto buf head build error + include_dirs = [ + "//third_party/protobuf/src", + "//third_party/protobuf/src/google", + "//third_party/protobuf/src/google/protobuf" + ] +} + +ohos_source_set("support_protobuf") { + use_exceptions = true + #protobuf + public_configs = common_configs + public_configs += [ + ":protobuf_config", + ] + public_deps = [ + ":proto_file_cpp", + "//utils/native/base:utilsecurec" + ] + + sources = [ "./src/report_protobuf_file.cpp" ] +} + +#protobuf { +proto_file_defines = [ + # add your proto file here + "report_sample" +] + +proto_base_dir = "proto" +proto_out_dir = "$target_gen_dir" + "/" + proto_base_dir + +proto_file_codegen = [] +proto_file_sources = [] + +foreach(proto_file, proto_file_defines) { + proto_file_codegen += [ + "$proto_out_dir" + "/" + "$proto_file.pb.h", + "$proto_out_dir" + "/" + "$proto_file.pb.cc", + ] + proto_file_sources += [ + "$proto_base_dir" + "/" + "$proto_file.proto" + ] +} + +# this is so bad , but someone config the protoc's subsystem_name +# the better way is build system need provider host tools path or prebuild tools path +if(is_double_framework) { + protoc_subsystem_out_path = "developtools/profiler" +} else { + protoc_subsystem_out_path = "developtools/developtools" +} +if(default_toolchain == current_toolchain) { + #if target build + host_out_path = "/" + get_label_info(host_toolchain,"name") +} else { + #if host build (for some linke mingw) + host_out_path = "/../" + get_label_info(host_toolchain,"name") +} +host_protoc_path = root_out_dir + host_out_path + "/" + protoc_subsystem_out_path + "/protoc" + +action("hiperf_host_build_proto") { + deps = [ "//third_party/protobuf:protoc(//build/toolchain/linux:clang_x64)" ] + args = [] + outputs = proto_file_codegen + sources = [] + script = "proto/build_proto.sh" + + args += [ rebase_path(host_protoc_path) ] + args += [ "--proto_path", rebase_path(proto_base_dir) ] + args += [ "--cpp_out",rebase_path(proto_out_dir)] + + foreach(proto_file_source, proto_file_sources) { + #tell gn to check which files as source time + sources += [ rebase_path(proto_file_source) ] + args += [ rebase_path(proto_file_source) ] + } +} + +config("proto_file_cpp_config") { + include_dirs = [ + proto_out_dir + ] +} + +ohos_source_set("proto_file_cpp") { + cflags = [] + + deps = [ ":hiperf_host_build_proto"] + public_deps = [ "//third_party/protobuf:protobuf_lite_static" ] + + sources = proto_file_codegen + public_configs = [ ":proto_file_cpp_config" ] +} +#protobuf } + +ohos_executable("hiperf") { + install_enable = true + sources = [ "./src/main.cpp" ] + deps = [ + ":hiperf_platform_common", + ":hiperf_platform_linux", + ] + + if(hiperf_target_static) { + static_link = true + } + + if(is_linux || is_mingw) { + # ld.lld: error: attempted static link of dynamic object hiviewdfx/hilog_native/libhilog.so + static_link = true + } + + subsystem_name = "developtools" + part_name = "hiperf" +} + +ohos_executable("hiperf_host") { + sources = [ "./src/main.cpp" ] + deps = [ ":hiperf_platform_common" ] + + static_link = true + + subsystem_name = "developtools" + part_name = "hiperf" +} + +ohos_source_set("hiperf_platform_host") { + sources = [ "./src/hiperf_libreport.cpp" ] + public_deps = [ ":hiperf_platform_common" ] +} + +ohos_shared_library("hiperf_host_lib") { + public_deps = [ ":hiperf_platform_host" ] + output_name = "hiperf_report" + + ldflags = [ "-static-libstdc++" ] + + subsystem_name = "developtools" + part_name = "hiperf" +} + +ohos_executable("hiperf_host_lib_demo") { + sources = [ "./src/hiperf_libreport_demo.cpp" ] + deps = [ ":hiperf_host_lib" ] + include_dirs = [ "${hiperf_path}/include" ] + + subsystem_name = "developtools" + part_name = "hiperf" +} + +ohos_copy("hiperf_host_python") { + sources = [ "./script" ] + outputs = [ target_out_dir + "/host/" ] + + module_source_dir = target_out_dir + "/$target_name" + module_install_name = "" + subsystem_name = "developtools" + part_name = "hiperf" +} + +ohos_source_set("hiperf_code_analyze") { + deps = [ + ":hiperf_platform_common", + ":hiperf_platform_linux", + ] +} + +group("hiperf_target") { + if(hiperf_target_host) { + deps = [ ":hiperf(${host_toolchain})" ] + } else { + deps = [ ":hiperf"] + } +} + +group("hiperf_test_target") { + testonly = true + deps = [ "test:hiperf_test" ] +} + +group("hiperf_target_all") { + if(is_double_framework) { + deps = [ + ":hiperf_target" + ] + } else { + deps = [ + ":hiperf_target", + ":hiperf_host(//build/toolchain/linux:clang_x64)", # host linux + ":hiperf_host(//build/toolchain/mingw:mingw_x86_64)", # host mingw + ":hiperf_host_lib_demo(//build/toolchain/linux:clang_x64)", # host linux + ":hiperf_host_lib(//build/toolchain/linux:clang_x64)", # host linux + ":hiperf_host_lib(//build/toolchain/mingw:mingw_x86_64)", # host mingw + ":hiperf_host_python", + "interfaces/innerkits/native:hiperf_client", # c++ api + ] + if(is_ohos) { + deps += [ "interfaces/kits/js/napi:hiperf_client_napi", ] # js api + } + } +} + +group("hiperf_demo") { + if(hiperf_target_host) { + deps = [ + "demo/cpp:hiperf_demo(${host_toolchain})", + ] + } else { + deps = [ + "demo/cpp:hiperf_demo", + ] + } +} + +group("hiperf_example_cmd") { + if(hiperf_target_host) { + deps = [ + "demo/cpp:hiperf_example_cmd(${host_toolchain})", + ] + } else { + deps = [ + "demo/cpp:hiperf_example_cmd", + ] + } +} + +group("hiperf_all") { + testonly = true + if (hiperf_code_analyze) { + deps = [ + ":hiperf_code_analyze" + ] + } else { + deps = [ + ":hiperf_target_all", + ":hiperf_example_cmd", + ] + if(!is_double_framework) { + deps += [ + ":hiperf_test_target", + ":hiperf_demo" + ] + } + } +} diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..29f81d8 --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/OAT.xml b/OAT.xml new file mode 100755 index 0000000..9087b6a --- /dev/null +++ b/OAT.xml @@ -0,0 +1,109 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/README.en.md b/README.en.md deleted file mode 100644 index ddff80d..0000000 --- a/README.en.md +++ /dev/null @@ -1,36 +0,0 @@ -# developtools_hiperf - -#### Description -{**When you're done, you can delete the content in this README and update the file with details for others getting started with your repository**} - -#### Software Architecture -Software architecture description - -#### Installation - -1. xxxx -2. xxxx -3. xxxx - -#### Instructions - -1. xxxx -2. xxxx -3. xxxx - -#### Contribution - -1. Fork the repository -2. Create Feat_xxx branch -3. Commit your code -4. Create Pull Request - - -#### Gitee Feature - -1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md -2. Gitee blog [blog.gitee.com](https://blog.gitee.com) -3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore) -4. The most valuable open source project [GVP](https://gitee.com/gvp) -5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help) -6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) diff --git a/README.md b/README.md deleted file mode 100644 index 25d1107..0000000 --- a/README.md +++ /dev/null @@ -1,39 +0,0 @@ -# developtools_hiperf - -#### 介绍 -{**以下是 Gitee 平台说明,您可以替换此简介** -Gitee 是 OSCHINA 推出的基于 Git 的代码托管平台(同时支持 SVN)。专为开发者提供稳定、高效、安全的云端软件开发协作平台 -无论是个人、团队、或是企业,都能够用 Gitee 实现代码托管、项目管理、协作开发。企业项目请看 [https://gitee.com/enterprises](https://gitee.com/enterprises)} - -#### 软件架构 -软件架构说明 - - -#### 安装教程 - -1. xxxx -2. xxxx -3. xxxx - -#### 使用说明 - -1. xxxx -2. xxxx -3. xxxx - -#### 参与贡献 - -1. Fork 本仓库 -2. 新建 Feat_xxx 分支 -3. 提交代码 -4. 新建 Pull Request - - -#### 特技 - -1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md -2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com) -3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目 -4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目 -5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) -6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) diff --git a/README_zh.md b/README_zh.md new file mode 100755 index 0000000..7dfb181 --- /dev/null +++ b/README_zh.md @@ -0,0 +1,407 @@ +# hiperf 应用性能优化剖析组件 + +- [简介](#简介) + - [架构](#架构) + +- [约束](#约束) +- [编译构建](编译构建) +- [目录](#目录) + - [使用说明](#使用说明) + - [接口说明](#接口说明) +- [相关仓](相关仓) + +## 简介 + +hiperf 是 Open Harmony 为开发人员提供的用于调试的命令行工具,用于抓取特定程序或者系统的性能数据,类似内核的 perf 工具,该工具支持在 Windows/Linux/Mac 等操作系统上运行。 + +### 架构 + +![image][1] + +## 目录 + +``` +/developtools/hiperf +├── demo # demo 程序 +│   ├── cpp # C++ demo 程序,示范了如何调用API和模拟的采样场景 +│   └── js # JS demo 程序,示范了如何调用API +├── include # 工程的头文件 +│   └── nonlinux # 交叉编译的头文件(非linux平台) +├── interfaces # 接口忘记 +│   ├── innerkits # C++ API 接口 +│   └── kits # JS API 接口 +├── proto # report 命令导出到proto的数据结构定义 +├── script # Host 脚本,包括 HTML +│   └── test # 脚本的单元测试 +├── src # 源代码文件夹 +└── test # 源代码的单元测试 + +``` + +## 约束 + +运行环境条件约束如下 + +| 依赖组件 | 版本 | +| -------- | ----- | +| Python | 3.7.0 | +| | | + + + +## 编译构建 + +#### 基础配置 + +- 确保组件名在于产品形态配置的 json 中 + - [产品形态配置](https://gitee.com/openharmony/productdefine_common) + - 加入 `"developtools:hiperf":{}` 即可 + + +#### 编译命令 + +| 编译说明 | 编译参数 | +| -------------------------------------- | ----------------------------------- | +| 只编译当前设备平台的二进制执行文件 | --build-target hiperf_target | +| 编译所有的平台的所有组件(包括单元测试) | --build-target hiperf_all | +| 编译目标为 x86_64 Linux 平台的工具 | --gn-args "hiperf_target_host=true" | +| 编译单元测试 | --build-target hiperf_unittest | +| 编译单元测试的接口部分(命令行部分) | --build-target hiperf_interfacetest | + + +#### 编译输出 #### + +| 编译目标 | 运行平台 | 文件位置 | 文件名 | +| ----------------- | -------- | ----------------------------------------------------- | -------------------- | +| Dev 端命令行程序 | arm | out\ohos-arm-release\developtools\hiperf\hiperf | hiperf | +| | linux | out\ohos-arm-release\clang_x64\developtools\hiperf | hiperf | +| Host 端命令行程序 | linux | out\ohos-arm-release\clang_x64\developtools\hiperf | hiperf_host | +| | windows | out\ohos-arm-release\mingw_x86_64\developtools\hiperf | hiperf_host.exe | +| Host 端动态库 | linux | out\ohos-arm-release\clang_x64\developtools\hiperf | libhiperf_report.so | +| | windows | out\ohos-arm-release\mingw_x86_64\developtools\hiperf | libhiperf_report.dll | + +也可以在编译完成后 + +运行 developtools/hiperf/script/package.sh 打包到out文件夹中 + +``` +host/ +└── developtools + ├── hiperf + │   ├── bin # 所有的二进制文件 + │   │   ├── linux # linux 平台 + │   │   │   └── x86_64 + │   │   │   ├── hiperf_host # PC运行的执行程序,支持Report和Dump命令 + │   │   │   └── libhiperf_report.so # PC运行的LIB文件,供python脚本使用 + │   │   ├── ohos + │   │   │   └── arm # arm 平台 + │   │   │   └── hiperf # 板端执行程序 + │   │   └── windows # windows 平台 + │   │   └── x86_64 + │   │   ├── hiperf_host.exe # PC运行的执行程序 + │   │   └── libhiperf_report.dll # PC运行的LIB文件 + │   │ + │   │ # 下面都是python文件,在PC侧执行 + │   ├── command_script.py # hiperf 命令行的包装脚本,产生采样数据 + │   ├── hiperf_utils.py # 脚本自己的工具类 + │   ├── loadlib_test.py # lib 测试脚本 + │   ├── make_diff.py # 产生Diff数据的脚本 + │   ├── make_report.py # 从采样数据产生报告的脚本 + │   ├── recv_binary_cache.py # 收集符号表的脚本 + │   └── report.html # HTML 展示页面的模板 + └── hiperf.tar.gz # 上述文件的打包文件 + +``` + + + +#### 带调试符号的版本 + +- 在对应的平台out里面找 exe.unstripped 和 lib.unstripped,例如: + + - out\ohos-arm-release\clang_x64\exe.unstripped\clang_x64\developtools\hiperf + + + +## 使用说明 + +### 测试代码 + +我们在 hiperf_example_cmd.cpp 里面提供了一些测试代码, + +用来验证一些采样功能,比如线程调度,内存申请,CPU 负荷等等。 + +代码位于 + +``` +hiperf\demo\cpp\hiperf_example_cmd.cpp +``` + +测试命令帮助 + +``` + ./hiperf_example_cmd --help +this is a demo test comand + Use the following commands to simulate different scenarios + --help + this page + --thread + setup the thread number, default is 5 second + --time