• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2020 The Pigweed Authors
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may not
4# use this file except in compliance with the License. You may obtain a copy of
5# the License at
6#
7#     https://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations under
13# the License.
14
15import("//build_overrides/pigweed.gni")
16
17import("$dir_pw_bloat/bloat.gni")
18import("$dir_pw_build/target_types.gni")
19import("$dir_pw_docgen/docs.gni")
20import("$dir_pw_protobuf_compiler/proto.gni")
21import("$dir_pw_third_party/nanopb/nanopb.gni")
22import("$dir_pw_unit_test/test.gni")
23
24config("default_config") {
25  include_dirs = [ "public" ]
26}
27
28pw_source_set("pw_metric") {
29  public_configs = [ ":default_config" ]
30  public = [ "public/pw_metric/metric.h" ]
31  sources = [ "metric.cc" ]
32  public_deps = [
33    "$dir_pw_tokenizer:base64",
34    dir_pw_assert,
35    dir_pw_containers,
36    dir_pw_log,
37    dir_pw_tokenizer,
38  ]
39  deps = [ dir_pw_span ]
40
41  # TODO: b/259746255 - Remove this when everything compiles with -Wconversion.
42  configs = [ "$dir_pw_build:conversion_warnings" ]
43}
44
45# This gives access to the "PW_METRIC_GLOBAL()" macros, for globally-registered
46# metric definitions.
47pw_source_set("global") {
48  public_configs = [ ":default_config" ]
49  public = [ "public/pw_metric/global.h" ]
50  sources = [ "global.cc" ]
51  public_deps = [
52    ":pw_metric",
53    dir_pw_tokenizer,
54  ]
55  deps = [ dir_pw_polyfill ]
56}
57
58################################################################################
59# Service
60pw_proto_library("metric_service_proto") {
61  sources = [ "pw_metric_proto/metric_service.proto" ]
62  inputs = [ "pw_metric_proto/metric_service.options" ]
63}
64
65# TODO(keir): Consider moving the nanopb service into the nanopb/ directory
66# instead of having it directly inside pw_metric/.
67
68# Common MetricWalker/MetricWriter used by RPC service.
69pw_source_set("metric_walker") {
70  visibility = [ ":*" ]
71  public = [ "pw_metric_private/metric_walker.h" ]
72  deps = [
73    ":pw_metric",
74    "$dir_pw_assert:assert",
75    "$dir_pw_containers",
76    "$dir_pw_status",
77    "$dir_pw_tokenizer",
78  ]
79}
80
81if (dir_pw_third_party_nanopb != "") {
82  pw_source_set("metric_service_nanopb") {
83    public_configs = [ ":default_config" ]
84    public_deps = [
85      ":metric_service_proto.nanopb_rpc",
86      ":pw_metric",
87      dir_pw_span,
88    ]
89    public = [ "public/pw_metric/metric_service_nanopb.h" ]
90    deps = [
91      ":metric_service_proto.nanopb_rpc",
92      ":metric_walker",
93      "$dir_pw_containers:vector",
94      dir_pw_tokenizer,
95    ]
96    sources = [ "metric_service_nanopb.cc" ]
97  }
98
99  pw_test("metric_service_nanopb_test") {
100    deps = [
101      ":global",
102      ":metric_service_nanopb",
103      "$dir_pw_rpc/nanopb:test_method_context",
104    ]
105    sources = [ "metric_service_nanopb_test.cc" ]
106  }
107}
108
109pw_source_set("metric_service_pwpb") {
110  public_configs = [ ":default_config" ]
111  public_deps = [
112    ":metric_service_proto.pwpb_rpc",
113    ":metric_service_proto.raw_rpc",
114    ":metric_walker",
115    ":pw_metric",
116    "$dir_pw_bytes",
117    "$dir_pw_containers",
118    "$dir_pw_rpc/raw:server_api",
119  ]
120  public = [ "public/pw_metric/metric_service_pwpb.h" ]
121  deps = [
122    ":metric_service_proto.pwpb",
123    ":metric_service_proto.raw_rpc",
124    "$dir_pw_assert",
125    "$dir_pw_containers:vector",
126    "$dir_pw_preprocessor",
127    "$dir_pw_span",
128    "$dir_pw_status",
129  ]
130  sources = [ "metric_service_pwpb.cc" ]
131}
132
133pw_test("metric_service_pwpb_test") {
134  deps = [
135    ":global",
136    ":metric_service_pwpb",
137    "$dir_pw_rpc/pwpb:test_method_context",
138    "$dir_pw_rpc/raw:test_method_context",
139  ]
140  sources = [ "metric_service_pwpb_test.cc" ]
141}
142
143################################################################################
144
145pw_test_group("tests") {
146  tests = [
147    ":metric_test",
148    ":global_test",
149    ":metric_service_pwpb_test",
150  ]
151  if (dir_pw_third_party_nanopb != "") {
152    tests += [ ":metric_service_nanopb_test" ]
153  }
154}
155
156pw_test("metric_test") {
157  sources = [ "metric_test.cc" ]
158  deps = [ ":pw_metric" ]
159}
160
161pw_test("global_test") {
162  sources = [ "global_test.cc" ]
163  deps = [ ":global" ]
164
165  # TODO: https://pwbug.dev/325509758 - Doesn't work on the Pico yet; has test
166  # failures.
167  if (pw_build_EXECUTABLE_TARGET_TYPE == "pico_executable") {
168    enable_if = false
169  }
170}
171
172pw_size_diff("metric_size_report") {
173  title = "Typical pw_metric use (no RPC service)"
174
175  binaries = [
176    {
177      target = "size_report:one_metric"
178      base = "size_report:base"
179      label = "1 metric and 1 group no dump or export"
180    },
181    {
182      target = "size_report:dump"
183      base = "size_report:base"
184      label = "(+) dump group and metrics to log"
185    },
186    {
187      target = "size_report:more_metrics"
188      base = "size_report:dump"
189      label = "(+) 1 group (+) 4 metrics"
190    },
191  ]
192}
193
194pw_doc_group("docs") {
195  sources = [ "docs.rst" ]
196  report_deps = [ ":metric_size_report" ]
197}
198