1# Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved. 2# Licensed under the Apache License, Version 2.0 (the "License"); 3# you may not use this file except in compliance with the License. 4# You may obtain a copy of the License at 5# 6# http://www.apache.org/licenses/LICENSE-2.0 7# 8# Unless required by applicable law or agreed to in writing, software 9# distributed under the License is distributed on an "AS IS" BASIS, 10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11# See the License for the specific language governing permissions and 12# limitations under the License. 13 14import("//build/ohos.gni") 15import("//developtools/profiler/device/base/config.gni") 16 17skel_src_dir = "$target_out_dir/src" 18skel_out_dir = "$root_gen_dir/cpp/developtools/profiler/hiebpf/ebpf_skeleton" 19 20config("common_config") { 21 cflags = [ 22 "-Wno-unused-command-line-argument", 23 "-Wno-unused-variable", 24 "-Wno-unused-function", 25 "-Wno-gnu-folding-constant", 26 "-fno-omit-frame-pointer", 27 "-mno-omit-leaf-frame-pointer", 28 "-fno-inline", 29 "-fno-optimize-sibling-calls", 30 "-Wno-format", 31 "-Wno-switch", 32 "-Wno-braced-scalar-init", 33 "-fno-common", 34 ] 35 defines = [ 36 "__KERNEL__", 37 "BPF_LOGGER_DEBUG", 38 "HH_LOGGER_DEBUG", 39 ] 40 include_dirs = [ 41 "$skel_out_dir", 42 "./include", 43 "//third_party/libbpf/src", 44 ] 45} 46 47config("user_common_config") { 48 cflags = [ 49 "-g", 50 "-Wno-unknown-attributes", 51 "-Wno-bitwise-op-parentheses", 52 "-Wno-shift-op-parentheses", 53 "-Wno-sign-compare", 54 "-Wno-format", 55 ] 56 include_dirs = [] 57 defines = [ "__aarch64__" ] 58} 59 60config("kern_common_config") { 61 cflags = [ 62 "-target", 63 "bpf", 64 "-g", 65 "-fno-stack-protector", 66 "-fno-data-sections", 67 ] 68 defines = [ "__aarch64__" ] 69 include_dirs = [] 70} 71 72ohos_source_set("hiebpf.bpf") { 73 remove_configs = [ "//build/config/coverage:default_coverage" ] 74 if (use_libfuzzer) { 75 remove_configs += [ "//build/config/sanitizers:default_sanitizer_flags" ] 76 } 77 cflags_c = [ "-fno-lto" ] 78 sources = [ "./src/hiebpf.bpf.c" ] 79 configs = [ 80 ":common_config", 81 ":kern_common_config", 82 ] 83 subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}" 84 part_name = "${OHOS_PROFILER_PART_NAME}" 85 output_name = "hiebpf.bpf.o" 86} 87 88action("gen_bpf_skeleton") { 89 script = "./scripts/gen_skeleton.sh" 90 sources = [] 91 outputs = [ "$skel_out_dir/hiebpf.skel.h" ] 92 bpftool_dir = rebase_path("//prebuilts/develop_tools/bpftool/bin/bpftool") 93 skel_src_dir_abs = rebase_path("${skel_src_dir}") 94 skel_out_dir_abs = rebase_path("${skel_out_dir}") 95 args = [ 96 bpftool_dir, 97 skel_src_dir_abs, 98 skel_out_dir_abs, 99 ] 100 deps = [ ":hiebpf.bpf" ] 101} 102 103ohos_source_set("hiebpf_source_common") { 104 public_configs = [ 105 ":common_config", 106 ":user_common_config", 107 "${OHOS_PROFILER_DIR}/device/base:hiprofiler_test_config", 108 ] 109 110 sources = [ 111 "./src/bpf_controller.cpp", 112 "./src/bpf_event_receiver.cpp", 113 "./src/bpf_log_reader.cpp", 114 "./src/command_helper.cpp", 115 "./src/elf_file.cpp", 116 "./src/elf_symbol_info.cpp", 117 "./src/fstrace_args_converter.cpp", 118 "./src/hhlog.cpp", 119 "./src/hiebpf_data_file.cpp", 120 "./src/ipc_unix_socket.cpp", 121 "./src/kernel_symbol_info.cpp", 122 "./src/libbpf_logger.cpp", 123 "./src/maps_info.cpp", 124 "./src/ringbuffer.cpp", 125 "./src/utilities.cpp", 126 ] 127 128 public_deps = [ 129 ":gen_bpf_skeleton", 130 "//third_party/bounds_checking_function:libsec_static", 131 "//third_party/libbpf:libbpf", 132 ] 133 subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}" 134 part_name = "${OHOS_PROFILER_PART_NAME}" 135} 136 137ohos_executable("hiebpf") { 138 sources = [ "./src/hiebpf.cpp" ] # this is main() 139 140 deps = [ ":hiebpf_source_common" ] 141 142 subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}" 143 part_name = "${OHOS_PROFILER_PART_NAME}" 144 output_name = "hiebpf" 145} 146 147group("hiebpf_tool") { 148 if (current_toolchain == "//build/toolchain/ohos:ohos_clang_arm64") { 149 if (!is_asan && use_musl) { 150 deps = [ 151 ":hiebpf", 152 ":hiebpf.bpf", 153 ] 154 } 155 } 156} 157 158group("hiebpf_all") { 159 testonly = true 160 deps = [ 161 ":hiebpf_tool", 162 "test:hiebpf_ut", 163 ] 164} 165