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("../../base/config.gni") 16 17config("hook_config") { 18 defines = [ 19 "HAVE_LIBUNWIND=0", 20 "HAVE_LIBUNWINDER=1", 21 "HIPERF_DEBUG", 22 "CONFIG_NO_HILOG", 23 ] 24 defines += [ "target_cpu_${target_cpu}" ] 25 if (!is_asan) { 26 defines += [ "HOOK_ENABLE" ] 27 } 28} 29 30ohos_source_set("native_hook_source") { 31 use_exceptions = true 32 sources = [ 33 "../../services/ipc/src/socket_context.cpp", 34 "../../services/ipc/src/unix_socket_client.cpp", 35 "../native_daemon/src/debug_logger.cpp", 36 "../native_daemon/src/get_thread_id.cpp", 37 "../native_daemon/src/register.cpp", 38 "../native_daemon/src/utilities.cpp", 39 "src/hook_client.cpp", 40 "src/hook_socket_client.cpp", 41 "src/runtime_stack_range.cpp", 42 "src/sampling.cpp", 43 "src/stack_writer.cpp", 44 ] 45 include_dirs = [ 46 "./include", 47 "../api/include", 48 "../api/src", 49 "../../base/include/", 50 "../native_daemon/include", 51 "${OHOS_PROFILER_DIR}/interfaces/kits", 52 "${OHOS_PROFILER_DIR}/device/services/ipc/include", 53 "${OHOS_PROFILER_DIR}/device/services/shared_memory/include", 54 ] 55 public_configs = [ 56 ":hook_config", 57 "${OHOS_PROFILER_DIR}/device/base:hiprofiler_test_config", 58 ] 59 deps = [ 60 "${OHOS_PROFILER_DIR}/device/services/shared_memory:shared_memory_lite", 61 "../../base:hiprofiler_base", 62 ] 63 if (hiprofiler_use_libunwind) { 64 public_deps = [ "//third_party/libunwind:unwind_source_${target_cpu}" ] 65 } 66 external_deps = [ 67 "bounds_checking_function:libsec_shared", 68 "c_utils:utils", 69 "ffrt:libffrt", 70 "hitrace:libhitracechain", 71 "init:libbegetutil", 72 "zlib:libz", 73 ] 74 if (hiprofiler_use_libunwinder) { 75 external_deps += [ "faultloggerd:libunwinder" ] 76 } 77 78 if (current_toolchain != host_toolchain) { 79 defines = [ "HAVE_HILOG" ] 80 external_deps += [ "hilog:libhilog_base" ] 81 } 82 subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}" 83 part_name = "${OHOS_PROFILER_PART_NAME}" 84 defines += [ "NO_PROTOBUF" ] 85 cflags = [ 86 "-Wno-error=inline-asm", 87 "-DPERF_TEST_DATA", 88 "-O3", 89 ] 90} 91 92ohos_shared_library("native_hook") { 93 output_name = "native_hook" 94 deps = [ ":native_hook_source" ] 95 if (current_toolchain != host_toolchain) { 96 defines = [ "HAVE_HILOG" ] 97 external_deps = [ "hilog:libhilog_base" ] 98 } 99 version_script = "libnative_hook.map" 100 install_enable = true 101 subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}" 102 part_name = "${OHOS_PROFILER_PART_NAME}" 103} 104 105ohos_executable("nativetest_c") { 106 output_name = "nativetest_c" 107 sources = [ "test/hook_test.c" ] 108 109 if (current_toolchain != host_toolchain) { 110 defines = [ "HAVE_HILOG" ] 111 if (use_musl && !is_asan) { 112 defines += [ "HOOK_ENABLE" ] 113 } 114 external_deps = [ "hilog:libhilog_base" ] 115 } 116 cflags = [ 117 "-Wno-error=inline-asm", 118 "-O3", 119 ] 120 external_deps += [ "bounds_checking_function:libsec_shared" ] 121 ldflags = [ "-rdynamic" ] 122 install_enable = false 123 subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}" 124 part_name = "${OHOS_PROFILER_PART_NAME}" 125} 126 127ohos_executable("nativetest_cpp") { 128 output_name = "nativetest_cpp" 129 sources = [ "test/hook_test.cpp" ] 130 131 if (current_toolchain != host_toolchain) { 132 defines = [ "HAVE_HILOG" ] 133 external_deps = [ "hilog:libhilog_base" ] 134 } 135 136 cflags = [ 137 "-Wno-error=inline-asm", 138 "-O3", 139 ] 140 ldflags = [ "-rdynamic" ] 141 142 install_enable = false 143 subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}" 144 part_name = "${OHOS_PROFILER_PART_NAME}" 145} 146 147ohos_shared_library("nativetest_so") { 148 output_name = "nativetest_so" 149 sources = [ "test/hook_so.cpp" ] 150 151 if (current_toolchain != host_toolchain) { 152 defines = [ "HAVE_HILOG" ] 153 external_deps = [ "hilog:libhilog_base" ] 154 } 155 156 cflags = [ 157 "-Wno-error=inline-asm", 158 "-O3", 159 ] 160 161 install_enable = false 162 subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}" 163 part_name = "${OHOS_PROFILER_PART_NAME}" 164} 165 166ohos_executable("malloctest_cpp") { 167 output_name = "malloctest_cpp" 168 sources = [ "test/malloc_test.cpp" ] 169 170 if (current_toolchain != host_toolchain) { 171 defines = [ "HAVE_HILOG" ] 172 external_deps = [ "hilog:libhilog_base" ] 173 } 174 175 cflags = [ 176 "-Wno-error=inline-asm", 177 "-O3", 178 ] 179 external_deps += [ 180 "bounds_checking_function:libsec_shared", 181 "hisysevent:libhisysevent", 182 ] 183 ldflags = [ "-rdynamic" ] 184 install_enable = false 185 subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}" 186 part_name = "${OHOS_PROFILER_PART_NAME}" 187} 188 189ohos_executable("perf_test_data") { 190 output_name = "perf_test_data" 191 sources = [ "test/perf_test_data.cpp" ] 192 193 if (current_toolchain != host_toolchain) { 194 defines = [ "HAVE_HILOG" ] 195 external_deps = [ "hilog:libhilog_base" ] 196 } 197 198 cflags = [ "-Wno-error=inline-asm" ] 199 install_enable = false 200 ldflags = [ "-rdynamic" ] 201 subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}" 202 part_name = "${OHOS_PROFILER_PART_NAME}" 203} 204 205ohos_executable("statisticstest_cpp") { 206 output_name = "statisticstest_cpp" 207 sources = [ "test/statistics_test.cpp" ] 208 209 if (current_toolchain != host_toolchain) { 210 defines = [ "HAVE_HILOG" ] 211 external_deps = [ "hilog:libhilog_base" ] 212 } 213 214 cflags = [ 215 "-Wno-error=inline-asm", 216 "-O3", 217 ] 218 ldflags = [ "-rdynamic" ] 219 external_deps += [ "bounds_checking_function:libsec_shared" ] 220 install_enable = false 221 subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}" 222 part_name = "${OHOS_PROFILER_PART_NAME}" 223} 224