chromium/services/tracing/public/cpp/BUILD.gn

# Copyright 2018 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//build/buildflag_header.gni")
import("//build/config/cast.gni")
import("//build/config/compiler/compiler.gni")
import("//build/config/features.gni")
import("//build_overrides/build.gni")
import("//services/tracing/public/cpp/stack_sampling/loader_lock_sampling.gni")

buildflag_header("buildflags") {
  header = "buildflags.h"
  flags = [ "ENABLE_LOADER_LOCK_SAMPLING=$enable_loader_lock_sampling" ]
}

source_set("traced_process") {
  sources = [
    "traced_process.cc",
    "traced_process.h",
  ]

  public_deps = [ "//services/tracing/public/mojom" ]

  deps = [
    ":cpp",
    "//build:blink_buildflags",
  ]
}

# On IOS and NACL we don't support tracing so we only include the minimum needed
# to support a fake typed TRACE_EVENT macro. However this means we don't have
# any .cc files and thus on iOS and NaCl it needs to be a source_set and not a
# component. |tracing_lib_type| decides which version to build.
if (!is_nacl && use_blink) {
  tracing_lib_type = "component"
} else {
  tracing_lib_type = "source_set"
}

target(tracing_lib_type, "cpp") {
  sources = [
    "perfetto/flow_event_utils.cc",
    "perfetto/flow_event_utils.h",
    "perfetto/macros.h",
  ]

  defines = [ "IS_TRACING_CPP_IMPL" ]
  output_name = "tracing_cpp"

  configs += [ "//build/config/compiler:wexit_time_destructors" ]

  public_deps = [ "//base" ]

  deps = [ "//third_party/perfetto/include/perfetto/protozero" ]

  all_dependent_configs = []

  if (!is_nacl && use_blink) {
    sources += [
      "base_agent.cc",
      "base_agent.h",
      "perfetto/custom_event_recorder.cc",
      "perfetto/custom_event_recorder.h",
      "perfetto/dummy_producer.cc",
      "perfetto/dummy_producer.h",
      "perfetto/interning_index.h",
      "perfetto/metadata_data_source.cc",
      "perfetto/metadata_data_source.h",
      "perfetto/perfetto_config.cc",
      "perfetto/perfetto_config.h",
      "perfetto/perfetto_producer.cc",
      "perfetto/perfetto_producer.h",
      "perfetto/perfetto_session.cc",
      "perfetto/perfetto_session.h",
      "perfetto/perfetto_traced_process.cc",
      "perfetto/perfetto_traced_process.h",
      "perfetto/perfetto_tracing_backend.cc",
      "perfetto/perfetto_tracing_backend.h",
      "perfetto/producer_client.cc",
      "perfetto/producer_client.h",
      "perfetto/shared_memory.cc",
      "perfetto/shared_memory.h",
      "perfetto/system_producer.cc",
      "perfetto/system_producer.h",
      "perfetto/system_trace_writer.h",
      "perfetto/trace_event_data_source.cc",
      "perfetto/trace_event_data_source.h",
      "perfetto/trace_packet_tokenizer.cc",
      "perfetto/trace_packet_tokenizer.h",
      "perfetto/trace_string_lookup.cc",
      "perfetto/trace_string_lookup.h",
      "perfetto/traced_value_proto_writer.cc",
      "perfetto/traced_value_proto_writer.h",
      "perfetto/track_event_thread_local_event_sink.cc",
      "perfetto/track_event_thread_local_event_sink.h",
      "perfetto/track_name_recorder.cc",
      "perfetto/track_name_recorder.h",
      "stack_sampling/tracing_sampler_profiler.cc",
      "stack_sampling/tracing_sampler_profiler.h",
      "trace_event_agent.cc",
      "trace_event_agent.h",
      "trace_event_args_allowlist.cc",
      "trace_event_args_allowlist.h",
      "trace_startup.cc",
      "trace_startup.h",
      "trace_startup_config.cc",
      "trace_startup_config.h",
      "traced_process_impl.cc",
      "traced_process_impl.h",
      "tracing_features.cc",
      "tracing_features.h",
      "triggers_data_source.cc",
      "triggers_data_source.h",
    ]

    if (is_android) {
      sources += [
        "perfetto/java_heap_profiler/hprof_buffer_android.cc",
        "perfetto/java_heap_profiler/hprof_buffer_android.h",
        "perfetto/java_heap_profiler/hprof_data_type_android.h",
        "perfetto/java_heap_profiler/hprof_instances_android.cc",
        "perfetto/java_heap_profiler/hprof_instances_android.h",
        "perfetto/java_heap_profiler/hprof_parser_android.cc",
        "perfetto/java_heap_profiler/hprof_parser_android.h",
        "perfetto/java_heap_profiler/java_heap_profiler_android.cc",
        "perfetto/java_heap_profiler/java_heap_profiler_android.h",
      ]
    }

    if (is_win && enable_loader_lock_sampling) {
      sources += [
        "stack_sampling/loader_lock_sampler_win.cc",
        "stack_sampling/loader_lock_sampler_win.h",
        "stack_sampling/loader_lock_sampling_thread_win.cc",
        "stack_sampling/loader_lock_sampling_thread_win.h",
      ]
    }

    public_deps += [
      "//components/tracing:startup_tracing",
      "//mojo/public/cpp/bindings",
      "//services/tracing/public/mojom",
    ]

    deps += [
      ":buildflags",
      "//build:chromecast_buildflags",
      "//build:chromeos_buildflags",
      "//third_party/perfetto/protos/perfetto/trace/chrome:minimal_complete_lite",
    ]

   if (!(is_chromeos_ash && target_cpu == "arm64" && current_cpu == "arm")) {
     deps += [
       "//components/variations",
     ]
   }

    # Add the SystemProducer implementations.
    if (is_posix || is_fuchsia) {
      sources += [
        "perfetto/posix_system_producer.cc",
        "perfetto/posix_system_producer.h",
      ]

      deps += [ "//third_party/perfetto/include/perfetto/ext/ipc:ipc" ]

      if (is_fuchsia) {
        sources += [
          "perfetto/fuchsia_perfetto_producer_connector.cc",
          "perfetto/fuchsia_perfetto_producer_connector.h",
        ]

        deps += [
          "//third_party/fuchsia-sdk/sdk/pkg/component_incoming_cpp",
          "//third_party/fuchsia-sdk/sdk/pkg/fidl_cpp_base",
          "//third_party/fuchsia-sdk/sdk/pkg/sys_cpp",
        ]
        public_deps += [ "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.tracing.perfetto:fuchsia.tracing.perfetto_cpp" ]
      } else if (!is_android) {
        sources += [
          "system_tracing_service.cc",
          "system_tracing_service.h",
        ]
      }
    }

    if (is_chromeos_ash) {
      deps += [ "//chromeos/dbus/constants" ]
    }
  }  # !is_ios && !is_nacl
}