1# Copyright (C) 2021 Huawei Device Co., Ltd. 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 sources = [ "./src/hiebpf.bpf.c" ] 78 configs = [ 79 ":common_config", 80 ":kern_common_config", 81 ] 82 subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}" 83 part_name = "${OHOS_PROFILER_PART_NAME}" 84 output_name = "hiebpf.bpf.o" 85} 86 87action("gen_bpf_skeleton") { 88 script = "./scripts/gen_skeleton.sh" 89 sources = [] 90 outputs = [ "$skel_out_dir/hiebpf.skel.h" ] 91 bpftool_dir = rebase_path("//prebuilts/develop_tools/bpftool/bin/bpftool") 92 skel_src_dir_abs = rebase_path("${skel_src_dir}") 93 skel_out_dir_abs = rebase_path("${skel_out_dir}") 94 args = [ 95 bpftool_dir, 96 skel_src_dir_abs, 97 skel_out_dir_abs, 98 ] 99 deps = [ ":hiebpf.bpf" ] 100} 101 102ohos_source_set("hiebpf_source_common") { 103 public_configs = [ 104 ":common_config", 105 ":user_common_config", 106 "${OHOS_PROFILER_DIR}/device/base:hiprofiler_test_config", 107 ] 108 109 sources = [ 110 "./src/bpf_controller.cpp", 111 "./src/bpf_event_receiver.cpp", 112 "./src/bpf_log_reader.cpp", 113 "./src/command_helper.cpp", 114 "./src/elf_file.cpp", 115 "./src/elf_symbol_info.cpp", 116 "./src/fstrace_args_converter.cpp", 117 "./src/hhlog.cpp", 118 "./src/hiebpf_data_file.cpp", 119 "./src/ipc_unix_socket.cpp", 120 "./src/kernel_symbol_info.cpp", 121 "./src/libbpf_logger.cpp", 122 "./src/maps_info.cpp", 123 "./src/ringbuffer.cpp", 124 "./src/utilities.cpp", 125 ] 126 127 public_deps = [ 128 ":gen_bpf_skeleton", 129 "//third_party/bounds_checking_function:libsec_static", 130 "//third_party/libbpf:libbpf", 131 ] 132 subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}" 133 part_name = "${OHOS_PROFILER_PART_NAME}" 134} 135 136ohos_executable("hiebpf") { 137 sources = [ "./src/hiebpf.cpp" ] # this is main() 138 139 deps = [ ":hiebpf_source_common" ] 140 141 subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}" 142 part_name = "${OHOS_PROFILER_PART_NAME}" 143 output_name = "hiebpf" 144} 145 146group("hiebpf_tool") { 147 if (current_toolchain == "//build/toolchain/ohos:ohos_clang_arm64") { 148 if (!is_asan && use_musl) { 149 deps = [ 150 ":hiebpf", 151 ":hiebpf.bpf", 152 ] 153 } 154 } 155} 156 157group("hiebpf_all") { 158 testonly = true 159 deps = [ 160 ":hiebpf_tool", 161 "test:hiebpf_ut", 162 ] 163} 164