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