1# Copyright 2019 The Chromium Authors 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5import("//build/config/python.gni") 6import("//testing/test.gni") 7import("//third_party/protobuf/proto_library.gni") 8 9# Structured metrics is subcomponent of UMA that gathers and reports structured 10# events with several attached metrics. 11static_library("structured") { 12 sources = [ 13 "event_storage.cc", 14 "event_storage.h", 15 "key_data.cc", 16 "key_data.h", 17 "key_data_provider.cc", 18 "key_data_provider.h", 19 "key_data_provider_file.cc", 20 "key_data_provider_file.h", 21 "persistent_proto.cc", 22 "persistent_proto.h", 23 "reporting/structured_metrics_log_metrics.cc", 24 "reporting/structured_metrics_log_metrics.h", 25 "reporting/structured_metrics_reporting_service.cc", 26 "reporting/structured_metrics_reporting_service.h", 27 "structured_metrics_prefs.cc", 28 "structured_metrics_prefs.h", 29 "structured_metrics_provider.cc", 30 "structured_metrics_provider.h", 31 "structured_metrics_recorder.cc", 32 "structured_metrics_recorder.h", 33 "structured_metrics_scheduler.cc", 34 "structured_metrics_scheduler.h", 35 "structured_metrics_service.cc", 36 "structured_metrics_service.h", 37 ] 38 39 public_deps = [ 40 ":common", 41 ":events", 42 ":storage", 43 "//third_party/metrics_proto", 44 ] 45 46 deps = [ 47 ":structured_events", 48 ":structured_metrics_validator", 49 "//base", 50 "//components/metrics", 51 "//components/metrics/structured/mojom", 52 "//components/prefs", 53 "//crypto", 54 ] 55} 56 57if (is_chromeos_ash) { 58 static_library("external_metrics") { 59 sources = [ 60 "external_metrics.cc", 61 "external_metrics.h", 62 ] 63 deps = [ 64 ":common", 65 ":storage", 66 ":structured_events", 67 "//base", 68 ] 69 } 70} 71 72static_library("events") { 73 sources = [ 74 "delegating_events_processor.cc", 75 "delegating_events_processor.h", 76 "enums.h", 77 "event.cc", 78 "event.h", 79 "events_processor_interface.h", 80 "structured_metrics_client.cc", 81 "structured_metrics_client.h", 82 ] 83 deps = [ 84 "//base", 85 "//third_party/metrics_proto", 86 ] 87} 88 89proto_library("storage") { 90 # These protos are only used internally, so make them visible only to 91 # subdirectories. 92 visibility = [ "./*" ] 93 proto_in_dir = "//" 94 generate_python = false 95 sources = [ "storage.proto" ] 96 97 # This is required because metrics_proto/BUILD.gn sets proto_in_dir as ".", 98 # which means protos can't be referred to by absolute paths from within other 99 # protos. 100 import_dirs = [ "//third_party/metrics_proto" ] 101 proto_deps = [ "//third_party/metrics_proto" ] 102 link_deps = [ "//third_party/metrics_proto" ] 103} 104 105# Sources used by all static libraries in this BUILD file. 106source_set("common") { 107 sources = [ 108 "histogram_util.cc", 109 "histogram_util.h", 110 "recorder.cc", 111 "recorder.h", 112 ] 113 114 public_deps = [ 115 ":events", 116 ":structured_metrics_features", 117 ] 118 119 deps = [ 120 ":storage", 121 ":structured_metrics_validator", 122 "//base", 123 "//components/prefs", 124 "//third_party/metrics_proto", 125 ] 126} 127 128static_library("structured_metrics_features") { 129 sources = [ 130 "structured_metrics_features.cc", 131 "structured_metrics_features.h", 132 ] 133 134 public_deps = [ "//base" ] 135} 136 137action("gen_structured_events") { 138 script = "//tools/metrics/structured/gen_events.py" 139 140 # Re-generate the outputs if the codegen code changes: 141 inputs = [ 142 "//tools/metrics/structured/codegen.py", 143 "//tools/metrics/structured/gen_events.py", 144 "//tools/metrics/structured/model.py", 145 "//tools/metrics/structured/model_util.py", 146 "//tools/metrics/structured/templates_events.py", 147 ] 148 sources = [ "//tools/metrics/structured/sync/structured.xml" ] 149 150 outdir = "$target_gen_dir" 151 152 outputs = [ 153 outdir + "/structured_events.cc", 154 outdir + "/structured_events.h", 155 ] 156 157 args = [ 158 "--input", 159 rebase_path(sources[0], root_build_dir), 160 "--output", 161 rebase_path(outdir, root_build_dir), 162 ] 163} 164 165# TODO(b/309122738): Generate the events by platform. 166static_library("structured_events") { 167 sources = get_target_outputs(":gen_structured_events") 168 169 deps = [ 170 ":common", 171 ":gen_structured_events", 172 "//base", 173 ] 174} 175 176action("gen_structured_metrics_validator") { 177 script = "//tools/metrics/structured/gen_validator.py" 178 179 # Re-generate the outputs if the codegen code changes: 180 inputs = [ 181 "//tools/metrics/structured/codegen.py", 182 "//tools/metrics/structured/gen_validator.py", 183 "//tools/metrics/structured/model.py", 184 "//tools/metrics/structured/model_util.py", 185 "//tools/metrics/structured/templates_validator.py", 186 ] 187 sources = [ "//tools/metrics/structured/sync/structured.xml" ] 188 189 outdir = "$target_gen_dir" 190 191 outputs = [ 192 outdir + "/structured_metrics_validator.cc", 193 outdir + "/structured_metrics_validator.h", 194 ] 195 196 args = [ 197 "--input", 198 rebase_path(sources[0], root_build_dir), 199 "--output", 200 rebase_path(outdir, root_build_dir), 201 ] 202} 203 204static_library("structured_metrics_validator") { 205 sources = get_target_outputs(":gen_structured_metrics_validator") + [ 206 "event_validator.cc", 207 "event_validator.h", 208 "project_validator.cc", 209 "project_validator.h", 210 ] 211 212 deps = [ 213 ":events", 214 ":gen_structured_metrics_validator", 215 "//base", 216 ] 217} 218 219static_library("test_support") { 220 testonly = true 221 sources = [ 222 "test/test_event_storage.cc", 223 "test/test_event_storage.h", 224 "test/test_key_data_provider.cc", 225 "test/test_key_data_provider.h", 226 "test/test_structured_metrics_provider.cc", 227 "test/test_structured_metrics_provider.h", 228 ] 229 deps = [ 230 ":structured", 231 ":structured_metrics_validator", 232 "//base", 233 "//base/test:test_support", 234 "//components/metrics:metrics", 235 ] 236} 237 238source_set("unit_tests") { 239 testonly = true 240 sources = [ 241 "key_data_unittest.cc", 242 "persistent_proto_unittest.cc", 243 "structured_metrics_provider_unittest.cc", 244 "structured_metrics_recorder_unittest.cc", 245 "structured_metrics_service_unittest.cc", 246 ] 247 248 deps = [ 249 ":events", 250 ":storage", 251 ":structured", 252 ":structured_events", 253 ":structured_metrics_validator", 254 ":test_support", 255 "//base", 256 "//base/test:test_support", 257 "//components/metrics", 258 "//components/metrics:test_support", 259 "//components/prefs", 260 "//components/prefs:test_support", 261 "//testing/gtest", 262 ] 263 264 if (is_chromeos_ash) { 265 sources += [ "external_metrics_unittest.cc" ] 266 267 deps += [ ":external_metrics" ] 268 } 269} 270 271# Convenience testing target 272test("structured_metrics_unittests") { 273 deps = [ 274 ":unit_tests", 275 "//components/metrics/structured/mojom:unit_tests", 276 "//components/test:run_all_unittests", 277 ] 278} 279