xref: /aosp_15_r20/external/pigweed/pw_metric/BUILD.gn (revision 61c4878ac05f98d0ceed94b57d316916de578985)
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 = [
63    "pw_metric_proto/metric_service.options",
64    "pw_metric_proto/metric_service.pwpb_options",
65  ]
66}
67
68# TODO(keir): Consider moving the nanopb service into the nanopb/ directory
69# instead of having it directly inside pw_metric/.
70
71# Common MetricWalker/MetricWriter used by RPC service.
72pw_source_set("metric_walker") {
73  visibility = [ ":*" ]
74  public = [ "pw_metric_private/metric_walker.h" ]
75  deps = [
76    ":pw_metric",
77    "$dir_pw_assert:assert",
78    "$dir_pw_containers",
79    "$dir_pw_status",
80    "$dir_pw_tokenizer",
81  ]
82}
83
84if (dir_pw_third_party_nanopb != "") {
85  pw_source_set("metric_service_nanopb") {
86    public_configs = [ ":default_config" ]
87    public_deps = [
88      ":metric_service_proto.nanopb_rpc",
89      ":pw_metric",
90      dir_pw_span,
91    ]
92    public = [ "public/pw_metric/metric_service_nanopb.h" ]
93    deps = [
94      ":metric_service_proto.nanopb_rpc",
95      ":metric_walker",
96      "$dir_pw_containers:vector",
97      dir_pw_tokenizer,
98    ]
99    sources = [ "metric_service_nanopb.cc" ]
100  }
101
102  pw_test("metric_service_nanopb_test") {
103    deps = [
104      ":global",
105      ":metric_service_nanopb",
106      "$dir_pw_rpc/nanopb:test_method_context",
107    ]
108    sources = [ "metric_service_nanopb_test.cc" ]
109  }
110}
111
112pw_source_set("metric_service_pwpb") {
113  public_configs = [ ":default_config" ]
114  public_deps = [
115    ":metric_service_proto.raw_rpc",
116    ":metric_walker",
117    ":pw_metric",
118    "$dir_pw_bytes",
119    "$dir_pw_containers",
120    "$dir_pw_rpc/raw:server_api",
121  ]
122  public = [ "public/pw_metric/metric_service_pwpb.h" ]
123  deps = [
124    ":metric_service_proto.pwpb",
125    ":metric_service_proto.raw_rpc",
126    "$dir_pw_assert",
127    "$dir_pw_containers:vector",
128    "$dir_pw_preprocessor",
129    "$dir_pw_span",
130    "$dir_pw_status",
131  ]
132  sources = [ "metric_service_pwpb.cc" ]
133}
134
135pw_test("metric_service_pwpb_test") {
136  deps = [
137    ":global",
138    ":metric_service_proto.pwpb",
139    ":metric_service_pwpb",
140    "$dir_pw_rpc/pwpb:test_method_context",
141    "$dir_pw_rpc/raw:test_method_context",
142  ]
143  sources = [ "metric_service_pwpb_test.cc" ]
144}
145
146################################################################################
147
148pw_test_group("tests") {
149  tests = [
150    ":metric_test",
151    ":global_test",
152    ":metric_service_pwpb_test",
153  ]
154  if (dir_pw_third_party_nanopb != "") {
155    tests += [ ":metric_service_nanopb_test" ]
156  }
157}
158
159pw_test("metric_test") {
160  sources = [ "metric_test.cc" ]
161  deps = [ ":pw_metric" ]
162}
163
164pw_test("global_test") {
165  sources = [ "global_test.cc" ]
166  deps = [ ":global" ]
167
168  # TODO: https://pwbug.dev/325509758 - Doesn't work on the Pico yet; has test
169  # failures.
170  if (pw_build_EXECUTABLE_TARGET_TYPE == "pico_executable") {
171    enable_if = false
172  }
173}
174
175pw_size_diff("metric_size_report") {
176  title = "Typical pw_metric use (no RPC service)"
177
178  binaries = [
179    {
180      target = "size_report:one_metric"
181      base = "size_report:base"
182      label = "1 metric and 1 group no dump or export"
183    },
184    {
185      target = "size_report:dump"
186      base = "size_report:base"
187      label = "(+) dump group and metrics to log"
188    },
189    {
190      target = "size_report:more_metrics"
191      base = "size_report:dump"
192      label = "(+) 1 group (+) 4 metrics"
193    },
194  ]
195}
196
197pw_doc_group("docs") {
198  sources = [ "docs.rst" ]
199  report_deps = [ ":metric_size_report" ]
200}
201