• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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("./hiperf.gni")
16
17declare_args() {
18  hiperf_feature_mingw_uapi_dir =
19      "../../kernel/linux/patches/linux-5.10/prebuilts/usr/include"
20}
21
22function_disable_define = []
23
24config("hiperf_inner_config") {
25  visibility = [ ":*" ]
26  ldflags = []
27  cflags = code_check_flag
28  defines = function_disable_define
29
30  if (hiperf_code_analyze && is_ohos) {
31    cflags += code_analyze_flag
32    cflags -= [ "-Werror" ]
33  }
34
35  if (build_variant == "user") {
36    cflags += [ "-DIS_RELEASE_VERSION" ]
37  }
38
39  if (is_mingw) {
40    # lld: error: unable to find library -latomic
41    # lld: error: unable to find library -ldl
42    # lld: error: unable to find library -lrt
43    ldflags += [
44      "-Wl,--whole-archive",
45      "-lpthread",
46      "-Wl,--no-whole-archive",
47    ]
48  } else if (is_linux) {
49    ldflags += [
50      "-Wl,--whole-archive",
51      "-lpthread",
52      "-latomic",
53      "-ldl",
54      "-lrt",
55      "-Wl,--no-whole-archive",
56    ]
57  }
58
59  include_dirs = [ "${hiperf_path}/include" ]
60
61  # debug link
62  # ldflags += [ "-v"]
63
64  if (hiperf_debug) {
65    defines += [
66      "HIPERF_DEBUG",
67      "HIPERF_DEBUG_PRINTF",  # if u want to see printf in the log ?
68    ]
69  }
70
71  if (hiperf_check_time) {
72    defines += [ "HIPERF_DEBUG_TIME" ]
73  }
74
75  cflags += [
76    "-std=c++17",
77    "-fvisibility=hidden",
78    "-fdata-sections",
79    "-ffunction-sections",
80    "-Os",
81  ]
82  cflags_cc = [
83    "-fvisibility-inlines-hidden",
84    "-Os",
85  ]
86  defines += [ "is_mingw=${is_mingw}" ]
87  defines += [ "is_linux=${is_linux}" ]
88  defines += [ "is_ohos=${is_ohos}" ]
89  defines += [ "is_emulator=${is_emulator}" ]
90  defines += [ "is_double_framework=${is_double_framework}" ]
91  if (hiperf_target_host) {
92    defines += [ "target_cpu_${host_cpu}" ]
93  } else {
94    defines += [ "target_cpu_${target_cpu}" ]
95  }
96
97  if (is_mingw) {
98    cflags += [ "-includeMingW64Fix.h" ]
99    defines += [ "WIN32_LEAN_AND_MEAN" ]
100    defines += [ "__LITTLE_ENDIAN_BITFIELD" ]
101
102    include_dirs += [
103      "${hiperf_path}/include/nonlinux/",
104      hiperf_feature_mingw_uapi_dir,
105    ]
106  }
107
108  if (hiperf_test_coverage && is_ohos) {
109    cflags += [
110      "-fprofile-arcs",
111      "-ftest-coverage",
112    ]
113    ldflags += [ "--coverage" ]
114  }
115}
116
117sources_platform_common = [
118  "./src/perf_file_format.cpp",
119  "./src/command.cpp",
120  "./src/subcommand.cpp",
121  "./src/option.cpp",
122  "./src/utilities.cpp",
123  "./src/symbols_file.cpp",
124  "./src/virtual_runtime.cpp",
125  "./src/virtual_thread.cpp",
126  "./src/perf_file_reader.cpp",
127  "./src/perf_event_record.cpp",
128  "./src/dwarf_encoding.cpp",
129  "./src/subcommand_help.cpp",
130  "./src/subcommand_dump.cpp",
131  "./src/subcommand_report.cpp",
132  "./src/report.cpp",
133  "./src/report_json_file.cpp",
134  "./src/register.cpp",
135  "./src/unique_stack_table.cpp",
136]
137
138if (is_ohos) {
139  sources_platform_common += [ "./src/callstack.cpp" ]
140}
141
142if (hiperf_debug) {
143  sources_platform_common += [
144    "./src/debug_logger.cpp",
145    "./src/option_debug.cpp",
146  ]
147}
148
149sources_platform_linux = [
150  "./src/perf_events.cpp",
151  "./src/tracked_command.cpp",
152  "./src/ring_buffer.cpp",
153  "./src/perf_file_writer.cpp",
154  "./src/subcommand_stat.cpp",
155  "./src/subcommand_record.cpp",
156  "./src/subcommand_list.cpp",
157  "./src/spe_decoder.cpp",
158]
159
160common_deps = [
161  ":support_elf",
162  ":support_protobuf",
163  "//third_party/zlib:libz",
164]
165
166common_configs = [
167  ":hiperf_inner_config",
168  "../../commonlibrary/c_utils/base:utils_config",
169  "//third_party/googletest:gtest_config",
170]
171
172if (hiperf_target_static) {
173  common_deps -= [ ":support_protobuf" ]
174}
175
176config("hiperf_syspara_config") {
177  defines = [ "CONFIG_HAS_SYSPARA" ]
178}
179
180config("libunwinder_config") {
181  defines = [ "HAVE_LIBUNWINDER=1" ]
182}
183
184if (hiperf_use_libunwinder) {
185  common_configs += [ ":libunwinder_config" ]
186}
187
188if (is_ohos && hiperf_use_syspara) {
189  common_configs += [ ":hiperf_syspara_config" ]
190}
191
192ohos_source_set("hiperf_platform_common") {
193  part_name = "hiperf"
194  subsystem_name = "developtools"
195  use_exceptions = true
196  public_deps = common_deps
197  public_configs = common_configs
198  defines = []
199
200  if (is_ohos) {
201    external_deps = [
202      "c_utils:utils",
203      "faultloggerd:libunwinder_static",
204      "hilog:libhilog",
205      "init:libbegetutil",
206      "ipc:ipc_core",
207      "samgr:samgr_proxy",
208    ]
209    if (bundle_framework_enable) {
210      external_deps += [
211        "bundle_framework:appexecfwk_base",
212        "bundle_framework:appexecfwk_core",
213      ]
214      defines += [ "BUNDLE_FRAMEWORK_ENABLE" ]
215    }
216    if (ability_base_enable) {
217      external_deps += [ "ability_base:extractortool" ]
218      defines += [ "ENABLE_HAP_EXTRACTOR" ]
219    }
220  } else {
221    external_deps = [ "faultloggerd:unwinder_host" ]
222    defines += [ "CONFIG_NO_HILOG" ]
223  }
224  external_deps += [ "bounds_checking_function:libsec_shared" ]
225  sources = sources_platform_common
226}
227
228config("platform_linux_config") {
229  defines = [ "SUPPORT_PERF_EVENT" ]
230}
231
232ohos_source_set("hiperf_platform_linux") {
233  part_name = "hiperf"
234  subsystem_name = "developtools"
235  use_exceptions = true
236  public_deps = common_deps
237  public_configs = common_configs
238
239  if (is_ohos) {
240    external_deps = [
241      "faultloggerd:libunwinder_static",
242      "hilog:libhilog",
243      "init:libbegetutil",
244    ]
245  } else {
246    external_deps = [ "faultloggerd:unwinder_host" ]
247  }
248  external_deps += [ "bounds_checking_function:libsec_shared" ]
249  public_configs += [ ":platform_linux_config" ]
250  configs = [ "interfaces/innerkits/native:hiperf_client_config" ]
251
252  sources = sources_platform_linux
253}
254
255config("libunwind_config") {
256  defines = [ "HAVE_LIBUNWIND=1" ]
257}
258
259config("elf_config") {
260}
261ohos_source_set("support_elf") {
262  part_name = "hiperf"
263  subsystem_name = "developtools"
264  public_configs = common_configs
265  public_configs += [ ":elf_config" ]
266}
267
268config("protobuf_config") {
269  defines = [ "HAVE_PROTOBUF=1" ]
270  include_dirs = [
271    "//third_party/protobuf/src",
272    "//third_party/protobuf/src/google",
273    "//third_party/protobuf/src/google/protobuf",
274  ]
275}
276
277ohos_source_set("support_protobuf") {
278  part_name = "hiperf"
279  subsystem_name = "developtools"
280  use_exceptions = true
281
282  #protobuf
283  public_configs = common_configs
284  public_configs += [ ":protobuf_config" ]
285  public_deps = [ ":proto_file_cpp" ]
286
287  if (is_ohos) {
288    external_deps = [ "faultloggerd:libunwinder_static" ]
289  } else {
290    external_deps = [ "faultloggerd:unwinder_host" ]
291  }
292  external_deps += [ "bounds_checking_function:libsec_shared" ]
293  sources = [ "./src/report_protobuf_file.cpp" ]
294}
295
296#protobuf {
297proto_file_defines = [
298  # add your proto file here
299  "report_sample",
300]
301
302proto_base_dir = "proto"
303proto_out_dir = "$target_gen_dir" + "/" + proto_base_dir
304
305proto_file_codegen = []
306proto_file_sources = []
307
308foreach(proto_file, proto_file_defines) {
309  proto_file_codegen += [
310    "$proto_out_dir" + "/" + "$proto_file.pb.h",
311    "$proto_out_dir" + "/" + "$proto_file.pb.cc",
312  ]
313  proto_file_sources += [ "$proto_base_dir" + "/" + "$proto_file.proto" ]
314}
315
316# this is so bad , but someone config the protoc's subsystem_name
317# the better way is build system need provider host tools path or prebuild tools path
318protoc_subsystem_out_path = "thirdparty/protobuf"
319
320if (default_toolchain == current_toolchain) {
321  #if target build
322  host_out_path = "/" + get_label_info(host_toolchain, "name")
323} else {
324  #if host build (for some linke mingw)
325  host_out_path = "/../" + get_label_info(host_toolchain, "name")
326}
327host_protoc_path =
328    root_out_dir + host_out_path + "/" + protoc_subsystem_out_path + "/protoc"
329
330action("hiperf_host_build_proto") {
331  deps = [
332    "//third_party/protobuf:protoc(//build/toolchain/linux:clang_${host_cpu})",
333  ]
334  args = []
335  outputs = proto_file_codegen
336  sources = []
337  script = "proto/build_proto.sh"
338
339  args += [ rebase_path(host_protoc_path) ]
340  args += [
341    "--proto_path",
342    rebase_path(proto_base_dir),
343  ]
344  args += [
345    "--cpp_out",
346    rebase_path(proto_out_dir),
347  ]
348
349  foreach(proto_file_source, proto_file_sources) {
350    #tell gn to check which files as source time
351    sources += [ rebase_path(proto_file_source) ]
352    args += [ rebase_path(proto_file_source) ]
353  }
354}
355
356config("proto_file_cpp_config") {
357  include_dirs = [ proto_out_dir ]
358}
359
360ohos_source_set("proto_file_cpp") {
361  part_name = "hiperf"
362  subsystem_name = "developtools"
363  cflags = []
364
365  deps = [ ":hiperf_host_build_proto" ]
366  public_deps = [ "//third_party/protobuf:protobuf_lite_static" ]
367
368  sources = proto_file_codegen
369  public_configs = [ ":proto_file_cpp_config" ]
370}
371
372#protobuf }
373
374ohos_executable("hiperf") {
375  install_enable = true
376  sources = [ "./src/main.cpp" ]
377  deps = [
378    ":hiperf_etc",
379    ":hiperf_platform_common",
380    ":hiperf_platform_linux",
381  ]
382
383  if (hiperf_target_static) {
384    static_link = true
385  }
386
387  if (is_linux || is_mingw) {
388    # ld.lld: error: attempted static link of dynamic object hiviewdfx/hilog_native/libhilog.so
389    static_link = true
390  }
391
392  external_deps = [
393    "bounds_checking_function:libsec_shared",
394    "faultloggerd:libunwinder_static",
395    "hilog:libhilog",
396  ]
397
398  subsystem_name = "developtools"
399  part_name = "hiperf"
400}
401
402ohos_executable("hiperf_host") {
403  sources = [ "./src/main.cpp" ]
404  deps = [ ":hiperf_platform_common" ]
405
406  external_deps = [
407    "bounds_checking_function:libsec_shared",
408    "faultloggerd:unwinder_host",
409  ]
410
411  subsystem_name = "developtools"
412  part_name = "hiperf"
413}
414
415ohos_prebuilt_etc("hiperf.para") {
416  source = "etc/hiperf.para"
417  install_images = [
418    "system",
419    "updater",
420  ]
421  module_install_dir = "etc/param"
422  part_name = "hiperf"
423  subsystem_name = "developtools"
424}
425
426ohos_prebuilt_etc("hiperf.para.dac") {
427  source = "etc/hiperf.para.dac"
428  install_images = [
429    "system",
430    "updater",
431  ]
432  module_install_dir = "etc/param"
433  part_name = "hiperf"
434  subsystem_name = "developtools"
435}
436
437ohos_prebuilt_etc("hiperf.cfg") {
438  source = "etc/hiperf.cfg"
439  relative_install_dir = "init"
440  subsystem_name = "developtools"
441  part_name = "hiperf"
442}
443
444group("hiperf_etc") {
445  deps = [
446    ":hiperf.cfg",
447    ":hiperf.para",
448    ":hiperf.para.dac",
449  ]
450}
451
452ohos_source_set("hiperf_platform_host") {
453  part_name = "hiperf"
454  subsystem_name = "developtools"
455  sources = [ "./src/hiperf_libreport.cpp" ]
456  public_deps = [ ":hiperf_platform_common" ]
457  external_deps = [
458    "bounds_checking_function:libsec_shared",
459    "faultloggerd:unwinder_host",
460  ]
461}
462
463ohos_shared_library("hiperf_host_lib") {
464  public_deps = [ ":hiperf_platform_host" ]
465  output_name = "hiperf_report"
466
467  ldflags = [ "-static-libstdc++" ]
468
469  subsystem_name = "developtools"
470  part_name = "hiperf"
471}
472
473ohos_executable("hiperf_host_lib_demo") {
474  sources = [ "./src/hiperf_libreport_demo.cpp" ]
475  deps = [ ":hiperf_host_lib" ]
476  include_dirs = [ "${hiperf_path}/include" ]
477
478  subsystem_name = "developtools"
479  part_name = "hiperf"
480}
481
482ohos_copy("hiperf_host_python") {
483  sources = [ "./script" ]
484  outputs = [ target_out_dir + "/host/" ]
485
486  module_source_dir = target_out_dir + "/$target_name"
487  module_install_name = ""
488  subsystem_name = "developtools"
489  part_name = "hiperf"
490}
491
492ohos_source_set("hiperf_code_analyze") {
493  part_name = "hiperf"
494  deps = [
495    ":hiperf_platform_common",
496    ":hiperf_platform_linux",
497  ]
498}
499
500group("hiperf_target") {
501  if (hiperf_target_host) {
502    deps = [ ":hiperf(${host_toolchain})" ]
503  } else {
504    deps = [ ":hiperf" ]
505  }
506}
507
508group("hiperf_test_target") {
509  testonly = true
510  deps = [ "test:hiperf_test" ]
511}
512
513group("hiperf_target_all") {
514  if (!is_emulator) {
515    if (is_double_framework) {
516      deps = [ ":hiperf_target" ]
517    } else {
518      deps = []
519      if (!use_libfuzzer) {
520        deps += [
521          ":hiperf_host(//build/toolchain/linux:clang_${host_cpu})",  # host_linux
522          ":hiperf_host_lib(//build/toolchain/linux:clang_${host_cpu})",  # host_linux
523          ":hiperf_host_lib_demo(//build/toolchain/linux:clang_${host_cpu})",  # host_linux
524          ":hiperf_host_python",
525        ]
526        if (!is_tsan) {
527          deps += [
528            ":hiperf_host(//build/toolchain/mingw:mingw_x86_64)",  # host mingw
529            ":hiperf_host_lib(//build/toolchain/mingw:mingw_x86_64)",  # host_mingw
530          ]
531        }
532      }
533      deps += [
534        ":hiperf_target",
535        "interfaces/innerkits/native:hiperf_client",  # c++ api
536      ]
537      if (is_ohos) {
538        deps += [ "interfaces/kits/js/napi:hiperf_client_napi" ]  # js api
539      }
540    }
541  }
542}
543
544group("hiperf_demo") {
545  if (hiperf_target_host) {
546    deps = [ "demo/cpp:hiperf_demo(${host_toolchain})" ]
547  } else {
548    deps = [ "demo/cpp:hiperf_demo" ]
549  }
550}
551
552group("hiperf_example_cmd") {
553  if (hiperf_target_host) {
554    deps = [ "demo/cpp:hiperf_example_cmd(${host_toolchain})" ]
555  } else {
556    deps = [ "demo/cpp:hiperf_example_cmd" ]
557  }
558}
559
560group("hiperf_all") {
561  testonly = true
562  if (hiperf_code_analyze) {
563    deps = [ ":hiperf_code_analyze" ]
564  } else {
565    deps = [
566      ":hiperf_example_cmd",
567      ":hiperf_target_all",
568    ]
569    if (!is_double_framework) {
570      deps += [
571        ":hiperf_demo",
572        ":hiperf_test_target",
573      ]
574    }
575  }
576}
577