# Copyright (C) 2019 The Android Open Source Project
#
# 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("../../../gn/fuzzer.gni")
import("../../../gn/perfetto.gni")
import("../../../gn/test.gni")

assert(enable_perfetto_traced_perf)

executable("traced_perf") {
  deps = [
    ":traced_perf_main",
    "../../../gn:default_deps",
  ]
  sources = [ "main.cc" ]
}

source_set("traced_perf_main") {
  deps = [
    ":proc_descriptors",
    ":producer",
    "../../../gn:default_deps",
    "../../../src/base",
    "../../../src/base:version",
    "../../../src/tracing/ipc/producer",
  ]
  sources = [
    "traced_perf.cc",
    "traced_perf.h",
  ]
}

source_set("producer") {
  public_deps = [
    ":common_types",
    ":regs_parsing",
    ":unwinding",
    "../../../include/perfetto/tracing/core",
    "../../../src/tracing/service",  # for metatrace
  ]
  deps = [
    ":proc_descriptors",
    "../../../gn:default_deps",
    "../../../protos/perfetto/common:cpp",
    "../../../protos/perfetto/common:zero",
    "../../../protos/perfetto/config:cpp",
    "../../../protos/perfetto/config/profiling:cpp",
    "../../../protos/perfetto/trace:zero",
    "../../../protos/perfetto/trace/profiling:zero",
    "../../../src/base",
    "../../../src/base:unix_socket",
    "../../../src/traced/probes/ftrace:tracefs",
    "../../../src/tracing/ipc/producer",
    "../common:callstack_trie",
    "../common:interner",
    "../common:interning_output",
    "../common:proc_cmdline",
    "../common:producer_support",
    "../common:profiler_guardrails",
  ]
  sources = [
    "event_config.cc",
    "event_config.h",
    "event_reader.cc",
    "event_reader.h",
    "perf_producer.cc",
    "perf_producer.h",
  ]
}

source_set("common_types") {
  public_deps = [ "../../../gn:libunwindstack" ]
  deps = [
    "../../../gn:default_deps",
    "../common:unwind_support",
  ]
  sources = [ "common_types.h" ]
}

source_set("unwinding") {
  public_deps = [
    "../../../gn:libunwindstack",
    "../../../src/tracing/service",  # for metatrace
  ]
  deps = [
    ":common_types",
    "../../../gn:default_deps",
    "../../../include/perfetto/ext/tracing/core",
    "../../../src/base",
    "../../../src/kallsyms",
    "../common:unwind_support",
  ]
  sources = [
    "frame_pointer_unwinder.cc",
    "frame_pointer_unwinder.h",
    "unwind_queue.h",
    "unwinding.cc",
    "unwinding.h",
  ]
}

source_set("regs_parsing") {
  public_deps = [ "../../../gn:libunwindstack" ]
  deps = [
    "../../../gn:bionic_kernel_uapi_headers",
    "../../../gn:default_deps",
    "../../../src/base",
  ]
  sources = [
    "regs_parsing.cc",
    "regs_parsing.h",
  ]
}

source_set("proc_descriptors") {
  deps = [
    "../../../gn:default_deps",
    "../../../src/base",
  ]
  sources = [
    "proc_descriptors.cc",
    "proc_descriptors.h",
  ]
}

source_set("producer_unittests") {
  testonly = true
  deps = [
    ":producer",
    ":unwinding",
    "../../../gn:default_deps",
    "../../../gn:gtest_and_gmock",
    "../../../protos/perfetto/common:cpp",
    "../../../protos/perfetto/config:cpp",
    "../../../protos/perfetto/config/profiling:cpp",
    "../../../protos/perfetto/trace:zero",
    "../../../src/protozero",
    "../../base",
  ]
  sources = [
    "event_config_unittest.cc",
    "frame_pointer_unwinder_unittest.cc",
    "perf_producer_unittest.cc",
    "unwind_queue_unittest.cc",
  ]
}
