# Copyright (c) 2022 The WebRTC project authors. All Rights Reserved.
#
# Use of this source code is governed by a BSD-style license
# that can be found in the LICENSE file in the root of the source
# tree. An additional intellectual property rights grant can be found
# in the file PATENTS.  All contributing project authors may
# be found in the AUTHORS file in the root of the source tree.

import("../../../webrtc.gni")
if (rtc_enable_protobuf) {
  import("//third_party/protobuf/proto_library.gni")
}

group("metrics") {
  deps = [
    ":global_metrics_logger_and_exporter",
    ":metric",
    ":metrics_accumulator",
    ":metrics_exporter",
    ":metrics_logger",
    ":stdout_metrics_exporter",
  ]
}

if (rtc_include_tests) {
  group("metrics_unittests") {
    testonly = true

    deps = [
      ":global_metrics_logger_and_exporter_test",
      ":metrics_accumulator_test",
      ":metrics_logger_test",
      ":print_result_proxy_metrics_exporter_test",
      ":stdout_metrics_exporter_test",
    ]

    if (rtc_enable_protobuf) {
      deps += [
        ":chrome_perf_dashboard_metrics_exporter_test",
        ":metrics_set_proto_file_exporter_test",
      ]
    }
  }
}

rtc_library("metric") {
  visibility = [ "*" ]
  sources = [
    "metric.cc",
    "metric.h",
  ]
  deps = [ "../../../api/units:timestamp" ]
}

rtc_library("metrics_logger") {
  visibility = [ "*" ]
  sources = [
    "metrics_logger.cc",
    "metrics_logger.h",
  ]
  deps = [
    ":metric",
    ":metrics_accumulator",
    "../..:array_view",
    "../../../rtc_base:macromagic",
    "../../../rtc_base/synchronization:mutex",
    "../../../system_wrappers",
    "../../numerics",
    "../../units:timestamp",
    "//third_party/abseil-cpp/absl/strings:string_view",
  ]
}

rtc_library("metrics_accumulator") {
  visibility = [ "*" ]
  sources = [
    "metrics_accumulator.cc",
    "metrics_accumulator.h",
  ]
  deps = [
    ":metric",
    "../../../rtc_base:macromagic",
    "../../../rtc_base/synchronization:mutex",
    "../../numerics",
    "../../units:timestamp",
    "//third_party/abseil-cpp/absl/strings:string_view",
  ]
}

rtc_library("metrics_exporter") {
  visibility = [ "*" ]
  sources = [ "metrics_exporter.h" ]
  deps = [
    ":metric",
    "../..:array_view",
  ]
}

rtc_library("stdout_metrics_exporter") {
  visibility = [ "*" ]
  sources = [
    "stdout_metrics_exporter.cc",
    "stdout_metrics_exporter.h",
  ]
  deps = [
    ":metric",
    ":metrics_exporter",
    "../..:array_view",
    "../../../rtc_base:stringutils",
  ]
}

rtc_library("chrome_perf_dashboard_metrics_exporter") {
  visibility = [ "*" ]
  testonly = true
  sources = [
    "chrome_perf_dashboard_metrics_exporter.cc",
    "chrome_perf_dashboard_metrics_exporter.h",
  ]
  deps = [
    ":metric",
    ":metrics_exporter",
    "../../../api:array_view",
    "../../../test:fileutils",
    "../../../test:perf_test",
    "//third_party/abseil-cpp/absl/memory",
    "//third_party/abseil-cpp/absl/strings:string_view",
  ]
}

if (rtc_enable_protobuf) {
  proto_library("metric_proto") {
    visibility = [ "*" ]
    sources = [ "proto/metric.proto" ]
    proto_out_dir = "api/test/metrics/proto"
    cc_generator_options = "lite"
  }
}

rtc_library("metrics_set_proto_file_exporter") {
  visibility = [ "*" ]
  testonly = true
  sources = [
    "metrics_set_proto_file_exporter.cc",
    "metrics_set_proto_file_exporter.h",
  ]
  deps = [
    ":metric",
    ":metrics_exporter",
    "../..:array_view",
    "../../../rtc_base:logging",
    "../../../test:fileutils",
    "//third_party/abseil-cpp/absl/strings:string_view",
  ]

  if (rtc_enable_protobuf) {
    deps += [ ":metric_proto" ]
  }
}

rtc_library("print_result_proxy_metrics_exporter") {
  visibility = [ "*" ]
  testonly = true
  sources = [
    "print_result_proxy_metrics_exporter.cc",
    "print_result_proxy_metrics_exporter.h",
  ]
  deps = [
    ":metric",
    ":metrics_exporter",
    "../..:array_view",
    "../../../test:perf_test",
  ]
}

rtc_library("global_metrics_logger_and_exporter") {
  visibility = [ "*" ]
  sources = [
    "global_metrics_logger_and_exporter.cc",
    "global_metrics_logger_and_exporter.h",
  ]
  deps = [
    ":metrics_exporter",
    ":metrics_logger",
    "../../../rtc_base:checks",
    "../../../system_wrappers",
  ]
}

if (rtc_include_tests) {
  rtc_library("metrics_logger_test") {
    testonly = true
    sources = [ "metrics_logger_test.cc" ]
    deps = [
      ":metric",
      ":metrics_logger",
      "../../../system_wrappers",
      "../../../test:test_support",
      "../../numerics",
      "../../units:timestamp",
    ]
  }

  rtc_library("metrics_accumulator_test") {
    testonly = true
    sources = [ "metrics_accumulator_test.cc" ]
    deps = [
      ":metric",
      ":metrics_accumulator",
      "../../../test:test_support",
      "../../units:timestamp",
    ]
  }

  rtc_library("stdout_metrics_exporter_test") {
    testonly = true
    sources = [ "stdout_metrics_exporter_test.cc" ]
    deps = [
      ":metric",
      ":stdout_metrics_exporter",
      "../../../test:test_support",
      "../../units:timestamp",
    ]
  }

  rtc_library("print_result_proxy_metrics_exporter_test") {
    testonly = true
    sources = [ "print_result_proxy_metrics_exporter_test.cc" ]
    deps = [
      ":metric",
      ":print_result_proxy_metrics_exporter",
      "../../../test:test_support",
      "../../units:timestamp",
    ]
  }

  rtc_library("global_metrics_logger_and_exporter_test") {
    testonly = true
    sources = [ "global_metrics_logger_and_exporter_test.cc" ]
    deps = [
      ":global_metrics_logger_and_exporter",
      ":metric",
      ":metrics_exporter",
      ":metrics_logger",
      "../../../system_wrappers",
      "../../../test:test_support",
    ]
  }

  if (rtc_enable_protobuf) {
    rtc_library("metrics_set_proto_file_exporter_test") {
      testonly = true
      sources = [ "metrics_set_proto_file_exporter_test.cc" ]
      deps = [
        ":metric",
        ":metric_proto",
        ":metrics_set_proto_file_exporter",
        "../../../rtc_base:protobuf_utils",
        "../../../test:fileutils",
        "../../../test:test_support",
        "../../units:timestamp",
      ]
    }

    rtc_library("chrome_perf_dashboard_metrics_exporter_test") {
      testonly = true
      sources = [ "chrome_perf_dashboard_metrics_exporter_test.cc" ]
      deps = [
        ":chrome_perf_dashboard_metrics_exporter",
        ":metric",
        "../../../api/units:timestamp",
        "../../../test:fileutils",
        "../../../test:test_support",
        "//third_party/catapult/tracing/tracing:histogram",
      ]
    }
  }
}
