pw_allocator: Make metrics configurable

Previously, metrics in pw_allocator have been controlled by one big
switch: the pw_allocator_COLLECT_METRICS build argument. This approach
has proven to be too inflexible and coarse grained for downstream
consumers.

This CL instead uses preprocessor directives, including a definition for
PW_ALLOCATOR_METRICS_ENABLE. Downstream consumers can use this to define
metrics structs that selectively enable specific metrics and pass these
to TrackingAllocator.

The TrackingAllocator class now includes an internal::Metrics, templated
on the same metrics struct. This object guards each access to a metric
with a constexpr-if condition, allowing the relevant code to be omitted
when the metric is not enabled.

Bug: b/326509341

Change-Id: Ib541eede9563b00ceebbf1d45c43726ebf44569c
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/193621
Presubmit-Verified: CQ Bot Account <pigweed-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keir Mierle <keir@google.com>
Commit-Queue: Aaron Green <aarongreen@google.com>
13 files changed
tree: 62a1f93827e4003545c9386cb3e85d2334a874ef
  1. .allstar/
  2. .vscode/
  3. build_overrides/
  4. docker/
  5. docs/
  6. kudzu/
  7. pw_alignment/
  8. pw_allocator/
  9. pw_analog/
  10. pw_android_toolchain/
  11. pw_arduino_build/
  12. pw_assert/
  13. pw_assert_basic/
  14. pw_assert_log/
  15. pw_assert_tokenized/
  16. pw_assert_zephyr/
  17. pw_async/
  18. pw_async2/
  19. pw_async2_basic/
  20. pw_async_basic/
  21. pw_base64/
  22. pw_bloat/
  23. pw_blob_store/
  24. pw_bluetooth/
  25. pw_bluetooth_hci/
  26. pw_bluetooth_profiles/
  27. pw_bluetooth_sapphire/
  28. pw_boot/
  29. pw_boot_cortex_m/
  30. pw_build/
  31. pw_build_info/
  32. pw_build_mcuxpresso/
  33. pw_bytes/
  34. pw_channel/
  35. pw_checksum/
  36. pw_chre/
  37. pw_chrono/
  38. pw_chrono_embos/
  39. pw_chrono_freertos/
  40. pw_chrono_rp2040/
  41. pw_chrono_stl/
  42. pw_chrono_threadx/
  43. pw_chrono_zephyr/
  44. pw_cli/
  45. pw_compilation_testing/
  46. pw_config_loader/
  47. pw_console/
  48. pw_containers/
  49. pw_cpu_exception/
  50. pw_cpu_exception_cortex_m/
  51. pw_crypto/
  52. pw_digital_io/
  53. pw_digital_io_linux/
  54. pw_digital_io_mcuxpresso/
  55. pw_digital_io_rp2040/
  56. pw_docgen/
  57. pw_doctor/
  58. pw_emu/
  59. pw_env_setup/
  60. pw_env_setup_zephyr/
  61. pw_file/
  62. pw_format/
  63. pw_function/
  64. pw_fuzzer/
  65. pw_grpc/
  66. pw_hdlc/
  67. pw_hex_dump/
  68. pw_i2c/
  69. pw_i2c_linux/
  70. pw_i2c_mcuxpresso/
  71. pw_ide/
  72. pw_interrupt/
  73. pw_interrupt_cortex_m/
  74. pw_interrupt_xtensa/
  75. pw_interrupt_zephyr/
  76. pw_intrusive_ptr/
  77. pw_json/
  78. pw_kvs/
  79. pw_libc/
  80. pw_libcxx/
  81. pw_log/
  82. pw_log_android/
  83. pw_log_basic/
  84. pw_log_null/
  85. pw_log_rpc/
  86. pw_log_string/
  87. pw_log_tokenized/
  88. pw_log_zephyr/
  89. pw_malloc/
  90. pw_malloc_freelist/
  91. pw_malloc_freertos/
  92. pw_metric/
  93. pw_minimal_cpp_stdlib/
  94. pw_module/
  95. pw_multibuf/
  96. pw_multisink/
  97. pw_package/
  98. pw_perf_test/
  99. pw_persistent_ram/
  100. pw_polyfill/
  101. pw_preprocessor/
  102. pw_presubmit/
  103. pw_protobuf/
  104. pw_protobuf_compiler/
  105. pw_random/
  106. pw_result/
  107. pw_ring_buffer/
  108. pw_router/
  109. pw_rpc/
  110. pw_rpc_transport/
  111. pw_rust/
  112. pw_snapshot/
  113. pw_software_update/
  114. pw_span/
  115. pw_spi/
  116. pw_spi_mcuxpresso/
  117. pw_spi_rp2040/
  118. pw_status/
  119. pw_stm32cube_build/
  120. pw_stream/
  121. pw_stream_shmem_mcuxpresso/
  122. pw_stream_uart_linux/
  123. pw_stream_uart_mcuxpresso/
  124. pw_string/
  125. pw_symbolizer/
  126. pw_sync/
  127. pw_sync_baremetal/
  128. pw_sync_embos/
  129. pw_sync_freertos/
  130. pw_sync_stl/
  131. pw_sync_threadx/
  132. pw_sync_zephyr/
  133. pw_sys_io/
  134. pw_sys_io_ambiq_sdk/
  135. pw_sys_io_arduino/
  136. pw_sys_io_baremetal_lm3s6965evb/
  137. pw_sys_io_baremetal_stm32f429/
  138. pw_sys_io_emcraft_sf2/
  139. pw_sys_io_mcuxpresso/
  140. pw_sys_io_rp2040/
  141. pw_sys_io_stdio/
  142. pw_sys_io_stm32cube/
  143. pw_sys_io_zephyr/
  144. pw_system/
  145. pw_target_runner/
  146. pw_thread/
  147. pw_thread_embos/
  148. pw_thread_freertos/
  149. pw_thread_stl/
  150. pw_thread_threadx/
  151. pw_thread_zephyr/
  152. pw_tls_client/
  153. pw_tls_client_boringssl/
  154. pw_tls_client_mbedtls/
  155. pw_tokenizer/
  156. pw_toolchain/
  157. pw_toolchain_bazel/
  158. pw_trace/
  159. pw_trace_tokenized/
  160. pw_transfer/
  161. pw_unit_test/
  162. pw_unit_test_zephyr/
  163. pw_varint/
  164. pw_watch/
  165. pw_web/
  166. pw_work_queue/
  167. seed/
  168. targets/
  169. third_party/
  170. ts/
  171. zephyr/
  172. .bazelignore
  173. .bazelrc
  174. .black.toml
  175. .clang-format
  176. .clang-tidy
  177. .eslintrc.cjs
  178. .git-blame-ignore-revs
  179. .gitattributes
  180. .gitignore
  181. .gn
  182. .mypy.ini
  183. .prettierignore
  184. .prettierrc.cjs
  185. .pw_ide.yaml
  186. .pylintrc
  187. activate.bat
  188. Android.bp
  189. AUTHORS
  190. bootstrap.bat
  191. bootstrap.sh
  192. BUILD.bazel
  193. BUILD.gn
  194. BUILDCONFIG.gn
  195. CMakeLists.txt
  196. jest.config.ts
  197. Kconfig.zephyr
  198. LICENSE
  199. modules.gni
  200. OWNERS
  201. package-lock.json
  202. package.json
  203. pigweed.json
  204. PIGWEED_MODULES
  205. README.md
  206. rollup.config.js
  207. tsconfig.json
  208. WORKSPACE
README.md

Pigweed

Pigweed is an open source collection of embedded-targeted libraries–or as we like to call them, modules. These modules are building blocks and infrastructure that enable faster and more reliable development on small-footprint MMU-less 32-bit microcontrollers like the STMicroelectronics STM32L452 or the Nordic nRF52832.

For more information please see our website: https://pigweed.dev/.

Links