1 Star 0 Fork 100

shuxinyiA/developtools_hiperf_head

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
BUILD.gn 11.22 KB
一键复制 编辑 原始数据 按行查看 历史
Mupceet 提交于 2022-07-05 15:53 . init
# 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 ?
]
}
if (product_name == "Hi3516DV300") {
defines += [ "LITTLE_MEMORY" ]
}
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_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/",
"//kernel/linux/linux-5.10/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 = [
":support_elf",
":support_libunwind",
":support_protobuf",
"//third_party/bounds_checking_function:libsec_static",
"//third_party/zlib:libz",
]
if (!hiperf_use_libunwind) {
common_deps -= [ ":support_libunwind" ]
}
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" ]
}
common_configs = [
":hiperf_inner_config",
"//third_party/bounds_checking_function:libsec_public_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/init/interfaces/innerkits:libbegetutil" ]
}
ohos_source_set("hiperf_platform_common") {
part_name = "hiperf"
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") {
part_name = "hiperf"
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") {
part_name = "hiperf"
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") {
part_name = "hiperf"
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"
use_exceptions = true
#protobuf
public_configs = common_configs
public_configs += [ ":protobuf_config" ]
public_deps = [
":proto_file_cpp",
"//third_party/bounds_checking_function:libsec_static",
]
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 = "developtools/profiler"
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"
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" ]
if (use_musl) {
static_link = true
}
subsystem_name = "developtools"
part_name = "hiperf"
}
ohos_source_set("hiperf_platform_host") {
part_name = "hiperf"
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") {
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_double_framework) {
deps = [ ":hiperf_target" ]
} else {
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",
":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/shuxinyia/developtools_hiperf_head.git
git@gitee.com:shuxinyia/developtools_hiperf_head.git
shuxinyia
developtools_hiperf_head
developtools_hiperf_head
master

搜索帮助