1 Star 0 Fork 100

mashaohua7/developtools_hiperf_2

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
BUILD.gn 13.54 KB
一键复制 编辑 原始数据 按行查看 历史
yuyanqing 提交于 2024-04-10 11:19 . unwinder remove depend abilitybase
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
# 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("./hiperf.gni")
declare_args() {
hiperf_feature_mingw_uapi_dir =
"../../kernel/linux/patches/linux-5.10/prebuilts/usr/include"
}
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 ?
]
}
if (hiperf_check_time) {
defines += [ "HIPERF_DEBUG_TIME" ]
}
cflags += [ "-std=c++17" ]
defines += [ "is_mingw=${is_mingw}" ]
defines += [ "is_linux=${is_linux}" ]
defines += [ "is_ohos=${is_ohos}" ]
defines += [ "is_emulator=${is_emulator}" ]
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" ]
defines += [ "WIN32_LEAN_AND_MEAN" ]
defines += [ "__LITTLE_ENDIAN_BITFIELD" ]
include_dirs += [
"${hiperf_path}/include/nonlinux/",
hiperf_feature_mingw_uapi_dir,
]
}
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/subcommand_help.cpp",
"./src/subcommand_dump.cpp",
"./src/subcommand_report.cpp",
"./src/report.cpp",
"./src/report_json_file.cpp",
"./src/register.cpp",
"./src/unique_stack_table.cpp",
]
if (is_ohos) {
sources_platform_common += [ "./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 = [
":support_elf",
":support_protobuf",
"//third_party/bounds_checking_function:libsec_static",
"//third_party/zlib:libz",
]
common_configs = [
":hiperf_inner_config",
"//third_party/bounds_checking_function:libsec_public_config",
"../../commonlibrary/c_utils/base:utils_config",
"//third_party/googletest:gtest_config",
]
if (is_ohos) {
common_deps += [ "//third_party/bounds_checking_function:libsec_shared" ]
common_deps -= [ "//third_party/bounds_checking_function:libsec_static" ]
}
if (hiperf_target_static) {
common_deps -= [ ":support_protobuf" ]
}
if (hiperf_use_libunwind) {
common_deps += [ ":support_libunwind" ]
}
config("hiperf_syspara_config") {
defines = [ "CONFIG_HAS_SYSPARA" ]
}
config("libunwinder_config") {
defines = [ "HAVE_LIBUNWINDER=1" ]
}
if (hiperf_use_libunwinder) {
common_configs += [ ":libunwinder_config" ]
}
if (is_ohos && hiperf_use_syspara) {
common_configs += [ ":hiperf_syspara_config" ]
}
ohos_source_set("hiperf_platform_common") {
part_name = "hiperf"
subsystem_name = "developtools"
use_exceptions = true
public_deps = common_deps
public_configs = common_configs
defines = []
if (is_ohos) {
external_deps = [
"c_utils:utils",
"faultloggerd:libunwinder_static",
"hilog:libhilog",
"init:libbegetutil",
"ipc:ipc_core",
"samgr:samgr_proxy",
]
if (bundle_framework_enable) {
external_deps += [
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
]
defines += [ "BUNDLE_FRAMEWORK_ENABLE" ]
}
if (ability_base_enable) {
external_deps += [ "ability_base:extractortool" ]
defines += [ "ENABLE_HAP_EXTRACTOR" ]
}
} else {
external_deps = [ "faultloggerd:unwinder_host" ]
defines += [ "CONFIG_NO_HILOG" ]
}
sources = sources_platform_common
}
config("platform_linux_config") {
defines = [ "SUPPORT_PERF_EVENT" ]
}
ohos_source_set("hiperf_platform_linux") {
part_name = "hiperf"
subsystem_name = "developtools"
use_exceptions = true
public_deps = common_deps
public_configs = common_configs
if (is_ohos) {
external_deps = [
"faultloggerd:libunwinder_static",
"hilog:libhilog",
"init:libbegetutil",
]
} else {
external_deps = [ "faultloggerd:unwinder_host" ]
}
public_configs += [ ":platform_linux_config" ]
configs = [ "interfaces/innerkits/native:hiperf_client_config" ]
sources = sources_platform_linux
}
config("libunwind_config") {
defines = [ "HAVE_LIBUNWIND=1" ]
}
ohos_source_set("support_libunwind") {
part_name = "hiperf"
subsystem_name = "developtools"
public_configs = common_configs
public_configs += [ ":libunwind_config" ]
if (hiperf_target_host) {
public_deps = [ "//third_party/libunwind:unwind_source_${host_cpu}" ]
} else {
if (target_cpu == "arm64") {
public_deps = [ "//third_party/libunwind:unwind_source_arm64_opt" ]
} else {
public_deps = [ "//third_party/libunwind:unwind_source_${target_cpu}" ]
}
}
}
config("elf_config") {
}
ohos_source_set("support_elf") {
part_name = "hiperf"
subsystem_name = "developtools"
public_configs = common_configs
public_configs += [ ":elf_config" ]
}
config("protobuf_config") {
defines = [ "HAVE_PROTOBUF=1" ]
include_dirs = [
"//third_party/protobuf/src",
"//third_party/protobuf/src/google",
"//third_party/protobuf/src/google/protobuf",
]
}
ohos_source_set("support_protobuf") {
part_name = "hiperf"
subsystem_name = "developtools"
use_exceptions = true
#protobuf
public_configs = common_configs
public_configs += [ ":protobuf_config" ]
public_deps = [
":proto_file_cpp",
"//third_party/bounds_checking_function:libsec_static",
]
if (is_ohos) {
external_deps = [ "faultloggerd:libunwinder_static" ]
} else {
external_deps = [ "faultloggerd:unwinder_host" ]
}
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
protoc_subsystem_out_path = "thirdparty/protobuf"
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") {
part_name = "hiperf"
subsystem_name = "developtools"
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_etc",
":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
}
external_deps = [
"faultloggerd:libunwinder_static",
"hilog:libhilog",
]
subsystem_name = "developtools"
part_name = "hiperf"
}
ohos_executable("hiperf_host") {
sources = [ "./src/main.cpp" ]
deps = [ ":hiperf_platform_common" ]
if (use_musl) {
static_link = true
}
external_deps = [ "faultloggerd:unwinder_host" ]
subsystem_name = "developtools"
part_name = "hiperf"
}
ohos_prebuilt_etc("hiperf.para") {
source = "etc/hiperf.para"
install_images = [
"system",
"updater",
]
module_install_dir = "etc/param"
part_name = "hiperf"
subsystem_name = "developtools"
}
ohos_prebuilt_etc("hiperf.para.dac") {
source = "etc/hiperf.para.dac"
install_images = [
"system",
"updater",
]
module_install_dir = "etc/param"
part_name = "hiperf"
subsystem_name = "developtools"
}
ohos_prebuilt_etc("hiperf.cfg") {
source = "etc/hiperf.cfg"
relative_install_dir = "init"
subsystem_name = "developtools"
part_name = "hiperf"
}
group("hiperf_etc") {
deps = [
":hiperf.cfg",
":hiperf.para",
":hiperf.para.dac",
]
}
ohos_source_set("hiperf_platform_host") {
part_name = "hiperf"
subsystem_name = "developtools"
sources = [ "./src/hiperf_libreport.cpp" ]
public_deps = [ ":hiperf_platform_common" ]
external_deps = [ "faultloggerd:unwinder_host" ]
}
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") {
part_name = "hiperf"
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_emulator) {
if (is_double_framework) {
deps = [ ":hiperf_target" ]
} else {
deps = []
if (!use_libfuzzer) {
deps += [
":hiperf_host(//build/toolchain/linux:clang_x64)", # host linux
":hiperf_host(//build/toolchain/mingw:mingw_x86_64)", # host mingw
":hiperf_host_lib(//build/toolchain/linux:clang_x64)", # host linux
":hiperf_host_lib(//build/toolchain/mingw:mingw_x86_64)", # host_mingw
":hiperf_host_lib_demo(//build/toolchain/linux:clang_x64)", # host_linux
":hiperf_host_python",
]
}
deps += [
":hiperf_target",
"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_example_cmd",
":hiperf_target_all",
]
if (!is_double_framework) {
deps += [
":hiperf_demo",
":hiperf_test_target",
]
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mashaohua7/developtools_hiperf_2.git
git@gitee.com:mashaohua7/developtools_hiperf_2.git
mashaohua7
developtools_hiperf_2
developtools_hiperf_2
master

搜索帮助